QOF  0.8.7
Files | Macros | Typedefs | Functions
Event: QOF event handlers.

Files

file  qofevent.h
 QOF event handling interface.
 

Macros

#define QOF_MAKE_EVENT(x)    (1<<(x))
 Allow application-specific events to be created. More...
 
#define QOF_EVENT_BASE   8
 

Typedefs

typedef gint QofEventId
 
typedef void(* QofEventHandler) (QofEntity *ent, QofEventId event_type, gpointer handler_data, gpointer event_data)
 Handler invoked when an event is generated. More...
 

Functions

gint qof_event_register_handler (QofEventHandler handler, gpointer handler_data)
 Register a handler for events. More...
 
void qof_event_unregister_handler (gint handler_id)
 Unregister an event handler. More...
 
void qof_event_gen (QofEntity *entity, QofEventId event_type, gpointer event_data)
 Invoke all registered event handlers using the given arguments. More...
 
void qof_event_suspend (void)
 Suspend all engine events. More...
 
void qof_event_resume (void)
 

Default events for backwards compatibility.

These defaults merely replicate previous behaviour, any process can define their own events.

Note
events 6, and 7 are "undefined" as of v0.6.3 for future libqof1 or libqof2 usage.
#define QOF_EVENT_NONE   (0)
 
#define QOF_EVENT_CREATE   QOF_MAKE_EVENT(0)
 
#define QOF_EVENT_MODIFY   QOF_MAKE_EVENT(1)
 an entity is about to be modified. More...
 
#define QOF_EVENT_DESTROY   QOF_MAKE_EVENT(2)
 
#define QOF_EVENT_ADD   QOF_MAKE_EVENT(3)
 
#define QOF_EVENT_REMOVE   QOF_MAKE_EVENT(4)
 
#define QOF_EVENT_COMMIT   QOF_MAKE_EVENT(5)
 an entity has been modified. More...
 
#define QOF_EVENT__LAST   QOF_MAKE_EVENT(QOF_EVENT_BASE-1)
 
#define QOF_EVENT_ALL   (0xff)
 

Detailed Description

Macro Definition Documentation

#define QOF_EVENT_BASE   8

Allow scope for more defaults in future. Additional event identifiers must be based on this when using QOF_MAKE_EVENT().

Definition at line 57 of file qofevent.h.

#define QOF_EVENT_COMMIT   QOF_MAKE_EVENT(5)

an entity has been modified.

Added for QofUndo so that the altered state of an entity can be stored to allow the change to be undone and then redone.

Since
0.7.0

Definition at line 92 of file qofevent.h.

#define QOF_EVENT_CREATE   QOF_MAKE_EVENT(0)

an entity has been created.

Definition at line 71 of file qofevent.h.

#define QOF_EVENT_DESTROY   QOF_MAKE_EVENT(2)

an entity is about to be destroyed.

Definition at line 81 of file qofevent.h.

#define QOF_EVENT_MODIFY   QOF_MAKE_EVENT(1)

an entity is about to be modified.

In addition to previous usage, can used for ::QofUndo so that the original state of an entity can be stored before modification to allow the change to be undone and then redone.

Definition at line 79 of file qofevent.h.

#define QOF_EVENT_NONE   (0)

init value - invalid.

Definition at line 69 of file qofevent.h.

#define QOF_MAKE_EVENT (   x)    (1<<(x))

Allow application-specific events to be created.

Used together with QOF_EVENT_BASE to simplify creation of application events without interfering with any new events added within QOF.

#define APP_EVENT_A QOF_MAKE_EVENT(QOF_EVENT_BASE+0)
#define APP_EVENT_B QOF_MAKE_EVENT(QOF_EVENT_BASE+1)

Definition at line 53 of file qofevent.h.

Typedef Documentation

typedef void(* QofEventHandler) (QofEntity *ent, QofEventId event_type, gpointer handler_data, gpointer event_data)

Handler invoked when an event is generated.

Parameters
entEntity generating the event
event_typeThe id of the event, including additional identifiers and the older defaults.
handler_datadata supplied when handler was registered.
event_datadata to be supplied when handler is invoked.

Definition at line 104 of file qofevent.h.

typedef gint QofEventId

Define the type of events allowed.

Definition at line 40 of file qofevent.h.

Function Documentation

void qof_event_gen ( QofEntity entity,
QofEventId  event_type,
gpointer  event_data 
)

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 book.
  • 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 book.

    Any other events are entirely the concern of the application.

    Note
    QofEventHandler routines do NOT support generating events from a GUID and QofIdType - you must specify a genuine QofEntity.
    Parameters
    entitythe entity generating the event
    event_typethe name of the event.
    event_dataData to be passed to the event handler just for this one event. Can be NULL.

Definition at line 235 of file qofevent.c.

236 {
237  if (!entity)
238  return;
239 
240  if (suspend_counter)
241  return;
242 
243  qof_event_generate_internal (entity, event_id, event_data);
244 }
gint qof_event_register_handler ( QofEventHandler  handler,
gpointer  handler_data 
)

Register a handler for events.

Parameters
handlerhandler to register
handler_datadata provided when handler is invoked
Returns
id identifying handler

Definition at line 72 of file qofevent.c.

73 {
74  HandlerInfo *hi;
75  gint handler_id;
76 
77  ENTER ("(handler=%p, data=%p)", handler, user_data);
78 
79  /* sanity check */
80  if (!handler)
81  {
82  PERR ("no handler specified");
83  return 0;
84  }
85 
86  /* look for a free handler id */
87  handler_id = find_next_handler_id ();
88 
89  /* Found one, add the handler */
90  hi = g_new0 (HandlerInfo, 1);
91 
92  hi->handler = handler;
93  hi->user_data = user_data;
94  hi->handler_id = handler_id;
95 
96  handlers = g_list_prepend (handlers, hi);
97  LEAVE ("(handler=%p, data=%p) handler_id=%d", handler, user_data,
98  handler_id);
99  return handler_id;
100 }
#define PERR(format, args...)
Definition: qoflog.h:183
#define LEAVE(format, args...)
Definition: qoflog.h:227
#define ENTER(format, args...)
Definition: qoflog.h:217
void qof_event_resume ( void  )

Resume engine event generation.

Definition at line 156 of file qofevent.c.

157 {
158  if (suspend_counter == 0)
159  {
160  PERR ("suspend counter underflow");
161  return;
162  }
163 
164  suspend_counter--;
165 }
#define PERR(format, args...)
Definition: qoflog.h:183
void qof_event_suspend ( void  )

Suspend all engine events.

This function may be called multiple times. To resume event generation, an equal number of calls to qof_event_resume must be made.

Definition at line 145 of file qofevent.c.

146 {
147  suspend_counter++;
148 
149  if (suspend_counter == 0)
150  {
151  PERR ("suspend counter overflow");
152  }
153 }
#define PERR(format, args...)
Definition: qoflog.h:183
void qof_event_unregister_handler ( gint  handler_id)

Unregister an event handler.

Parameters
handler_idthe id of the handler to unregister

Definition at line 103 of file qofevent.c.

104 {
105  GList *node;
106 
107  ENTER ("(handler_id=%d)", handler_id);
108  for (node = handlers; node; node = node->next)
109  {
110  HandlerInfo *hi = node->data;
111 
112  if (hi->handler_id != handler_id)
113  continue;
114 
115  /* Normally, we could actually remove the handler's node from the
116  list, but we may be unregistering the event handler as a result
117  of a generated event, such as GNC_EVENT_DESTROY. In that case,
118  we're in the middle of walking the GList and it is wrong to
119  modify the list. So, instead, we just NULL the handler. */
120  if (hi->handler)
121  LEAVE ("(handler_id=%d) handler=%p data=%p", handler_id,
122  hi->handler, hi->user_data);
123 
124  /* safety -- clear the handler in case we're running events now */
125  hi->handler = NULL;
126 
127  if (handler_run_level == 0)
128  {
129  handlers = g_list_remove_link (handlers, node);
130  g_list_free_1 (node);
131  g_free (hi);
132  }
133  else
134  {
135  pending_deletes++;
136  }
137 
138  return;
139  }
140 
141  PERR ("no such handler: %d", handler_id);
142 }
#define PERR(format, args...)
Definition: qoflog.h:183
#define LEAVE(format, args...)
Definition: qoflog.h:227
#define ENTER(format, args...)
Definition: qoflog.h:217