ALBA
|
#include <albaAgentEventQueue.h>
Public Types | |
enum | DispatchModalities { SelfProcessMode = 0 , BroadcastMode } |
enum | PopModalities { SingleEventMode = 0 , MultipleEventMode } |
enum | PushModalities { DispatchEventMode =0 , PollingMode } |
Public Member Functions | |
ALBA_ID_DEC (EVENT_DISPATCH) | |
albaTypeMacro (albaAgentEventQueue, albaAgent) | |
bool | PushEvent (albaEventBase &event) |
virtual bool | PushEvent (albaEventBase *event) |
bool | PushEvent (albaID event_id, void *sender, void *data=NULL) |
albaEventBase * | PeekEvent () |
albaEventBase * | PeekLastEvent () |
int | GetQueueSize () |
bool | IsQueueEmpty () |
virtual bool | DispatchEvents () |
void | SetDequeueMode (int mode) |
int | GetDequeueMode () |
void | SetDequeueModeToMultipleEvent () |
void | SetDequeueModeToSingleEvent () |
void | SetDispatchMode (int mode) |
int | GetDispatchMode () |
void | SetDispatchModeToSelfProcess () |
void | SetDispatchModeToBroadcast () |
void | SetPushMode (int mode) |
int | GetPushMode () |
void | SetPushModeToDispatchEvent () |
void | SetPushModeToPolling () |
Public Member Functions inherited from albaAgent | |
albaAbstractTypeMacro (albaAgent, albaReferenceCounted) | |
ALBA_ID_DEC (AGENT_INITIALIZE) | |
void | AddObserver (albaObserver *listener, albaID channel=MCH_UP) |
void | RemoveObserver (albaObserver *listener) |
void | RemoveAllObservers () |
virtual void | OnEvent (albaEventBase *event) |
bool | HasObservers (albaID channel) |
void | GetObservers (albaID channel, std::vector< albaObserver * > &olist) |
int | Initialize () |
void | Shutdown () |
int | IsInitialized () |
virtual void | SetName (const char *name) |
const char * | GetName () |
Public Member Functions inherited from albaReferenceCounted | |
albaReferenceCounted () | |
virtual | ~albaReferenceCounted () |
albaAbstractTypeMacro (albaReferenceCounted, albaObject) | |
virtual void | Delete () |
void | Register (void *obj) |
virtual void | UnRegister (void *obj) |
int | GetReferenceCount () |
void | SetReferenceCount (int) |
Public Member Functions inherited from albaObject | |
albaObject () | |
virtual | ~albaObject () |
virtual void | Delete () |
virtual const char * | GetTypeName () const |
virtual bool | IsA (const char *type_name) const |
virtual bool | IsA (const albaTypeID &type_id) const |
virtual albaObject * | NewObjectInstance () const =0 |
virtual const albaTypeID & | GetTypeId () const |
virtual void | Print (std::ostream &os, const int indent=0) const |
albaObject (const albaObject &c) | |
Public Member Functions inherited from albaObserver | |
albaObserver () | |
virtual | ~albaObserver () |
virtual void | OnEvent (albaEventBase *e)=0 |
Public Member Functions inherited from albaEventBroadcaster | |
albaEventBroadcaster (void *owner=NULL) | |
virtual | ~albaEventBroadcaster () |
albaEventBroadcaster (const albaEventBroadcaster &c) | |
void | AddObserver (albaObserver *obj) |
void | AddObserver (albaObserver &obj) |
albaObserverCallback * | AddObserverCallback (void(*f)(void *sender, albaID eid, void *clientdata, void *calldata)) |
bool | RemoveObserver (albaObserver *obj) |
void | RemoveAllObservers () |
bool | IsObserver (albaObserver *obj) |
bool | HasObservers () |
void | GetObservers (std::vector< albaObserver * > &olist) |
void | InvokeEvent (albaEventBase &e) |
void | InvokeEvent (albaEventBase *e) |
void | InvokeEvent (void *sender, albaID id=ID_NO_EVENT, void *data=NULL) |
void | SetChannel (albaID ch) |
albaID | GetChannel () |
virtual void | SetListener (albaObserver *o) |
Public Member Functions inherited from albaEventSender | |
albaEventSender () | |
virtual void | SetListener (albaObserver *o) |
virtual albaObserver * | GetListener () |
virtual bool | HasListener () |
virtual void | InvokeEvent (albaEventBase &e) |
virtual void | InvokeEvent (albaEventBase *e) |
virtual void | InvokeEvent (void *sender, albaID id=ID_NO_EVENT, void *data=NULL) |
Protected Member Functions | |
albaAgentEventQueue () | |
virtual | ~albaAgentEventQueue () |
albaEventBase * | PopEvent () |
int | PopEvent (albaEventBase &event) |
virtual int | PopEvent (albaEventBase *&event) |
bool | GetDispatched () |
void | SetDispatched (bool value=true) |
virtual void | RequestForDispatching () |
Protected Member Functions inherited from albaAgent | |
albaAgent () | |
virtual | ~albaAgent () |
virtual int | InternalInitialize () |
virtual void | InternalShutdown () |
void | InvokeEvent (albaEventBase &event, albaID channel=-1) |
void | InvokeEvent (albaEventBase *event, albaID channel=-1) |
void | InvokeEvent (void *sender, int id, albaID channel=MCH_UP, void *data=NULL) |
Protected Attributes | |
InternalEventQueue * | m_EventQueue |
albaMutexLock * | m_Mutex |
int | m_DispatchMode |
int | m_DequeueMode |
int | m_PushMode |
bool | m_Dispatched |
Protected Attributes inherited from albaAgent | |
albaString | m_Name |
bool | m_Initialized |
std::vector< albaEventBroadcaster * > | m_Channels |
Protected Attributes inherited from albaReferenceCounted | |
int | m_ReferenceCount |
Protected Attributes inherited from albaObject | |
bool | m_HeapFlag |
Protected Attributes inherited from albaEventBroadcaster | |
albaObserversList | m_Observers |
albaID | m_Channel |
Protected Attributes inherited from albaEventSender | |
albaObserver * | m_Listener |
Additional Inherited Members | |
Static Public Member Functions inherited from albaObject | |
static const char * | GetStaticTypeName () |
static bool | IsStaticType (const char *type_name) |
static bool | IsStaticType (const albaTypeID &type_id) |
static const albaTypeID & | GetStaticTypeId () |
static albaObject * | SafeDownCast (albaObject *o) |
Protected Types inherited from albaEventBroadcaster | |
typedef std::list< albaObserver * > | albaObserversList |
Base class for managing event queueing and synchronized dispatching.
This class is thought to manage events queueing and synchronized dispatching in a multithreaded events oriented architecture. An EventQueue is a albaAgent (i.e. able to listen to events coming from other objects and passed as arguments of the OnEvent() function), but it can also process events in its queue. Events in the queue are also processed by OnEvent(), while to queue events you can use the PushEvent() function. Queued events are dispatched when the DispatchEvents() function is called. Dispatching an event means either to pass the dequeued events to the OnEvent() function (SelfProcessMode) or to rise a broadcast event having as "callData" the event itself (BroadcastMode). The default OnEvent() function forwards the event to the queue listener, but subclasses can override this virtual method. The EventQueue class is also the base class for managing the synchronization. To do this, when the first event is queued (i.e. the queue was previously empty), the albaAgentEventQueue creates a new event with ID "albaAgentEventQueue::EVENT_DISPATCH", (it's a request for dispatching) and sends it to its Listener (if present). This event should be managed by a dispatcher object, usually another queue or better a threaded agent (
When dispatching events (i.e. when DispatchEvents() is called), if the EventQueue finds a request for dispatching in the queue it calls the DispatchEvents() function of the sender (i.e. triggers the dispatching of events in that queue). As already stated, each dispatched event is either self processed by means of the OnEvent() function or broadcasted rising a broadcasting event on the original queue on the original channel. Whether self process or broadcast depends on SelfProcessMode flag (default is broadcasting).
This class is the base for managing events coming from multiple sources and to perform synchronizations (i.e. a basic form of data fusion). More complex data fusions can be performed redefining the DispacthEvents function.
Definition at line 60 of file albaAgentEventQueue.h.
Enumerator | |
---|---|
SelfProcessMode | |
BroadcastMode |
Definition at line 70 of file albaAgentEventQueue.h.
Enumerator | |
---|---|
SingleEventMode | |
MultipleEventMode |
Definition at line 75 of file albaAgentEventQueue.h.
Enumerator | |
---|---|
DispatchEventMode | |
PollingMode |
Definition at line 80 of file albaAgentEventQueue.h.
|
protected |
|
protectedvirtual |
albaAgentEventQueue::albaTypeMacro | ( | albaAgentEventQueue | , |
albaAgent | |||
) |
|
inline |
Push an event in the queue (FIFO)
Definition at line 88 of file albaAgentEventQueue.h.
References PushEvent().
Referenced by PushEvent().
|
virtual |
bool albaAgentEventQueue::PushEvent | ( | albaID | event_id, |
void * | sender, | ||
void * | data = NULL |
||
) |
albaEventBase * albaAgentEventQueue::PeekEvent | ( | ) |
return the first event in the queue (FIFO)
albaEventBase * albaAgentEventQueue::PeekLastEvent | ( | ) |
return the last event in the queue (FIFO)
int albaAgentEventQueue::GetQueueSize | ( | ) |
Return event queue size.
|
inline |
return false if there are events in the queue
Definition at line 103 of file albaAgentEventQueue.h.
|
virtual |
Dispatch events in queue;.
Reimplemented in albaDeviceManager.
|
inline |
Set the dequeuing modality during dispatching.
Possible values are SingleEventMode or MultipleEventMode, i.e. dispatching one event per time or all events contemporary.
Definition at line 111 of file albaAgentEventQueue.h.
|
inline |
Definition at line 112 of file albaAgentEventQueue.h.
|
inline |
Definition at line 113 of file albaAgentEventQueue.h.
|
inline |
Definition at line 114 of file albaAgentEventQueue.h.
|
inline |
Set the dispatch modality, i.e.
what action to perform to SingleEvent or MultipleEvent, i.e. dispatch one event per time or all events contemporary.
Definition at line 119 of file albaAgentEventQueue.h.
|
inline |
Definition at line 120 of file albaAgentEventQueue.h.
|
inline |
Definition at line 121 of file albaAgentEventQueue.h.
|
inline |
Definition at line 122 of file albaAgentEventQueue.h.
|
inline |
Set the Push modality.
If in EVENT_DISPATCH mode, the first time a new event is pushed in the queue, a EVENT_DISPATCH is sent to the Listener. If in polling mode no event is sent and events can be dispatched by explicitly calling the EVENT_DISPATCH function.
Definition at line 128 of file albaAgentEventQueue.h.
|
inline |
Definition at line 129 of file albaAgentEventQueue.h.
|
inline |
Definition at line 130 of file albaAgentEventQueue.h.
|
inline |
Definition at line 131 of file albaAgentEventQueue.h.
|
protected |
return the first event of the queue (FIFO) and remove it from the queue.
If the queue is empty the first function returns an event with dispatcher==NULL, the second returns "false" and set the event with a NULL sender.
|
protected |
|
protectedvirtual |
|
inlineprotected |
Get/Set the Dispatched flag.
This flags is true when events are in queue and not completelly dispatched yet. This function is thread safe and should be used by disps triggering the dispatching of this object events.
Definition at line 155 of file albaAgentEventQueue.h.
|
protected |
|
protectedvirtual |
Internal function used to request the dispatching.
Reimplemented in albaAgentEventHandler, and albaAgentThreaded.
|
protected |
Definition at line 164 of file albaAgentEventQueue.h.
|
protected |
Definition at line 166 of file albaAgentEventQueue.h.
|
protected |
Definition at line 168 of file albaAgentEventQueue.h.
|
protected |
Definition at line 169 of file albaAgentEventQueue.h.
|
protected |
Definition at line 170 of file albaAgentEventQueue.h.
|
protected |
Definition at line 172 of file albaAgentEventQueue.h.