![]() |
OpendTect
6.3
|
Object that can be MT-safely monitored from cradle to grave. More...
Classes | |
| class | AccessLocker |
| class | ChangeData |
Public Types | |
| typedef int | ChangeType |
| typedef int64_t | IDType |
| typedef int64_t | DirtyCountType |
| typedef CNotifier< Monitorable, ChangeData > | ChangeDataNotifier |
Public Member Functions | |
| Monitorable (const Monitorable &) | |
| virtual | ~Monitorable () |
| Monitorable & | operator= (const Monitorable &) |
| bool | operator== (const Monitorable &) const |
| virtual Monitorable * | clone () const |
| virtual ChangeDataNotifier & | objectChanged () const |
| virtual Notifier< Monitorable > & | objectToBeDeleted () const |
| virtual void | touch () const |
| virtual DirtyCountType | dirtyCount () const |
| virtual ChangeType | compareWith (const Monitorable &) const |
| void | sendChangeNotification (const ChangeData &) const |
| void | sendEntireObjectChangeNotification () const |
| void | transferNotifsTo (const Monitorable &, 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 | detachCB (const NotifierAccess &, const CallBack &) const |
| void | detachCB (const NotifierAccess *notif, const CallBack &cb) const |
| bool | isNotifierAttached (const NotifierAccess *) const |
| Only for debugging purposes, don't use. More... | |
| virtual bool | isCapsule () const |
| void | stopReceivingNotifications () const |
Static Public Member Functions | |
| static Notifier< Monitorable > & | instanceCreated () |
| defines static instanceCreated() More... | |
| static ChangeType | cEntireObjectChange () |
| static ChangeType | cNoChange () |
| static IDType | cUnspecChgID () |
| static IDType | cEntireObjectChgID () |
| static ChangeType | changeNotificationTypeOf (CallBacker *) |
Static Public Member Functions inherited from CallBacker | |
| static void | createReceiverForCurrentThread () |
| static void | removeReceiverForCurrentThread () |
Protected Types | |
| typedef Threads::Atomic< DirtyCountType > | DirtyCounter |
Protected Member Functions | |
| Monitorable () | |
| virtual Monitorable * | getClone () const =0 |
| void | copyAll (const Monitorable &) |
| void | sendChgNotif (AccessLocker &, const ChangeData &) const |
| calls objectChanged with released lock More... | |
| void | sendChgNotif (AccessLocker &, ChangeType, IDType) const |
| calls objectChanged with released lock More... | |
| void | sendDelNotif () const |
| void | stopChangeNotifications () const |
| void | resumeChangeNotifications () const |
| template<class T > | |
| T | getMemberSimple (const T &) const |
| the get function used by mImplSimpleMonitoredGet More... | |
| template<class TMember , class TSetTo > | |
| void | setMemberSimple (TMember &, TSetTo, ChangeType, IDType) |
| the set function used by mImplSimpleMonitoredSet More... | |
Protected Member Functions inherited from CallBacker | |
| void | detachAllNotifiers () const |
| Call from the destructor of your inherited object. More... | |
Protected Attributes | |
| Threads::Lock | accesslock_ |
Private Member Functions | |
| ChangeType | compareClassData (const Monitorable &) const |
Private Attributes | |
| DirtyCounter | dirtycount_ |
| Threads::Atomic< int > | chgnotifblocklevel_ |
| ChangeDataNotifier | chgnotif_ |
| Notifier< Monitorable > | delnotif_ |
| bool | delalreadytriggered_ |
Friends | |
| class | MonitorLock |
| class | ChangeNotifyBlocker |
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 Monitorable 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 Monitorable, 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 Monitorables 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 NamedMonitorable, or Pick::Set. For usage, try visSurvey::LocationDisplay.
| typedef int Monitorable::ChangeType |
|
protected |
| typedef int64_t Monitorable::DirtyCountType |
| typedef int64_t Monitorable::IDType |
| Monitorable::Monitorable | ( | const Monitorable & | ) |
|
virtual |
|
protected |
|
inlinestatic |
|
inlinestatic |
|
static |
|
inlinevirtual |
Reimplemented in SurveyInfo, BufferDataPack, SaveableManager, DataPack, ProbeManager, NamedMonitorable, ChangeRecorder, and SharedObject.
|
inlinestatic |
|
private |
|
virtual |
Reimplemented in SurveyInfo, BufferDataPack, DataPack, NamedMonitorable, ChangeRecorder, and SharedObject.
|
protected |
|
inlinestatic |
|
inlinevirtual |
Reimplemented in Well::Data.
|
protectedpure virtual |
Implemented in SurveyInfo, BufferDataPack, DBMan, and NamedMonitorable.
|
inlineprotected |
the get function used by mImplSimpleMonitoredGet
|
static |
defines static instanceCreated()
|
inlinevirtual |
|
inlinevirtual |
| Monitorable& Monitorable::operator= | ( | const Monitorable & | ) |
| bool Monitorable::operator== | ( | const Monitorable & | ) | const |
|
protected |
| void Monitorable::sendChangeNotification | ( | const ChangeData & | ) | const |
|
protected |
calls objectChanged with released lock
|
protected |
calls objectChanged with released lock
|
protected |
| void Monitorable::sendEntireObjectChangeNotification | ( | ) | const |
|
inlineprotected |
the set function used by mImplSimpleMonitoredSet
|
inlineprotected |
|
inlinevirtual |
Reimplemented in Well::Data.
| void Monitorable::transferNotifsTo | ( | const Monitorable & | , |
| const CallBacker * | onlyfor = 0 |
||
| ) | const |
|
friend |
|
friend |
|
mutableprotected |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
|
mutableprivate |
Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017