29 #include "qofevent-p.h" 32 static guint suspend_counter = 0;
33 static gint next_handler_id = 1;
34 static guint handler_run_level = 0;
35 static guint pending_deletes = 0;
36 static GList *handlers = NULL;
39 static QofLogModule log_module = QOF_MOD_ENGINE;
44 find_next_handler_id(
void)
51 handler_id = next_handler_id;
58 if (hi->handler_id == handler_id)
68 next_handler_id = handler_id + 1;
78 ENTER (
"(handler=%p, data=%p)", handler, user_data);
83 PERR (
"no handler specified");
88 handler_id = find_next_handler_id();
93 hi->handler = handler;
94 hi->user_data = user_data;
95 hi->handler_id = handler_id;
97 handlers = g_list_prepend (handlers, hi);
98 LEAVE (
"(handler=%p, data=%p) handler_id=%d", handler, user_data, handler_id);
107 ENTER (
"(handler_id=%d)", handler_id);
108 for (node = handlers; node; node = node->next)
112 if (hi->handler_id != handler_id)
121 LEAVE (
"(handler_id=%d) handler=%p data=%p", handler_id,
122 hi->handler, hi->user_data);
127 if (handler_run_level == 0)
129 handlers = g_list_remove_link (handlers, node);
130 g_list_free_1 (node);
141 PERR (
"no such handler: %d", handler_id);
149 if (suspend_counter == 0)
151 PERR (
"suspend counter overflow");
158 if (suspend_counter == 0)
160 PERR (
"suspend counter underflow");
172 GList *next_node = NULL;
174 g_return_if_fail(entity);
186 for (node = handlers; node; node = next_node)
190 next_node = node->next;
193 PINFO(
"id=%d hi=%p han=%p data=%p", hi->handler_id, hi,
194 hi->handler, event_data);
195 hi->handler (entity, event_id, hi->user_data, event_data);
203 if (handler_run_level == 0 && pending_deletes)
205 for (node = handlers; node; node = next_node)
208 next_node = node->next;
209 if (hi->handler == NULL)
212 handlers = g_list_remove_link (handlers, node);
213 g_list_free_1 (node);
227 qof_event_generate_internal (entity, event_id, event_data);
239 qof_event_generate_internal (entity, event_id, event_data);
void(* QofEventHandler)(QofInstance *ent, QofEventId event_type, gpointer handler_data, gpointer event_data)
Handler invoked when an event is generated.
#define PINFO(format, args...)
Print an informational note.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
gint QofEventId
Define the type of events allowed.
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
#define QOF_EVENT_NONE
Default events for backwards compatibility.
void qof_event_suspend(void)
Suspend all engine events.
void qof_event_resume(void)
Resume engine event generation.
#define LEAVE(format, args...)
Print a function exit debugging message.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.