OpendTect  7.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
MonitoredObject Class Referenceabstract

Object that can be MT-safely monitored from cradle to grave. More...

Inheritance diagram for MonitoredObject:
[legend]

Classes

class  AccessLocker
 
class  ChangeData
 

Public Types

typedef CNotifier< MonitoredObject, ChangeDataChangeDataNotifier
 
typedef int ChangeType
 
typedef std::int64_t IDType
 
typedef Threads ::Locker Locker
 

Public Member Functions

 MonitoredObject (const MonitoredObject &)
 
virtual ~MonitoredObject ()
 
virtual MonitoredObjectclone () const
 
virtual ChangeType compareWith (const MonitoredObject &) const
 
virtual DirtyCountType dirtyCount () const
 
virtual ChangeDataNotifierobjectChanged () const
 
virtual Notifier< MonitoredObject > & objectToBeDeleted () const
 
MonitoredObjectoperator= (const MonitoredObject &)
 
bool operator== (const MonitoredObject &) const
 
void sendChangeNotification (const ChangeData &) const
 
void sendEntireObjectChangeNotification () const
 
virtual void touch () const
 
void transferNotifsTo (const MonitoredObject &, const CallBacker *onlyfor=0) const
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (const NotifierAccess &, const CallBack &, bool onlyifnew=false) const
 
bool attachCB (const NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false) const
 
void detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
virtual bool isCapsule () const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
void stopReceivingNotifications () const
 
virtual CallBackertrueCaller ()
 

Static Public Member Functions

static ChangeType cEntireObjectChange ()
 
static IDType cEntireObjectChgID ()
 
static ChangeType changeNotificationTypeOf (CallBacker *)
 
static ChangeType cNoChange ()
 
static IDType cUnspecChgID ()
 
static Notifier< MonitoredObject > & instanceCreated ()
 defines static instanceCreated() More...
 
- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 

Protected Member Functions

 MonitoredObject ()
 
void copyAll (const MonitoredObject &)
 
virtual MonitoredObjectgetClone () const =0
 
template<class T >
getMemberSimple (const T &) const
 the get function used by mImplSimpleMonitoredGet More...
 
void resumeChangeNotifications () const
 
void sendChgNotif (AccessLocker &, ChangeType, IDType) const
 calls objectChanged with released lock More...
 
void sendChgNotif (AccessLocker &, const ChangeData &) const
 calls objectChanged with released lock More...
 
void sendDelNotif () const
 
template<class TMember , class TSetTo >
void setMemberSimple (TMember &, TSetTo, ChangeType, IDType)
 the set function used by mImplSimpleMonitoredSet More...
 
void stopChangeNotifications () const
 

Protected Attributes

Threads::Lock accesslock_
 

Private Member Functions

ChangeType compareClassData (const MonitoredObject &) const
 

Private Attributes

ChangeDataNotifier chgnotif_
 
Threads::Atomic< int > chgnotifblocklevel_
 
bool delalreadytriggered_
 
Notifier< MonitoredObjectdelnotif_
 
DirtyCounter dirtycount_
 

Friends

class ChangeNotifyBlocker
 
class MonitorLock
 

Detailed Description

Object that can be MT-safely monitored from cradle to grave.

Traditionally, the MVC concept was all about automatic updates. This can still be done, but nowadays more important seems the integrity for MT.

The instanceCreated() will tell you when any MonitoredObject is created. To make your class really monitorable, use mDeclInstanceCreatedNotifierAccess for your subclass, too. Note that you'll need to add mTriggerInstanceCreatedNotifier() to the constructor, and add mDefineInstanceCreatedNotifierAccess(YourClassName) to a .cc.

Similarly, you have to trigger the objectToBeDeleted() at the start of your destructor - if you do not have one, make one. For that, use sendDelNotif(), it avoids double notifications; this base class will eventually do such a thing but then it's too late for many purposes: the subclass part of the object is then already dead. Thus, at the beginning of the your destructor, call sendDelNotif().

You can also monitor the object's changes. First of all, a dirtyCount() is maintained. To make more precise event handling possible, the change notifier will deliver an int with a change type. This type can be specific for the MonitoredObject, and could be available with symbolic constants in that class. The default is 0 - 'General change'.

For simple class variables, there are simple macros for get and set that will lock and unlock right: mImplSimpleMonitoredGet, mImplSimpleMonitoredSet, and the most common mImplSimpleMonitoredGetSet.

Locking for more complex things should be done using macros: mLock4Read, mLock4Write, mLock2Write, and mUnlockAllAccess. After write (i.e. object change) operations, you need to unlock and send the notification. Use mSendChgNotif or mSendEntireObjChgNotif.

To handle change notifications, you'll want to unpack the capsule with one of the macros mGetMonitoredChgData or mGetMonitoredChgDataDoAll. Example:

void MyObj::chgCB( CallBacker* cb ) { mGetMonitoredChgDataDoAll( cb, chgdata, caller, return redrawAll() ); if ( chgdata.changeType() == MonObj::cSomeChange() ) doSomething( chgdata.ID() ); }

The choice of cNoChange being zero is deliberate; the guarantee is that you can use a ChangeType as a boolean to see whether there is any change.

Lastly, copying of MonitoredObject needs to be done right. For this, you want to use the mDeclMonitorableAssignment and mImplMonitorableAssignment macros: these provide correct handling and even make your task easier than otherwise. To make it work, in the .cc file you have to implement a void copyClassData(const clss&) function. It is called already locked, and should only copy the class' own data.

For typical subclass implementations see NamedMonitoredObject, or Pick::Set. For usage, try visSurvey::LocationDisplay.

<>

Member Typedef Documentation

◆ ChangeDataNotifier

◆ ChangeType

◆ IDType

typedef std::int64_t MonitoredObject::IDType

◆ Locker

typedef Threads :: Locker MonitoredObject::Locker

Constructor & Destructor Documentation

◆ MonitoredObject() [1/2]

MonitoredObject::MonitoredObject ( const MonitoredObject )

◆ ~MonitoredObject()

virtual MonitoredObject::~MonitoredObject ( )
virtual

◆ MonitoredObject() [2/2]

MonitoredObject::MonitoredObject ( )
protected

Member Function Documentation

◆ cEntireObjectChange()

static ChangeType MonitoredObject::cEntireObjectChange ( )
inlinestatic

◆ cEntireObjectChgID()

static IDType MonitoredObject::cEntireObjectChgID ( )
inlinestatic

◆ changeNotificationTypeOf()

static ChangeType MonitoredObject::changeNotificationTypeOf ( CallBacker )
static

◆ clone()

virtual MonitoredObject* MonitoredObject::clone ( ) const
inlinevirtual

Reimplemented in NamedMonitoredObject, and ChangeRecorder.

◆ cNoChange()

static ChangeType MonitoredObject::cNoChange ( )
inlinestatic

◆ compareClassData()

ChangeType MonitoredObject::compareClassData ( const MonitoredObject ) const
private

◆ compareWith()

virtual ChangeType MonitoredObject::compareWith ( const MonitoredObject ) const
virtual

Reimplemented in NamedMonitoredObject, and ChangeRecorder.

◆ copyAll()

void MonitoredObject::copyAll ( const MonitoredObject )
protected

◆ cUnspecChgID()

static IDType MonitoredObject::cUnspecChgID ( )
inlinestatic

◆ dirtyCount()

virtual DirtyCountType MonitoredObject::dirtyCount ( ) const
inlinevirtual

◆ getClone()

virtual MonitoredObject* MonitoredObject::getClone ( ) const
protectedpure virtual

Implemented in NamedMonitoredObject.

◆ getMemberSimple()

template<class T >
T MonitoredObject::getMemberSimple ( const T &  memb) const
inlineprotected

the get function used by mImplSimpleMonitoredGet

◆ instanceCreated()

static Notifier< MonitoredObject >& MonitoredObject::instanceCreated ( )
static

defines static instanceCreated()

◆ objectChanged()

virtual ChangeDataNotifier& MonitoredObject::objectChanged ( ) const
inlinevirtual

◆ objectToBeDeleted()

virtual Notifier<MonitoredObject>& MonitoredObject::objectToBeDeleted ( ) const
inlinevirtual

◆ operator=()

MonitoredObject& MonitoredObject::operator= ( const MonitoredObject )

◆ operator==()

bool MonitoredObject::operator== ( const MonitoredObject ) const

◆ resumeChangeNotifications()

void MonitoredObject::resumeChangeNotifications ( ) const
protected

◆ sendChangeNotification()

void MonitoredObject::sendChangeNotification ( const ChangeData ) const

◆ sendChgNotif() [1/2]

void MonitoredObject::sendChgNotif ( AccessLocker ,
ChangeType  ,
IDType   
) const
protected

calls objectChanged with released lock

◆ sendChgNotif() [2/2]

void MonitoredObject::sendChgNotif ( AccessLocker ,
const ChangeData  
) const
protected

calls objectChanged with released lock

◆ sendDelNotif()

void MonitoredObject::sendDelNotif ( ) const
protected

◆ sendEntireObjectChangeNotification()

void MonitoredObject::sendEntireObjectChangeNotification ( ) const

◆ setMemberSimple()

template<class TMember , class TSetTo >
void MonitoredObject::setMemberSimple ( TMember &  memb,
TSetTo  setto,
ChangeType  typ,
IDType  id 
)
inlineprotected

the set function used by mImplSimpleMonitoredSet

◆ stopChangeNotifications()

void MonitoredObject::stopChangeNotifications ( ) const
inlineprotected

◆ touch()

virtual void MonitoredObject::touch ( ) const
inlinevirtual

◆ transferNotifsTo()

void MonitoredObject::transferNotifsTo ( const MonitoredObject ,
const CallBacker onlyfor = 0 
) const

Friends And Related Function Documentation

◆ ChangeNotifyBlocker

friend class ChangeNotifyBlocker
friend

◆ MonitorLock

friend class MonitorLock
friend

Member Data Documentation

◆ accesslock_

Threads::Lock MonitoredObject::accesslock_
mutableprotected

◆ chgnotif_

ChangeDataNotifier MonitoredObject::chgnotif_
mutableprivate

◆ chgnotifblocklevel_

Threads::Atomic<int> MonitoredObject::chgnotifblocklevel_
mutableprivate

◆ delalreadytriggered_

bool MonitoredObject::delalreadytriggered_
mutableprivate

◆ delnotif_

Notifier<MonitoredObject> MonitoredObject::delnotif_
mutableprivate

◆ dirtycount_

DirtyCounter MonitoredObject::dirtycount_
mutableprivate

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2024