00001 #ifndef _PNOTIFIER_H
00002 #define _PNOTIFIER_H
00003
00004 #include <ptlib.h>
00005 #include <ptlib/smartptr.h>
00006
00008
00009
00032 class PNotifierFunction : public PSmartObject
00033 {
00034 PCLASSINFO(PNotifierFunction, PSmartObject);
00035
00036 public:
00038 PNotifierFunction(
00039 void * obj
00040 ) { object = PAssertNULL(obj); }
00041
00045 virtual void Call(
00046 PObject & notifier,
00047 INT extra
00048 ) const = 0;
00049
00050 protected:
00051
00053 void * object;
00054 };
00055
00056
00075 class PNotifier : public PSmartPointer
00076 {
00077 PCLASSINFO(PNotifier, PSmartPointer);
00078
00079 public:
00081 PNotifier(
00082 PNotifierFunction * func = NULL
00083 ) : PSmartPointer(func) { }
00084
00090 virtual void operator()(
00091 PObject & notifier,
00092 INT extra
00093 ) const {
00094 if (PAssertNULL(object) != NULL)
00095 ((PNotifierFunction*)object)->Call(notifier,extra);
00096 }
00097 };
00098
00099
00123 #define PDECLARE_NOTIFIER(notifier, notifiee, func) \
00124 class func##_PNotifier : public PNotifierFunction { \
00125 public: \
00126 func##_PNotifier(notifiee * obj) : PNotifierFunction(obj) { } \
00127 virtual void Call(PObject & note, INT extra) const \
00128 { ((notifiee*)object)->func((notifier &)note, extra); } \
00129 }; \
00130 friend class func##_PNotifier; \
00131 virtual void func(notifier & note, INT extra)
00132
00141 #define PCREATE_NOTIFIER2(obj, func) PNotifier(new func##_PNotifier(obj))
00142
00151 #define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(this, func)
00152
00153 #endif
00154
00155