Ocean
Ocean::EventManager Class Reference

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...

Inheritance diagram for Ocean::EventManager:

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< EventCallbackEventCallbacks
 Definition of a set of callback functions. More...
 
typedef std::map< unsigned int, EventCallbacksEventCallbacksMap
 Definition of a map mapping event types to callback functions. More...
 
typedef std::vector< RegistrationRequestRegistrationRequests
 Definition of a vector holding registration requests. More...
 
typedef std::queue< EventRefEventQueue
 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...
 
Threadoperator= (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 EventManagerget ()
 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...
 

Detailed Description

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.

See also
Event.

Member Typedef Documentation

◆ EventCallback

Definition of a callback function for events.

◆ EventCallbacks

Definition of a set of callback functions.

◆ EventCallbacksMap

typedef std::map<unsigned int, EventCallbacks> Ocean::EventManager::EventCallbacksMap
protected

Definition of a map mapping event types to callback functions.

◆ EventQueue

typedef std::queue<EventRef> Ocean::EventManager::EventQueue
protected

Definition of a queue holding events.

◆ RegistrationRequests

Definition of a vector holding registration requests.

Constructor & Destructor Documentation

◆ EventManager()

Ocean::EventManager::EventManager ( )
protected

Creates a new event manager object.

◆ ~EventManager()

Ocean::EventManager::~EventManager ( )
protected

Destructs an event manger object.

Member Function Documentation

◆ addEventFunction()

void Ocean::EventManager::addEventFunction ( const unsigned int  eventTypes,
const EventCallback eventCallback 
)
private

Adds an event function.

Parameters
eventTypesThe type(s) of events which will be forwarded to the provided callback function
eventCallbackThe callback function which will receive the events with the defined type

◆ pushEvent()

void Ocean::EventManager::pushEvent ( const EventRef eventObject)

Pushes a new event to the event queue.

Parameters
eventObjectThe new event to push

◆ registerEventFunction()

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.

Parameters
eventTypesThe type(s) of events which will be forwarded to the provided callback function
eventCallbackThe callback function which will receive the events with the defined type
See also
unregisterEventFunction().

◆ removeEventFunction()

void Ocean::EventManager::removeEventFunction ( const unsigned int  eventTypes,
const EventCallback eventCallback 
)
private

Removes an event function.

Parameters
eventTypesThe type(s) of events which have been added
eventCallbackThe callback function which has been added

◆ threadRun()

virtual void Ocean::EventManager::threadRun ( )
protectedvirtual

The internal thread function.

See also
Thread::threadRun().

Implements Ocean::Thread.

◆ unregisterEventFunction()

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.

Parameters
eventTypesThe type(s) of events which have been registered
eventCallbackThe callback function which has been registered
See also
registerEventFunction().

Friends And Related Function Documentation

◆ Singleton< EventManager >

friend class Singleton< EventManager >
friend

Field Documentation

◆ managerEventCallbacksMap

EventCallbacksMap Ocean::EventManager::managerEventCallbacksMap
protected

The map of callback functions.

◆ managerEventQueue

EventQueue Ocean::EventManager::managerEventQueue
protected

The queue of events waiting to be distributed.

◆ managerLock

Lock Ocean::EventManager::managerLock
protected

The lock for the entire manager.

◆ managerRegistrationRequestLock

Lock Ocean::EventManager::managerRegistrationRequestLock
protected

The lock for the registration requests.

◆ managerRegistrationRequests

RegistrationRequests Ocean::EventManager::managerRegistrationRequests
protected

The registration requests which are used to modify the map of callback functions.

◆ managerRequestCounter

unsigned int Ocean::EventManager::managerRequestCounter
protected

The counter for registration requests.

◆ managerRequestSet

IndexSet32 Ocean::EventManager::managerRequestSet
protected

The set of pending registration requests.


The documentation for this class was generated from the following file: