UtiLite  0.3.1
A lite utilities library
Static Public Member Functions | Protected Member Functions | Private Member Functions | Friends
UEventsManager Class Reference

#include <UEventsManager.h>

Inherits UThread.

List of all members.

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 >

Detailed Description

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
See also:
UEvent
UEventsHandler
post()
addHandler()
removeHandler()

Member Function Documentation

void UEventsManager::addHandler ( UEventsHandler handler) [static]

This method is used to add an events handler to the list of handlers.

Parameters:
handlerthe 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.

Parameters:
eventthe event to be posted.
asyncif 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.

Parameters:
handlerthe handler to be removed.

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Friends Defines