ALBA
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
albaAgentThreaded Class Reference

#include <albaAgentThreaded.h>

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

Public Member Functions

 ALBA_ID_DEC (AGENT_ASYNC_DISPATCH)
 
 albaTypeMacro (albaAgentThreaded, albaAgentEventQueue)
 
int GetThreaded ()
 
void SetThreaded (int flag)
 
int Update ()
 
virtual void OnEvent (albaEventBase *event)
 
void AsyncSendEvent (albaObserver *target, albaEventBase *event, albaID channel=MCH_UP)
 
void AsyncSendEvent (albaObserver *target, void *sender, albaID id, albaID channel=MCH_UP, void *data=NULL)
 
void AsyncInvokeEvent (albaEventBase *event, albaID channel=MCH_UP)
 
void AsyncInvokeEvent (albaID id, albaID channel=MCH_UP, void *data=NULL)
 
- Public Member Functions inherited from albaAgentEventQueue
 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

 albaAgentThreaded ()
 
virtual ~albaAgentThreaded ()
 
virtual void RequestForDispatching ()
 
void StopThread ()
 
virtual int InternalInitialize ()
 
virtual void InternalShutdown ()
 
virtual int InternalUpdate ()
 
int GetActiveFlag ()
 
void SignalNewMessage ()
 
void WaitForNewMessage ()
 
- Protected Member Functions inherited from albaAgentEventQueue
 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)
 

Static Protected Member Functions

static void UpdateLoop (mmuThreadInfoStruct *data)
 

Protected Attributes

albaMultiThreaderm_Threader
 
mmuThreadInfoStructm_ThreadData
 
int m_ThreadId
 
int m_Threaded
 
int m_ActiveFlag
 
albaMutexLockm_Gate
 
- Protected Attributes inherited from albaAgentEventQueue
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

- Public Types inherited from albaAgentEventQueue
enum  DispatchModalities { SelfProcessMode = 0 , BroadcastMode }
 
enum  PopModalities { SingleEventMode = 0 , MultipleEventMode }
 
enum  PushModalities { DispatchEventMode =0 , PollingMode }
 
- 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

An agent processing the queued events on a separate thread.

This is a special case of agent, able to run a separate thread for processing queued events. The class also features an asynchronous mechanism for sending events to observers, allowing the internal thread to send an event to be processed by a separate thread. This happens by queuing the output event wrapped in a AGENT_ASYNC_DISPATCH, which is later on processed in the main thread, by using the original albaAgentEventQueue mechanism for dispatching. Notice that, the asynchronous mechanism requires the of this class to be called on a different thread. Dispatching on another thread is therefore responsibility of a different class, specifically designed to process it incoming events on a different tread (e.g. albaAgentEventHandler). The albaAgentThreaded DispatchEvents() will take care of extracting the message contained inside a AGENT_ASYNC_DISPATCH event type and dispatch it.

See also
albaAgent albaAgentEventQueue albaEventBase

Definition at line 43 of file albaAgentThreaded.h.

Constructor & Destructor Documentation

◆ albaAgentThreaded()

albaAgentThreaded::albaAgentThreaded ( )
protected

◆ ~albaAgentThreaded()

virtual albaAgentThreaded::~albaAgentThreaded ( )
protectedvirtual

Member Function Documentation

◆ ALBA_ID_DEC()

albaAgentThreaded::ALBA_ID_DEC ( AGENT_ASYNC_DISPATCH  )

◆ albaTypeMacro()

albaAgentThreaded::albaTypeMacro ( albaAgentThreaded  ,
albaAgentEventQueue   
)

◆ GetThreaded()

int albaAgentThreaded::GetThreaded ( )
inline

Return true if this is a Agent with its own polling thread.

Dispatchers requiring a polling thread set this variable to != 0, which makes the initialize function to spawn a thread with a loop continuously calling the InternalUpdate() function.

Definition at line 57 of file albaAgentThreaded.h.

◆ SetThreaded()

void albaAgentThreaded::SetThreaded ( int  flag)
inline

This is used to enable thread spawning for this Agent.

Definition at line 61 of file albaAgentThreaded.h.

◆ Update()

int albaAgentThreaded::Update ( )
inline

This function forces the agent to update its state.

Return 0 if Update is OK.

Definition at line 65 of file albaAgentThreaded.h.

References albaAgent::IsInitialized().

Here is the call graph for this function:

◆ OnEvent()

virtual void albaAgentThreaded::OnEvent ( albaEventBase event)
virtual

This function enques events to be processed by agent.

Events are processed by agent's thread by means of the ProcessDispatchedEvent() function.

Reimplemented from albaAgent.

Reimplemented in albaDevice, albaDeviceButtonsPadMouse, albaDeviceButtonsPadTracker, and albaDeviceSet.

◆ AsyncSendEvent() [1/2]

void albaAgentThreaded::AsyncSendEvent ( albaObserver target,
albaEventBase event,
albaID  channel = MCH_UP 
)

Send an event to the specified object (i.e.

Post to that listener) asynchronously. This happens by queuing the output event wrapped in a AGENT_ASYNC_DISPATCH, which is processed in the main thread, by using the original albaAgentEventQueue mechanism for dispatching.

See also
SendEvent() for general semantic

◆ AsyncSendEvent() [2/2]

void albaAgentThreaded::AsyncSendEvent ( albaObserver target,
void *  sender,
albaID  id,
albaID  channel = MCH_UP,
void *  data = NULL 
)

◆ AsyncInvokeEvent() [1/2]

void albaAgentThreaded::AsyncInvokeEvent ( albaEventBase event,
albaID  channel = MCH_UP 
)

This function implements asynchronous forward of an event.

This happens by queuing the output event wrapped in a AGENT_ASYNC_DISPATCH, which is processed in the main thread, by using the original albaAgentEventQueue mechanism for dispatching.

See also
InvokeEvent() for general semantic

◆ AsyncInvokeEvent() [2/2]

void albaAgentThreaded::AsyncInvokeEvent ( albaID  id,
albaID  channel = MCH_UP,
void *  data = NULL 
)

◆ RequestForDispatching()

virtual void albaAgentThreaded::RequestForDispatching ( )
protectedvirtual

Internal function used to request the dispatching.

Reimplemented from albaAgentEventQueue.

◆ StopThread()

void albaAgentThreaded::StopThread ( )
protected

◆ InternalInitialize()

virtual int albaAgentThreaded::InternalInitialize ( )
protectedvirtual

This function is overridden by subclasses to perform custom initialization.

Reimplemented from albaAgent.

Reimplemented in albaDevice, albaDeviceButtonsPadTracker, albaDeviceButtonsPadTrackerP5Glove, albaDeviceSet, and albaDeviceTrackerWIIMote.

◆ InternalShutdown()

virtual void albaAgentThreaded::InternalShutdown ( )
protectedvirtual

to be redefined by subclasses to define the shutdown actions

Reimplemented from albaAgent.

Reimplemented in albaDeviceButtonsPadTracker, albaDeviceButtonsPadTrackerP5Glove, albaDeviceSet, and albaDeviceTrackerWIIMote.

◆ InternalUpdate()

virtual int albaAgentThreaded::InternalUpdate ( )
protectedvirtual

This function must be overridden by subclasses to perform custom polling of dispatcher when in threaded mode.

This function should poll the dispatcher and return 0. In case it returns a value !=0 the polling loop is stopped. The default function stops immediately the loop.

Reimplemented in albaDeviceButtonsPadTrackerP5Glove, and albaDeviceTrackerWIIMote.

◆ UpdateLoop()

static void albaAgentThreaded::UpdateLoop ( mmuThreadInfoStruct data)
staticprotected

This function is used to startup the thread.

Subclasses should override the InternalUpdateLoop() function which is called by this one.

◆ GetActiveFlag()

int albaAgentThreaded::GetActiveFlag ( )
protected

Get the present value of the Thread Active flag.

This function is thread safe and returns the value of the activeFlag member variable of the ThreadInfoStruct stored in ThreadData.

◆ SignalNewMessage()

void albaAgentThreaded::SignalNewMessage ( )
protected

Internal functions used to send a wakeup signal among the different threads.

◆ WaitForNewMessage()

void albaAgentThreaded::WaitForNewMessage ( )
protected

Member Data Documentation

◆ m_Threader

albaMultiThreader* albaAgentThreaded::m_Threader
protected

Definition at line 121 of file albaAgentThreaded.h.

◆ m_ThreadData

mmuThreadInfoStruct* albaAgentThreaded::m_ThreadData
protected

Definition at line 122 of file albaAgentThreaded.h.

◆ m_ThreadId

int albaAgentThreaded::m_ThreadId
protected

Definition at line 124 of file albaAgentThreaded.h.

◆ m_Threaded

int albaAgentThreaded::m_Threaded
protected

Definition at line 125 of file albaAgentThreaded.h.

◆ m_ActiveFlag

int albaAgentThreaded::m_ActiveFlag
protected

Definition at line 126 of file albaAgentThreaded.h.

◆ m_Gate

albaMutexLock* albaAgentThreaded::m_Gate
protected

This mutex is normally locked.

It is used to block the execution of the receiving process when the send has not been called yet.

Definition at line 135 of file albaAgentThreaded.h.


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