|
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...
#include <Event.h>
Data Structures | |
| class | RegistrationRequest |
| Definition of a class encapsulating a registration request. More... | |
Public Types | |
| using | EventCallback = Callback< void, const EventRef & > |
| Definition of a callback function for events. | |
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. | |
| void | registerEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
| Registers a callback function for a specific type or types of events. | |
| void | unregisterEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
| Unregisters a callback function for a specific type or types of events. | |
Public Member Functions inherited from Ocean::Thread | |
| Thread (const std::string &name=std::string()) | |
| Creates a new thread object. | |
| Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string()) | |
| Creates a new thread object. | |
| virtual | ~Thread () |
| Destructs a thread object. | |
| bool | startThread () |
| Starts the thread. | |
| void | stopThread () |
| Informs the thread to stop. | |
| bool | terminateThread () |
| Terminates the thread. | |
| bool | joinThread (const unsigned int timeout=(unsigned int)(-1)) |
| Waits until this thread has been stopped. | |
| bool | shouldThreadStop () const |
| Returns whether this thread should stop. | |
| bool | isThreadInvokedToStart () const |
| Returns whether this thread has been invoked to start immediately. | |
| bool | isThreadActive () const |
| Returns whether this thread is active. | |
Protected Types | |
| using | EventCallbacks = Callbacks< EventCallback > |
| Definition of a set of callback functions. | |
| using | EventCallbacksMap = std::map< unsigned int, EventCallbacks > |
| Definition of a map mapping event types to callback functions. | |
| using | RegistrationRequests = std::vector< RegistrationRequest > |
| Definition of a vector holding registration requests. | |
| using | EventQueue = std::queue< EventRef > |
| Definition of a queue holding events. | |
Protected Types inherited from Ocean::Thread | |
| using | TimedJoinPair = std::pair< pthread_t, bool > |
| Definition of a pair holding a thread id and a boolean state. | |
Protected Member Functions | |
| EventManager () | |
| Creates a new event manager object. | |
| ~EventManager () | |
| Destructs an event manger object. | |
| virtual void | threadRun () |
| The internal thread function. | |
Protected Member Functions inherited from Ocean::Singleton< EventManager > | |
| Singleton ()=default | |
| Default constructor. | |
Protected Member Functions inherited from Ocean::Thread | |
| Thread (const Thread &thread)=delete | |
| Disabled copy constructor. | |
| void | createThread () |
| Creates the thread itself. | |
| void | destroyThread () |
| Destroys the thread itself. | |
| void | stopThreadExplicitly (const unsigned int timeout=5000u) |
| Tries to stop the thread gracefully. | |
| Thread & | operator= (const Thread &thread)=delete |
| The disabled assign operator. | |
Protected Attributes | |
| EventQueue | managerEventQueue |
| The queue of events waiting to be distributed. | |
| EventCallbacksMap | managerEventCallbacksMap |
| The map of callback functions. | |
| RegistrationRequests | managerRegistrationRequests |
| The registration requests which are used to modify the map of callback functions. | |
| unsigned int | managerRequestCounter |
| The counter for registration requests. | |
| IndexSet32 | managerRequestSet |
| The set of pending registration requests. | |
| Lock | managerLock |
| The lock for the entire manager. | |
| Lock | managerRegistrationRequestLock |
| The lock for the registration requests. | |
Private Member Functions | |
| void | addEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
| Adds an event function. | |
| void | removeEventFunction (const unsigned int eventTypes, const EventCallback &eventCallback) |
| Removes an event function. | |
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. | |
Static Public Member Functions inherited from Ocean::Thread | |
| static void | sleep (unsigned int ms) |
| Sleeps the calling thread for a given time. | |
| static void | giveUp () |
| Gives up the remaining thread time. | |
| static ThreadId | currentThreadId () |
| Returns the thread id of the current (calling) thread. | |
| static ThreadPriority | threadPriority () |
| Returns the priority of the current thread. | |
| static bool | setThreadPriority (const ThreadPriority priority) |
| Sets the priority of the current thread. | |
| 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. | |
| 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. | |
| static int | pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime) |
| Implements a thread join function with timeout value. | |
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.
| using Ocean::EventManager::EventCallback = Callback<void, const EventRef&> |
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.