Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

notifier_ext.h

Go to the documentation of this file.
00001 /* 00002 * notifier_ext.h 00003 * 00004 * Smart Notifiers and Notifier Lists 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 2004 Reitek S.p.A. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Post Increment 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: notifier_ext.h,v $ 00027 * Revision 1.4 2004/05/17 11:02:39 csoutheren 00028 * Added extra documentation 00029 * 00030 * Revision 1.3 2004/05/09 07:23:48 rjongbloed 00031 * More work on XMPP, thanks Federico Pinna and Reitek S.p.A. 00032 * 00033 * Revision 1.2 2004/04/26 01:34:58 rjongbloed 00034 * Change nofier list to be able to used in containers, thanks Federico Pinna, Reitek S.p.A. 00035 * 00036 * Revision 1.1 2004/04/22 12:31:00 rjongbloed 00037 * Added PNotifier extensions and XMPP (Jabber) support, 00038 * thanks to Federico Pinna and Reitek S.p.A. 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 // Removes smart pointers to deleted objects 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 // Moves all the notifiers in "that" to "this" 00134 void Move(PNotifierList& that); 00135 }; 00136 00137 00138 #endif // _PNOTIFIER_EXT 00139 00140 // End of File /////////////////////////////////////////////////////////////// 00141 00142 00143

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7