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