ALBA
albaAgentThreaded.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaAgentThreaded
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 __albaAgentThreaded_h
18#define __albaAgentThreaded_h
19
20#include "albaAgentEventQueue.h"
21#include "albaMultiThreader.h"
22
23//------------------------------------------------------------------------------
24// Forward declarations:
25//------------------------------------------------------------------------------
26class albaMutexLock;
27
43class ALBA_EXPORT albaAgentThreaded : public albaAgentEventQueue
44{
45public:
46 //------------------------------------------------------------------------------
47 // Events
48 //------------------------------------------------------------------------------
49 ALBA_ID_DEC(AGENT_ASYNC_DISPATCH);
50
52
57 int GetThreaded() {return m_Threaded;}
58
61 void SetThreaded(int flag){m_Threaded=flag;}
62
65 int Update() {return IsInitialized()?InternalUpdate():-1;}
66
70 virtual void OnEvent(albaEventBase *event);
71
78 void AsyncSendEvent(albaObserver *target,albaEventBase *event, albaID channel=MCH_UP);
79 void AsyncSendEvent(albaObserver *target, void *sender, albaID id, albaID channel=MCH_UP,void *data=NULL);
80
87 void AsyncInvokeEvent(albaID id, albaID channel=MCH_UP,void *data=NULL);
88
89protected:
92
94 virtual void RequestForDispatching();
95 void StopThread();
96 virtual int InternalInitialize();
97 virtual void InternalShutdown();
98
103 virtual int InternalUpdate();
104
108 static void UpdateLoop(mmuThreadInfoStruct *data);
109
115
120
123
127
128#ifdef _WIN32
129
131 HANDLE m_MessageSignal;
132#else
133
136#endif
137
138private:
139 albaAgentThreaded(const albaAgentThreaded&); // Not implemented.
140 void operator=(const albaAgentThreaded&); // Not implemented.
141};
142
143#endif
MCH_UP
channel used to send events up in the tree
Definition: albaDecl.h:387
long albaID
type for IDs inside ALBA
Definition: albaDefines.h:58
#define mmuThreadInfoStruct
This is the structure that is passed to the thread that is created from the SingleMethodExecute,...
Base class for managing event queueing and synchronized dispatching.
An agent processing the queued events on a separate thread.
int GetActiveFlag()
Get the present value of the Thread Active flag.
static void UpdateLoop(mmuThreadInfoStruct *data)
This function is used to startup the thread.
ALBA_ID_DEC(AGENT_ASYNC_DISPATCH)
virtual int InternalInitialize()
This function is overridden by subclasses to perform custom initialization.
virtual int InternalUpdate()
This function must be overridden by subclasses to perform custom polling of dispatcher when in thread...
void AsyncSendEvent(albaObserver *target, albaEventBase *event, albaID channel=MCH_UP)
Send an event to the specified object (i.e.
virtual ~albaAgentThreaded()
void SignalNewMessage()
Internal functions used to send a wakeup signal among the different threads.
void SetThreaded(int flag)
This is used to enable thread spawning for this Agent.
virtual void InternalShutdown()
to be redefined by subclasses to define the shutdown actions
virtual void OnEvent(albaEventBase *event)
This function enques events to be processed by agent.
int GetThreaded()
Return true if this is a Agent with its own polling thread.
albaTypeMacro(albaAgentThreaded, albaAgentEventQueue)
mmuThreadInfoStruct * m_ThreadData
void WaitForNewMessage()
void AsyncSendEvent(albaObserver *target, void *sender, albaID id, albaID channel=MCH_UP, void *data=NULL)
void AsyncInvokeEvent(albaEventBase *event, albaID channel=MCH_UP)
This function implements asynchronous forward of an event.
void AsyncInvokeEvent(albaID id, albaID channel=MCH_UP, void *data=NULL)
albaMutexLock * m_Gate
This mutex is normally locked.
albaMultiThreader * m_Threader
int Update()
This function forces the agent to update its state.
virtual void RequestForDispatching()
Internal function used to request the dispatching.
int IsInitialized()
Return true if this agent has been initialized.
Definition: albaAgent.h:95
Implementation of the message object for the Subject/Observer design pattern.
Definition: albaEventBase.h:49
albaMultiThreader - A class for performing multithreaded execution.
Critical section locking class that can be allocated on the stack.
Definition: albaMutexLock.h:33
Interface implementing the Observer of the Subject/Observer design pattern.
Definition: albaObserver.h:36