reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TuSelector.cxx
Go to the documentation of this file.
7
11#include "rutil/Logger.hxx"
12#define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
13
14using namespace resip;
15
17 mFallBackFifo(fallBackFifo),
18 mCongestionManager(0),
19 mFallbackPostNotify(0),
20 mTuSelectorMode(false),
21 mStatsPayload()
22{
23 mShutdownFifo.setDescription("TuSelector::mShutdownFifo");
24}
25
27{
28 //assert(mTuList.empty());
29}
30
31
32void
34{
35 mFallbackPostNotify = handler;
36}
37
38void
40{
41 if (mShutdownFifo.messageAvailable())
42 {
43 TransactionUserMessage* msg = mShutdownFifo.getNext();
44
45 switch (msg->type())
46 {
48 InfoLog (<< "TransactionUserMessage::RequestShutdown " << *(msg->getTransactionUser()));
49 markShuttingDown(msg->getTransactionUser());
50 break;
52 InfoLog (<< "TransactionUserMessage::RemoveTransactionUser " << *(msg->getTransactionUser()));
53 remove(msg->getTransactionUser());
54 break;
55 default:
56 resip_assert(0);
57 break;
58 }
59 delete msg;
60 }
61}
62
63void
65{
66 if (msg->hasTransactionUser())
67 {
68 if (exists(msg->getTransactionUser()))
69 {
70 DebugLog (<< "Send to " << *(msg->getTransactionUser()) << " " << std::endl << std::endl << *msg);
71 msg->getTransactionUser()->postToTransactionUser(msg, usage);
72 }
73 else
74 {
75 WarningLog (<< "Send to TU that no longer exists: " << std::endl << std::endl << *msg);
76 delete msg;
77 }
78 }
79 else
80 {
81 StatisticsMessage* stats = dynamic_cast<StatisticsMessage*>(msg);
82 if (stats)
83 {
84 InfoLog(<< "Stats message " );
85 stats->loadOut(mStatsPayload);
86 stats->logStats(RESIPROCATE_SUBSYSTEM, mStatsPayload);
87 delete msg;
88 }
89 else
90 {
91 DebugLog(<< "Send to default TU: " << std::endl << std::endl << *msg);
92 mFallBackFifo.add(msg, usage);
93 if ( mFallbackPostNotify )
94 mFallbackPostNotify->handleProcessNotification();
95 }
96 }
97}
98
99void
101{
102 InfoLog (<< "Sending " << term->brief() << " to TUs");
103
104 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
105 {
106 if (!it->shuttingDown && it->tu->isRegisteredForConnectionTermination())
107 {
108 it->tu->post(term->clone());
109 }
110 }
111}
112
113void
115{
116 //InfoLog (<< "Sending " << *pong << " to TUs");
117
118 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
119 {
120 if (!it->shuttingDown && it->tu->isRegisteredForKeepAlivePongs())
121 {
122 it->tu->post(pong->clone());
123 }
124 }
125}
126
127bool
129{
130 if (mTuSelectorMode)
131 {
132 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
133 {
134 if (!it->shuttingDown && !it->tu->wouldAccept(usage))
135 {
136 return false;
137 }
138 }
139 return true;
140 }
141 else
142 {
143 return mFallBackFifo.wouldAccept(usage);
144 }
145}
146
147unsigned int
149{
150 if (mTuSelectorMode)
151 {
152 unsigned int total=0;
153 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
154 {
155 total += it->tu->size();
156 }
157 return total;
158 }
159 else
160 {
161 return mFallBackFifo.size();
162 }
163}
164
165void
167{
168 mTuSelectorMode = true;
169 if(front)
170 {
171 mTuList.insert(mTuList.begin(), Item(&tu));
172 }
173 else
174 {
175 mTuList.push_back(Item(&tu));
176 }
177}
178
179void
185
186void
192
195{
196 DebugLog(<< "TuSelector::selectTransactionUser: Checking which TU message belongs to:" << std::endl << std::endl << msg);
197 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
198 {
199 if (it->tu->isForMe(msg))
200 {
201 return it->tu;
202 }
203 }
204 return 0;
205}
206
207void
208TuSelector::markShuttingDown(TransactionUser* tu)
209{
210 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
211 {
212 if (it->tu == tu)
213 {
214 it->shuttingDown = true;
215 return;
216 }
217 }
218 resip_assert(0);
219}
220
221void
222TuSelector::remove(TransactionUser* tu)
223{
224 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
225 {
226 if (it->tu == tu)
227 {
229 tu->post(done);
230 mTuList.erase(it);
231 return;
232 }
233 }
234 resip_assert(0);
235}
236
237bool
238TuSelector::exists(TransactionUser* tu)
239{
240 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
241 {
242 if (it->tu == tu)
243 {
244 return true;
245 }
246 }
247 return false;
248}
249
250unsigned int
252{
253 if(mShutdownFifo.messageAvailable()) // || !mFallBackFifo.messageAvailable()) // .slg. fallback fifo is not really used
254 {
255 return 0;
256 }
257 else
258 {
259 return INT_MAX;
260 }
261}
262
263bool
265{
266 if (mTuSelectorMode)
267 {
268 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
269 {
270 if (!it->shuttingDown && it->tu == tu)
271 {
272 return true;
273 }
274 }
275 }
276 return false;
277}
278
279void
281{
282 for(TuList::iterator i=mTuList.begin(); i!=mTuList.end();++i)
283 {
284 i->tu->setCongestionManager(manager);
285 }
286
287 // Note: We are intentionally not registering the following Fifos
288 // mFallbackFifo - this is the same fifo as SipStack::TuFifo (passed in
289 // constructor).
290 // mShutdownFifo - since it is only used at shutdown time, it doesn need
291 // congestion management
292}
293
296{
297 if(!mCongestionManager)
298 {
300 }
301
302 if(tu)
303 {
304 return tu->getRejectionBehavior();
305 }
306
307 return mCongestionManager->getRejectionBehavior(&mFallBackFifo);
308}
309
312{
313 if(tu)
314 {
315 return tu->getExpectedWait();
316 }
317
318 return (uint32_t)mFallBackFifo.expectedWaitTimeMilliSec();
319}
320
321
322
323/* ====================================================================
324 * The Vovida Software License, Version 1.0
325 *
326 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
327 *
328 * Redistribution and use in source and binary forms, with or without
329 * modification, are permitted provided that the following conditions
330 * are met:
331 *
332 * 1. Redistributions of source code must retain the above copyright
333 * notice, this list of conditions and the following disclaimer.
334 *
335 * 2. Redistributions in binary form must reproduce the above copyright
336 * notice, this list of conditions and the following disclaimer in
337 * the documentation and/or other materials provided with the
338 * distribution.
339 *
340 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
341 * and "Vovida Open Communication Application Library (VOCAL)" must
342 * not be used to endorse or promote products derived from this
343 * software without prior written permission. For written
344 * permission, please contact vocal@vovida.org.
345 *
346 * 4. Products derived from this software may not be called "VOCAL", nor
347 * may "VOCAL" appear in their name, without prior written
348 * permission of Vovida Networks, Inc.
349 *
350 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
351 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
352 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
353 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
354 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
355 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
356 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
357 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
358 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
359 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
360 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
361 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
362 * DAMAGE.
363 *
364 * ====================================================================
365 *
366 * This software consists of voluntary contributions made by Vovida
367 * Networks, Inc. and many individuals on behalf of Vovida Networks,
368 * Inc. For more information on Vovida Networks, Inc., please see
369 * <http://www.vovida.org/>.
370 *
371 */
#define RESIPROCATE_SUBSYSTEM
#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.
static void usage(void)
Definition adig.c:755
virtual void handleProcessNotification()=0
Abstract base class that provides a basic congestion management interface.
virtual RejectionBehavior getRejectionBehavior(const FifoStatsInterface *fifo) const =0
Return the current rejection behavior for this fifo.
@ NORMAL
Not rejecting any work.
virtual Message * clone() const
virtual Message * clone() const
The base-class used for message-passing.
Definition Message.hxx:21
virtual Brief brief() const
return a facet for brief encoding of message
Definition Message.cxx:16
bool hasTransactionUser() const
Definition Message.hxx:47
TransactionUser * getTransactionUser()
Definition Message.hxx:49
Represents a SIP message.
void loadOut(Payload &payload) const
static void logStats(const Subsystem &subsystem, const Payload &stats)
The base-class for an RFC 3261 Transaction User.
virtual const uint16_t getExpectedWait() const
void post(Message *msg)
Posts a Message to this TransactionUser's fifo.
CongestionManager::RejectionBehavior getRejectionBehavior() const
TransactionUser * selectTransactionUser(const SipMessage &msg)
CongestionManager::RejectionBehavior getRejectionBehavior(TransactionUser *tu) const
void requestTransactionUserShutdown(TransactionUser &)
bool wouldAccept(TimeLimitFifo< Message >::DepthUsage usage) const
void add(Message *msg, TimeLimitFifo< Message >::DepthUsage usage)
uint32_t getExpectedWait(TransactionUser *tu) const
void setFallbackPostNotify(AsyncProcessHandler *handler)
unsigned int size() const
unsigned int getTimeTillNextProcessMS()
void setCongestionManager(CongestionManager *manager)
bool isTransactionUserStillRegistered(const TransactionUser *) const
TuSelector(TimeLimitFifo< Message > &fallBackFifo)
void unregisterTransactionUser(TransactionUser &)
void registerTransactionUser(TransactionUser &, const bool front=false)
dcm! – add UnusedChecking(_enum) below;
unsigned int uint32_t
Definition Stun.hxx:34