reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TurnAllocationManager.cxx
Go to the documentation of this file.
1#include <rutil/Lock.hxx>
2
4#include "TurnAllocation.hxx"
5#include <rutil/Logger.hxx>
6#include "ReTurnSubsystem.hxx"
7
8#define RESIPROCATE_SUBSYSTEM ReTurnSubsystem::RETURN
9
10using namespace std;
11
12namespace reTurn {
13
17
19{
20 TurnAllocationMap::iterator it = mTurnAllocationMap.begin();
21 for(;it != mTurnAllocationMap.end();it++)
22 {
23 delete it->second;
24 }
25
26 InfoLog(<< "Turn Allocation Manager destroyed.");
27}
28
29void
31{
32 resip_assert(findTurnAllocation(turnAllocation->getKey()) == 0);
33 mTurnAllocationMap[turnAllocation->getKey()] = turnAllocation;
34}
35
36void
38{
39 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
40 if(it != mTurnAllocationMap.end())
41 {
42 delete it->second;
43 mTurnAllocationMap.erase(it);
44 }
45}
46
49{
50 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
51 if(it != mTurnAllocationMap.end())
52 {
53 return it->second;
54 }
55 return 0;
56}
57
60{
61 TurnAllocationMap::iterator it;
62 for(it = mTurnAllocationMap.begin(); it != mTurnAllocationMap.end(); it++)
63 {
64 if(it->second->getRequestedTuple() == requestedTuple)
65 {
66 return it->second;
67 }
68 }
69 return 0;
70}
71
72void
73TurnAllocationManager::allocationExpired(const asio::error_code& e, const TurnAllocationKey& turnAllocationKey)
74{
75 if (e != asio::error::operation_aborted) // Note: nothing currently stops timers
76 {
77 // Timer was not cancelled, take necessary action.
78 InfoLog(<< "Turn Allocation Expired! clientLocal=" << turnAllocationKey.getClientLocalTuple() << " clientRemote=" << turnAllocationKey.getClientRemoteTuple());
79
80 TurnAllocationMap::iterator it = mTurnAllocationMap.find(turnAllocationKey);
81 if(it != mTurnAllocationMap.end())
82 {
83 if(time(0) >= it->second->getExpires())
84 {
85 delete it->second;
86 mTurnAllocationMap.erase(it);
87 }
88 }
89 }
90}
91
92} // namespace
93
94
95/* ====================================================================
96
97 Copyright (c) 2007-2008, Plantronics, Inc.
98 All rights reserved.
99
100 Redistribution and use in source and binary forms, with or without
101 modification, are permitted provided that the following conditions are
102 met:
103
104 1. Redistributions of source code must retain the above copyright
105 notice, this list of conditions and the following disclaimer.
106
107 2. Redistributions in binary form must reproduce the above copyright
108 notice, this list of conditions and the following disclaimer in the
109 documentation and/or other materials provided with the distribution.
110
111 3. Neither the name of Plantronics nor the names of its contributors
112 may be used to endorse or promote products derived from this
113 software without specific prior written permission.
114
115 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
116 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
117 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
118 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
119 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
120 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
121 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
122 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
123 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
124 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
125 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
126
127 ==================================================================== */
#define InfoLog(args_)
Definition Logger.hxx:131
#define resip_assert(x)
This file needs to work for both C and C++ code.
const StunTuple & getClientRemoteTuple() const
const StunTuple & getClientLocalTuple() const
void allocationExpired(const asio::error_code &e, const TurnAllocationKey &turnAllocationKey)
void removeTurnAllocation(const TurnAllocationKey &turnAllocationKey)
TurnAllocation * findTurnAllocation(const TurnAllocationKey &turnAllocationKey)
void addTurnAllocation(TurnAllocation *turnAllocation)
const TurnAllocationKey & getKey() const noexcept