C++ bindings for cgul_event_router
More...
#include <cgul_event_router_cxx.h>
Public Types | |
typedef cgul_event_router__callback_t | callback_t |
typedef cgul_event_router__listener_t | listener_t |
Public Member Functions | |
listener_t | add_listener (const char *rendezvous, callback_t cb, const void *data) |
void | remove_listener (listener_t listener) |
void | send_event (const char *rendezvous, const void *event) |
void | set_data (listener_t listener, const void *data) |
size_t | get_listener_count (const char *rendezvous) const |
Static Public Member Functions | |
static cgul_event_router_cxx * | get_instance () |
static void | delete_instance () |
This class provides the C++ bindings for C cgul_event_router
objects. The main purpose of this class is to convert the C-style function calls and exception handling in cgul_event_router
into C++-style function calls and exception handling.
In order to register to listen to events, you must implement a function that is of type callback_t
.
Opaque pointer a listener
instance. An object of this type is passed back to the user by add_listener()
. It can be used to remove a listener or change the data passed to a listener.
|
inlinestatic |
Return the single instance of this class. Because cgul_event_router_cxx
is a singleton, the caller is generally not responsible for cleaning up by arranging for the instance to be deleted. If memory cannot be allocated, an exception is thrown.
References cgul_event_router__get_instance().
Referenced by delete_instance().
|
inlinestatic |
Destructor for the cgul_event_router_cxx
instance. In a typical program, the instance should only be deleted once (if at all) immediately before the program exists.
References cgul_event_router__delete(), and get_instance().
|
inline |
This method adds cb
to listen for the event specified by the rendezvous string rendezvous
. A copy of rendezvous
is made so the client does not have to keep rendezvous
in scope.
Events will be sent to the listeners in the order in which the listeners were added.
The "all" rendezvous string is special; if you use it, your listener will receive all events without having to explicitly register for each one. Furthermore, the "all" event listeners will receive the events before the normal event listeners. This makes the output of a logger that is attached to the "all" event sane when your code recursively sends events.
The cb
callback can be added more than once per rendezvous string. This makes it possible to use this class with C++ code when using a single private "static" method to forward the callback to a member method for more than one object of the C++ class. When using this tactic, each C++ object has be to registered individually, and this class makes it possible to do so.
cb
should return true if it wants the event to be sent to all remaining listeners. If cb
returns false, the event will not be sent to any function that was added after cb
.
This class is reentrant so it is safe to recursively add or remove listeners or even send events from cb
.
If an error occurs, an exception will be thrown.
[in] | rendezvous | rendezvous string |
[in] | cb | callback function |
[in] | data | opaque client data to pass back to cb |
References cgul_event_router__add_listener().
|
inline |
Remove listener
. After calling this method, listener
is invalid and should not be used again by the client.
This class is reentrant so it is safe to recursively add or remove listeners or even send events from the callback associated with listener
.
[in] | listener | listener |
References cgul_event_router__remove_listener().
|
inline |
Send event
to all listeners registered for events associated with the rendezvous
string. Events will be sent to the listeners in the order in which the listeners were added. This class is reentrant so it is safe to call this method from the callbacks associated with listeners thereby recursively sending events. If an error occurs, an exception will be thrown.
[in] | rendezvous | rendezvous string |
[in] | event | event to send |
References cgul_event_router__send_event().
|
inline |
This method sets the client data that is passed back to listener
when it is sent an event.
[in] | listener | listener |
[in] | data | client data |
References cgul_event_router__set_data().
|
inline |
Get the count of listeners currently registered for the event associated with the rendezvous
string.
[in] | rendezvous | rendezvous string |
References cgul_event_router__get_listener_count().