Slicer 5.6
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,
76 unsigned long eid, void *clientData, void *callData);
77
82 vtkObservation *AddObservation (vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify, float priority=0.0f);
83
87 vtkObservation *AddObservation (vtkObject *subject, const char *event, const char *script);
88
91 void RemoveObservation (vtkObservation *observation);
92
98 void RemoveObservations (vtkObject *observer);
99 void RemoveObservations (vtkObject *subject, vtkObject *observer);
100 void RemoveObservations (vtkObject *subject, unsigned long event, vtkObject *observer);
101 void RemoveObservations (vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify);
102 void RemoveObservationsForSubjectByTag (vtkObject *subject, unsigned long tag);
110 unsigned long event = 0,
111 vtkObject *observer = nullptr,
112 vtkCallbackCommand *notify = nullptr,
113 unsigned int maxReturnedObservations = 0);
115 bool GetObservationExist (vtkObject *subject,
116 unsigned long event = 0,
117 vtkObject *observer = nullptr,
118 vtkCallbackCommand *notify = nullptr);
119 ObservationVector GetObservationsForSubjectByTag (vtkObject *subject, unsigned long tag);
120
125 vtkCollection *GetObservationsForSubject (vtkObject *subject);
126 vtkCollection *GetObservationsForObserver (vtkObject *observer);
127 vtkCollection *GetObservationsForCallback (vtkCallbackCommand* callback);
128
133
136 void ProcessEvent (vtkObservation *observation, vtkObject *caller, unsigned long eid, void *callData);
137
141 vtkBooleanMacro (EventLogging, int);
142 vtkSetMacro (EventLogging, int);
143 vtkGetMacro (EventLogging, int);
144
148 vtkSetMacro (EventNestingLevel, int);
149 vtkGetMacro (EventNestingLevel, int);
150
153 vtkSetStringMacro (LogFileName);
154 vtkGetStringMacro (LogFileName);
155
158 virtual void SetTimerLog(vtkTimerLog* timerLog);
159 vtkGetObjectMacro (TimerLog, vtkTimerLog);
160
163 void OpenLogFile ();
165
169 void LogEvent (vtkObservation *observation);
170
174 int GenerateGraphFile ( const char *graphFile );
175
176
184 Asynchronous
185 };
186 vtkGetMacro(EventMode, int);
187 void SetEventMode(int eventMode)
188 {
189 if (eventMode != this->EventMode)
190 {
191 this->EventMode = eventMode;
192 this->ProcessEventQueue();
193 this->Modified();
194 }
195 };
196
199 const char * GetEventModeAsString() {
200 if (this->EventMode == vtkEventBroker::Synchronous) return ("Synchronous");
201 if (this->EventMode == vtkEventBroker::Asynchronous) return ("Asynchronous");
202 return "Undefined";
203 }
204
205
207
216 void QueueObservation (vtkObservation *observation, unsigned long eid,
217 void *callData);
221 void InvokeObservation (vtkObservation *observation, unsigned long eid,
222 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
278
280 typedef std::map< vtkObject*, ObservationVector > ObjectToObservationVectorMap;
281
285
287 std::deque< vtkObservation * > EventQueue;
288
289 void (*ScriptHandler) (const char* script, void* clientData);
291
295 vtkTimerLog *TimerLog;
296
299
300 std::ofstream LogFile;
301
302 vtkCallbackCommand* RequestModifiedCallback;
303
304private:
308 void DetachObservations();
310 friend class vtkObservation;
311};
312
314class VTK_MRML_EXPORT vtkEventBrokerInitialize
315{
316public:
318
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
Class that manages adding and deleting of observers with events.
static void classFinalize()
void RemoveObservations(vtkObject *subject, vtkObject *observer)
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
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)
std::map< vtkObject *, ObservationVector > ObjectToObservationVectorMap
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)
std::set< vtkObservation * > ObservationVector
vtkCallbackCommand * RequestModifiedCallback
void operator=(const vtkEventBroker &)
vtkObservation * AddObservation(vtkObject *subject, const char *event, const char *script)
std::deque< vtkObservation * > EventQueue
The event queue of triggered but not-yet-invoked observations.
vtkEventBroker Self
void CloseLogFile()
int GetNumberOfQueuedObservations()
vtkTimerLog * TimerLog
ObjectToObservationVectorMap ObserverMap
void RemoveObservations(vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify)
static vtkEventBroker * New()
~vtkEventBroker() override
Stores information about the relationship between a Subject and an Observer.
static vtkEventBrokerInitialize vtkEventBrokerInitializer