Classes | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
UEventsManager Class Reference

#include <UEventsManager.h>

Inheritance diagram for UEventsManager:
Inheritance graph
[legend]

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 (const Handle &H)
 
static int Detach (Handle H)
 
static int Join (const Handle &H)
 
static int Join (Handle H)
 
static int Kill (const Handle &H)
 
static int Kill (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 UEventsManagergetInstance ()
 
- 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< Pipepipes_
 
UMutex pipesMutex_
 
USemaphore postEventSem_
 

Static Private Attributes

static UDestroyer< UEventsManagerdestroyer_
 
static UEventsManagerinstance_ = 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 ()
 

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()

Definition at line 78 of file UEventsManager.h.

Constructor & Destructor Documentation

◆ UEventsManager()

UEventsManager::UEventsManager ( )
protected

Definition at line 136 of file UEventsManager.cpp.

◆ ~UEventsManager()

UEventsManager::~UEventsManager ( )
protectedvirtual

Definition at line 140 of file UEventsManager.cpp.

Member Function Documentation

◆ _addHandler()

void UEventsManager::_addHandler ( UEventsHandler handler)
private

Definition at line 245 of file UEventsManager.cpp.

◆ _createPipe()

void UEventsManager::_createPipe ( const UEventsSender sender,
const UEventsHandler receiver,
const std::string eventName 
)
private

Definition at line 367 of file UEventsManager.cpp.

◆ _postEvent()

void UEventsManager::_postEvent ( UEvent event,
bool  async = true,
const UEventsSender sender = 0 
)
private

Definition at line 300 of file UEventsManager.cpp.

◆ _removeAllPipes()

void UEventsManager::_removeAllPipes ( const UEventsSender sender)
private

Definition at line 444 of file UEventsManager.cpp.

◆ _removeHandler()

void UEventsManager::_removeHandler ( UEventsHandler handler)
private

Definition at line 269 of file UEventsManager.cpp.

◆ _removeNullPipes()

void UEventsManager::_removeNullPipes ( const UEventsSender sender)
private

Definition at line 461 of file UEventsManager.cpp.

◆ _removePipe()

void UEventsManager::_removePipe ( const UEventsSender sender,
const UEventsHandler receiver,
const std::string eventName 
)
private

Definition at line 414 of file UEventsManager.cpp.

◆ addHandler()

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.

Definition at line 28 of file UEventsManager.cpp.

◆ createPipe()

void UEventsManager::createPipe ( const UEventsSender sender,
const UEventsHandler receiver,
const std::string eventName 
)
static

Definition at line 67 of file UEventsManager.cpp.

◆ dispatchEvent()

bool UEventsManager::dispatchEvent ( UEvent event,
const UEventsSender sender 
)
privatevirtual

Definition at line 201 of file UEventsManager.cpp.

◆ dispatchEvents()

void UEventsManager::dispatchEvents ( )
privatevirtual

Definition at line 170 of file UEventsManager.cpp.

◆ getInstance()

UEventsManager * UEventsManager::getInstance ( )
staticprotected

Definition at line 125 of file UEventsManager.cpp.

◆ getPipes()

std::list< UEventsHandler * > UEventsManager::getPipes ( const UEventsSender sender,
const std::string eventName 
)
private

Definition at line 329 of file UEventsManager.cpp.

◆ mainLoop()

void UEventsManager::mainLoop ( )
protectedvirtual

The UEventsManager's main loop.

Implements UThread.

Definition at line 156 of file UEventsManager.cpp.

◆ mainLoopKill()

void UEventsManager::mainLoopKill ( )
privatevirtual

Reimplemented to wake up UEventsManager on termination.

Reimplemented from UThread.

Definition at line 165 of file UEventsManager.cpp.

◆ post()

void UEventsManager::post ( UEvent event,
bool  async = true,
const UEventsSender sender = 0 
)
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).

Definition at line 54 of file UEventsManager.cpp.

◆ removeAllPipes()

void UEventsManager::removeAllPipes ( const UEventsSender sender)
static

Definition at line 99 of file UEventsManager.cpp.

◆ removeHandler()

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.

Definition at line 41 of file UEventsManager.cpp.

◆ removeNullPipes()

void UEventsManager::removeNullPipes ( const UEventsSender sender)
static

Definition at line 112 of file UEventsManager.cpp.

◆ removePipe()

void UEventsManager::removePipe ( const UEventsSender sender,
const UEventsHandler receiver,
const std::string eventName 
)
static

Definition at line 83 of file UEventsManager.cpp.

Friends And Related Function Documentation

◆ UDestroyer< UEventsManager >

friend class UDestroyer< UEventsManager >
friend

Definition at line 155 of file UEventsManager.h.

Member Data Documentation

◆ destroyer_

UDestroyer< UEventsManager > UEventsManager::destroyer_
staticprivate

Definition at line 243 of file UEventsManager.h.

◆ events_

std::list<std::pair<UEvent*, const UEventsSender * > > UEventsManager::events_
private

Definition at line 244 of file UEventsManager.h.

◆ eventsMutex_

UMutex UEventsManager::eventsMutex_
private

Definition at line 246 of file UEventsManager.h.

◆ handlers_

std::list<UEventsHandler*> UEventsManager::handlers_
private

Definition at line 245 of file UEventsManager.h.

◆ handlersMutex_

UMutex UEventsManager::handlersMutex_
private

Definition at line 247 of file UEventsManager.h.

◆ instance_

UEventsManager * UEventsManager::instance_ = 0
staticprivate

Definition at line 242 of file UEventsManager.h.

◆ pipes_

std::list<Pipe> UEventsManager::pipes_
private

Definition at line 249 of file UEventsManager.h.

◆ pipesMutex_

UMutex UEventsManager::pipesMutex_
private

Definition at line 250 of file UEventsManager.h.

◆ postEventSem_

USemaphore UEventsManager::postEventSem_
private

Definition at line 248 of file UEventsManager.h.


The documentation for this class was generated from the following files:
UEventsManager::post
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
Definition: UEventsManager.cpp:54


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:26