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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef _PNOTIFIER_EXT
00047 #define _PNOTIFIER_EXT
00048
00049 #ifdef P_USE_PRAGMA
00050 #pragma interface
00051 #endif
00052
00061 class PSmartNotifieeRegistrar
00062 {
00063 public:
00064 PSmartNotifieeRegistrar() : m_ID(P_MAX_INDEX) {}
00065 ~PSmartNotifieeRegistrar() { UnregisterNotifiee(m_ID); }
00066
00067 void Init(void * obj) { if (m_ID == P_MAX_INDEX) m_ID = RegisterNotifiee(obj); }
00068 unsigned GetID() const { return m_ID; }
00069
00070 static unsigned RegisterNotifiee(void * obj);
00071 static BOOL UnregisterNotifiee(unsigned id);
00072 static BOOL UnregisterNotifiee(void * obj);
00073 static void * GetNotifiee(unsigned id);
00074
00075 protected:
00076 unsigned m_ID;
00077 };
00078
00079 class PSmartNotifierFunction : public PNotifierFunction
00080 {
00081 PCLASSINFO(PSmartNotifierFunction, PNotifierFunction);
00082
00083 protected:
00084 unsigned m_NotifieeID;
00085
00086 public:
00087 PSmartNotifierFunction(unsigned id) : PNotifierFunction(&id), m_NotifieeID(id) { }
00088 unsigned GetNotifieeID() const { return m_NotifieeID; }
00089 void * GetNotifiee() const { return PSmartNotifieeRegistrar::GetNotifiee(m_NotifieeID); }
00090 BOOL IsValid() const { return GetNotifiee() != 0; }
00091 };
00092
00093 #define PDECLARE_SMART_NOTIFIEE \
00094 PSmartNotifieeRegistrar m_Registrar; \
00095
00096 #define PCREATE_SMART_NOTIFIEE m_Registrar.Init(this)
00097
00098 #define PDECLARE_SMART_NOTIFIER(notifier, notifiee, func) \
00099 class func##_PSmartNotifier : public PSmartNotifierFunction { \
00100 public: \
00101 func##_PSmartNotifier(unsigned id) : PSmartNotifierFunction(id) { } \
00102 virtual void Call(PObject & note, INT extra) const \
00103 { \
00104 void * obj = GetNotifiee(); \
00105 if (obj) \
00106 ((notifiee*)obj)->func((notifier &)note, extra); \
00107 else \
00108 PTRACE(2, "Invalid notifiee"); \
00109 } \
00110 }; \
00111 friend class func##_PSmartNotifier; \
00112 virtual void func(notifier & note, INT extra)
00113
00114 #define PCREATE_SMART_NOTIFIER(func) PNotifier(new func##_PSmartNotifier(m_Registrar.GetID()))
00115
00116
00117 class PNotifierList : public PObject
00118 {
00119 PCLASSINFO(PNotifierList, PObject);
00120 private:
00121 PLIST(_PNotifierList, PNotifier);
00122
00123 _PNotifierList m_TheList;
00124
00125
00126 void Cleanup();
00127
00128 public:
00129 PINDEX GetSize() const { return m_TheList.GetSize(); }
00130
00131 void Add(PNotifier * handler) { m_TheList.Append(handler); }
00132 void Remove(PNotifier * handler) { m_TheList.Remove(handler); }
00133 BOOL RemoveTarget(PObject * obj);
00134 BOOL Fire(PObject& obj, INT val = 0);
00135
00136
00137 void Move(PNotifierList& that);
00138 };
00139
00140
00141 #endif // _PNOTIFIER_EXT
00142
00143
00144
00145
00146