#include <UEventsManager.h>
Classes | |
class | Pipe |
Static Public Member Functions | |
static void | addHandler (UEventsHandler *handler) |
static void | createPipe (const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName) |
static void | post (UEvent *event, bool async=true, const UEventsSender *sender=0) |
static void | removeAllPipes (const UEventsSender *sender) |
static void | removeHandler (UEventsHandler *handler) |
static void | removeNullPipes (const UEventsSender *sender) |
static void | removePipe (const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName) |
Static Public Member Functions inherited from UThread | |
static unsigned long | currentThreadId () |
Static Public Member Functions inherited from UThreadC< void > | |
static int | Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) |
static int | Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) |
static int | Detach (Handle H) |
static int | Detach (const Handle &H) |
static int | Join (const Handle &H) |
static int | Join (Handle H) |
static int | Kill (Handle H) |
static int | Kill (const Handle &H) |
Protected Member Functions | |
virtual void | mainLoop () |
UEventsManager () | |
virtual | ~UEventsManager () |
Protected Member Functions inherited from UThreadC< void > | |
UThreadC () | |
UThreadC () | |
Static Protected Member Functions | |
static UEventsManager * | getInstance () |
Static Protected Member Functions inherited from UThreadC< void > | |
static void | Exit () |
static void | Exit () |
static Handle | Self () |
static int | Self () |
static void | TestCancel () |
static void | TestCancel () |
Private Member Functions | |
void | _addHandler (UEventsHandler *handler) |
void | _createPipe (const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName) |
void | _postEvent (UEvent *event, bool async=true, const UEventsSender *sender=0) |
void | _removeAllPipes (const UEventsSender *sender) |
void | _removeHandler (UEventsHandler *handler) |
void | _removeNullPipes (const UEventsSender *sender) |
void | _removePipe (const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName) |
virtual bool | dispatchEvent (UEvent *event, const UEventsSender *sender) |
virtual void | dispatchEvents () |
std::list< UEventsHandler * > | getPipes (const UEventsSender *sender, const std::string &eventName) |
virtual void | mainLoopKill () |
Private Attributes | |
std::list< std::pair< UEvent *, const UEventsSender *> > | events_ |
UMutex | eventsMutex_ |
std::list< UEventsHandler * > | handlers_ |
UMutex | handlersMutex_ |
std::list< Pipe > | pipes_ |
UMutex | pipesMutex_ |
USemaphore | postEventSem_ |
Static Private Attributes | |
static UDestroyer< UEventsManager > | destroyer_ |
static UEventsManager * | instance_ = 0 |
Friends | |
class | UDestroyer< UEventsManager > |
Additional Inherited Members | |
Public Types inherited from UThread | |
enum | Priority { kPLow, kPBelowNormal, kPNormal, kPAboveNormal, kPRealTime } |
Public Types inherited from UThreadC< void > | |
typedef THREAD_HANDLE | Handle |
typedef THREAD_HANDLE | Handle |
typedef void(* | Handler) () |
typedef void(* | Handler) () |
Public Member Functions inherited from UThread | |
Handle | getThreadHandle () const |
unsigned long | getThreadId () const |
bool | isCreating () const |
bool | isIdle () const |
bool | isKilled () const |
bool | isRunning () const |
void | join (bool killFirst=false) |
void | kill () |
void | setAffinity (int cpu=0) |
void | setPriority (Priority priority) |
void | start () |
UThread (Priority priority=kPNormal) | |
virtual | ~UThread () |
Public Member Functions inherited from UThreadC< void > | |
int | Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
int | Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
int | Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
int | Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
virtual | ~UThreadC () |
virtual | ~UThreadC () |
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().
Definition at line 78 of file UEventsManager.h.
|
protected |
Definition at line 136 of file UEventsManager.cpp.
|
protectedvirtual |
Definition at line 140 of file UEventsManager.cpp.
|
private |
Definition at line 245 of file UEventsManager.cpp.
|
private |
Definition at line 367 of file UEventsManager.cpp.
|
private |
Definition at line 300 of file UEventsManager.cpp.
|
private |
Definition at line 444 of file UEventsManager.cpp.
|
private |
Definition at line 269 of file UEventsManager.cpp.
|
private |
Definition at line 461 of file UEventsManager.cpp.
|
private |
Definition at line 414 of file UEventsManager.cpp.
|
static |
This method is used to add an events handler to the list of handlers.
handler | the handler to be added. |
Definition at line 28 of file UEventsManager.cpp.
|
static |
Definition at line 67 of file UEventsManager.cpp.
|
privatevirtual |
Definition at line 201 of file UEventsManager.cpp.
|
privatevirtual |
Definition at line 170 of file UEventsManager.cpp.
|
staticprotected |
Definition at line 125 of file UEventsManager.cpp.
|
private |
Definition at line 329 of file UEventsManager.cpp.
|
protectedvirtual |
The UEventsManager's main loop.
Implements UThread.
Definition at line 156 of file UEventsManager.cpp.
|
privatevirtual |
Reimplemented to wake up UEventsManager on termination.
Reimplemented from UThread.
Definition at line 165 of file UEventsManager.cpp.
|
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). |
Definition at line 54 of file UEventsManager.cpp.
|
static |
Definition at line 99 of file UEventsManager.cpp.
|
static |
This method is used to remove an events handler from the list of handlers.
handler | the handler to be removed. |
Definition at line 41 of file UEventsManager.cpp.
|
static |
Definition at line 112 of file UEventsManager.cpp.
|
static |
Definition at line 83 of file UEventsManager.cpp.
|
friend |
Definition at line 155 of file UEventsManager.h.
|
staticprivate |
Definition at line 243 of file UEventsManager.h.
|
private |
Definition at line 244 of file UEventsManager.h.
|
private |
Definition at line 246 of file UEventsManager.h.
|
private |
Definition at line 245 of file UEventsManager.h.
|
private |
Definition at line 247 of file UEventsManager.h.
|
staticprivate |
Definition at line 242 of file UEventsManager.h.
|
private |
Definition at line 249 of file UEventsManager.h.
|
private |
Definition at line 250 of file UEventsManager.h.
|
private |
Definition at line 248 of file UEventsManager.h.