ALBA
albaAgentEventQueue.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaAgentEventQueue
5 Authors: Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16
17#ifndef __albaAgentEventQueue_h
18#define __albaAgentEventQueue_h
19
20#include "albaAgent.h"
21
22
23//----------------------------------------------------------------------------
24// forward declarations
25//----------------------------------------------------------------------------
26class albaMutexLock;
27
60class ALBA_EXPORT albaAgentEventQueue : public albaAgent
61{
62public:
63 //------------------------------------------------------------------------------
64 // Events
65 //------------------------------------------------------------------------------
68 ALBA_ID_DEC(EVENT_DISPATCH);
69
71 SelfProcessMode = 0,
72 BroadcastMode
73 };
74
76 SingleEventMode = 0,
77 MultipleEventMode
78 };
79
81 DispatchEventMode=0,
82 PollingMode
83 };
84
86
88 bool PushEvent(albaEventBase &event) {return PushEvent(&event);}
89 virtual bool PushEvent(albaEventBase *event);
90 bool PushEvent(albaID event_id, void *sender, void *data=NULL);
91
95
98
101
103 bool IsQueueEmpty() {return this->GetQueueSize()==0;}
104
106 virtual bool DispatchEvents();
107
111 void SetDequeueMode(int mode) {m_DequeueMode=mode;}
112 int GetDequeueMode() {return m_DequeueMode;}
113 void SetDequeueModeToMultipleEvent() {SetDequeueMode(MultipleEventMode);}
114 void SetDequeueModeToSingleEvent() {SetDequeueMode(SingleEventMode);}
115
119 void SetDispatchMode(int mode) {m_DispatchMode=mode;}
120 int GetDispatchMode() {return m_DispatchMode;}
121 void SetDispatchModeToSelfProcess() {SetDispatchMode(SelfProcessMode);}
122 void SetDispatchModeToBroadcast() {SetDispatchMode(BroadcastMode);}
123
128 void SetPushMode(int mode) {m_PushMode=mode;}
129 int GetPushMode() {return m_PushMode;}
130 void SetPushModeToDispatchEvent() {m_PushMode=DispatchEventMode;}
131 void SetPushModeToPolling() {m_PushMode=PollingMode;}
132
133protected:
136
137 //------------------------------------------------------------------------------
138 // Forward declarations
139 //------------------------------------------------------------------------------
140 class EventQueueItem;
141 struct InternalEventQueue;
142
149 virtual int PopEvent(albaEventBase *&event);
150
155 bool GetDispatched() {return m_Dispatched;}
156 void SetDispatched(bool value=true);
157
158 //virtual void SetListener(albaAgent *listener) {this->Superclass::SetListener(listener);}
159
162 virtual void RequestForDispatching();
163
164 InternalEventQueue *m_EventQueue;
165
167
171
173
174private:
175 albaAgentEventQueue(const albaAgentEventQueue&); // Not implemented.
176 void operator=(const albaAgentEventQueue&); // Not implemented.
177
178};
179
180
181#endif
long albaID
type for IDs inside ALBA
Definition: albaDefines.h:58
Base class for managing event queueing and synchronized dispatching.
bool GetDispatched()
Get/Set the Dispatched flag.
virtual int PopEvent(albaEventBase *&event)
bool PushEvent(albaID event_id, void *sender, void *data=NULL)
albaTypeMacro(albaAgentEventQueue, albaAgent)
void SetPushMode(int mode)
Set the Push modality.
bool PushEvent(albaEventBase &event)
Push an event in the queue (FIFO)
void SetDispatched(bool value=true)
virtual bool PushEvent(albaEventBase *event)
virtual ~albaAgentEventQueue()
InternalEventQueue * m_EventQueue
virtual void RequestForDispatching()
Internal function used to request the dispatching.
void SetDequeueMode(int mode)
Set the dequeuing modality during dispatching.
bool IsQueueEmpty()
return false if there are events in the queue
int PopEvent(albaEventBase &event)
int GetQueueSize()
Return event queue size.
albaEventBase * PeekLastEvent()
return the last event in the queue (FIFO)
void SetDispatchMode(int mode)
Set the dispatch modality, i.e.
albaEventBase * PopEvent()
return the first event of the queue (FIFO) and remove it from the queue.
albaEventBase * PeekEvent()
return the first event in the queue (FIFO)
virtual bool DispatchEvents()
Dispatch events in queue;.
An agent is a computational object with a default I/O interface.
Definition: albaAgent.h:50
Implementation of the message object for the Subject/Observer design pattern.
Definition: albaEventBase.h:49
Critical section locking class that can be allocated on the stack.
Definition: albaMutexLock.h:33
ALBA_ID_DEC(EVENT_DISPATCH)
This is used by queues to manage synchronization (see class description)