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

Base class for all observers. More...

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

Inheritance diagram for Observer:
[legend]

Public Member Functions

void destroy ()
 
const EventIDgetEventID () const
 
void moveToThread (QThread *thread)
 
virtual void update (const ObservableEvent &event)
 

Protected Member Functions

 Observer (const Observer &)
 
 Observer (Observable &subject, const EventID &eventID, bool ownedBySubject=false, bool attach=true)
 
virtual ~Observer ()
 
bool isOwnedBySubject () const
 
void setOwnedBySubject (bool ownedBySubject) const
 
virtual bool updateInNotificationThread (const ObservableEvent &event)
 
virtual void updateInObserverThread (const ObservableEvent &event)
 

Detailed Description

Note
Clients would not normally want to subclass Observer directly. Rather, most situations are better handled by using an ObserverSet and calling one of its templated add() functions.

An Observer can respond to events in the same thread as the notification, in the thread used to create the Observer, or in a combination of both. The default implementation of update() allows an observer to respond first in the notification thread, and then if required, in the observer's thread. See update() for more details.

Subclasses which only ever want to support responding in the notification thread should re-implement update(). Those subclasses which may want to respond in the observer's thread should instead look at updateInObserverThread() and possibly also updateInNotificationThread().

An Observer is permitted to delete itself in responding to a notification.

An Observer MUST NOT destroy the object it is observing.

Warning
When re-implementing updateInObserverThread(), the observer should only be created in a thread (which we will call the receiving thread) that was itself created by Qt's QThread class or in the main Qt thread. This restriction is required because the updateInObserverThread() function is called via the receiving thread's own Qt event loop. Therefore, if the receiving thread was not created by Qt or its event loop is not running, the notifying thread will be blocked forever because there is no event loop to process the request that is responsible for unblocking it.

Constructor & Destructor Documentation

◆ Observer() [1/2]

Observer ( Observable subject,
const EventID eventID,
bool  ownedBySubject = false,
bool  attach = true 
)
protected

◆ Observer() [2/2]

Observer ( const Observer )
protected

◆ ~Observer()

virtual ~Observer ( )
protectedvirtual

Member Function Documentation

◆ destroy()

void destroy ( )

◆ getEventID()

const EventID & getEventID ( ) const

◆ isOwnedBySubject()

bool isOwnedBySubject ( ) const
protected

◆ moveToThread()

void moveToThread ( QThread *  thread)

◆ setOwnedBySubject()

void setOwnedBySubject ( bool  ownedBySubject) const
protected

◆ update()

virtual void update ( const ObservableEvent event)
virtual

◆ updateInNotificationThread()

virtual bool updateInNotificationThread ( const ObservableEvent event)
protectedvirtual

Reimplemented in BaseUpdater.

◆ updateInObserverThread()

virtual void updateInObserverThread ( const ObservableEvent event)
protectedvirtual