PTLib
Version 2.10.10
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
notifier_ext.h
Go to the documentation of this file.
1
/*
2
* notifier_ext.h
3
*
4
* Smart Notifiers and Notifier Lists
5
*
6
* Portable Windows Library
7
*
8
* Copyright (c) 2004 Reitek S.p.A.
9
*
10
* The contents of this file are subject to the Mozilla Public License
11
* Version 1.0 (the "License"); you may not use this file except in
12
* compliance with the License. You may obtain a copy of the License at
13
* http://www.mozilla.org/MPL/
14
*
15
* Software distributed under the License is distributed on an "AS IS"
16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17
* the License for the specific language governing rights and limitations
18
* under the License.
19
*
20
* The Original Code is Portable Windows Library.
21
*
22
* The Initial Developer of the Original Code is Post Increment
23
*
24
* Contributor(s): ______________________________________.
25
*
26
* $Revision: 21788 $
27
* $Author: rjongbloed $
28
* $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
29
*/
30
31
#ifndef PTLIB_NOTIFIER_EXT_H
32
#define PTLIB_NOTIFIER_EXT_H
33
34
#ifdef P_USE_PRAGMA
35
#pragma interface
36
#endif
37
46
class
PSmartNotifieeRegistrar
47
{
48
public
:
49
PSmartNotifieeRegistrar
() :
m_ID
(P_MAX_INDEX) {}
50
~PSmartNotifieeRegistrar
() {
UnregisterNotifiee
(
m_ID
); }
51
52
void
Init
(
void
* obj) {
if
(
m_ID
== P_MAX_INDEX)
m_ID
=
RegisterNotifiee
(obj); }
53
unsigned
GetID
()
const
{
return
m_ID
; }
54
55
static
unsigned
RegisterNotifiee
(
void
* obj);
56
static
PBoolean
UnregisterNotifiee
(
unsigned
id
);
57
static
PBoolean
UnregisterNotifiee
(
void
* obj);
58
static
void
*
GetNotifiee
(
unsigned
id
);
59
60
protected
:
61
unsigned
m_ID
;
62
};
63
64
class
PSmartNotifierFunction
:
public
PNotifierFunction
65
{
66
PCLASSINFO(
PSmartNotifierFunction
,
PNotifierFunction
);
67
68
protected
:
69
unsigned
m_NotifieeID
;
70
71
public
:
72
PSmartNotifierFunction
(
unsigned
id
) :
PNotifierFunction
(&id),
m_NotifieeID
(id) { }
73
unsigned
GetNotifieeID
()
const
{
return
m_NotifieeID
; }
74
void
*
GetNotifiee
()
const
{
return
PSmartNotifieeRegistrar::GetNotifiee
(
m_NotifieeID
); }
75
PBoolean
IsValid
()
const
{
return
GetNotifiee
() != 0; }
76
};
77
78
#define PDECLARE_SMART_NOTIFIEE \
79
PSmartNotifieeRegistrar m_Registrar; \
80
81
#define PCREATE_SMART_NOTIFIEE m_Registrar.Init(this)
82
83
#define PDECLARE_SMART_NOTIFIER(notifier, notifiee, func) \
84
class func##_PSmartNotifier : public PSmartNotifierFunction { \
85
public: \
86
func##_PSmartNotifier(unsigned id) : PSmartNotifierFunction(id) { } \
87
virtual void Call(PObject & note, INT extra) const \
88
{ \
89
void * obj = GetNotifiee(); \
90
if (obj) \
91
((notifiee*)obj)->func((notifier &)note, extra); \
92
else \
93
PTRACE(2, "PWLib\tInvalid notifiee"); \
94
} \
95
}; \
96
friend class func##_PSmartNotifier; \
97
virtual void func(notifier & note, INT extra)
98
99
#define PCREATE_SMART_NOTIFIER(func) PNotifier(new func##_PSmartNotifier(m_Registrar.GetID()))
100
101
102
class
PNotifierList
:
public
PObject
103
{
104
PCLASSINFO(
PNotifierList
,
PObject
);
105
private
:
106
PLIST(_PNotifierList,
PNotifier
);
107
108
_PNotifierList m_TheList;
109
110
// Removes smart pointers to deleted objects
111
void
Cleanup();
112
113
public
:
114
PINDEX
GetSize
()
const
{
return
m_TheList.GetSize(); }
115
116
void
Add
(
PNotifier
* handler) { m_TheList.Append(handler); }
117
void
Remove
(
PNotifier
* handler) { m_TheList.Remove(handler); }
118
PBoolean
RemoveTarget
(
PObject
* obj);
119
PBoolean
Fire
(
PObject
& obj, INT val = 0);
120
121
// Moves all the notifiers in "that" to "this"
122
void
Move
(
PNotifierList
& that);
123
};
124
125
126
#endif // PTLIB_NOTIFIER_EXT_H
127
128
129
// End of File ///////////////////////////////////////////////////////////////
include
ptlib
notifier_ext.h
Generated on Tue May 7 2013 17:25:45 for PTLib by
1.8.3.1