OpendTect  6.6
notify.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H.Bril
8  Date: 8-11-1995
9  Contents: Notification and Callbacks
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "basicmod.h"
16 #include "callback.h"
17 
18 
22 {
23 
24  friend class NotifyStopper;
25  friend class CallBacker;
26 
27 public:
28 
31  virtual ~NotifierAccess();
32 
33  inline bool isEmpty() const { return cbs_.isEmpty(); }
34  inline void setEmpty() { cbs_.setEmpty(); }
35  inline bool isEnabled() const { return !cbs_.hasAnyDisabled(); }
36  inline void enable( bool yn=true ){ cbs_.disableAll(!yn); }
37  inline void disable() { cbs_.disableAll(true); }
38 
39  bool willCall(const CallBacker*) const;
42  void notify(const CallBack&,bool first=false) const;
43  bool notifyIfNotNotified(const CallBack&) const;
45  void remove(const CallBack&) const;
46  bool removeWith(const CallBacker*,bool wait=true) const;
48 
50  const CallBacker* only_for,
51  const CallBacker* not_for=0) const;
52 
55 
56 protected:
57 
58  static void doTrigger(CallBackSet&,const CallBacker*);
59  void addShutdownSubscription(const CallBacker*) const;
61  bool wait) const;
63 
67 
68 public:
69 
70  bool isShutdownSubscribed(const CallBacker*) const;
72 
73 };
74 
75 
124 template <class T>
126 {
127 public:
128 
129  // Following functions are usually used by T class only:
130  Notifier( T* c ) { cber_ = c; }
131 
132  inline void trigger()
133  { if ( !cbs_.isEmpty() ) doTrigger( cbs_, cber_ ); }
134  inline void trigger( T& t )
135  { if ( !cbs_.isEmpty() ) doTrigger( cbs_, &t ); }
136  inline void trigger( CallBacker* c )
137  { if ( !cbs_.isEmpty() ) doTrigger( cbs_, c ); }
138 
139 };
140 
141 
142 #define mAttachObjCB( objptr, notifier, func, chk ) \
143  attachCB( notifier, CallBack( objptr, mCBFn(func) ), chk )
144 #define mDetachObjCB( objptr, notifier, func ) \
145  detachCB( notifier, CallBack( objptr, mCBFn(func) ) )
146 
147 #define mAttachCB( notifier, func ) \
148  mAttachObjCB( this, notifier, func, false )
149 
150 #define mAttachCBIfNotAttached( notifier, func ) \
151  mAttachObjCB( this, notifier, func, true )
152 
153 #define mDetachCB( notifier, func ) \
154  mDetachObjCB( this, notifier, func )
155 
156 
169 template <class T,class PayLoad>
171 {
172 public:
173  CNotifier( T* cb ) { cber_ = cb; }
174 
175  inline void trigger( PayLoad pl )
176  {
177  CBCapsule<PayLoad> caps( pl, cber_ );
178  doTrigger( cbs_, &caps );
179  }
180 
181  inline void trigger( PayLoad pl, CallBacker* cb )
182  {
183  if ( !cb )
184  trigger( pl );
185  else
186  {
187  CBCapsule<PayLoad> caps( pl, cb );
188  doTrigger( cbs_, &caps );
189  }
190  }
191  inline void trigger( PayLoad pl, T& t )
192  { trigger(pl,&t); }
193 
194 };
195 
196 
217 {
218 public:
221 
224 
225 protected:
226 
230 
231  void setDisabled(bool);
232 
233 public:
234 
235  mDeprecated("use enableNotification") void restore()
236  { enableNotification(); }
237  mDeprecated("use enableNotification") void enable()
238  { enableNotification(); }
239  mDeprecated("use disableNotification") void disable()
240  { disableNotification(); }
241 
242 };
243 
244 
247 
248 #define mDeclInstanceCreatedNotifierAccess(clss) \
249  static Notifier<clss>& instanceCreated()
250 
251 #define mDefineInstanceCreatedNotifierAccess(clss) \
252 Notifier<clss>& clss::instanceCreated() \
253 { \
254  mDefineStaticLocalObject( Notifier<clss>, theNotif, (0)); \
255  return theNotif; \
256 }
257 
258 #define mTriggerInstanceCreatedNotifier() \
259  instanceCreated().trigger( this )
NotifierAccess::~NotifierAccess
virtual ~NotifierAccess()
NotifierAccess::isEmpty
bool isEmpty() const
Definition: notify.h:33
Notifier::trigger
void trigger()
Definition: notify.h:132
NotifierAccess::removeShutdownSubscription
bool removeShutdownSubscription(const CallBacker *, bool wait) const
NotifierAccess::isEnabled
bool isEnabled() const
Definition: notify.h:35
ObjectSet< const CallBacker >
NotifierAccess::disable
void disable()
Definition: notify.h:37
Notifier::Notifier
Notifier(T *c)
Definition: notify.h:130
NotifierAccess::removeWith
bool removeWith(const CallBacker *, bool wait=true) const
NotifierAccess::cbs_
CallBackSet & cbs_
Definition: notify.h:53
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
CallBackSet
TypeSet of CallBacks with a few extras.
Definition: callback.h:152
Notifier::trigger
void trigger(CallBacker *c)
Definition: notify.h:136
NotifierAccess::cber_
CallBacker * cber_
Definition: notify.h:54
callback.h
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
NotifyStopper::~NotifyStopper
~NotifyStopper()
NotifierAccess::doTrigger
static void doTrigger(CallBackSet &, const CallBacker *)
NotifyStopper::isdisabled_
bool isdisabled_
Definition: notify.h:228
NotifierAccess::notifyIfNotNotified
bool notifyIfNotNotified(const CallBack &) const
NotifierAccess::addShutdownSubscription
void addShutdownSubscription(const CallBacker *) const
CallBack
CallBacks object-oriented (object + method).
Definition: callback.h:62
NotifierAccess::remove
void remove(const CallBack &) const
NotifyStopper::enableNotification
void enableNotification()
NotifierAccess::shutdownsubscriberlock_
Threads::Lock shutdownsubscriberlock_
Definition: notify.h:66
NotifyStopper::NotifyStopper
NotifyStopper(NotifierAccess &, const CallBacker *only_for=0)
Notifier::trigger
void trigger(T &t)
Definition: notify.h:134
NotifierAccess::willCall
bool willCall(const CallBacker *) const
NotifierAccess
Interface class for Notifier. See comments there.
Definition: notify.h:22
mClass
#define mClass(module)
Definition: commondefs.h:181
mDeprecated
#define mDeprecated(msg)
Definition: plfdefs.h:215
CNotifier::trigger
void trigger(PayLoad pl, CallBacker *cb)
Definition: notify.h:181
Notifier
Class to help setup a callback handling.
Definition: notify.h:126
CNotifier::trigger
void trigger(PayLoad pl)
Definition: notify.h:175
NotifierAccess::enable
void enable(bool yn=true)
Definition: notify.h:36
NotifyStopper
Temporarily disables a Notifier.
Definition: notify.h:217
NotifierAccess::isShutdownSubscribed
bool isShutdownSubscribed(const CallBacker *) const
Only for debugging purposes, don't use.
CNotifier::trigger
void trigger(PayLoad pl, T &t)
Definition: notify.h:191
NotifierAccess::shutdownsubscribers_
ObjectSet< const CallBacker > shutdownsubscribers_
Definition: notify.h:65
NotifierAccess::NotifierAccess
NotifierAccess()
NotifyStopper::setDisabled
void setDisabled(bool)
NotifierAccess::transferCBSTo
void transferCBSTo(const NotifierAccess &, const CallBacker *only_for, const CallBacker *not_for=0) const
NotifyStopper::disableNotification
void disableNotification()
NotifyStopper::thenotif_
NotifierAccess & thenotif_
Definition: notify.h:227
NotifyStopper::onlyfor_
const CallBacker * onlyfor_
Definition: notify.h:229
CNotifier::CNotifier
CNotifier(T *cb)
Definition: notify.h:173
CBCapsule
Capsule class to wrap any class into a CallBacker.
Definition: callback.h:255
NotifierAccess::setEmpty
void setEmpty()
Definition: notify.h:34
NotifierAccess::NotifierAccess
NotifierAccess(const NotifierAccess &)
Threads::Lock
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class.
Definition: threadlock.h:53
NotifierAccess::notify
void notify(const CallBack &, bool first=false) const
CNotifier
Notifier with automatic capsule creation.
Definition: notify.h:171

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