Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkEventBroker.h
Go to the documentation of this file.
1/*=auto=========================================================================
2
3 Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8 Program: 3D Slicer
9 Module: $RCSfile: vtkEventBroker.h,v $
10 Date: $Date: 2006/01/08 04:48:05 $
11 Version: $Revision: 1.45 $
12
13=========================================================================auto=*/
14
15#ifndef __vtkEventBroker_h
16#define __vtkEventBroker_h
17
18// MRML includes
19#include "vtkMRML.h"
20
21// VTK includes
22#include <vtkObject.h>
23class vtkTimerLog;
24
25// STD includes
26#include <deque>
27#include <vector>
28#include <set>
29#include <map>
30#include <fstream>
31
32class vtkCollection;
33class vtkCallbackCommand;
34class vtkObservation;
35
44//
49class VTK_MRML_EXPORT vtkEventBroker : public vtkObject
50{
51public:
52 vtkTypeMacro(vtkEventBroker, vtkObject);
53 void PrintSelf(ostream& os, vtkIndent indent) override;
54
55 typedef std::set<vtkObservation*> ObservationVector;
56
60
68
75 static void Callback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
76
81 vtkObservation* AddObservation(vtkObject* subject, unsigned long event, vtkObject* observer, vtkCallbackCommand* notify, float priority = 0.0f);
82
86 vtkObservation* AddObservation(vtkObject* subject, const char* event, const char* script);
87
91
97 void RemoveObservations(vtkObject* observer);
98 void RemoveObservations(vtkObject* subject, vtkObject* observer);
99 void RemoveObservations(vtkObject* subject, unsigned long event, vtkObject* observer);
100 void RemoveObservations(vtkObject* subject, unsigned long event, vtkObject* observer, vtkCallbackCommand* notify);
101 void RemoveObservationsForSubjectByTag(vtkObject* subject, unsigned long tag);
109 unsigned long event = 0,
110 vtkObject* observer = nullptr,
111 vtkCallbackCommand* notify = nullptr,
112 unsigned int maxReturnedObservations = 0);
114 bool GetObservationExist(vtkObject* subject, unsigned long event = 0, vtkObject* observer = nullptr, vtkCallbackCommand* notify = nullptr);
115 ObservationVector GetObservationsForSubjectByTag(vtkObject* subject, unsigned long tag);
116
121 vtkCollection* GetObservationsForSubject(vtkObject* subject);
122 vtkCollection* GetObservationsForObserver(vtkObject* observer);
123 vtkCollection* GetObservationsForCallback(vtkCallbackCommand* callback);
124
129
132 void ProcessEvent(vtkObservation* observation, vtkObject* caller, unsigned long eid, void* callData);
133
137 vtkBooleanMacro(EventLogging, int);
138 vtkSetMacro(EventLogging, int);
139 vtkGetMacro(EventLogging, int);
140
144 vtkSetMacro(EventNestingLevel, int);
145 vtkGetMacro(EventNestingLevel, int);
146
149 vtkSetStringMacro(LogFileName);
150 vtkGetStringMacro(LogFileName);
151
154 virtual void SetTimerLog(vtkTimerLog* timerLog);
155 vtkGetObjectMacro(TimerLog, vtkTimerLog);
156
161
165 void LogEvent(vtkObservation* observation);
166
170 int GenerateGraphFile(const char* graphFile);
171
182 vtkGetMacro(EventMode, int);
183 void SetEventMode(int eventMode)
184 {
185 if (eventMode != this->EventMode)
186 {
187 this->EventMode = eventMode;
188 this->ProcessEventQueue();
189 this->Modified();
190 }
191 };
192
196 {
198 {
199 return ("Synchronous");
200 }
202 {
203 return ("Asynchronous");
204 }
205 return "Undefined";
206 }
207
209
218 void QueueObservation(vtkObservation* observation, unsigned long eid, void* callData);
222 void InvokeObservation(vtkObservation* observation, unsigned long eid, void* callData);
224
232 vtkBooleanMacro(CompressCallData, int);
233 vtkGetMacro(CompressCallData, int);
234 vtkSetMacro(CompressCallData, int);
235
238 void SetScriptHandler(void (*scriptHandler)(const char* script, void* clientData), void* clientData)
239 {
240 this->ScriptHandler = scriptHandler;
241 this->ScriptHandlerClientData = clientData;
242 }
243
248 virtual bool RequestModified(vtkObject* object);
249
252 virtual void SetRequestModifiedCallback(vtkCallbackCommand* callback);
253 vtkGetObjectMacro(RequestModifiedCallback, vtkCallbackCommand);
254
255protected:
257 ~vtkEventBroker() override;
260
263 static void classInitialize();
264 static void classFinalize();
265
274
277
279 typedef std::map<vtkObject*, ObservationVector> ObjectToObservationVectorMap;
280
284
286 std::deque<vtkObservation*> EventQueue;
287
288 void (*ScriptHandler)(const char* script, void* clientData);
290
294 vtkTimerLog* TimerLog;
295
298
299 std::ofstream LogFile;
300
301 vtkCallbackCommand* RequestModifiedCallback;
302
303private:
307 void DetachObservations();
309 friend class vtkObservation;
310};
311
313class VTK_MRML_EXPORT vtkEventBrokerInitialize
314{
315public:
317
320
321private:
322 static unsigned int Count;
323};
324
329
330#endif
Utility class to make sure qSlicerModuleManager is initialized before it is used.
vtkEventBrokerInitialize Self
static void classFinalize()
void RemoveObservations(vtkObject *subject, vtkObject *observer)
std::set< vtkObservation * > ObservationVector
void RemoveObservations(vtkObject *subject, unsigned long event, vtkObject *observer)
static void Callback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
const char * GetEventModeAsString()
bool GetObservationExist(vtkObject *subject, unsigned long event=0, vtkObject *observer=nullptr, vtkCallbackCommand *notify=nullptr)
Returns true if such an observation exists (arguments are same as for GetObservations)
void RemoveObservations(vtkObject *observer)
vtkObservation * DequeueObservation()
void SetEventModeToSynchronous()
int GenerateGraphFile(const char *graphFile)
virtual void SetRequestModifiedCallback(vtkCallbackCommand *callback)
void * ScriptHandlerClientData
std::deque< vtkObservation * > EventQueue
The event queue of triggered but not-yet-invoked observations.
std::map< vtkObject *, ObservationVector > ObjectToObservationVectorMap
void SetEventModeToAsynchronous()
void InvokeObservation(vtkObservation *observation, unsigned long eid, void *callData)
void QueueObservation(vtkObservation *observation, unsigned long eid, void *callData)
Event queue processing.
virtual void SetTimerLog(vtkTimerLog *timerLog)
Timer log class for calculating elapsed time for event invocations.
virtual bool RequestModified(vtkObject *object)
static vtkEventBroker * GetInstance()
Return the singleton instance with no reference counting.
void SetEventMode(int eventMode)
void LogEvent(vtkObservation *observation)
void DetachObservation(vtkObservation *observation)
void RemoveObservation(vtkObservation *observation)
Remove observation from the broker and event queue.
vtkObservation * GetNthQueuedObservation(int n)
std::ofstream LogFile
void RemoveObservations(ObservationVector observations)
ObservationVector GetObservations(vtkObject *subject, unsigned long event=0, vtkObject *observer=nullptr, vtkCallbackCommand *notify=nullptr, unsigned int maxReturnedObservations=0)
int GetNumberOfObservations()
Accessors for Observations.
void ProcessEvent(vtkObservation *observation, vtkObject *caller, unsigned long eid, void *callData)
Process any event that comes from either subject or observer.
void SetScriptHandler(void(*scriptHandler)(const char *script, void *clientData), void *clientData)
Sets the method pointer to be used for processing script observations.
vtkObservation * AddObservation(vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify, float priority=0.0f)
vtkCollection * GetObservationsForObserver(vtkObject *observer)
ObservationVector GetSubjectObservations(vtkObject *subject)
Fast retrieve of all observations of a given subject.
vtkEventBroker(const vtkEventBroker &)
static void classInitialize()
Singleton management functions.
void ProcessEventQueue()
void RemoveObservationsForSubjectByTag(vtkObject *subject, unsigned long tag)
vtkObservation * GetNthObservation(int n)
ObjectToObservationVectorMap SubjectMap
maps to manage quick lookup by object
void PrintSelf(ostream &os, vtkIndent indent) override
void AttachObservation(vtkObservation *observation)
vtkCollection * GetObservationsForCallback(vtkCallbackCommand *callback)
void OpenLogFile()
Open and close the log file.
ObservationVector GetObservationsForSubjectByTag(vtkObject *subject, unsigned long tag)
vtkCollection * GetObservationsForSubject(vtkObject *subject)
friend class vtkObservation
vtkObservation can call these methods
vtkCallbackCommand * RequestModifiedCallback
void operator=(const vtkEventBroker &)
vtkObservation * AddObservation(vtkObject *subject, const char *event, const char *script)
vtkEventBroker Self
void CloseLogFile()
void(* ScriptHandler)(const char *script, void *clientData)
int GetNumberOfQueuedObservations()
vtkTimerLog * TimerLog
ObjectToObservationVectorMap ObserverMap
void RemoveObservations(vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify)
friend class vtkEventBrokerInitialize
static vtkEventBroker * New()
~vtkEventBroker() override
Stores information about the relationship between a Subject and an Observer.
static vtkEventBrokerInitialize vtkEventBrokerInitializer