00001 #ifndef _PNOTIFIER_H
00002 #define _PNOTIFIER_H
00003
00004 #include <ptlib.h>
00005 #include <ptlib/smartptr.h>
00006
00008
00009
00034 class PNotifierFunction : public PSmartObject
00035 {
00036 PCLASSINFO(PNotifierFunction, PSmartObject);
00037
00038 public:
00040 PNotifierFunction(
00041 void * obj
00042 ) { object = PAssertNULL(obj); }
00043
00047 virtual void Call(
00048 PObject & notifier,
00049 INT extra
00050 ) const = 0;
00051
00052 protected:
00053
00055 void * object;
00056 };
00057
00058
00079 class PNotifier : public PSmartPointer
00080 {
00081 PCLASSINFO(PNotifier, PSmartPointer);
00082
00083 public:
00085 PNotifier(
00086 PNotifierFunction * func = NULL
00087 ) : PSmartPointer(func) { }
00088
00094 virtual void operator()(
00095 PObject & notifier,
00096 INT extra
00097 ) const {
00098 if (PAssertNULL(object) != NULL)
00099 ((PNotifierFunction*)object)->Call(notifier,extra);
00100 }
00101 };
00102
00103
00127 #define PDECLARE_NOTIFIER(notifier, notifiee, func) \
00128 class func##_PNotifier : public PNotifierFunction { \
00129 public: \
00130 func##_PNotifier(notifiee * obj) : PNotifierFunction(obj) { } \
00131 virtual void Call(PObject & note, INT extra) const \
00132 { ((notifiee*)object)->func((notifier &)note, extra); } \
00133 }; \
00134 friend class func##_PNotifier; \
00135 virtual void func(notifier & note, INT extra)
00136
00145 #define PCREATE_NOTIFIER2(obj, func) PNotifier(new func##_PNotifier(obj))
00146
00155 #define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(this, func)
00156
00157 #endif
00158