ALBA
|
#include <albaAgentThreaded.h>
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) |
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 | |
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 () |
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) |
Static Protected Member Functions | |
static void | UpdateLoop (mmuThreadInfoStruct *data) |
Protected Attributes | |
albaMultiThreader * | m_Threader |
mmuThreadInfoStruct * | m_ThreadData |
int | m_ThreadId |
int | m_Threaded |
int | m_ActiveFlag |
albaMutexLock * | m_Gate |
Protected Attributes inherited from albaAgentEventQueue | |
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 | |
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 albaTypeID & | GetStaticTypeId () |
static albaObject * | SafeDownCast (albaObject *o) |
Protected Types inherited from albaEventBroadcaster | |
typedef std::list< albaObserver * > | albaObserversList |
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.
Definition at line 43 of file albaAgentThreaded.h.
|
protected |
|
protectedvirtual |
albaAgentThreaded::ALBA_ID_DEC | ( | AGENT_ASYNC_DISPATCH | ) |
albaAgentThreaded::albaTypeMacro | ( | albaAgentThreaded | , |
albaAgentEventQueue | |||
) |
|
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.
|
inline |
This is used to enable thread spawning for this Agent.
Definition at line 61 of file albaAgentThreaded.h.
|
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().
|
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.
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.
void albaAgentThreaded::AsyncSendEvent | ( | albaObserver * | target, |
void * | sender, | ||
albaID | id, | ||
albaID | channel = MCH_UP , |
||
void * | data = NULL |
||
) |
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.
|
protectedvirtual |
Internal function used to request the dispatching.
Reimplemented from albaAgentEventQueue.
|
protected |
|
protectedvirtual |
This function is overridden by subclasses to perform custom initialization.
Reimplemented from albaAgent.
Reimplemented in albaDevice, albaDeviceButtonsPadTracker, albaDeviceButtonsPadTrackerP5Glove, albaDeviceSet, and albaDeviceTrackerWIIMote.
|
protectedvirtual |
to be redefined by subclasses to define the shutdown actions
Reimplemented from albaAgent.
Reimplemented in albaDeviceButtonsPadTracker, albaDeviceButtonsPadTrackerP5Glove, albaDeviceSet, and albaDeviceTrackerWIIMote.
|
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.
|
staticprotected |
This function is used to startup the thread.
Subclasses should override the InternalUpdateLoop() function which is called by this one.
|
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.
|
protected |
Internal functions used to send a wakeup signal among the different threads.
|
protected |
|
protected |
Definition at line 121 of file albaAgentThreaded.h.
|
protected |
Definition at line 122 of file albaAgentThreaded.h.
|
protected |
Definition at line 124 of file albaAgentThreaded.h.
|
protected |
Definition at line 125 of file albaAgentThreaded.h.
|
protected |
Definition at line 126 of file albaAgentThreaded.h.
|
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.