cgul_event_router_cxx Class Reference

C++ bindings for cgul_event_router More...

#include <cgul_event_router_cxx.h>

Collaboration diagram for cgul_event_router_cxx:
Collaboration graph

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_cxxget_instance ()
 
static void delete_instance ()
 

Detailed Description

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.

Member Typedef Documentation

§ callback_t

In order to register to listen to events, you must implement a function that is of type callback_t.

See also
cgul_event_router__callback_t

§ listener_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.

Member Function Documentation

§ get_instance()

static cgul_event_router_cxx* cgul_event_router_cxx::get_instance ( )
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.

Returns
single instance of this class.

References cgul_event_router__get_instance().

Referenced by delete_instance().

§ delete_instance()

static void cgul_event_router_cxx::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().

§ add_listener()

listener_t cgul_event_router_cxx::add_listener ( const char *  rendezvous,
callback_t  cb,
const void *  data 
)
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.

Parameters
[in]rendezvousrendezvous string
[in]cbcallback function
[in]dataopaque client data to pass back to cb
Returns
listener

References cgul_event_router__add_listener().

§ remove_listener()

void cgul_event_router_cxx::remove_listener ( listener_t  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.

Parameters
[in]listenerlistener

References cgul_event_router__remove_listener().

§ send_event()

void cgul_event_router_cxx::send_event ( const char *  rendezvous,
const void *  event 
)
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.

Parameters
[in]rendezvousrendezvous string
[in]eventevent to send

References cgul_event_router__send_event().

§ set_data()

void cgul_event_router_cxx::set_data ( listener_t  listener,
const void *  data 
)
inline

This method sets the client data that is passed back to listener when it is sent an event.

Parameters
[in]listenerlistener
[in]dataclient data

References cgul_event_router__set_data().

§ get_listener_count()

size_t cgul_event_router_cxx::get_listener_count ( const char *  rendezvous) const
inline

Get the count of listeners currently registered for the event associated with the rendezvous string.

Parameters
[in]rendezvousrendezvous string
Returns
listener count

References cgul_event_router__get_listener_count().


The documentation for this class was generated from the following file: