ALBA
albaAgent.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaAgent
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 __albaAgent_h
18#define __albaAgent_h
19
21#include "albaObserver.h"
23#include "albaString.h"
24#include "albaEventBase.h"
25
26#ifdef ALBA_EXPORTS
27#include "albaDllMacros.h"
29#endif
30
31//----------------------------------------------------------------------------
32// forward declarations
33//----------------------------------------------------------------------------
34class vtkObject;
35class vtkCallbackCommand;
37
49class ALBA_EXPORT albaAgent: public albaReferenceCounted, public albaObserver, public albaEventBroadcaster
50{
51public:
53
54 //------------------------------------------------------------------------------
55 // Events
56 //------------------------------------------------------------------------------
59 ALBA_ID_DEC(AGENT_INITIALIZE);
60
67 void AddObserver(albaObserver *listener,albaID channel=MCH_UP);
70
76 virtual void OnEvent(albaEventBase *event);
77
79 bool HasObservers(albaID channel);
80
82 void GetObservers(albaID channel,std::vector<albaObserver *> &olist);
83
88
92 void Shutdown();
93
95 int IsInitialized() {return m_Initialized;}
96
99 virtual void SetName(const char *name) {m_Name=name;}
100 const char *GetName() {return m_Name;}
101
102protected:
104 virtual ~albaAgent();
105
108 virtual int InternalInitialize() {return 0;};
109
111 virtual void InternalShutdown() {};
112
113#ifdef ALBA_USE_VTK
117 static void InternalProcessVTKEvents(vtkObject* sender, unsigned long channel, void* clientdata, void* calldata);
118#endif
119
124 void InvokeEvent(albaEventBase &event, albaID channel=-1);
125 void InvokeEvent(albaEventBase *event, albaID channel=-1);
126 void InvokeEvent(void *sender, int id, albaID channel=MCH_UP,void *data=NULL);
127
129 bool m_Initialized; // flag set true by Initialize()
130
131 std::vector<albaEventBroadcaster *> m_Channels;
132
133#ifdef ALBA_USE_VTK
134 vtkCallbackCommand *m_EventCallbackCommand;
135#endif
136
137private:
138 albaAgent(const albaAgent&); // Not implemented.
139 void operator=(const albaAgent&); // Not implemented.
140
141};
142
143#endif
144
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 EXPORT_STL_VECTOR(declspec_, T_)
Definition: albaDllMacros.h:84
An agent is a computational object with a default I/O interface.
Definition: albaAgent.h:50
albaString m_Name
Definition: albaAgent.h:128
void InvokeEvent(albaEventBase &event, albaID channel=-1)
This function make an event to be passed to observers of this class for the specified channel.
void InvokeEvent(albaEventBase *event, albaID channel=-1)
albaAbstractTypeMacro(albaAgent, albaReferenceCounted)
virtual void OnEvent(albaEventBase *event)
Process an event: the event is processed immediately and synchronously, i.e.
virtual void InternalShutdown()
to be redefined by subclasses to define the shutdown actions
Definition: albaAgent.h:111
void Shutdown()
Shutdown the agent, Subclasses can redefine InternalShutdown() to customize actions for shutting down...
void AddObserver(albaObserver *listener, albaID channel=MCH_UP)
Attach/Detach this object as event source for the specified listener.
void InvokeEvent(void *sender, int id, albaID channel=MCH_UP, void *data=NULL)
void RemoveObserver(albaObserver *listener)
void GetObservers(albaID channel, std::vector< albaObserver * > &olist)
return a list of the observers on a channel
const char * GetName()
Definition: albaAgent.h:100
virtual ~albaAgent()
int IsInitialized()
Return true if this agent has been initialized.
Definition: albaAgent.h:95
bool m_Initialized
Definition: albaAgent.h:129
virtual void SetName(const char *name)
The Agent name is used to identify the Agent in a unique way.
Definition: albaAgent.h:99
virtual int InternalInitialize()
This function is overridden by subclasses to perform custom initialization.
Definition: albaAgent.h:108
std::vector< albaEventBroadcaster * > m_Channels
Definition: albaAgent.h:131
bool HasObservers(albaID channel)
return true if there's an observer on the specified channel.
int Initialize()
Initialize this agent.
void RemoveAllObservers()
Implementation of the message object for the Subject/Observer design pattern.
Definition: albaEventBase.h:49
This class inerith form albaEventSender and extends albaEventSender with the capacity of send events ...
Interface implementing the Observer of the Subject/Observer design pattern.
Definition: albaObserver.h:36
albaReferenceCounted - abstract base class for ALBA objects with reference counting.
albaString - performs common string operations on c-strings.
Definition: albaString.h:43
ALBA_ID_DEC(AGENT_INITIALIZE)
Event used to force initialization of this object.