reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TupleMarkManager.cxx
Go to the documentation of this file.
2
4#include "rutil/Lock.hxx"
5#include "rutil/Timer.hxx"
6
7namespace resip
8{
9
12{
13 ListEntry entry(tuple,0);
14 TupleList::iterator i=mList.find(entry);
15
16 if(i!=mList.end())
17 {
19 if(i->first.mExpiry > now)
20 {
21 return i->second;
22 }
23 else
24 {
25 removeMark(tuple, i);
26 }
27 }
28
29 return OK;
30}
31
32void
34{
35 // .amr. Notify listeners first so they can change the entry if they want
36 notifyListeners(tuple,expiry,mark);
37 ListEntry entry(tuple,expiry);
38 mList[entry]=mark;
39}
40
41void
42TupleMarkManager::unmark(const Tuple& tuple, MarkType markFilter)
43{
44 ListEntry entry(tuple, 0);
45 TupleList::iterator i = mList.find(entry);
46
47 if (i != mList.end())
48 {
49 if (markFilter == BLACK || markFilter == i->second)
50 {
51 removeMark(tuple, i);
52 }
53 }
54}
55
56void
58{
59 mListeners.insert(listener);
60}
61
62void
64{
65 mListeners.erase(listener);
66}
67
68void
69TupleMarkManager::removeMark(const Tuple& tuple, TupleList::iterator i)
70{
71 mList.erase(i);
72 // ?bwc? Should we do this?
73 uint64_t expiry = 0;
75 notifyListeners(tuple, expiry, mark);
76}
77
78void
79TupleMarkManager::notifyListeners(const resip::Tuple& tuple, uint64_t& expiry, MarkType& mark)
80{
81 for(Listeners::iterator i = mListeners.begin(); i!=mListeners.end(); ++i)
82 {
83 (*i)->onMark(tuple,expiry,mark);
84 }
85}
86
87TupleMarkManager::ListEntry::ListEntry(const Tuple& tuple, uint64_t expiry)
88 : mTuple(tuple),
89 mExpiry(expiry)
90{}
91
92TupleMarkManager::ListEntry::ListEntry(const TupleMarkManager::ListEntry& orig)
93 : mTuple(orig.mTuple),
94 mExpiry(orig.mExpiry)
95{}
96
97TupleMarkManager::ListEntry::~ListEntry()
98{}
99
100bool
101TupleMarkManager::ListEntry::operator<(const TupleMarkManager::ListEntry& rhs) const
102{
103 if(mTuple < rhs.mTuple)
104 {
105 return true;
106 }
107 else if(rhs.mTuple < mTuple)
108 {
109 return false;
110 }
111
112 return mTuple.getTargetDomain() < rhs.mTuple.getTargetDomain();
113}
114
115bool
116TupleMarkManager::ListEntry::operator>(const TupleMarkManager::ListEntry& rhs) const
117{
118 if(rhs.mTuple < mTuple)
119 {
120 return true;
121 }
122 else if(mTuple < rhs.mTuple)
123 {
124 return false;
125 }
126
127 return mTuple.getTargetDomain() > rhs.mTuple.getTargetDomain();
128}
129
130bool
131TupleMarkManager::ListEntry::operator==(const TupleMarkManager::ListEntry& rhs) const
132{
133 return (mTuple==rhs.mTuple && mTuple.getTargetDomain()==rhs.mTuple.getTargetDomain());
134}
135
136
137}
138
139/* ====================================================================
140 * The Vovida Software License, Version 1.0
141 *
142 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
143 *
144 * Redistribution and use in source and binary forms, with or without
145 * modification, are permitted provided that the following conditions
146 * are met:
147 *
148 * 1. Redistributions of source code must retain the above copyright
149 * notice, this list of conditions and the following disclaimer.
150 *
151 * 2. Redistributions in binary form must reproduce the above copyright
152 * notice, this list of conditions and the following disclaimer in
153 * the documentation and/or other materials provided with the
154 * distribution.
155 *
156 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
157 * and "Vovida Open Communication Application Library (VOCAL)" must
158 * not be used to endorse or promote products derived from this
159 * software without prior written permission. For written
160 * permission, please contact vocal@vovida.org.
161 *
162 * 4. Products derived from this software may not be called "VOCAL", nor
163 * may "VOCAL" appear in their name, without prior written
164 * permission of Vovida Networks, Inc.
165 *
166 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
167 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
168 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
169 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
170 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
171 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
172 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
173 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
174 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
175 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
176 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
177 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
178 * DAMAGE.
179 *
180 * ====================================================================
181 *
182 * This software consists of voluntary contributions made by Vovida
183 * Networks, Inc. and many individuals on behalf of Vovida Networks,
184 * Inc. For more information on Vovida Networks, Inc., please see
185 * <http://www.vovida.org/>.
186 *
187 */
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Timer.hxx:72
void registerMarkListener(MarkListener *)
void mark(const Tuple &tuple, uint64_t expiry, MarkType mark)
void unregisterMarkListener(MarkListener *)
MarkType getMarkType(const Tuple &tuple)
void unmark(const Tuple &tuple, MarkType markFilter)
Represents a network address.
Definition Tuple.hxx:59
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39
unsigned __int64 uint64_t
Definition stdint.h:95