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