Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
vtkEventBroker Class Reference

Class that manages adding and deleting of observers with events. More...

#include <Libs/MRML/Core/vtkEventBroker.h>

Inheritance diagram for vtkEventBroker:
Inheritance graph
[legend]
Collaboration diagram for vtkEventBroker:
Collaboration graph
[legend]

Public Types

enum  EventMode { Synchronous, Asynchronous }
 
typedef std::set< vtkObservation *> ObservationVector
 
typedef vtkObject Superclass
 

Public Member Functions

vtkObservationAddObservation (vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify, float priority=0.0f)
 
vtkObservationAddObservation (vtkObject *subject, const char *event, const char *script)
 
void CloseLogFile ()
 
virtual void CompressCallDataOff ()
 
virtual void CompressCallDataOn ()
 
vtkObservationDequeueObservation ()
 
virtual void EventLoggingOff ()
 
virtual void EventLoggingOn ()
 
int GenerateGraphFile (const char *graphFile)
 
virtual const char * GetClassName ()
 
virtual int GetCompressCallData ()
 
virtual int GetEventLogging ()
 
virtual int GetEventMode ()
 
const char * GetEventModeAsString ()
 
virtual int GetEventNestingLevel ()
 
virtual char * GetLogFileName ()
 
vtkObservationGetNthObservation (int n)
 
vtkObservationGetNthQueuedObservation (int n)
 
int GetNumberOfObservations ()
 
Accessors for Observations More...
 
int GetNumberOfQueuedObservations ()
 
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) More...
 
ObservationVector GetObservations (vtkObject *subject, unsigned long event=0, vtkObject *observer=nullptr, vtkCallbackCommand *notify=nullptr, unsigned int maxReturnedObservations=0)
 
vtkCollection * GetObservationsForCallback (vtkCallbackCommand *callback)
 
vtkCollection * GetObservationsForObserver (vtkObject *observer)
 
vtkCollection * GetObservationsForSubject (vtkObject *subject)
 
ObservationVector GetObservationsForSubjectByTag (vtkObject *subject, unsigned long tag)
 
virtual vtkCallbackCommand * GetRequestModifiedCallback ()
 
ObservationVector GetSubjectObservations (vtkObject *subject)
 Fast retrieve of all observations of a given subject. More...
 
virtual vtkTimerLog * GetTimerLog ()
 
void InvokeObservation (vtkObservation *observation, unsigned long eid, void *callData)
 
virtual int IsA (const char *type)
 
void LogEvent (vtkObservation *observation)
 
void OpenLogFile ()
 
Open and close the log file More...
 
void PrintSelf (ostream &os, vtkIndent indent) override
 
void ProcessEvent (vtkObservation *observation, vtkObject *caller, unsigned long eid, void *callData)
 
Process any event that comes from either subject or observer More...
 
void ProcessEventQueue ()
 
void QueueObservation (vtkObservation *observation, unsigned long eid, void *callData)
 Event queue processing. More...
 
void RemoveObservation (vtkObservation *observation)
 
Remove observation from the broker and event queue More...
 
void RemoveObservations (ObservationVector observations)
 
void RemoveObservations (vtkObject *observer)
 
void RemoveObservations (vtkObject *subject, vtkObject *observer)
 
void RemoveObservations (vtkObject *subject, unsigned long event, vtkObject *observer)
 
void RemoveObservations (vtkObject *subject, unsigned long event, vtkObject *observer, vtkCallbackCommand *notify)
 
void RemoveObservationsForSubjectByTag (vtkObject *subject, unsigned long tag)
 
virtual bool RequestModified (vtkObject *object)
 
virtual void SetCompressCallData (int)
 
virtual void SetEventLogging (int)
 
void SetEventMode (int eventMode)
 
void SetEventModeToAsynchronous ()
 
void SetEventModeToSynchronous ()
 
virtual void SetEventNestingLevel (int)
 
virtual void SetLogFileName (const char *)
 
File to write event logs to when EventLoging is turned on More...
 
virtual void SetRequestModifiedCallback (vtkCallbackCommand *callback)
 
void SetScriptHandler (void(*scriptHandler)(const char *script, void *clientData), void *clientData)
 
Sets the method pointer to be used for processing script observations More...
 
virtual void SetTimerLog (vtkTimerLog *timerLog)
 
Timer log class for calculating elapsed time for event invocations More...
 

Static Public Member Functions

static void Callback (vtkObject *caller, unsigned long eid, void *clientData, void *callData)
 
static vtkEventBrokerGetInstance ()
 
Return the singleton instance with no reference counting. More...
 
static int IsTypeOf (const char *type)
 
static vtkEventBrokerNew ()
 
static vtkEventBrokerSafeDownCast (vtkObject *o)
 

Protected Types

typedef std::map< vtkObject *, ObservationVectorObjectToObservationVectorMap
 
typedef vtkEventBroker Self
 

Protected Member Functions

void AttachObservation (vtkObservation *observation)
 
void DetachObservation (vtkObservation *observation)
 
void operator= (const vtkEventBroker &)
 
 vtkEventBroker ()
 
 vtkEventBroker (const vtkEventBroker &)
 
 ~vtkEventBroker () override
 

Static Protected Member Functions

static void classFinalize ()
 
static void classInitialize ()
 
Singleton management functions. More...
 

Protected Attributes

int CompressCallData
 
int EventLogging
 
int EventMode
 
int EventNestingLevel
 
std::deque< vtkObservation *> EventQueue
 The event queue of triggered but not-yet-invoked observations. More...
 
std::ofstream LogFile
 
char * LogFileName
 
ObjectToObservationVectorMap ObserverMap
 
vtkCallbackCommand * RequestModifiedCallback
 
void(* ScriptHandler )(const char *script, void *clientData)
 
void * ScriptHandlerClientData
 
ObjectToObservationVectorMap SubjectMap
 maps to manage quick lookup by object More...
 
vtkTimerLog * TimerLog
 

Friends

class vtkEventBrokerInitialize
 
class vtkObservation
 vtkObservation can call these methods More...
 

Detailed Description

Class that manages adding and deleting of observers with events.

This class keeps track of observers and events added to each vtk object. It caches tags returned by AddObserver method so that observers can be removed properly. See also: https://wiki.na-mic.org/Wiki/index.php/Slicer3:EventBroker https://en.wikipedia.org/wiki/Observer_pattern Other interesting observer implementations: http://xlobject.sourceforge http://sigslot.sourceforge.net/ http://doc.trolltech.com/4.3/signalsandslots.html

Definition at line 49 of file vtkEventBroker.h.

Member Typedef Documentation

◆ ObjectToObservationVectorMap

typedef std::map< vtkObject*, ObservationVector > vtkEventBroker::ObjectToObservationVectorMap
protected

Definition at line 280 of file vtkEventBroker.h.

◆ ObservationVector

Definition at line 55 of file vtkEventBroker.h.

◆ Self

Definition at line 276 of file vtkEventBroker.h.

◆ Superclass

typedef vtkObject vtkEventBroker::Superclass

Definition at line 52 of file vtkEventBroker.h.

Member Enumeration Documentation

◆ EventMode

Event Queue processing modes

In synchronous mode, observations are invoked immediately when the event takes place. In asynchronous mode, observations are added to the event queue for later invocation.

Enumerator
Synchronous 
Asynchronous 

Definition at line 182 of file vtkEventBroker.h.

Constructor & Destructor Documentation

◆ vtkEventBroker() [1/2]

vtkEventBroker::vtkEventBroker ( )
protected

◆ ~vtkEventBroker()

vtkEventBroker::~vtkEventBroker ( )
overrideprotected

◆ vtkEventBroker() [2/2]

vtkEventBroker::vtkEventBroker ( const vtkEventBroker )
protected

Member Function Documentation

◆ AddObservation() [1/2]

vtkObservation* vtkEventBroker::AddObservation ( vtkObject *  subject,
unsigned long  event,
vtkObject *  observer,
vtkCallbackCommand *  notify,
float  priority = 0.0f 
)

Adding and Removing Observation objects

Request that an observer be added to the subject (or "observee")

  • this is the "Attach" operation

◆ AddObservation() [2/2]

vtkObservation* vtkEventBroker::AddObservation ( vtkObject *  subject,
const char *  event,
const char *  script 
)

Scripted version of observation

  • creates an observation that will be invoked using the ScriptHandler method

◆ AttachObservation()

void vtkEventBroker::AttachObservation ( vtkObservation observation)
protected

Attach adds the observers to the object. Detach removes the observers These routines manage the internal datastructures and should be the only methods used to modified the internal Observations member Please note that they don't update the SubjectMap nor the ObserverMap.

◆ Callback()

static void vtkEventBroker::Callback ( vtkObject *  caller,
unsigned long  eid,
void *  clientData,
void *  callData 
)
static

the static function used by the command callback (used by vtkObservation)

  • each observation has a vtkCallbackCommand method which stores the pointer to the vtkObservation class as the clientData
  • the vtkObservation has a pointer to vtkEventBroker, which knows how to process that event for that Observation

◆ classFinalize()

static void vtkEventBroker::classFinalize ( )
staticprotected

◆ classInitialize()

static void vtkEventBroker::classInitialize ( )
staticprotected


Singleton management functions.

◆ CloseLogFile()

void vtkEventBroker::CloseLogFile ( )

◆ CompressCallDataOff()

virtual void vtkEventBroker::CompressCallDataOff ( )
virtual

◆ CompressCallDataOn()

virtual void vtkEventBroker::CompressCallDataOn ( )
virtual

two modes -

  • CompressCallDataOn: only keep the most recent call data. this means that if the observation is in the queue, replace the call data with the current value
  • CompressCallDataOff: maintain the list of all call data values, but only one unique entry for each Compression is ON by default

◆ DequeueObservation()

vtkObservation* vtkEventBroker::DequeueObservation ( )

◆ DetachObservation()

void vtkEventBroker::DetachObservation ( vtkObservation observation)
protected

◆ EventLoggingOff()

virtual void vtkEventBroker::EventLoggingOff ( )
virtual

◆ EventLoggingOn()

virtual void vtkEventBroker::EventLoggingOn ( )
virtual

Event Logging

Turn on event tracing (requires TraceFile)

◆ GenerateGraphFile()

int vtkEventBroker::GenerateGraphFile ( const char *  graphFile)

Graph File

Write out the current list of observations in graphviz format (.dot)

◆ GetClassName()

virtual const char* vtkEventBroker::GetClassName ( )
virtual

◆ GetCompressCallData()

virtual int vtkEventBroker::GetCompressCallData ( )
virtual

◆ GetEventLogging()

virtual int vtkEventBroker::GetEventLogging ( )
virtual

◆ GetEventMode()

virtual int vtkEventBroker::GetEventMode ( )
virtual

◆ GetEventModeAsString()

const char* vtkEventBroker::GetEventModeAsString ( )
inline

Definition at line 199 of file vtkEventBroker.h.

◆ GetEventNestingLevel()

virtual int vtkEventBroker::GetEventNestingLevel ( )
virtual

◆ GetInstance()

static vtkEventBroker* vtkEventBroker::GetInstance ( )
static


Return the singleton instance with no reference counting.

◆ GetLogFileName()

virtual char* vtkEventBroker::GetLogFileName ( )
virtual

◆ GetNthObservation()

vtkObservation* vtkEventBroker::GetNthObservation ( int  n)

◆ GetNthQueuedObservation()

vtkObservation* vtkEventBroker::GetNthQueuedObservation ( int  n)

◆ GetNumberOfObservations()

int vtkEventBroker::GetNumberOfObservations ( )


Accessors for Observations

◆ GetNumberOfQueuedObservations()

int vtkEventBroker::GetNumberOfQueuedObservations ( )

◆ GetObservationExist()

bool vtkEventBroker::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)

◆ GetObservations()

ObservationVector vtkEventBroker::GetObservations ( vtkObject *  subject,
unsigned long  event = 0,
vtkObject *  observer = nullptr,
vtkCallbackCommand *  notify = nullptr,
unsigned int  maxReturnedObservations = 0 
)

If event is != 0 , only observations matching the events are returned If observer is != 0 , only observations matching the observer are returned If notify is != 0, only observations matching the callback are returned If maxReturnedObservations is != 0, only up to this number of observations are are returned

◆ GetObservationsForCallback()

vtkCollection* vtkEventBroker::GetObservationsForCallback ( vtkCallbackCommand *  callback)

◆ GetObservationsForObserver()

vtkCollection* vtkEventBroker::GetObservationsForObserver ( vtkObject *  observer)

◆ GetObservationsForSubject()

vtkCollection* vtkEventBroker::GetObservationsForSubject ( vtkObject *  subject)

Description Accessors for intropsection Note: vtkCollection object is allocated internally and must be freed by the caller

◆ GetObservationsForSubjectByTag()

ObservationVector vtkEventBroker::GetObservationsForSubjectByTag ( vtkObject *  subject,
unsigned long  tag 
)

◆ GetRequestModifiedCallback()

virtual vtkCallbackCommand* vtkEventBroker::GetRequestModifiedCallback ( )
virtual

◆ GetSubjectObservations()

ObservationVector vtkEventBroker::GetSubjectObservations ( vtkObject *  subject)

Fast retrieve of all observations of a given subject.

◆ GetTimerLog()

virtual vtkTimerLog* vtkEventBroker::GetTimerLog ( )
virtual

◆ InvokeObservation()

void vtkEventBroker::InvokeObservation ( vtkObservation observation,
unsigned long  eid,
void *  callData 
)

◆ IsA()

virtual int vtkEventBroker::IsA ( const char *  type)
virtual

◆ IsTypeOf()

static int vtkEventBroker::IsTypeOf ( const char *  type)
static

◆ LogEvent()

void vtkEventBroker::LogEvent ( vtkObservation observation)

actually write to the log file (also manages state of the LogFile ivar based on the filename and the EventLogging variable)

◆ New()

static vtkEventBroker* vtkEventBroker::New ( )
static

This is a singleton pattern New. There will only be ONE reference to a vtkEventBroker object per process. Clients that call this must call Delete on the object so that the reference counting will work. The single instance will be unreferenced when the program exits.

◆ OpenLogFile()

void vtkEventBroker::OpenLogFile ( )


Open and close the log file

◆ operator=()

void vtkEventBroker::operator= ( const vtkEventBroker )
protected

◆ PrintSelf()

void vtkEventBroker::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
override

◆ ProcessEvent()

void vtkEventBroker::ProcessEvent ( vtkObservation observation,
vtkObject *  caller,
unsigned long  eid,
void *  callData 
)


Process any event that comes from either subject or observer

◆ ProcessEventQueue()

void vtkEventBroker::ProcessEventQueue ( )

◆ QueueObservation()

void vtkEventBroker::QueueObservation ( vtkObservation observation,
unsigned long  eid,
void *  callData 
)

Event queue processing.

Event queue handling routines Note:

  • assume here that the information in a vtkObservation contains enough information for the observer to handle the event (that is, we don't pass the callData field of the event back) TODO: if the callData is needed, we will need another class/struct to go into the event queue that saves them

◆ RemoveObservation()

void vtkEventBroker::RemoveObservation ( vtkObservation observation)


Remove observation from the broker and event queue

◆ RemoveObservations() [1/5]

void vtkEventBroker::RemoveObservations ( ObservationVector  observations)

Remove all observations that match

  • various signatures provided as helpers
  • when specifying the tag, a 0 matches all tags

◆ RemoveObservations() [2/5]

void vtkEventBroker::RemoveObservations ( vtkObject *  observer)

◆ RemoveObservations() [3/5]

void vtkEventBroker::RemoveObservations ( vtkObject *  subject,
vtkObject *  observer 
)

◆ RemoveObservations() [4/5]

void vtkEventBroker::RemoveObservations ( vtkObject *  subject,
unsigned long  event,
vtkObject *  observer 
)

◆ RemoveObservations() [5/5]

void vtkEventBroker::RemoveObservations ( vtkObject *  subject,
unsigned long  event,
vtkObject *  observer,
vtkCallbackCommand *  notify 
)

◆ RemoveObservationsForSubjectByTag()

void vtkEventBroker::RemoveObservationsForSubjectByTag ( vtkObject *  subject,
unsigned long  tag 
)

◆ RequestModified()

virtual bool vtkEventBroker::RequestModified ( vtkObject *  object)
virtual

Request invoking modified event. Modified event is called later (e.g., when the application becomes idle) on the main thread (therefore it is safe to call this method from any thread). Returns true if the request was successfully submitted.

◆ SafeDownCast()

static vtkEventBroker* vtkEventBroker::SafeDownCast ( vtkObject *  o)
static

◆ SetCompressCallData()

virtual void vtkEventBroker::SetCompressCallData ( int  )
virtual

◆ SetEventLogging()

virtual void vtkEventBroker::SetEventLogging ( int  )
virtual

◆ SetEventMode()

void vtkEventBroker::SetEventMode ( int  eventMode)
inline

Definition at line 187 of file vtkEventBroker.h.

◆ SetEventModeToAsynchronous()

void vtkEventBroker::SetEventModeToAsynchronous ( )
inline

Definition at line 198 of file vtkEventBroker.h.

◆ SetEventModeToSynchronous()

void vtkEventBroker::SetEventModeToSynchronous ( )
inline

Definition at line 197 of file vtkEventBroker.h.

◆ SetEventNestingLevel()

virtual void vtkEventBroker::SetEventNestingLevel ( int  )
virtual

Current level of indent (event nesting) shows what is called by what when in synchronous mode

◆ SetLogFileName()

virtual void vtkEventBroker::SetLogFileName ( const char *  )
virtual


File to write event logs to when EventLoging is turned on

◆ SetRequestModifiedCallback()

virtual void vtkEventBroker::SetRequestModifiedCallback ( vtkCallbackCommand *  callback)
virtual

Set callback command for RequestModified. This command must be implemented so that it is safe to be called from any thread.

◆ SetScriptHandler()

void vtkEventBroker::SetScriptHandler ( void(*)(const char *script, void *clientData)  scriptHandler,
void *  clientData 
)
inline


Sets the method pointer to be used for processing script observations

Definition at line 238 of file vtkEventBroker.h.

◆ SetTimerLog()

virtual void vtkEventBroker::SetTimerLog ( vtkTimerLog *  timerLog)
virtual


Timer log class for calculating elapsed time for event invocations

Friends And Related Function Documentation

◆ vtkEventBrokerInitialize

friend class vtkEventBrokerInitialize
friend

Definition at line 275 of file vtkEventBroker.h.

◆ vtkObservation

friend class vtkObservation
friend

vtkObservation can call these methods

Definition at line 310 of file vtkEventBroker.h.

Member Data Documentation

◆ CompressCallData

int vtkEventBroker::CompressCallData
protected

Definition at line 298 of file vtkEventBroker.h.

◆ EventLogging

int vtkEventBroker::EventLogging
protected

Definition at line 292 of file vtkEventBroker.h.

◆ EventMode

Definition at line 297 of file vtkEventBroker.h.

◆ EventNestingLevel

int vtkEventBroker::EventNestingLevel
protected

Definition at line 293 of file vtkEventBroker.h.

◆ EventQueue

std::deque< vtkObservation * > vtkEventBroker::EventQueue
protected

The event queue of triggered but not-yet-invoked observations.

Definition at line 287 of file vtkEventBroker.h.

◆ LogFile

std::ofstream vtkEventBroker::LogFile
protected

Definition at line 300 of file vtkEventBroker.h.

◆ LogFileName

char* vtkEventBroker::LogFileName
protected

Definition at line 294 of file vtkEventBroker.h.

◆ ObserverMap

ObjectToObservationVectorMap vtkEventBroker::ObserverMap
protected

Definition at line 284 of file vtkEventBroker.h.

◆ RequestModifiedCallback

vtkCallbackCommand* vtkEventBroker::RequestModifiedCallback
protected

Definition at line 302 of file vtkEventBroker.h.

◆ ScriptHandler

void(* vtkEventBroker::ScriptHandler) (const char *script, void *clientData)
protected

Definition at line 289 of file vtkEventBroker.h.

◆ ScriptHandlerClientData

void* vtkEventBroker::ScriptHandlerClientData
protected

Definition at line 290 of file vtkEventBroker.h.

◆ SubjectMap

ObjectToObservationVectorMap vtkEventBroker::SubjectMap
protected

maps to manage quick lookup by object

Definition at line 283 of file vtkEventBroker.h.

◆ TimerLog

vtkTimerLog* vtkEventBroker::TimerLog
protected

Definition at line 295 of file vtkEventBroker.h.


The documentation for this class was generated from the following file: