reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
HandleManager.cxx
Go to the documentation of this file.
1#include "rutil/ResipAssert.h"
2#include "rutil/Logger.hxx"
3#include "rutil/Inserter.hxx"
6
7using namespace resip;
8#define RESIPROCATE_SUBSYSTEM Subsystem::DUM
9
11 mShuttingDown(false),
12 mLastId(Handled::npos)
13{
14}
15
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: Deleting handlemanager that still has Handled objects: " );
27 //throw HandleException("Deleting handlemanager that still has Handled objects", __FILE__, __LINE__);
28 }
29}
30
33{
34 mHandleMap[++mLastId] = handled;
35 return mLastId;
36}
37
39{
40 mShuttingDown = true;
41 if (mHandleMap.empty())
42 {
44 }
45 else
46 {
47 DebugLog (<< "Shutdown waiting for all usages to be deleted (" << mHandleMap.size() << ")");
48#if 1
49 for (HandleMap::iterator i=mHandleMap.begin() ; i != mHandleMap.end(); ++i)
50 {
51 DebugLog (<< i->first << " -> " << *(i->second));
52 }
53#endif
54 }
55}
56
57#if 0
58// !jf! this will leak if there are active usages
60{
61 WarningLog(<< "Forcing shutdown " << mHandleMap.size() << " active usages");
62 for (HandleMap::const_iterator i = mHandleMap.begin();
63 i != mHandleMap.end(); ++i)
64 {
65 InfoLog(<< "Handled left at force shutdown: " << *i->second);
66 }
67 mHandleMap.clear();
68}
69#endif
70
71void
73{
74 HandleMap::iterator i = mHandleMap.find(id);
75 resip_assert (i != mHandleMap.end());
76 mHandleMap.erase(i);
77 if (mShuttingDown)
78 {
79 if(mHandleMap.empty())
80 {
82 }
83 else
84 {
85 DebugLog (<< "Waiting for usages to be deleted (" << mHandleMap.size() << ")");
86 }
87 }
88}
89
90void
92{
93 DebugLog (<< "Waiting for usages to be deleted (" << mHandleMap.size() << ")");
94 for (HandleMap::const_iterator i=mHandleMap.begin() ; i != mHandleMap.end(); ++i)
95 {
96 DebugLog (<< i->first << " -> " << *(i->second));
97 }
98}
99
100bool
102{
103 return mHandleMap.find(id) != mHandleMap.end();
104}
105
106Handled*
108{
109 HandleMap::const_iterator i = mHandleMap.find(id);
110 if (i == mHandleMap.end())
111 {
112 InfoLog (<< "Reference to stale handle: " << id);
113 resip_assert(0);
114 throw HandleException("Stale handle", __FILE__, __LINE__);
115 }
116 else
117 {
118 resip_assert(i->second);
119 return i->second;
120 }
121}
122
123
124/* ====================================================================
125 * The Vovida Software License, Version 1.0
126 *
127 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
128 *
129 * Redistribution and use in source and binary forms, with or without
130 * modification, are permitted provided that the following conditions
131 * are met:
132 *
133 * 1. Redistributions of source code must retain the above copyright
134 * notice, this list of conditions and the following disclaimer.
135 *
136 * 2. Redistributions in binary form must reproduce the above copyright
137 * notice, this list of conditions and the following disclaimer in
138 * the documentation and/or other materials provided with the
139 * distribution.
140 *
141 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
142 * and "Vovida Open Communication Application Library (VOCAL)" must
143 * not be used to endorse or promote products derived from this
144 * software without prior written permission. For written
145 * permission, please contact vocal@vovida.org.
146 *
147 * 4. Products derived from this software may not be called "VOCAL", nor
148 * may "VOCAL" appear in their name, without prior written
149 * permission of Vovida Networks, Inc.
150 *
151 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
152 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
153 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
154 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
155 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
156 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
157 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
158 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
159 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
160 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
161 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
162 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
163 * DAMAGE.
164 *
165 * ====================================================================
166 *
167 * This software consists of voluntary contributions made by Vovida
168 * Networks, Inc. and many individuals on behalf of Vovida Networks,
169 * Inc. For more information on Vovida Networks, Inc., please see
170 * <http://www.vovida.org/>.
171 *
172 */
173
#define DebugLog(args_)
Definition Logger.hxx:128
#define InfoLog(args_)
Definition Logger.hxx:131
#define WarningLog(args_)
Definition Logger.hxx:134
#define resip_assert(x)
This file needs to work for both C and C++ code.
void remove(Handled::Id id)
bool isValidHandle(Handled::Id) const
Handled * getHandled(Handled::Id) const
virtual void shutdownWhenEmpty()
virtual void onAllHandlesDestroyed()=0
Handled::Id create(Handled *handled)
virtual void dumpHandles() const
unsigned long Id
Definition Handled.hxx:15
dcm! – add UnusedChecking(_enum) below;
InserterPClass< T > InserterP(const T &t)
Templatized function to construct an instance of InserterClass for a container to be inserted.
Definition Inserter.hxx:558