[Gnucash-changes] r13325 - gnucash/trunk/lib/libqof/qof - replacing
gnc-event with qofevent
Neil Williams
codehelp at cvs.gnucash.org
Mon Feb 20 14:54:04 EST 2006
Author: codehelp
Date: 2006-02-20 14:54:03 -0500 (Mon, 20 Feb 2006)
New Revision: 13325
Trac: http://svn.gnucash.org/trac/changeset/13325
Added:
gnucash/trunk/lib/libqof/qof/qofevent-p.h
gnucash/trunk/lib/libqof/qof/qofevent.c
gnucash/trunk/lib/libqof/qof/qofevent.h
Removed:
gnucash/trunk/lib/libqof/qof/gnc-event-p.h
gnucash/trunk/lib/libqof/qof/gnc-event.c
gnucash/trunk/lib/libqof/qof/gnc-event.h
Modified:
gnucash/trunk/lib/libqof/qof/Makefile.am
gnucash/trunk/lib/libqof/qof/deprecated.c
gnucash/trunk/lib/libqof/qof/deprecated.h
gnucash/trunk/lib/libqof/qof/qof.h
gnucash/trunk/lib/libqof/qof/qofbook.c
Log:
replacing gnc-event with qofevent
Modified: gnucash/trunk/lib/libqof/qof/Makefile.am
===================================================================
--- gnucash/trunk/lib/libqof/qof/Makefile.am 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/Makefile.am 2006-02-20 19:54:03 UTC (rev 13325)
@@ -12,7 +12,6 @@
gnc-date.c \
gnc-engine-util.c \
gnc-numeric.c \
- gnc-event.c \
guid.c \
kvp_frame.c \
kvp-util.c \
@@ -24,6 +23,7 @@
qofinstance.c \
qofquery.c \
qofbook.c \
+ qofevent.c \
qoflog.c \
qofobject.c \
qofquerycore.c \
@@ -38,7 +38,6 @@
gnc-date.h \
gnc-engine-util.h \
gnc-numeric.h \
- gnc-event.h \
guid.h \
kvp_frame.h \
kvp-util.h \
@@ -49,6 +48,7 @@
qofbackend-p.h \
qofclass.h \
qofchoice.h \
+ qofevent.h \
qofgobj.h \
qofid.h \
qofid-p.h \
@@ -68,7 +68,6 @@
qofla-dir.h
noinst_HEADERS = \
- gnc-event-p.h \
md5.h \
qofclass-p.h \
qofmath128.h \
@@ -76,6 +75,7 @@
qofquery-deserial.h \
qofquery-serialize.h \
qofbook-p.h \
+ qofevent-p.h \
qofobject-p.h \
qofquerycore-p.h \
qofsession-p.h
Modified: gnucash/trunk/lib/libqof/qof/deprecated.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/deprecated.c 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/deprecated.c 2006-02-20 19:54:03 UTC (rev 13325)
@@ -56,3 +56,25 @@
{
return qof_log_check(log_module, log_level);
}
+gint
+gnc_engine_register_event_handler (GNCEngineEventHandler handler,
+ gpointer user_data)
+{
+ return qof_event_register_old_handler(handler, user_data);
+}
+void gnc_engine_unregister_event_handler (gint handler_id)
+{
+ qof_event_unregister_handler(handler_id);
+}
+void gnc_engine_suspend_events (void)
+{
+ qof_event_suspend();
+}
+void gnc_engine_resume_events (void)
+{
+ qof_event_resume();
+}
+void gnc_engine_gen_event (QofEntity *entity, GNCEngineEventType event_type)
+{
+ qof_event_gen(entity, event_type);
+}
Modified: gnucash/trunk/lib/libqof/qof/deprecated.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/deprecated.h 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/deprecated.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -86,4 +86,44 @@
/** \deprecated use qof_report_clock_total */
void gnc_report_clock_total (int, QofLogModule, gncLogLevel, const char*, const char*, ...);
+/** \deprecated use QOF_EVENT_NONE instead. */
+#define GNC_EVENT_NONE QOF_EVENT_NONE
+/** \deprecated use QOF_EVENT_CREATE instead. */
+#define GNC_EVENT_CREATE QOF_EVENT_CREATE
+/** \deprecated use QOF_EVENT_MODIFY instead. */
+#define GNC_EVENT_MODIFY QOF_EVENT_MODIFY
+/** \deprecated use QOF_EVENT_DESTROY instead. */
+#define GNC_EVENT_DESTROY QOF_EVENT_DESTROY
+/** \deprecated use QOF_EVENT_ADD instead. */
+#define GNC_EVENT_ADD QOF_EVENT_ADD
+/** \deprecated use QOF_EVENT_REMOVE instead. */
+#define GNC_EVENT_REMOVE QOF_EVENT_REMOVE
+/** \deprecated */
+#define GNC_EVENT_ALL QOF_EVENT_ALL
+/** \deprecated use QofEventName instead. */
+#define GNCEngineEventType QofEventId
+/** \deprecated use QofEventHandler instead. */
+typedef void (*GNCEngineEventHandler) (GUID *entity, QofIdType type,
+ GNCEngineEventType event_type,
+ gpointer user_data);
+/** \deprecated For backwards compatibility - New code must not use
+this function. The function and the handler prototype will be remove
+from qofevent.c in libqoqf2 */
+gint qof_event_register_old_handler(GNCEngineEventHandler old_handler,
+ gpointer user_data);
+/** \deprecated use qof_event_register_handler instead. */
+gint gnc_engine_register_event_handler (GNCEngineEventHandler handler,
+ gpointer user_data);
+/** \deprecated use qof_event_unregister_handler instead. */
+void gnc_engine_unregister_event_handler (gint handler_id);
+/** \deprecated use qof_event_gen instead. */
+void gnc_engine_gen_event (QofEntity *entity, GNCEngineEventType event_type);
+/** \deprecated use qof_event_suspend instead. */
+void gnc_engine_suspend_events (void);
+/** \deprecated use qof_event_resume instead. */
+void gnc_engine_resume_events (void);
+/** \deprecated use qof_event_generate instead. */
+void gnc_engine_generate_event (const GUID *guid, QofIdType e_type,
+ GNCEngineEventType event_type);
+
#endif /* _DEPRECATED_H */
Deleted: gnucash/trunk/lib/libqof/qof/gnc-event-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event-p.h 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/gnc-event-p.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -1,37 +0,0 @@
-/********************************************************************
- * gnc-event-p.h -- private engine event handling interface *
- * Copyright 2000 Dave Peticolas <dave at krondo.com> *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
- ********************************************************************/
-
-#ifndef GNC_EVENT_P_H
-#define GNC_EVENT_P_H
-
-#include "gnc-event.h"
-#include "qofid.h"
-
-/** \deprecated */
-void gnc_engine_generate_event (const GUID *, QofIdType, GNCEngineEventType);
-
-/* generates an event even when events are suspended! */
-void gnc_engine_force_event (QofEntity *entity,
- GNCEngineEventType event_type);
-
-#endif
Deleted: gnucash/trunk/lib/libqof/qof/gnc-event.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event.c 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/gnc-event.c 2006-02-20 19:54:03 UTC (rev 13325)
@@ -1,255 +0,0 @@
-/********************************************************************
- * gnc-event.c -- engine event handling implementation *
- * Copyright 2000 Dave Peticolas <dave at krondo.com> *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
- ********************************************************************/
-
-#include "config.h"
-#include "qof.h"
-#include "gnc-event-p.h"
-
-/* Declarations ****************************************************/
-
-typedef struct
-{
- GNCEngineEventHandler handler;
- gpointer user_data;
-
- gint handler_id;
-} HandlerInfo;
-
-/* Static Variables ************************************************/
-static guint suspend_counter = 0;
-static gint next_handler_id = 1;
-static guint handler_run_level = 0;
-static guint pending_deletes = 0;
-static GList *handlers = NULL;
-
-/* This static indicates the debugging module that this .o belongs to. */
-static QofLogModule log_module = QOF_MOD_ENGINE;
-
-/* Implementations *************************************************/
-
-gint
-gnc_engine_register_event_handler (GNCEngineEventHandler handler,
- gpointer user_data)
-{
- HandlerInfo *hi;
- gint handler_id;
- GList *node;
-
- ENTER ("(handler=%p, data=%p)", handler, user_data);
- /* sanity check */
- if (!handler)
- {
- PERR ("no handler specified");
- return 0;
- }
-
- /* look for a free handler id */
- handler_id = next_handler_id;
- node = handlers;
-
- while (node)
- {
- hi = node->data;
-
- if (hi->handler_id == handler_id)
- {
- handler_id++;
- node = handlers;
- continue;
- }
-
- node = node->next;
- }
-
- /* Found one, add the handler */
- hi = g_new0 (HandlerInfo, 1);
-
- hi->handler = handler;
- hi->user_data = user_data;
- hi->handler_id = handler_id;
-
- handlers = g_list_prepend (handlers, hi);
-
- /* Update id for next registration */
- next_handler_id = handler_id + 1;
-
- LEAVE ("(handler=%p, data=%p) handler_id=%d", handler, user_data, handler_id);
- return handler_id;
-}
-
-void
-gnc_engine_unregister_event_handler (gint handler_id)
-{
- GList *node;
-
- ENTER ("(handler_id=%d)", handler_id);
- for (node = handlers; node; node = node->next)
- {
- HandlerInfo *hi = node->data;
-
- if (hi->handler_id != handler_id)
- continue;
-
- /* Normally, we could actually remove the handler's node from the
- list, but we may be unregistering the event handler as a result
- of a generated event, such as GNC_EVENT_DESTROY. In that case,
- we're in the middle of walking the GList and it is wrong to
- modify the list. So, instead, we just NULL the handler. */
-
- LEAVE ("(handler_id=%d) handler=%p data=%p", handler_id,
- hi->handler, hi->user_data);
-
- /* safety -- clear the handler in case we're running events now */
- hi->handler = NULL;
-
- if (handler_run_level == 0) {
- handlers = g_list_remove_link (handlers, node);
- g_list_free_1 (node);
- g_free (hi);
- } else {
- pending_deletes++;
- }
-
- return;
- }
-
- PERR ("no such handler: %d", handler_id);
-}
-
-void
-gnc_engine_suspend_events (void)
-{
- suspend_counter++;
-
- if (suspend_counter == 0)
- {
- PERR ("suspend counter overflow");
- }
-}
-
-void
-gnc_engine_resume_events (void)
-{
- if (suspend_counter == 0)
- {
- PERR ("suspend counter underflow");
- return;
- }
-
- suspend_counter--;
-}
-
-static void
-gnc_engine_generate_event_internal (QofEntity *entity,
- GNCEngineEventType event_type)
-{
- GList *node;
- GList *next_node = NULL;
-
- g_return_if_fail(entity);
-
- switch (event_type)
- {
- case GNC_EVENT_NONE:
- return;
-
- case GNC_EVENT_CREATE:
- case GNC_EVENT_MODIFY:
- case GNC_EVENT_DESTROY:
- case GNC_EVENT_ADD:
- case GNC_EVENT_REMOVE:
- break;
-
- default:
- PERR ("bad event type %d", event_type);
- return;
- }
-
- handler_run_level++;
- for (node = handlers; node; node = next_node)
- {
- HandlerInfo *hi = node->data;
-
- next_node = node->next;
- PINFO ("id=%d hi=%p han=%p", hi->handler_id, hi, hi->handler);
- if (hi->handler)
- hi->handler ((GUID *)&entity->guid, entity->e_type,
- event_type, hi->user_data);
- }
- handler_run_level--;
-
- /* If we're the outtermost event runner and we have pending deletes
- * then go delete the handlers now.
- */
- if (handler_run_level == 0 && pending_deletes)
- {
- for (node = handlers; node; node = next_node)
- {
- HandlerInfo *hi = node->data;
- next_node = node->next;
- if (hi->handler == NULL)
- {
- /* remove this node from the list, then free this node */
- handlers = g_list_remove_link (handlers, node);
- g_list_free_1 (node);
- g_free (hi);
- }
- }
- pending_deletes = 0;
- }
-}
-
-void
-gnc_engine_force_event (QofEntity *entity,
- GNCEngineEventType event_type)
-{
- if (!entity)
- return;
-
- gnc_engine_generate_event_internal (entity, event_type);
-}
-
-void
-gnc_engine_gen_event (QofEntity *entity, GNCEngineEventType event_type)
-{
- if (!entity)
- return;
-
- if (suspend_counter)
- return;
-
- gnc_engine_generate_event_internal (entity, event_type);
-}
-
-void
-gnc_engine_generate_event (const GUID *guid, QofIdType e_type,
- GNCEngineEventType event_type)
-{
- QofEntity ent;
- ent.guid = *guid;
- ent.e_type = e_type;
- if (suspend_counter) return;
- gnc_engine_generate_event_internal (&ent, event_type);
-}
-
-/* =========================== END OF FILE ======================= */
Deleted: gnucash/trunk/lib/libqof/qof/gnc-event.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event.h 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/gnc-event.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -1,119 +0,0 @@
-/********************************************************************
- * gnc-event.h -- engine event handling interface *
- * Copyright 2000 Dave Peticolas <dave at krondo.com> *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
- ********************************************************************/
-
-/** @addtogroup Event
-@{
-*/
-/** @file gnc-event.h
- @brief engine event handling interface
- (to be renamed qofevent.h in libqof2)
- @author Copyright 2000 Dave Peticolas <dave at krondo.com>
-*/
-
-#ifndef GNC_EVENT_H
-#define GNC_EVENT_H
-
-#include <glib.h>
-
-#include "guid.h"
-#include "qofid.h"
-
-typedef enum
-{
- GNC_EVENT_NONE = 0,
- GNC_EVENT_CREATE = 1 << 0,
- GNC_EVENT_MODIFY = 1 << 1,
- GNC_EVENT_DESTROY = 1 << 2,
- GNC_EVENT_ADD = 1 << 3,
- GNC_EVENT_REMOVE = 1 << 4,
- GNC_EVENT_ALL = 0xff
-} GNCEngineEventType;
-
-
-/** GNCEngineEventHandler
-
- * Handler invoked when an engine event occurs.
- *
- * @param entity: GUID of entity generating event
- * @param type: QofIdType of the entity generating the event
- * @param event_type: one of the single-bit GNCEngineEventTypes, not a combination
- * @param user_data: user_data supplied when handler was registered.
- */
-typedef void (*GNCEngineEventHandler) (GUID *entity, QofIdType type,
- GNCEngineEventType event_type,
- gpointer user_data);
-
-/** gnc_engine_register_event_handler
-
- * Register a handler for engine events.
- *
- * @param handler: handler to register
- * @param user_data: data provided when handler is invoked
- *
- * @return id identifying handler
- */
-gint gnc_engine_register_event_handler (GNCEngineEventHandler handler,
- gpointer user_data);
-
-/** gnc_engine_unregister_event_handler
-
- * Unregister an engine event handler.
- *
- * @param handler_id: the id of the handler to unregister
- */
-void gnc_engine_unregister_event_handler (gint handler_id);
-
-/** gnc_engine_generate_event
-
- * Invoke all registered event handlers using the given arguments.
- *
- * GNC_EVENT_CREATE events should be generated after the object
- * has been created and registered in the engine entity table.
- * GNC_EVENT_MODIFY events should be generated whenever any data
- * member or submember (i.e., splits) is changed.
- * GNC_EVENT_DESTROY events should be called before the object
- * has been destroyed or removed from the entity table.
- *
- * @param entity: the GUID of the entity generating the event
- * @param event_type: the type of event -- this should be one of the
- * single-bit GNCEngineEventType values, not a combination.
- */
-void gnc_engine_gen_event (QofEntity *entity,
- GNCEngineEventType event_type);
-/** gnc_engine_suspend_events
-
- * Suspend all engine events. This function may be
- * called multiple times. To resume event generation,
- * an equal number of calls to gnc_engine_resume_events
- * must be made.
- */
-void gnc_engine_suspend_events (void);
-
-/** gnc_engine_resume_events
-
- * Resume engine event generation.
- */
-void gnc_engine_resume_events (void);
-
-#endif
-/** @} */
Modified: gnucash/trunk/lib/libqof/qof/qof.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qof.h 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/qof.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -80,7 +80,6 @@
#include "qoflog.h"
#include "gnc-date.h"
#include "gnc-numeric.h"
-#include "gnc-event.h"
#include "gnc-engine-util.h"
#include "guid.h"
#include "kvp_frame.h"
@@ -91,6 +90,7 @@
#include "qofinstance-p.h"
#include "qofbook.h"
#include "qofclass.h"
+#include "qofevent.h"
#include "qofobject.h"
#include "qofquery.h"
#include "qofquerycore.h"
Modified: gnucash/trunk/lib/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook.c 2006-02-20 19:50:42 UTC (rev 13324)
+++ gnucash/trunk/lib/libqof/qof/qofbook.c 2006-02-20 19:54:03 UTC (rev 13325)
@@ -40,7 +40,7 @@
#include <glib.h>
#include "qof.h"
-#include "gnc-event-p.h"
+#include "qofevent-p.h"
#include "qofbackend-p.h"
#include "qofbook-p.h"
#include "qofid-p.h"
@@ -86,7 +86,7 @@
qof_book_init(book);
qof_object_book_begin (book);
- gnc_engine_gen_event (&book->inst.entity, GNC_EVENT_CREATE);
+ qof_event_gen (&book->inst.entity, QOF_EVENT_CREATE);
LEAVE ("book=%p", book);
return book;
}
@@ -108,7 +108,7 @@
ENTER ("book=%p", book);
book->shutting_down = TRUE;
- gnc_engine_force_event (&book->inst.entity, GNC_EVENT_DESTROY);
+ qof_event_force (&book->inst.entity, QOF_EVENT_DESTROY);
/* Call the list of finalizers, let them do their thing.
* Do this before tearing into the rest of the book.
Copied: gnucash/trunk/lib/libqof/qof/qofevent-p.h (from rev 13311, gnucash/trunk/lib/libqof/qof/gnc-event-p.h)
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event-p.h 2006-02-20 00:02:01 UTC (rev 13311)
+++ gnucash/trunk/lib/libqof/qof/qofevent-p.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -0,0 +1,51 @@
+/********************************************************************
+ * gnc-event-p.h -- private engine event handling interface *
+ * Copyright 2000 Dave Peticolas <dave at krondo.com> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+ ********************************************************************/
+
+#ifndef QOF_EVENT_P_H
+#define QOF_EVENT_P_H
+
+#include "qofevent.h"
+#include "qofid.h"
+
+/* for backwards compatibility - to be moved back to qofevent.c in libqof2 */
+typedef struct
+{
+ GNCEngineEventHandler old_handler;
+ QofEventHandler handler;
+ gpointer user_data;
+
+ gint handler_id;
+} HandlerInfo;
+
+/** \deprecated Prevents handlers locating the QofCollection or casting
+to the QofInstance and locating the book, editlevel or dirty flag.
+Use qof_event_gen instead.
+*/
+void
+qof_event_generate (const GUID *guid, QofIdType e_type,
+ QofEventId event_id);
+
+/* generates an event even when events are suspended! */
+void qof_event_force (QofEntity *entity, QofEventId event_id);
+
+#endif
Copied: gnucash/trunk/lib/libqof/qof/qofevent.c (from rev 13311, gnucash/trunk/lib/libqof/qof/gnc-event.c)
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event.c 2006-02-20 00:02:01 UTC (rev 13311)
+++ gnucash/trunk/lib/libqof/qof/qofevent.c 2006-02-20 19:54:03 UTC (rev 13325)
@@ -0,0 +1,303 @@
+/********************************************************************
+ * qofevent.c -- QOF event handling implementation *
+ * Copyright 2000 Dave Peticolas <dave at krondo.com> *
+ * Copyright 2006 Neil Williams <linux at codehelp.co.uk> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+ ********************************************************************/
+
+#include "config.h"
+#include "qof.h"
+#include "qofevent-p.h"
+
+/* Static Variables ************************************************/
+static guint suspend_counter = 0;
+static gint next_handler_id = 1;
+static guint handler_run_level = 0;
+static guint pending_deletes = 0;
+static GList *handlers = NULL;
+
+/* This static indicates the debugging module that this .o belongs to. */
+static QofLogModule log_module = QOF_MOD_ENGINE;
+
+/* Implementations *************************************************/
+
+static gint
+find_next_handler_id(void)
+{
+ HandlerInfo *hi;
+ gint handler_id;
+ GList *node;
+
+ /* look for a free handler id */
+ handler_id = next_handler_id;
+ node = handlers;
+
+ while (node)
+ {
+ hi = node->data;
+
+ if (hi->handler_id == handler_id)
+ {
+ handler_id++;
+ node = handlers;
+ continue;
+ }
+
+ node = node->next;
+ }
+ /* Update id for next registration */
+ next_handler_id = handler_id + 1;
+ return handler_id;
+}
+
+/* support deprecated code with a private function*/
+gint
+qof_event_register_old_handler (GNCEngineEventHandler handler, gpointer user_data)
+{
+ HandlerInfo *hi;
+ gint handler_id;
+
+ ENTER ("(handler=%p, data=%p)", handler, user_data);
+
+ /* sanity check */
+ if (!handler)
+ {
+ PERR ("no handler specified");
+ return 0;
+ }
+ PWARN (" DEPRECATED handler specified!");
+
+ handler_id = find_next_handler_id();
+ /* Found one, add the handler */
+ hi = g_new0 (HandlerInfo, 1);
+
+ hi->old_handler = handler;
+ hi->user_data = user_data;
+ hi->handler_id = handler_id;
+
+ handlers = g_list_prepend (handlers, hi);
+
+ LEAVE (" (handler=%p, data=%p) handler_id=%d", handler, user_data, handler_id);
+ return handler_id;
+
+}
+
+gint
+qof_event_register_handler (QofEventHandler handler, gpointer user_data)
+{
+ HandlerInfo *hi;
+ gint handler_id;
+
+ ENTER ("(handler=%p, data=%p)", handler, user_data);
+
+ /* sanity check */
+ if (!handler)
+ {
+ PERR ("no handler specified");
+ return 0;
+ }
+
+ /* look for a free handler id */
+ handler_id = find_next_handler_id();
+
+ /* Found one, add the handler */
+ hi = g_new0 (HandlerInfo, 1);
+
+ hi->handler = handler;
+ hi->user_data = user_data;
+ hi->handler_id = handler_id;
+
+ handlers = g_list_prepend (handlers, hi);
+
+ LEAVE ("(handler=%p, data=%p) handler_id=%d", handler, user_data, handler_id);
+ return handler_id;
+}
+
+void
+qof_event_unregister_handler (gint handler_id)
+{
+ GList *node;
+
+ ENTER ("(handler_id=%d)", handler_id);
+ for (node = handlers; node; node = node->next)
+ {
+ HandlerInfo *hi = node->data;
+
+ if (hi->handler_id != handler_id)
+ continue;
+
+ /* Normally, we could actually remove the handler's node from the
+ list, but we may be unregistering the event handler as a result
+ of a generated event, such as GNC_EVENT_DESTROY. In that case,
+ we're in the middle of walking the GList and it is wrong to
+ modify the list. So, instead, we just NULL the handler. */
+ if(hi->handler)
+ LEAVE ("(handler_id=%d) handler=%p data=%p", handler_id,
+ hi->handler, hi->user_data);
+ if(hi->old_handler)
+ LEAVE ("(handler_id=%d) handler=%p data=%p", handler_id,
+ hi->old_handler, hi->user_data);
+
+ /* safety -- clear the handler in case we're running events now */
+ hi->handler = NULL;
+ hi->old_handler = NULL;
+
+ if (handler_run_level == 0) {
+ handlers = g_list_remove_link (handlers, node);
+ g_list_free_1 (node);
+ g_free (hi);
+ } else {
+ pending_deletes++;
+ }
+
+ return;
+ }
+
+ PERR ("no such handler: %d", handler_id);
+}
+
+void
+qof_event_suspend (void)
+{
+ suspend_counter++;
+
+ if (suspend_counter == 0)
+ {
+ PERR ("suspend counter overflow");
+ }
+}
+
+void
+qof_event_resume (void)
+{
+ if (suspend_counter == 0)
+ {
+ PERR ("suspend counter underflow");
+ return;
+ }
+
+ suspend_counter--;
+}
+
+static void
+qof_event_generate_internal (QofEntity *entity, QofEventId event_id)
+{
+ GList *node;
+ GList *next_node = NULL;
+ gboolean use_old_handlers = FALSE;
+
+ g_return_if_fail(entity);
+
+ if(event_id <= QOF_DEFAULT_LIMIT)
+ {
+ use_old_handlers = TRUE;
+ }
+
+ switch (event_id)
+ {
+ case QOF_EVENT_NONE: {
+ /* if none, don't log, just return. */
+ return;
+ }
+ case QOF_EVENT_CREATE :
+ case QOF_EVENT_MODIFY :
+ case QOF_EVENT_DESTROY :
+ case QOF_EVENT_ADD :
+ case QOF_EVENT_REMOVE :
+ break;
+ }
+
+ handler_run_level++;
+ for (node = handlers; node; node = next_node)
+ {
+ HandlerInfo *hi = node->data;
+
+ next_node = node->next;
+ if ((hi->old_handler)&&(use_old_handlers))
+ {
+ PINFO (" deprecated: id=%d hi=%p han=%p", hi->handler_id, hi,
+ hi->old_handler);
+ hi->old_handler ((GUID *)&entity->guid, entity->e_type,
+ event_id, hi->user_data);
+ }
+ if (hi->handler)
+ {
+ PINFO ("id=%d hi=%p han=%p", hi->handler_id, hi, hi->handler);
+ hi->handler (entity, event_id, hi->user_data);
+ }
+ }
+ handler_run_level--;
+
+ /* If we're the outtermost event runner and we have pending deletes
+ * then go delete the handlers now.
+ */
+ if (handler_run_level == 0 && pending_deletes)
+ {
+ for (node = handlers; node; node = next_node)
+ {
+ HandlerInfo *hi = node->data;
+ next_node = node->next;
+ if ((hi->handler == NULL)&&(hi->old_handler == NULL))
+ {
+ /* remove this node from the list, then free this node */
+ handlers = g_list_remove_link (handlers, node);
+ g_list_free_1 (node);
+ g_free (hi);
+ }
+ }
+ pending_deletes = 0;
+ }
+}
+
+void
+qof_event_force (QofEntity *entity, QofEventId event_id)
+{
+ if (!entity)
+ return;
+
+ qof_event_generate_internal (entity, event_id);
+}
+
+void
+qof_event_gen (QofEntity *entity, QofEventId event_id)
+{
+ if (!entity)
+ return;
+
+ if (suspend_counter)
+ return;
+
+ qof_event_generate_internal (entity, event_id);
+}
+
+/* deprecated */
+void
+qof_event_generate (const GUID *guid, QofIdType e_type,
+ QofEventId event_id)
+{
+ QofEntity ent;
+ ent.guid = *guid;
+ ent.e_type = e_type;
+ if (suspend_counter) return;
+ /* caution: this is an incomplete entity! */
+ qof_event_generate_internal (&ent, event_id);
+}
+
+/* =========================== END OF FILE ======================= */
Copied: gnucash/trunk/lib/libqof/qof/qofevent.h (from rev 13311, gnucash/trunk/lib/libqof/qof/gnc-event.h)
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-event.h 2006-02-20 00:02:01 UTC (rev 13311)
+++ gnucash/trunk/lib/libqof/qof/qofevent.h 2006-02-20 19:54:03 UTC (rev 13325)
@@ -0,0 +1,117 @@
+/********************************************************************
+ * qofevent.h -- QOF event handling interface *
+ * Copyright 2000 Dave Peticolas <dave at krondo.com> *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License as *
+ * published by the Free Software Foundation; either version 2 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact: *
+ * *
+ * Free Software Foundation Voice: +1-617-542-5942 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+ * *
+ ********************************************************************/
+
+/** @addtogroup Event
+@{
+*/
+/** @file qofevent.h
+ @brief QOF event handling interface
+ @author Copyright 2000 Dave Peticolas <dave at krondo.com>
+ @author Copyright 2006 Neil Williams <linux at codehelp.co.uk>
+*/
+
+#ifndef QOF_EVENT_H
+#define QOF_EVENT_H
+
+#include <glib.h>
+#include "qof.h"
+
+/** Define the type of events allowed. */
+typedef gint QofEventId;
+
+/** \brief Default events for backwards compatibility.
+
+These defaults merely replicate previous behaviour,
+any process can define their own events.
+*/
+#define QOF_EVENT_NONE 0
+#define QOF_EVENT_CREATE 1
+#define QOF_EVENT_MODIFY 2
+#define QOF_EVENT_DESTROY 3
+#define QOF_EVENT_ADD 4
+#define QOF_EVENT_REMOVE 5
+#define QOF_EVENT_ALL 6 /**< unused */
+
+/** Allow scope for more defaults in future. Additional
+event identifiers must be larger than this. */
+#define QOF_DEFAULT_LIMIT 10
+
+/** \brief Handler invoked when an engine event occurs.
+ *
+ * @param ent: Entity generating the event
+ * @param event_type: The name of the event, including additional names and
+ the older defaults.
+ * @param user_data: user_data supplied when handler was registered.
+ */
+typedef void (*QofEventHandler) (QofEntity *ent, QofEventId event_type,
+ gpointer user_data);
+
+/** \brief Register a handler for engine events.
+ *
+ * @param handler: handler to register
+ * @param user_data: data provided when handler is invoked
+ *
+ * @return id identifying handler
+ */
+gint qof_event_register_handler (QofEventHandler handler, gpointer user_data);
+
+/** \brief Unregister an engine event handler.
+ *
+ * @param handler_id: the id of the handler to unregister
+ */
+void qof_event_unregister_handler (gint handler_id);
+
+/** \brief Invoke all registered event handlers using the given arguments.
+
+ Certain default events are used by QOF:
+
+-QOF_EVENT_DEFAULT_CREATE events should be generated after the object
+ has been created and registered in the engine entity table.
+-QOF_EVENT_DEFAULT_MODIFY events should be generated whenever any data
+ member or submember (i.e., splits) is changed.
+-QOF_EVENT_DEFAULT_DESTROY events should be called before the object
+ has been destroyed or removed from the entity table.
+
+ Any other events are entirely the concern of the application.
+
+ \note QofEventHandler routines do \b NOT support generating
+ events from a GUID and QofIdType - you must specify a genuine QofEntity.
+
+ @param entity: the entity generating the event
+ @param event_type: the name of the event.
+*/
+void qof_event_gen (QofEntity *entity, QofEventId event_type);
+
+/** \brief Suspend all engine events.
+ *
+ * This function may be called multiple times. To resume event generation,
+ * an equal number of calls to gnc_engine_resume_events
+ * must be made.
+ */
+void qof_event_suspend (void);
+
+/** Resume engine event generation. */
+void qof_event_resume (void);
+
+#endif
+/** @} */
More information about the gnucash-changes
mailing list