Yate
|
A message dispatching hub. More...
#include <yatengine.h>
Public Member Functions | |
MessageDispatcher () | |
~MessageDispatcher () | |
bool | install (MessageHandler *handler) |
bool | uninstall (MessageHandler *handler) |
bool | dispatch (Message &msg) |
bool | enqueue (Message *msg) |
void | dequeue () |
bool | dequeueOne () |
void | warnTime (u_int64_t usec) |
void | clear () |
unsigned int | messageCount () |
unsigned int | handlerCount () |
void | setHook (MessagePostHook *hook, bool remove=false) |
A message dispatching hub.
The dispatcher class is a hub that holds a list of handlers to be called for the messages that pass trough the hub. It can also handle a queue of messages that are typically dispatched by a separate thread.
Creates a new message dispatcher.
~MessageDispatcher | ( | ) |
Destroys the dispatcher and the installed handlers.
void clear | ( | ) | [inline] |
Clear all the message handlers and post-dispatch hooks
void dequeue | ( | ) |
Dispatch all messages from the waiting queue
bool dequeueOne | ( | ) |
Dispatch one message from the waiting queue
Synchronously dispatch a message to the installed handlers. Handlers matching the message name and filter parameter are called in their installed order (based on priority) until one returns true. If the message has the broadcast flag set all matching handlers are called and the return value is true if any handler returned true. Note that in some cases when a handler is removed from the list other handlers with equal priority may be called twice.
msg | The message to dispatch |
Put a message in the waiting queue for asynchronous dispatching
msg | The message to enqueue, will be destroyed after dispatching |
unsigned int handlerCount | ( | ) |
Get the number of handlers in this dispatcher
bool install | ( | MessageHandler * | handler | ) |
Installs a handler in the dispatcher. The handlers are installed in ascending order of their priorities. There is NO GUARANTEE on the order of handlers with equal priorities although for avoiding uncertainity such handlers are sorted by address.
handler | A pointer to the handler to install |
unsigned int messageCount | ( | ) |
Get the number of messages waiting in the queue
void setHook | ( | MessagePostHook * | hook, |
bool | remove = false |
||
) |
Install or remove a hook to catch messages after being dispatched
hook | Pointer to a post-dispatching message hook |
remove | Set to True to remove the hook instead of adding |
bool uninstall | ( | MessageHandler * | handler | ) |
Uninstalls a handler from the dispatcher.
handler | A pointer to the handler to uninstall |
void warnTime | ( | u_int64_t | usec | ) | [inline] |
Set a limit to generate warning when a message took too long to dispatch
usec | Warning time limit in microseconds, zero to disable |