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 template <typename ParmType>
00063 class PNotifierFunctionTemplate : public PSmartObject
00064 {
00065 PCLASSINFO(PNotifierFunctionTemplate, PSmartObject);
00066
00067 public:
00069 PNotifierFunctionTemplate(
00070 void * obj
00071 ) { object = PAssertNULL(obj); }
00072
00076 virtual void Call(
00077 PObject & notifier,
00078 ParmType extra
00079 ) const = 0;
00080
00081 protected:
00082
00084 void * object;
00085 };
00086
00087 typedef PNotifierFunctionTemplate<INT> PNotifierFunction;
00088
00089
00108 template <typename ParmType>
00109 class PNotifierTemplate : public PSmartPointer
00110 {
00111 PCLASSINFO(PNotifierTemplate, PSmartPointer);
00112
00113 public:
00115 PNotifierTemplate(
00116 PNotifierFunctionTemplate<ParmType> * func = NULL
00117 ) : PSmartPointer(func) { }
00118
00124 virtual void operator()(
00125 PObject & notifier,
00126 ParmType extra
00127 ) const {
00128 if (PAssertNULL(object) != NULL)
00129 ((PNotifierFunctionTemplate<ParmType>*)object)->Call(notifier,extra);
00130 }
00131 };
00132
00136 typedef PNotifierTemplate<INT> PNotifier;
00137
00138
00163 #define PDECLARE_NOTIFIER2(notifier, notifiee, func, type) \
00164 class func##_PNotifier : public PNotifierFunctionTemplate<type> { \
00165 public: \
00166 func##_PNotifier(notifiee * obj) : PNotifierFunctionTemplate<type>(obj) { } \
00167 virtual void Call(PObject & note, type extra) const \
00168 { ((notifiee*)object)->func((notifier &)note, extra); } \
00169 }; \
00170 friend class func##_PNotifier; \
00171 virtual void func(notifier & note, type extra)
00172
00174 #define PDECLARE_NOTIFIER(notifier, notifiee, func) \
00175 PDECLARE_NOTIFIER2(notifier, notifiee, func, INT)
00176
00177
00186 #define PCREATE_NOTIFIER2_EXT(obj, notifiee, func, type) PNotifierTemplate<type>(new notifiee::func##_PNotifier(obj))
00187
00189 #define PCREATE_NOTIFIER_EXT( obj, notifiee, func) PCREATE_NOTIFIER2_EXT(obj, notifiee, func, INT)
00190
00191
00200 #define PCREATE_NOTIFIER2(func, type) PNotifierTemplate<type>(new func##_PNotifier(this))
00201
00203 #define PCREATE_NOTIFIER(func) PCREATE_NOTIFIER2(func, INT)
00204
00205
00206 #endif // PTLIB_NOTIFIER_H
00207
00208
00209