8 #ifndef META_OCEAN_BASE_EVENT_H
9 #define META_OCEAN_BASE_EVENT_H
53 inline unsigned int type()
const;
59 inline unsigned int subtype()
const;
66 template <
typename T>
const T& cast()
const;
73 template <
typename T> T& cast();
82 inline Event(
const unsigned int type,
const unsigned int subtype);
103 template <
typename T>
138 inline void leave()
const;
236 inline unsigned int id()
const;
359 inline Event::Event(
const unsigned int type,
const unsigned int subtype) :
361 eventSubtype(subtype)
376 template <
typename T>
379 ocean_assert(
dynamic_cast<const T*
>(
this));
380 return dynamic_cast<const T&
>(*this);
383 template <
typename T>
386 ocean_assert(
dynamic_cast<const T*
>(
this));
387 return dynamic_cast<T&
>(*this);
390 template <
typename T>
392 scopedBreakEvent(breakEvent),
393 scopedLeaveEvent(leaveEvent),
394 scopedCallbacks(callbacks),
395 scopedEventLeave(false)
400 template <
typename T>
403 if (scopedEventLeave)
404 scopedCallbacks(scopedLeaveEvent);
406 scopedCallbacks(scopedBreakEvent);
409 template <
typename T>
412 scopedEventLeave =
true;
415 template <
typename T>
418 return scopedBreakEvent;
421 template <
typename T>
424 return scopedBreakEvent;
427 template <
typename T>
430 return scopedLeaveEvent;
433 template <
typename T>
436 return scopedLeaveEvent;
440 requestRegisterCallback(registerCallback),
442 requestEventTypes(eventTypes),
443 requestCallback(callback)
450 return requestRegisterCallback;
460 return requestEventTypes;
465 return requestCallback;
This class implements a container for callback functions.
Definition: Callback.h:3456
This class implements the base class for all event classes.
Definition: Event.h:41
Event(const unsigned int type, const unsigned int subtype)
Creates a new event object.
Definition: Event.h:359
unsigned int eventSubtype
The sub-type of the event.
Definition: Event.h:90
unsigned int subtype() const
Returns the sub-type of this event.
Definition: Event.h:371
unsigned int eventType
The type of the event.
Definition: Event.h:87
unsigned int type() const
Returns the type of this event.
Definition: Event.h:366
virtual ~Event()
Destructs an event object.
const T & cast() const
Casts this event to an event with specified type.
Definition: Event.h:377
Definition of a class encapsulating a registration request.
Definition: Event.h:214
unsigned int requestId
The registration request id of the new object.
Definition: Event.h:256
unsigned int id() const
Returns the registration request id of this object.
Definition: Event.h:453
RegistrationRequest(const bool registerCallback, const unsigned int id, const unsigned int eventTypes, const EventCallback &callback)
Creates a new registration request.
Definition: Event.h:439
bool requestRegisterCallback
True, to register the callback function; False, to unregister the callback function.
Definition: Event.h:253
const EventCallback & callback() const
Returns the callback function of this request object.
Definition: Event.h:463
bool registerCallback() const
Returns whether the request intends an register or unregister execution.
Definition: Event.h:448
unsigned int eventTypes() const
Returns the event types for which the callback function will be registered or unregistered.
Definition: Event.h:458
unsigned int requestEventTypes
The event types for which the callback function will be registered or unregistered.
Definition: Event.h:259
EventCallback requestCallback
The callback function of this request.
Definition: Event.h:262
This class implements a central manager for events that can be pushed and received from/in individual...
Definition: Event.h:188
Lock managerRegistrationRequestLock
The lock for the registration requests.
Definition: Event.h:356
void pushEvent(const EventRef &eventObject)
Pushes a new event to the event queue.
~EventManager()
Destructs an event manger object.
Callback< void, const EventRef & > EventCallback
Definition of a callback function for events.
Definition: Event.h:196
Callbacks< EventCallback > EventCallbacks
Definition of a set of callback functions.
Definition: Event.h:203
std::queue< EventRef > EventQueue
Definition of a queue holding events.
Definition: Event.h:273
RegistrationRequests managerRegistrationRequests
The registration requests which are used to modify the map of callback functions.
Definition: Event.h:344
EventCallbacksMap managerEventCallbacksMap
The map of callback functions.
Definition: Event.h:341
void addEventFunction(const unsigned int eventTypes, const EventCallback &eventCallback)
Adds an event function.
Lock managerLock
The lock for the entire manager.
Definition: Event.h:353
EventManager()
Creates a new event manager object.
void removeEventFunction(const unsigned int eventTypes, const EventCallback &eventCallback)
Removes an event function.
EventQueue managerEventQueue
The queue of events waiting to be distributed.
Definition: Event.h:338
virtual void threadRun()
The internal thread function.
std::map< unsigned int, EventCallbacks > EventCallbacksMap
Definition of a map mapping event types to callback functions.
Definition: Event.h:208
unsigned int managerRequestCounter
The counter for registration requests.
Definition: Event.h:347
void unregisterEventFunction(const unsigned int eventTypes, const EventCallback &eventCallback)
Unregisters a callback function for a specific type or types of events.
IndexSet32 managerRequestSet
The set of pending registration requests.
Definition: Event.h:350
void registerEventFunction(const unsigned int eventTypes, const EventCallback &eventCallback)
Registers a callback function for a specific type or types of events.
std::vector< RegistrationRequest > RegistrationRequests
Definition of a vector holding registration requests.
Definition: Event.h:268
This class implements a recursive lock object.
Definition: Lock.h:31
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class implements a scoped event.
Definition: Event.h:105
T & scopedBreakEvent
Break event which will be invoked if the leave() function has not been called before this object is d...
Definition: Event.h:167
bool scopedEventLeave
Leave statement of this object.
Definition: Event.h:176
T & scopedLeaveEvent
Leave event which will be invoked if the leave() function has been called before this object is dispo...
Definition: Event.h:170
~ScopedEvent()
Destructs this scoped event object.
Definition: Event.h:401
const T & leaveEvent() const
Returns the leave-event of this object, nothing else will be done.
Definition: Event.h:428
void leave() const
Activates the leave event of this object.
Definition: Event.h:410
ScopedEvent(const T &enterEvent, T &breakEvent, T &leaveEvent, const EventCallbacks &callbacks)
Creates a new scoped event object.
Definition: Event.h:391
const EventCallbacks & scopedCallbacks
A list of callback functions to those the events will be sent.
Definition: Event.h:173
Callbacks< EventCallback > EventCallbacks
Definition of a list of callback functions.
Definition: Event.h:116
const T & breakEvent() const
Returns the break-event of this object, nothing else will be done.
Definition: Event.h:416
Callback< void, const T & > EventCallback
Definition of a callback function providing the event as single parameter.
Definition: Event.h:111
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class implements a thread.
Definition: Thread.h:115
std::set< Index32 > IndexSet32
Definition of a set holding 32 bit indices.
Definition: Base.h:114
ObjectRef< Event > EventRef
Definition of an object reference holding an event object.
Definition: Event.h:23
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15