/[resiprocate]/main/sip/resiprocate/TuSelector.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/TuSelector.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4602 - (show annotations) (download)
Thu May 12 01:27:52 2005 UTC (14 years, 7 months ago) by derek
File size: 6710 byte(s)
added missing vocal licences
1 #include "resiprocate/TuSelector.hxx"
2 #include "resiprocate/TransactionUser.hxx"
3 #include "resiprocate/TransactionUserMessage.hxx"
4 #include "resiprocate/SipStack.hxx"
5 #include "resiprocate/os/TimeLimitFifo.hxx"
6 #include "resiprocate/os/WinLeakCheck.hxx"
7
8 #include "resiprocate/os/Logger.hxx"
9 #define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
10
11 using namespace resip;
12
13 TuSelector::TuSelector(TimeLimitFifo<Message>& fallBackFifo) :
14 mFallBackFifo(fallBackFifo) ,
15 mTuSelectorMode(false),
16 mStatsPayload()
17 {
18 }
19
20 TuSelector::~TuSelector()
21 {
22 //assert(mTuList.empty());
23 }
24
25 void
26 TuSelector::process()
27 {
28 if (mShutdownFifo.messageAvailable())
29 {
30 TransactionUserMessage* msg = mShutdownFifo.getNext();
31
32 switch (msg->type())
33 {
34 case TransactionUserMessage::RequestShutdown:
35 InfoLog (<< "TransactionUserMessage::RequestShutdown " << *(msg->tu));
36 markShuttingDown(msg->tu);
37 break;
38 case TransactionUserMessage::RemoveTransactionUser:
39 InfoLog (<< "TransactionUserMessage::RemoveTransactionUser " << *(msg->tu));
40 remove(msg->tu);
41 break;
42 default:
43 assert(0);
44 break;
45 }
46 delete msg;
47 }
48 }
49
50 void
51 TuSelector::add(Message* msg, TimeLimitFifo<Message>::DepthUsage usage)
52 {
53 if (msg->hasTransactionUser())
54 {
55 if (exists(msg->getTransactionUser()))
56 {
57 msg->getTransactionUser()->postToTransactionUser(msg, usage);
58 }
59 else
60 {
61 delete msg;
62 }
63 }
64 else
65 {
66 StatisticsMessage* stats = dynamic_cast<StatisticsMessage*>(msg);
67 if (stats)
68 {
69 InfoLog(<< "Stats message " );
70 stats->loadOut(mStatsPayload);
71 stats->logStats(RESIPROCATE_SUBSYSTEM, mStatsPayload);
72 delete msg;
73 }
74 else
75 {
76 mFallBackFifo.add(msg, usage);
77 }
78 }
79 }
80
81 bool
82 TuSelector::wouldAccept(TimeLimitFifo<Message>::DepthUsage usage) const
83 {
84 if (mTuSelectorMode)
85 {
86 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
87 {
88 if (!it->shuttingDown && !it->tu->wouldAccept(usage))
89 {
90 return false;
91 }
92 }
93 return true;
94 }
95 else
96 {
97 return mFallBackFifo.wouldAccept(usage);
98 }
99 }
100
101 unsigned int
102 TuSelector::size() const
103 {
104 if (mTuSelectorMode)
105 {
106 unsigned int total=0;
107 for(TuList::const_iterator it = mTuList.begin(); it != mTuList.end(); it++)
108 {
109 total += it->tu->size();
110 }
111 return total;
112 }
113 else
114 {
115 return mFallBackFifo.size();
116 }
117 }
118
119 void
120 TuSelector::registerTransactionUser(TransactionUser& tu)
121 {
122 mTuSelectorMode = true;
123 mTuList.push_back(Item(&tu));
124 }
125
126 void
127 TuSelector::requestTransactionUserShutdown(TransactionUser& tu)
128 {
129 TransactionUserMessage* msg = new TransactionUserMessage(TransactionUserMessage::RequestShutdown, &tu);
130 mShutdownFifo.add(msg);
131 }
132
133 void
134 TuSelector::unregisterTransactionUser(TransactionUser& tu)
135 {
136 TransactionUserMessage* msg = new TransactionUserMessage(TransactionUserMessage::RemoveTransactionUser, &tu);
137 mShutdownFifo.add(msg);
138 }
139
140 TransactionUser*
141 TuSelector::selectTransactionUser(const SipMessage& msg)
142 {
143 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
144 {
145 if (it->tu->isForMe(msg))
146 {
147 return it->tu;
148 }
149 }
150 return 0;
151 }
152
153 void
154 TuSelector::markShuttingDown(TransactionUser* tu)
155 {
156 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
157 {
158 if (it->tu == tu)
159 {
160 it->shuttingDown = true;
161 return;
162 }
163 }
164 assert(0);
165 }
166
167 void
168 TuSelector::remove(TransactionUser* tu)
169 {
170 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
171 {
172 if (it->tu == tu)
173 {
174 TransactionUserMessage* done = new TransactionUserMessage(TransactionUserMessage::TransactionUserRemoved, tu);
175 tu->postToTransactionUser(done, TimeLimitFifo<resip::Message>::InternalElement);
176 mTuList.erase(it);
177 return;
178 }
179 }
180 assert(0);
181 }
182
183 bool
184 TuSelector::exists(TransactionUser* tu)
185 {
186 for(TuList::iterator it = mTuList.begin(); it != mTuList.end(); it++)
187 {
188 if (it->tu == tu)
189 {
190 return true;
191 }
192 }
193 return false;
194 }
195
196
197 /* ====================================================================
198 * The Vovida Software License, Version 1.0
199 *
200 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
201 *
202 * Redistribution and use in source and binary forms, with or without
203 * modification, are permitted provided that the following conditions
204 * are met:
205 *
206 * 1. Redistributions of source code must retain the above copyright
207 * notice, this list of conditions and the following disclaimer.
208 *
209 * 2. Redistributions in binary form must reproduce the above copyright
210 * notice, this list of conditions and the following disclaimer in
211 * the documentation and/or other materials provided with the
212 * distribution.
213 *
214 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
215 * and "Vovida Open Communication Application Library (VOCAL)" must
216 * not be used to endorse or promote products derived from this
217 * software without prior written permission. For written
218 * permission, please contact vocal@vovida.org.
219 *
220 * 4. Products derived from this software may not be called "VOCAL", nor
221 * may "VOCAL" appear in their name, without prior written
222 * permission of Vovida Networks, Inc.
223 *
224 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
225 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
226 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
227 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
228 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
229 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
230 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
231 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
232 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
233 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
234 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
235 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
236 * DAMAGE.
237 *
238 * ====================================================================
239 *
240 * This software consists of voluntary contributions made by Vovida
241 * Networks, Inc. and many individuals on behalf of Vovida Networks,
242 * Inc. For more information on Vovida Networks, Inc., please see
243 * <http://www.vovida.org/>.
244 *
245 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27