poser
A C framework for POsix SERvices
|
A simple event class. More...
#include <poser/core/event.h>
Public Member Functions | |
PSC_Event * | PSC_Event_create (void *sender) |
PSC_Event constructor. | |
void | PSC_Event_register (PSC_Event *self, void *receiver, PSC_EventHandler handler, int id) |
Register an event handler. | |
void | PSC_Event_unregister (PSC_Event *self, void *receiver, PSC_EventHandler handler, int id) |
Unregister an event handler. | |
void | PSC_Event_raise (PSC_Event *self, int id, void *args) |
Raise an event. | |
void | PSC_Event_destroy (PSC_Event *self) |
PSC_Event destructor. | |
A simple event class.
Events can be raised and subscribed to. The class emitting an event should own it and provide an accessor method for consumers to subscribe to it.
When an event is raised, all subscribers are called directly. No mechanism to cross threads is offered, so always use functions/objects wired by events on the same thread.
PSC_Event * PSC_Event_create | ( | void * | sender | ) |
PSC_Event constructor.
sender | the object owning the event, or NULL for static classes |
void PSC_Event_raise | ( | PSC_Event * | self, |
int | id, | ||
void * | args | ||
) |
Raise an event.
Called by the event owner to notify all subscribers that the event occured. Only handlers with the same identifier will be called.
self | the PSC_Event |
id | optional identifier to be matched, use 0 if not applicable |
args | optional event args to pass to the handler(s) |
void PSC_Event_register | ( | PSC_Event * | self, |
void * | receiver, | ||
PSC_EventHandler | handler, | ||
int | id | ||
) |
Register an event handler.
self | the PSC_Event |
receiver | the object that should receive the event |
handler | the handler to be called |
id | optional identifier to be matched, use 0 if not applicable |
void PSC_Event_unregister | ( | PSC_Event * | self, |
void * | receiver, | ||
PSC_EventHandler | handler, | ||
int | id | ||
) |
Unregister an event handler.
When this is called with the exact same parameters as PSC_Event_register(), it removes the event handler from the event again.
self | the PSC_Event |
receiver | the object that should receive the event |
handler | the handler to be called |
id | optional identifier to be matched, use 0 if not applicable |