UtiLite
0.3.1
A lite utilities library
|
#include <UEventsManager.h>
Inherits UThread.
Static Public Member Functions | |
static void | addHandler (UEventsHandler *handler) |
static void | removeHandler (UEventsHandler *handler) |
static void | post (UEvent *event, bool async=true) |
Protected Member Functions | |
virtual void | mainLoop () |
Private Member Functions | |
virtual void | mainLoopKill () |
Friends | |
class | UDestroyer< UEventsManager > |
This class is used to post events between threads in the application. It is Thread-Safe and the events are sent to receivers in the same order they are posted (FIFO). It works like the design pattern Mediator. It is also a Singleton, so it can be used anywhere in the application.
To send an event, use UEventsManager::post(). Events are automatically deleted after they are posted.
The EventsManager have a list of handlers to which it sends posted events. To add an handler, use UEventsManager::addHandler(). To remove, use UEventsManager::removeHandler().
// Anywhere in the code: UEventsManager::post(new MyEvent()); // where MyEvent is an implemented UEvent
void UEventsManager::addHandler | ( | UEventsHandler * | handler | ) | [static] |
This method is used to add an events handler to the list of handlers.
handler | the handler to be added. |
void UEventsManager::mainLoop | ( | ) | [protected, virtual] |
The UEventsManager's main loop.
Implements UThread.
void UEventsManager::mainLoopKill | ( | ) | [private, virtual] |
Reimplemented to wake up UEventsManager on termination.
Reimplemented from UThread.
void UEventsManager::post | ( | UEvent * | event, |
bool | async = true |
||
) | [static] |
This method is used to post an event to handlers.
Event can be posted asynchronously or not. In the first case, the event is dispatched by the UEventsManager's thread. In the second case, the event is handled immediately by event's receivers, thus in the sender thread.
event | the event to be posted. |
async | if true, the event is dispatched by the UEventsManager thread, otherwise it's in the caller thread (synchronous). |
void UEventsManager::removeHandler | ( | UEventsHandler * | handler | ) | [static] |
This method is used to remove an events handler from the list of handlers.
handler | the handler to be removed. |