/[resiprocate]/branches/b-identity-0505/dum/HandleManager.cxx
ViewVC logotype

Contents of /branches/b-identity-0505/dum/HandleManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 7 months ago) by derek
File size: 5530 byte(s)
set svn:eol-style to LF
1 #include <cassert>
2 #include "resiprocate/os/Logger.hxx"
3 #include "resiprocate/os/Inserter.hxx"
4 #include "resiprocate/dum/HandleManager.hxx"
5 #include "resiprocate/dum/HandleException.hxx"
6
7 using namespace resip;
8 #define RESIPROCATE_SUBSYSTEM Subsystem::DUM
9
10 HandleManager::HandleManager() :
11 mShuttingDown(false),
12 mLastId(Handled::npos)
13 {
14 }
15
16 HandleManager::~HandleManager()
17 {
18 // !jf! do nothing?
19 // !dcm! -- this is the best we can do w/out a back-ptr to each handle
20 // DUM currently cleans up properly, so not an issue unless users make their
21 // own handled objects, could clean up memeory, but the app will crash first
22 // handle deference regardless.
23 if (!mHandleMap.empty())
24 {
25 DebugLog ( << "&&&&&& HandleManager::~HandleManager " );
26 DebugLog ( << Inserter(mHandleMap) );
27 //throw HandleException("Deleting handlemanager that still has Handled objects", __FILE__, __LINE__);
28 }
29 }
30
31 Handled::Id
32 HandleManager::create(Handled* handled)
33 {
34 if (!mShuttingDown)
35 {
36 mHandleMap[++mLastId] = handled;
37 return mLastId;
38 }
39 else
40 {
41 return Handled::npos;
42 }
43 }
44
45 void HandleManager::shutdownWhenEmpty()
46 {
47 mShuttingDown = true;
48 if (mHandleMap.empty())
49 {
50 onAllHandlesDestroyed();
51 }
52 else
53 {
54 DebugLog (<< "Shutdown waiting for all usages to be deleted (" << mHandleMap.size() << ")");
55 #if 1
56 for (HandleMap::iterator i=mHandleMap.begin() ; i != mHandleMap.end(); ++i)
57 {
58 DebugLog (<< i->first << " -> " << *(i->second));
59 }
60 #endif
61 }
62 }
63
64 #if 0
65 // !jf! this will leak if there are active usages
66 void HandleManager::onAllHandlesDestroyed()
67 {
68 WarningLog(<< "Forcing shutdown " << mHandleMap.size() << " active usages");
69 for (HandleMap::const_iterator i = mHandleMap.begin();
70 i != mHandleMap.end(); ++i)
71 {
72 InfoLog(<< "Handled left at force shutdown: " << *i->second);
73 }
74 mHandleMap.clear();
75 }
76 #endif
77
78 void
79 HandleManager::remove(Handled::Id id)
80 {
81 HandleMap::iterator i = mHandleMap.find(id);
82 assert (i != mHandleMap.end());
83 mHandleMap.erase(i);
84 if (mShuttingDown)
85 {
86 if(mHandleMap.empty())
87 {
88 onAllHandlesDestroyed();
89 }
90 else
91 {
92 DebugLog (<< "Waiting for usages to be deleted (" << mHandleMap.size() << ")");
93 }
94 }
95 }
96
97 void
98 HandleManager::dumpHandles() const
99 {
100 DebugLog (<< "Waiting for usages to be deleted (" << mHandleMap.size() << ")");
101 for (HandleMap::const_iterator i=mHandleMap.begin() ; i != mHandleMap.end(); ++i)
102 {
103 DebugLog (<< i->first << " -> " << *(i->second));
104 }
105 }
106
107 bool
108 HandleManager::isValidHandle(Handled::Id id) const
109 {
110 //!dcm! -- fix; use find
111 return mHandleMap.count(id) != 0;
112 }
113
114 Handled*
115 HandleManager::getHandled(Handled::Id id) const
116 {
117 HandleMap::const_iterator i = mHandleMap.find(id);
118 if (i == mHandleMap.end())
119 {
120 InfoLog (<< "Reference to stale handle: " << id);
121 assert(0);
122 throw HandleException("Stale handle", __FILE__, __LINE__);
123 }
124 else
125 {
126 assert(i->second);
127 return i->second;
128 }
129 }
130
131
132 /* ====================================================================
133
134 * The Vovida Software License, Version 1.0
135
136 *
137
138 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
139
140 *
141
142 * Redistribution and use in source and binary forms, with or without
143
144 * modification, are permitted provided that the following conditions
145
146 * are met:
147
148 *
149
150 * 1. Redistributions of source code must retain the above copyright
151
152 * notice, this list of conditions and the following disclaimer.
153
154 *
155
156 * 2. Redistributions in binary form must reproduce the above copyright
157
158 * notice, this list of conditions and the following disclaimer in
159
160 * the documentation and/or other materials provided with the
161
162 * distribution.
163
164 *
165
166 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
167
168 * and "Vovida Open Communication Application Library (VOCAL)" must
169
170 * not be used to endorse or promote products derived from this
171
172 * software without prior written permission. For written
173
174 * permission, please contact vocal@vovida.org.
175
176 *
177
178 * 4. Products derived from this software may not be called "VOCAL", nor
179
180 * may "VOCAL" appear in their name, without prior written
181
182 * permission of Vovida Networks, Inc.
183
184 *
185
186 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
187
188 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189
190 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
191
192 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
193
194 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
195
196 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
197
198 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
199
200 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
201
202 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
203
204 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
205
206 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
207
208 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
209
210 * DAMAGE.
211
212 *
213
214 * ====================================================================
215
216 *
217
218 * This software consists of voluntary contributions made by Vovida
219
220 * Networks, Inc. and many individuals on behalf of Vovida Networks,
221
222 * Inc. For more information on Vovida Networks, Inc., please see
223
224 * <http://www.vovida.org/>.
225
226 *
227
228 */
229

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27