Workspace 6.21.5
Public Member Functions | Protected Member Functions | List of all members
Observable Class Reference

Base class for all observable classes. More...

#include <Workspace/DataExecution/Events/observable.h>

Inheritance diagram for Observable:
[legend]

Public Member Functions

virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 

Protected Member Functions

 Observable ()
 
 Observable (const Observable &)
 

Detailed Description

All public functions in this class are thread-safe. Clients are allowed to attach and detach observers at any time, including an observer currently responding to an event notification. The constructor is inherently thread-safe since a new independent object is created with each invocation. Destructors are never thread-safe, since an object can only be destroyed once.

Constructor & Destructor Documentation

◆ Observable() [1/2]

Observable ( )
protected

Newly constructed Observable objects have no-one to notify.

◆ Observable() [2/2]

Observable ( const Observable )
protected

The copy constructor does not copy the source object's list of observers. Therefore, the new object is created with no observers regardless of what is passed to this constructor (actually, the parameter is not used at all).

◆ ~Observable()

~Observable ( )
virtual

The destructor will destroy all observers still attached to it. Therefore, it is important that all such observers were dynamically allocated and are not local stack objects.

Member Function Documentation

◆ attachObserver()

void attachObserver ( Observer observer)
Parameters
observerThe observer to attach.
See also
detachObserver()

◆ destroy()

void destroy ( )

◆ detachObserver()

void detachObserver ( Observer observer)
Parameters
observerThe observer to detach.

Allows an observer to be detached. If an observer was attached for a specific event type, then it cannot simply be detached by passing the result of AllObservableEvents::eventID() for eventID. An observer must be detached with the identical eventID for which it was attached.

See also
attachObserver()

◆ notifyEvent()

void notifyEvent ( const ObservableEvent event)
Parameters
eventThe event for which all interested objects should be notified.

Initiates an event of type event and notifies all currently attached observers interested in that event type (or all event types). Those observers attached for this specific event type will be notified first, followed by observers attached to respond for all events.

It is safe for an observer to detach itself as part of responding to the event. Internal checks are performed which will delay the detachment until the observer has finished responding to the event. The observer can safely delete itself, since the detachment does not use the observer in any way.