Ocean
|
This class implements a central manager for events that can be pushed and received from/in individual components of an application or a software package. More...
Data Structures | |
class | RegistrationRequest |
Definition of a class encapsulating a registration request. More... | |
Public Types | |
typedef Callback< void, const EventRef & > | EventCallback |
Definition of a callback function for events. More... | |
Public Types inherited from Ocean::Thread | |
enum | ThreadPriority { PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL , PRIORTY_HIGH , PRIORTY_REALTIME } |
Definition of different thread priority values. More... | |
Public Member Functions | |
void | pushEvent (const EventRef &eventObject) |
Pushes a new event to the event queue. More... | |
void | registerEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
Registers a callback function for a specific type or types of events. More... | |
void | unregisterEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
Unregisters a callback function for a specific type or types of events. More... | |
Public Member Functions inherited from Ocean::Thread | |
Thread (const std::string &name=std::string()) | |
Creates a new thread object. More... | |
Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string()) | |
Creates a new thread object. More... | |
virtual | ~Thread () |
Destructs a thread object. More... | |
bool | startThread () |
Starts the thread. More... | |
void | stopThread () |
Informs the thread to stop. More... | |
bool | terminateThread () |
Terminates the thread. More... | |
bool | joinThread (const unsigned int timeout=(unsigned int)(-1)) |
Waits until this thread has been stopped. More... | |
bool | shouldThreadStop () const |
Returns whether this thread should stop. More... | |
bool | isThreadInvokedToStart () const |
Returns whether this thread has been invoked to start immediately. More... | |
bool | isThreadActive () const |
Returns whether this thread is active. More... | |
Protected Types | |
typedef Callbacks< EventCallback > | EventCallbacks |
Definition of a set of callback functions. More... | |
typedef std::map< unsigned int, EventCallbacks > | EventCallbacksMap |
Definition of a map mapping event types to callback functions. More... | |
typedef std::vector< RegistrationRequest > | RegistrationRequests |
Definition of a vector holding registration requests. More... | |
typedef std::queue< EventRef > | EventQueue |
Definition of a queue holding events. More... | |
Protected Types inherited from Ocean::Thread | |
typedef std::pair< pthread_t, bool > | TimedJoinPair |
Definition of a pair holding a thread id and a boolean state. More... | |
Protected Member Functions | |
EventManager () | |
Creates a new event manager object. More... | |
~EventManager () | |
Destructs an event manger object. More... | |
virtual void | threadRun () |
The internal thread function. More... | |
Protected Member Functions inherited from Ocean::Singleton< EventManager > | |
Singleton ()=default | |
Default constructor. More... | |
Protected Member Functions inherited from Ocean::Thread | |
Thread (const Thread &thread)=delete | |
Disabled copy constructor. More... | |
void | createThread () |
Creates the thread itself. More... | |
void | destroyThread () |
Destroys the thread itself. More... | |
void | stopThreadExplicitly (const unsigned int timeout=5000u) |
Tries to stop the thread gracefully. More... | |
Thread & | operator= (const Thread &thread)=delete |
The disabled assign operator. More... | |
Protected Attributes | |
EventQueue | managerEventQueue |
The queue of events waiting to be distributed. More... | |
EventCallbacksMap | managerEventCallbacksMap |
The map of callback functions. More... | |
RegistrationRequests | managerRegistrationRequests |
The registration requests which are used to modify the map of callback functions. More... | |
unsigned int | managerRequestCounter |
The counter for registration requests. More... | |
IndexSet32 | managerRequestSet |
The set of pending registration requests. More... | |
Lock | managerLock |
The lock for the entire manager. More... | |
Lock | managerRegistrationRequestLock |
The lock for the registration requests. More... | |
Private Member Functions | |
void | addEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
Adds an event function. More... | |
void | removeEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
Removes an event function. More... | |
Friends | |
class | Singleton< EventManager > |
Additional Inherited Members | |
Static Public Member Functions inherited from Ocean::Singleton< EventManager > | |
static EventManager & | get () |
Returns a reference to the unique object. More... | |
Static Public Member Functions inherited from Ocean::Thread | |
static void | sleep (unsigned int ms) |
Sleeps the calling thread for a given time. More... | |
static void | giveUp () |
Gives up the remaining thread time. More... | |
static ThreadId | currentThreadId () |
Returns the thread id of the current (calling) thread. More... | |
static ThreadPriority | threadPriority () |
Returns the priority of the current thread. More... | |
static bool | setThreadPriority (const ThreadPriority priority) |
Sets the priority of the current thread. More... | |
template<typename TObject , typename TExpectedValue > | |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0) |
Waits until an object/variable has an expected value. More... | |
template<typename TObject , typename TExpectedValue > | |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0) |
Waits until an object/variable has an expected value. More... | |
static int | pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime) |
Implements a thread join function with timeout value. More... | |
This class implements a central manager for events that can be pushed and received from/in individual components of an application or a software package.
The manager has an own thread distributing the events.
typedef Callback<void, const EventRef&> Ocean::EventManager::EventCallback |
Definition of a callback function for events.
|
protected |
Definition of a set of callback functions.
|
protected |
Definition of a map mapping event types to callback functions.
|
protected |
Definition of a queue holding events.
|
protected |
Definition of a vector holding registration requests.
|
protected |
Creates a new event manager object.
|
protected |
Destructs an event manger object.
|
private |
Adds an event function.
eventTypes | The type(s) of events which will be forwarded to the provided callback function |
eventCallback | The callback function which will receive the events with the defined type |
void Ocean::EventManager::pushEvent | ( | const EventRef & | eventObject | ) |
Pushes a new event to the event queue.
eventObject | The new event to push |
void Ocean::EventManager::registerEventFunction | ( | const unsigned int | eventTypes, |
const EventCallback & | eventCallback | ||
) |
Registers a callback function for a specific type or types of events.
Each registered callback function must be unregistered later.
eventTypes | The type(s) of events which will be forwarded to the provided callback function |
eventCallback | The callback function which will receive the events with the defined type |
|
private |
Removes an event function.
eventTypes | The type(s) of events which have been added |
eventCallback | The callback function which has been added |
|
protectedvirtual |
void Ocean::EventManager::unregisterEventFunction | ( | const unsigned int | eventTypes, |
const EventCallback & | eventCallback | ||
) |
Unregisters a callback function for a specific type or types of events.
The callback function must have been registered before.
eventTypes | The type(s) of events which have been registered |
eventCallback | The callback function which has been registered |
|
friend |
|
protected |
The map of callback functions.
|
protected |
The queue of events waiting to be distributed.
|
protected |
The lock for the entire manager.
|
protected |
The lock for the registration requests.
|
protected |
The registration requests which are used to modify the map of callback functions.
|
protected |
The counter for registration requests.
|
protected |
The set of pending registration requests.