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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3309 - (show annotations) (download)
Mon Sep 13 02:14:37 2004 UTC (15 years, 4 months ago) by dlb
File size: 5675 byte(s)
ParseUtil deprecated; use DnsUtil & added TimeLimitFifo
1 #if defined(HAVE_CONFIG_H)
2 #include "resiprocate/config.hxx"
3 #endif
4
5
6 #include <limits.h>
7
8 #include "resiprocate/os/Socket.hxx"
9
10 #include "resiprocate/TimerQueue.hxx"
11 #include "resiprocate/TimerMessage.hxx"
12 #include "resiprocate/os/Logger.hxx"
13
14 using namespace resip;
15 using namespace std;
16
17 #define RESIPROCATE_SUBSYSTEM Subsystem::TRANSACTION
18
19 TimerQueue::TimerQueue(Fifo<TransactionMessage>& stateMachineFifo,
20 TimeLimitFifo<Message>& tuFifo)
21 : mStateMachineFifo(stateMachineFifo),
22 mTuFifo(tuFifo)
23 {}
24
25 unsigned int
26 TimerQueue::msTillNextTimer()
27 {
28 if (!mTimers.empty())
29 {
30 UInt64 next = mTimers.begin()->mWhen;
31 UInt64 now = Timer::getTimeMs();
32 if (now > next)
33 {
34 return 0;
35 }
36 else
37 {
38 UInt64 ret64 = next - now;
39 if ( ret64 > UInt64(INT_MAX) )
40 {
41 return INT_MAX;
42 }
43 else
44 {
45 int ret = int(ret64);
46 return ret;
47 }
48 }
49 }
50 else
51 {
52 return INT_MAX;
53 }
54 }
55
56 Timer::Id
57 TimerQueue::add(Timer::Type type, const Data& transactionId, unsigned long msOffset)
58 {
59 Timer t(msOffset, type, transactionId);
60 mTimers.insert(t);
61 DebugLog (<< "Adding timer: " << Timer::toData(type) << " tid=" << transactionId << " ms=" << msOffset);
62
63 return t.getId();
64 }
65
66 Timer::Id
67 TimerQueue::add(const Timer& t)
68 {
69 mTimers.insert(t);
70 DebugLog(<< "Adding application timer: " << t.getMessage()->brief());
71
72 return t.getId();
73 }
74
75 int
76 TimerQueue::size() const
77 {
78 return mTimers.size();
79 }
80
81 bool
82 TimerQueue::empty() const
83 {
84 return mTimers.empty();
85 }
86
87 void
88 TimerQueue::process()
89 {
90 // get the set of timers that have fired and insert TimerMsg into the state
91 // machine fifo and application messages into the TU fifo
92
93 Timer now(0);
94 for (std::multiset<Timer>::iterator i = mTimers.begin();
95 i != mTimers.upper_bound(now);)
96 {
97 if (i->mType != Timer::ApplicationTimer)
98 {
99 TimerMessage* t = new TimerMessage(i->mTransactionId, i->mType, i->mDuration);
100 // Leaked !ah! BUGBUG valgrind says leaked.
101 // 206884 bytes in 2270 blocks are definitely lost (...)
102 // by 0x8178A20: operator new(unsigned)
103 // by 0x80CDF75: resip::TimerQueue::process() (TimerQueue.cxx:63)
104 // by 0x80F6A4B: resip::Executive::processTimer() (Executive.cxx:52)
105
106 //DebugLog (<< Timer::toData(i->mType) << " fired (" << i->mTransactionId << ") adding to fifo");
107 mStateMachineFifo.add(t);
108 }
109 else
110 {
111 //DebugLog(<< "ApplicationTimer " << *i->getMessage());
112 // application timer -- queue the payload message
113 assert(i->getMessage());
114 if (!mTuFifo.add(i->getMessage(), TimeLimitFifo<Message>::InternalElement))
115 {
116 CritLog(<< "Hard fifo limit exceeded -- probably doomed");
117 }
118 }
119 mTimers.erase(i++);
120 }
121 }
122
123 void
124 TimerQueue::run()
125 {
126 assert(0);
127 // for the thread
128 }
129
130 ostream&
131 resip::operator<<(ostream& str, const TimerQueue& tq)
132 {
133 str << "TimerQueue[" ;
134
135 for (std::multiset<Timer>::const_iterator i = tq.mTimers.begin();
136 i != tq.mTimers.end(); ++i)
137 {
138 str << *i << " " ;
139 }
140
141 str << "]" << endl;
142 return str;
143 }
144
145
146 /* ====================================================================
147 * The Vovida Software License, Version 1.0
148 *
149 * Copyright (c) 2004 Vovida Networks, Inc. All rights reserved.
150 *
151 * Redistribution and use in source and binary forms, with or without
152 * modification, are permitted provided that the following conditions
153 * are met:
154 *
155 * 1. Redistributions of source code must retain the above copyright
156 * notice, this list of conditions and the following disclaimer.
157 *
158 * 2. Redistributions in binary form must reproduce the above copyright
159 * notice, this list of conditions and the following disclaimer in
160 * the documentation and/or other materials provided with the
161 * distribution.
162 *
163 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
164 * and "Vovida Open Communication Application Library (VOCAL)" must
165 * not be used to endorse or promote products derived from this
166 * software without prior written permission. For written
167 * permission, please contact vocal@vovida.org.
168 *
169 * 4. Products derived from this software may not be called "VOCAL", nor
170 * may "VOCAL" appear in their name, without prior written
171 * permission of Vovida Networks, Inc.
172 *
173 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
174 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
175 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
176 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
177 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
178 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
179 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
180 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
181 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
182 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
183 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
184 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
185 * DAMAGE.
186 *
187 * ====================================================================
188 *
189 * This software consists of voluntary contributions made by Vovida
190 * Networks, Inc. and many individuals on behalf of Vovida Networks,
191 * Inc. For more information on Vovida Networks, Inc., please see
192 * <http://www.vovida.org/>.
193 *
194 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27