00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PTLIB_NOTIFIER_H
00032 #define PTLIB_NOTIFIER_H
00033
00034 #include <ptlib.h>
00035 #include <ptlib/smartptr.h>
00036
00038
00039
00062 class PNotifierFunction : public PSmartObject
00063 {
00064 PCLASSINFO(PNotifierFunction, PSmartObject);
00065
00066 public:
00068 PNotifierFunction(
00069 void * obj
00070 ) { object = PAssertNULL(obj); }
00071
00075 virtual void Call(
00076 PObject & notifier,
00077 INT extra
00078 ) const = 0;
00079
00080 protected:
00081
00083 void * object;
00084 };
00085
00086
00105 class PNotifier : public PSmartPointer
00106 {
00107 PCLASSINFO(PNotifier, PSmartPointer);
00108
00109 public:
00111 PNotifier(
00112 PNotifierFunction * func = NULL
00113 ) : PSmartPointer(func) { }
00114
00120 virtual void operator()(
00121 PObject & notifier,
00122 INT extra
00123 ) const {
00124 if (PAssertNULL(object) != NULL)
00125 ((PNotifierFunction*)object)->Call(notifier,extra);
00126 }
00127 };
00128
00129
00153 #define PDECLARE_NOTIFIER(notifier, notifiee, func) \
00154 class func##_PNotifier : public PNotifierFunction { \
00155 public: \
00156 func##_PNotifier(notifiee * obj) : PNotifierFunction(obj) { } \
00157 virtual void Call(PObject & note, INT extra) const \
00158 { ((notifiee*)object)->func((notifier &)note, extra); } \
00159 }; \
00160 friend class func##_PNotifier; \
00161 virtual void func(notifier & note, INT extra)
00162
00171 #define PCREATE_NOTIFIER2(obj, func) PNotifier(new func##_PNotifier(obj))
00172
00181 #define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(this, func)
00182
00183
00184 #endif // PTLIB_NOTIFIER_H
00185
00186
00187