ALBA
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
albaAgentEventQueue Class Reference

#include <albaAgentEventQueue.h>

Inheritance diagram for albaAgentEventQueue:
Inheritance graph
[legend]
Collaboration diagram for albaAgentEventQueue:
Collaboration graph
[legend]

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)
 
albaEventBasePeekEvent ()
 
albaEventBasePeekLastEvent ()
 
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 albaObjectNewObjectInstance () const =0
 
virtual const albaTypeIDGetTypeId () 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)
 
albaObserverCallbackAddObserverCallback (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 albaObserverGetListener ()
 
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 ()
 
albaEventBasePopEvent ()
 
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
 
albaMutexLockm_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
albaObserverm_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 albaTypeIDGetStaticTypeId ()
 
static albaObjectSafeDownCast (albaObject *o)
 
- Protected Types inherited from albaEventBroadcaster
typedef std::list< albaObserver * > albaObserversList
 

Detailed Description

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 (

See also
mflThreadedAgent and albaEventHandler). If a albaAgentEventQueue::EVENT_DISPATCH is found, while dispatching events in the queue, it's not processed by OnEvent and neither broadcasted, but the DispatchEvents() function of the sender object is called. Dispatching of events in a separate thread can be performed by calling PushEvent() when an incoming event is found to be a albaAgentEventQueue::EVENT_DISPATCH during the OnEvent() (see albaDeviceManager).

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.

See also
albaAgent albaAgentThreaded albaAgentEventHandler

Definition at line 60 of file albaAgentEventQueue.h.

Member Enumeration Documentation

◆ DispatchModalities

Enumerator
SelfProcessMode 
BroadcastMode 

Definition at line 70 of file albaAgentEventQueue.h.

◆ PopModalities

Enumerator
SingleEventMode 
MultipleEventMode 

Definition at line 75 of file albaAgentEventQueue.h.

◆ PushModalities

Enumerator
DispatchEventMode 
PollingMode 

Definition at line 80 of file albaAgentEventQueue.h.

Constructor & Destructor Documentation

◆ albaAgentEventQueue()

albaAgentEventQueue::albaAgentEventQueue ( )
protected

◆ ~albaAgentEventQueue()

virtual albaAgentEventQueue::~albaAgentEventQueue ( )
protectedvirtual

Member Function Documentation

◆ albaTypeMacro()

albaAgentEventQueue::albaTypeMacro ( albaAgentEventQueue  ,
albaAgent   
)

◆ PushEvent() [1/3]

bool albaAgentEventQueue::PushEvent ( albaEventBase event)
inline

Push an event in the queue (FIFO)

Definition at line 88 of file albaAgentEventQueue.h.

References PushEvent().

Referenced by PushEvent().

Here is the call graph for this function:

◆ PushEvent() [2/3]

virtual bool albaAgentEventQueue::PushEvent ( albaEventBase event)
virtual

◆ PushEvent() [3/3]

bool albaAgentEventQueue::PushEvent ( albaID  event_id,
void *  sender,
void *  data = NULL 
)

◆ PeekEvent()

albaEventBase * albaAgentEventQueue::PeekEvent ( )

return the first event in the queue (FIFO)

◆ PeekLastEvent()

albaEventBase * albaAgentEventQueue::PeekLastEvent ( )

return the last event in the queue (FIFO)

◆ GetQueueSize()

int albaAgentEventQueue::GetQueueSize ( )

Return event queue size.

◆ IsQueueEmpty()

bool albaAgentEventQueue::IsQueueEmpty ( )
inline

return false if there are events in the queue

Definition at line 103 of file albaAgentEventQueue.h.

◆ DispatchEvents()

virtual bool albaAgentEventQueue::DispatchEvents ( )
virtual

Dispatch events in queue;.

Reimplemented in albaDeviceManager.

◆ SetDequeueMode()

void albaAgentEventQueue::SetDequeueMode ( int  mode)
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.

◆ GetDequeueMode()

int albaAgentEventQueue::GetDequeueMode ( )
inline

Definition at line 112 of file albaAgentEventQueue.h.

◆ SetDequeueModeToMultipleEvent()

void albaAgentEventQueue::SetDequeueModeToMultipleEvent ( )
inline

Definition at line 113 of file albaAgentEventQueue.h.

◆ SetDequeueModeToSingleEvent()

void albaAgentEventQueue::SetDequeueModeToSingleEvent ( )
inline

Definition at line 114 of file albaAgentEventQueue.h.

◆ SetDispatchMode()

void albaAgentEventQueue::SetDispatchMode ( int  mode)
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.

◆ GetDispatchMode()

int albaAgentEventQueue::GetDispatchMode ( )
inline

Definition at line 120 of file albaAgentEventQueue.h.

◆ SetDispatchModeToSelfProcess()

void albaAgentEventQueue::SetDispatchModeToSelfProcess ( )
inline

Definition at line 121 of file albaAgentEventQueue.h.

◆ SetDispatchModeToBroadcast()

void albaAgentEventQueue::SetDispatchModeToBroadcast ( )
inline

Definition at line 122 of file albaAgentEventQueue.h.

◆ SetPushMode()

void albaAgentEventQueue::SetPushMode ( int  mode)
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.

◆ GetPushMode()

int albaAgentEventQueue::GetPushMode ( )
inline

Definition at line 129 of file albaAgentEventQueue.h.

◆ SetPushModeToDispatchEvent()

void albaAgentEventQueue::SetPushModeToDispatchEvent ( )
inline

Definition at line 130 of file albaAgentEventQueue.h.

◆ SetPushModeToPolling()

void albaAgentEventQueue::SetPushModeToPolling ( )
inline

Definition at line 131 of file albaAgentEventQueue.h.

◆ PopEvent() [1/3]

albaEventBase * albaAgentEventQueue::PopEvent ( )
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.

◆ PopEvent() [2/3]

int albaAgentEventQueue::PopEvent ( albaEventBase event)
protected

◆ PopEvent() [3/3]

virtual int albaAgentEventQueue::PopEvent ( albaEventBase *&  event)
protectedvirtual

◆ GetDispatched()

bool albaAgentEventQueue::GetDispatched ( )
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.

◆ SetDispatched()

void albaAgentEventQueue::SetDispatched ( bool  value = true)
protected

◆ RequestForDispatching()

virtual void albaAgentEventQueue::RequestForDispatching ( )
protectedvirtual

Internal function used to request the dispatching.

Reimplemented in albaAgentEventHandler, and albaAgentThreaded.

Member Data Documentation

◆ m_EventQueue

InternalEventQueue* albaAgentEventQueue::m_EventQueue
protected

Definition at line 164 of file albaAgentEventQueue.h.

◆ m_Mutex

albaMutexLock* albaAgentEventQueue::m_Mutex
protected

Definition at line 166 of file albaAgentEventQueue.h.

◆ m_DispatchMode

int albaAgentEventQueue::m_DispatchMode
protected

Definition at line 168 of file albaAgentEventQueue.h.

◆ m_DequeueMode

int albaAgentEventQueue::m_DequeueMode
protected

Definition at line 169 of file albaAgentEventQueue.h.

◆ m_PushMode

int albaAgentEventQueue::m_PushMode
protected

Definition at line 170 of file albaAgentEventQueue.h.

◆ m_Dispatched

bool albaAgentEventQueue::m_Dispatched
protected

Definition at line 172 of file albaAgentEventQueue.h.


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