39 #define mCBFn(clss,fn) ((CallBackFunction)(&clss::fn)) 42 #define mCB(obj,clss,fn) CallBack( static_cast<clss*>(obj), mCBFn(clss,fn)) 45 #define mSCB(fn) CallBack( ((StaticCallBackFunction)(&fn)) ) 63 : obj_( o ), fn_( f ), sfn_( 0 ) {}
65 : obj_( 0 ), fn_( 0 ), sfn_( f ) {}
67 {
return obj_==c.
obj_ && fn_==c.
fn_ && sfn_==c.
sfn_; }
69 {
return !(*
this==cb); }
72 {
return (obj_ && fn_) || sfn_; }
80 static bool addToMainThread(
const CallBack&,
CallBacker* =0);
85 static bool callInMainThread(
const CallBack&,
CallBacker* =0);
93 static void removeFromMainThread(
const CallBacker*);
108 static bool queueIfNotInMainThread(CallBack,
115 #define mMainThreadCall( func ) \ 116 CallBack::callInMainThread( CallBack( this, ((CallBackFunction)(&func) ) ), 0) 118 #define mEnsureExecutedInMainThread( func ) \ 119 if ( CallBack::queueIfNotInMainThread( \ 120 CallBack( this, ((CallBackFunction)(&func) ) ), 0 ) ) \ 148 bool doEnable(
bool yn=
true );
171 virtual ~NotifierAccess();
173 void notify(
const CallBack&,
bool first=
false);
174 bool notifyIfNotNotified(
const CallBack&);
180 inline bool isEnabled()
const {
return cbs_.isEnabled(); }
181 inline bool enable(
bool yn=
true ) {
return cbs_.doEnable(yn); }
182 inline bool disable() {
return cbs_.doEnable(
false); }
184 inline bool isEmpty()
const {
return cbs_.isEmpty(); }
199 bool removeShutdownSubscription(
CallBacker*,
bool wait);
264 { doTrigger( cbs_, c ? c : cber_, exclude ); }
278 virtual ~CallBacker();
281 bool onlyifnew=
false);
287 bool onlyifnew=
false)
288 {
return notif ? attachCB(*notif,cb,onlyifnew):
false; }
295 {
if ( notif ) detachCB( *notif, cb ); }
302 void detachAllNotifiers();
314 #define mAttachCB( notifier, func ) \ 315 attachCB( notifier, CallBack( this, ((CallBackFunction)(&func) ) ), false ) 317 #define mAttachCBIfNotAttached( notifier, func ) \ 318 attachCB( notifier, CallBack( this, ((CallBackFunction)(&func) ) ), true ) 320 #define mDetachCB( notifier, func ) \ 321 detachCB( notifier, CallBack( this, ((CallBackFunction)(&func) ) ) ) 339 : data(d), caller(c) {}
369 #define mCBCapsuleGet(T,var,cb) \ 370 CBCapsule<T>* var = dynamic_cast< CBCapsule<T>* >( cb ); 372 #define mCBCapsuleUnpack(T,var,cb) \ 373 mCBCapsuleGet(T,cb##caps,cb) \ 374 T var = cb##caps->data 376 #define mCBCapsuleUnpackWithCaller(T,var,cber,cb) \ 377 mCBCapsuleGet(T,cb##caps,cb) \ 378 T var = cb##caps->data; \ 379 CallBacker* cber = cb##caps->caller 394 template <
class T,
class C>
450 #define mDeclInstanceCreatedNotifierAccess(clss) \ 451 static Notifier<clss>& instanceCreated() 453 #define mDefineInstanceCreatedNotifierAccess(clss) \ 454 Notifier<clss>& clss::instanceCreated() \ 456 mDefineStaticLocalObject( Notifier<clss>, theNotif, (0)); \ 460 #define mTriggerInstanceCreatedNotifier() \ 461 instanceCreated().trigger( this ) #define mRefCountImpl(ClassName)
Macro to setup a class with destructor for reference counting.
Definition: refcount.h:163
#define mExpClass(module)
Definition: commondefs.h:160
Capsule class to wrap any class into a CallBacker.
Definition: callback.h:335
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
Temporarily disables a Notifier.
Definition: callback.h:429
bool enable(bool yn=true)
Definition: callback.h:181
bool isEmpty() const
Definition: callback.h:184
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
bool enabled_
Definition: callback.h:153
NotifierAccess & thenotif_
Definition: callback.h:441
void(* StaticCallBackFunction)(CallBacker *)
Definition: callback.h:44
void trigger(C c, T &t)
Definition: callback.h:399
bool disable()
Definition: callback.h:182
Interface class for Notifier. See comments there.
Definition: callback.h:161
friend class CallBacker
Definition: callback.h:165
Threads::Lock shutdownsubscriberlock_
Definition: callback.h:205
void(CallBacker::* CallBackFunction)(CallBacker *)
Definition: callback.h:38
bool willCall() const
Definition: callback.h:71
CallBacker * caller
Definition: callback.h:342
int operator==(const CallBack &c) const
Definition: callback.h:66
CallBack(CallBacker *o=0, CallBackFunction f=0)
Definition: callback.h:62
friend class NotifierAccess
Definition: callback.h:274
Definition: callback.h:254
T data
Definition: callback.h:341
Set of (small) copyable elements.
Definition: commontypes.h:30
int operator!=(const CallBack &cb) const
Definition: callback.h:68
bool isEnabled() const
Definition: callback.h:147
void trigger(C c, CallBacker *cb=0)
Definition: callback.h:405
void trigger(T &t)
Definition: callback.h:258
CNotifier(T *cb)
Definition: callback.h:403
StaticCallBackFunction scbFn() const
Definition: callback.h:78
bool isEnabled() const
Definition: callback.h:180
ObjectSet< NotifierAccess > attachednotifiers_
Definition: callback.h:309
CallBacker * obj_
Definition: callback.h:100
bool attachCB(NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false)
Definition: callback.h:286
ObjectSet< CallBacker > shutdownsubscribers_
Definition: callback.h:204
Notifier(T *c)
Definition: callback.h:261
CallBack(StaticCallBackFunction f)
Definition: callback.h:64
void trigger(CallBacker *c=0, CallBacker *exclude=0)
Definition: callback.h:263
StaticCallBackFunction sfn_
Definition: callback.h:102
CallBacker * cbObj()
Definition: callback.h:75
Threads::Lock attachednotifierslock_
Definition: callback.h:310
bool oldst_
Definition: callback.h:442
CallBackFunction cbFn() const
Definition: callback.h:77
static void doTrigger(CallBackSet &, CallBacker *c, CallBacker *exclude)
void detachCB(NotifierAccess *notif, const CallBack &cb)
Definition: callback.h:294
CallBackFunction fn_
Definition: callback.h:101
TypeSet of CallBacks with a few extras.
Definition: callback.h:128
Notifier with automatic capsule creation.
Definition: callback.h:395
CallBackSet & cbs_
Definition: callback.h:190
friend class NotifyStopper
Definition: callback.h:164
#define mClass(module)
Definition: commondefs.h:164
CallBacks object-oriented (object + method).
Definition: callback.h:57
CBCapsule(T d, CallBacker *c)
Definition: callback.h:338
Threads::Lock lock_
Definition: callback.h:151
const CallBacker * cbObj() const
Definition: callback.h:76
CallBacker * cber_
Definition: callback.h:191