reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Timer.hxx
Go to the documentation of this file.
1#if !defined(RESIP_TIMER_HXX)
2#define RESIP_TIMER_HXX
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8#include "rutil/Data.hxx"
10#include <iostream>
11#include "rutil/Time.hxx"
12
18
19namespace resip
20{
21
22class Message;
23
30class Timer
31{
32 public:
56
57 static Data toData(Type timer);
58
61 static void setupTimeOffsets()
62 {}
63
67 {
69 }
73 {
74 return ResipClock::getTimeMs();
75 }
79 {
81 }
86 {
87 return ResipClock::getRandomFutureTimeMs(futureMs);
88 }
92 {
94 }
95
104 static unsigned getMaxSystemTimeWaitMs(void)
105 {
107 }
108
109 static void resetT1(unsigned long t1);
110
111 // These values can be changed but it is not recommended to do so after a
112 // stack is up and running since they are not mutexed
113 // These times are all in ms
114 static unsigned long T1;
115 static unsigned long T2;
116 static unsigned long T4;
117 static unsigned long T100;
118
119 static unsigned long TB; // default 64*T1
120 static unsigned long TC;
121 static unsigned long TF; // default 64*T1
122 static unsigned long TH; // default 64*T1
123
124 static unsigned long TD;
125 static unsigned long TS;
126
127 static unsigned long TcpConnectTimeout;
128};
129
130// !bwc! There is some duplicated code between TransactionTimer and
131// TimerWithPayload. Should eventually create a single template class like the
132// following, and use it with Payload=Message* and Payload=TransactionTimer
133// template <typename Payload>
134// class Timestamped
135// {
136// // blah blah blah
137// private:
138// UInt64 mTimestamp;
139// Payload mPayload;
140// };
142{
143 public:
145
146 TransactionTimer(unsigned long ms,
147 Timer::Type type,
148 const Data& transactionId);
149
151
152 const Data& getTransactionId() const {return mTransactionId;}
153 Timer::Type getType() const { return mType; }
154 unsigned long getDuration() const { return mDuration;}
155
156 uint64_t getWhen() const {return mWhen;}
157#ifndef RESIP_USE_STL_STREAMS
158 EncodeStream& encode(EncodeStream& str) const;
159#endif
160 std::ostream& encode(std::ostream& str) const;
161
162 inline bool operator<(const TransactionTimer& rhs) const
163 {
164 return mWhen < rhs.mWhen;
165 }
166
167 inline bool operator>(const TransactionTimer& rhs) const
168 {
169 return mWhen > rhs.mWhen;
170 }
171
172 protected:
176 unsigned long mDuration; // duration of time in ms
177
178 private:
179 // disabled
181};
182
184{
185 public:
187
188 TimerWithPayload(unsigned long ms, Message* message);
190
191 // return the message to queue, possibly null
192 Message* getMessage() const { return mMessage; }
193
194 uint64_t getWhen() const {return mWhen;}
195#ifndef RESIP_USE_STL_STREAMS
196 EncodeStream& encode(EncodeStream& str) const;
197#endif
198 std::ostream& encode(std::ostream& str) const;
199
200 inline bool operator<(const TimerWithPayload& rhs) const
201 {
202 return mWhen < rhs.mWhen;
203 }
204
205 inline bool operator>(const TimerWithPayload& rhs) const
206 {
207 return mWhen > rhs.mWhen;
208 }
209
210 protected:
212 Message* mMessage; // message to queue on timeout
213
214 private:
215 // disabled
217};
218
219
220inline std::ostream& operator<<(std::ostream& str, const TransactionTimer& t)
221{
222 return t.encode(str);
223}
224
225inline std::ostream& operator<<(std::ostream& str, const TimerWithPayload& t)
226{
227 return t.encode(str);
228}
229
230#ifndef RESIP_USE_STL_STREAMS
232{
233 return t.encode(str);
234}
235
237{
238 return t.encode(str);
239}
240#endif
241
242}
243
244#if 0
245Timer Value Section Meaning
246----------------------------------------------------------------------
247T1 500ms default Section 17.1.1.1 RTT Estimate
248T2 4s Section 17.1.2.2 The maximum retransmit
252T4 5s Section 17.1.2.2 Maximum duration a
253 message will
255Timer A initially T1 Section 17.1.1.2 INVITE request retransmit
256 interval, for UDP only
257Timer B 64*T1 Section 17.1.1.2 INVITE transaction
258 timeout timer
259Timer C > 3min Section 16.6 proxy INVITE transaction
260 bullet 11 timeout
261Timer D > 32s for UDP Section 17.1.1.2 Wait time for response
262 0s for TCP/SCTP retransmits
263Timer E initially T1 Section 17.1.2.2 non-INVITE request
264 retransmit interval,
265 UDP only
266Timer F 64*T1 Section 17.1.2.2 non-INVITE transaction
267 timeout timer
268Timer G initially T1 Section 17.2.1 INVITE response
269 retransmit interval
270Timer H 64*T1 Section 17.2.1 Wait time for
272Timer I T4 for UDP Section 17.2.1 Wait time for
274Timer J 64*T1 for UDP Section 17.2.2 Wait time for
277Timer K T4 for UDP Section 17.1.2.2 Wait time for
279
280 Table 4: Summary of timers
281#endif
282
283#endif
284
285/* ====================================================================
286 * The Vovida Software License, Version 1.0
287 *
288 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
289 *
290 * Redistribution and use in source and binary forms, with or without
291 * modification, are permitted provided that the following conditions
292 * are met:
293 *
294 * 1. Redistributions of source code must retain the above copyright
295 * notice, this list of conditions and the following disclaimer.
296 *
297 * 2. Redistributions in binary form must reproduce the above copyright
298 * notice, this list of conditions and the following disclaimer in
299 * the documentation and/or other materials provided with the
300 * distribution.
301 *
302 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
303 * and "Vovida Open Communication Application Library (VOCAL)" must
304 * not be used to endorse or promote products derived from this
305 * software without prior written permission. For written
306 * permission, please contact vocal@vovida.org.
307 *
308 * 4. Products derived from this software may not be called "VOCAL", nor
309 * may "VOCAL" appear in their name, without prior written
310 * permission of Vovida Networks, Inc.
311 *
312 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
313 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
314 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
315 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
316 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
317 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
318 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
319 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
320 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
321 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
322 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
323 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
324 * DAMAGE.
325 *
326 * ====================================================================
327 *
328 * This software consists of voluntary contributions made by Vovida
329 * Networks, Inc. and many individuals on behalf of Vovida Networks,
330 * Inc. For more information on Vovida Networks, Inc., please see
331 * <http://www.vovida.org/>.
332 *
333 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
The base-class used for message-passing.
Definition Message.hxx:21
static unsigned getMaxSystemTimeWaitMs(void)
Some monotonic clock implementations may internally only return 32-bit values that will wrap.
Definition Time.hxx:92
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Time.hxx:69
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Time.hxx:76
static uint64_t getForever()
Infinit time in future.
Definition Time.cxx:245
static uint64_t getRandomFutureTimeMs(uint64_t futureMs)
Returns an absolute time in ms that is between 50% and 90% of passed in ms from now.
Definition Time.cxx:256
static uint64_t getTimeMicroSec()
Returns the current clock time in microseconds.
Definition Time.hxx:61
RESIP_HeapCount(TimerWithPayload)
EncodeStream & encode(EncodeStream &str) const
Definition Timer.cxx:189
bool operator>(const TimerWithPayload &rhs) const
Definition Timer.hxx:205
uint64_t getWhen() const
Definition Timer.hxx:194
bool operator<(const TimerWithPayload &rhs) const
Definition Timer.hxx:200
Message * getMessage() const
Definition Timer.hxx:192
This class is used to get the current system time.
Definition Timer.hxx:31
static unsigned long T100
Definition Timer.hxx:117
static unsigned long TF
Definition Timer.hxx:121
static Data toData(Type timer)
Definition Timer.cxx:71
static unsigned long TcpConnectTimeout
Definition Timer.hxx:127
static unsigned long TS
Definition Timer.hxx:125
static unsigned long TC
Definition Timer.hxx:120
static unsigned getMaxSystemTimeWaitMs(void)
On windows, change getSystemTime() to not use the actual clock time returned by ::GetSystemTime().
Definition Timer.hxx:104
static unsigned long T1
Definition Timer.hxx:114
static uint64_t getRandomFutureTimeMs(uint64_t futureMs)
Returns an absolute time in ms that is between 50% and 90% of passed in ms from now.
Definition Timer.hxx:85
@ TimerStateless
Definition Timer.hxx:51
@ ApplicationTimer
Definition Timer.hxx:53
@ TimerStaleClient
Definition Timer.hxx:49
@ TcpConnectTimer
Definition Timer.hxx:54
@ TimerStaleServer
Definition Timer.hxx:50
static void resetT1(unsigned long t1)
Definition Timer.cxx:60
static unsigned long TB
Definition Timer.hxx:119
static unsigned long TH
Definition Timer.hxx:122
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Timer.hxx:72
static unsigned long T4
Definition Timer.hxx:116
static uint64_t getForever()
Infinit time in future.
Definition Timer.hxx:91
RESIP_HeapCount(Timer)
static unsigned long T2
Definition Timer.hxx:115
static unsigned long TD
Definition Timer.hxx:124
static uint64_t getTimeMicroSec()
Returns the current clock time in microseconds.
Definition Timer.hxx:66
static void setupTimeOffsets()
Definition Timer.hxx:61
static uint64_t getTimeSecs()
Returns the current clock time in seconds.
Definition Timer.hxx:78
unsigned long getDuration() const
Definition Timer.hxx:154
unsigned long mDuration
Definition Timer.hxx:176
RESIP_HeapCount(TransactionTimer)
Timer::Type getType() const
Definition Timer.hxx:153
EncodeStream & encode(EncodeStream &str) const
Definition Timer.cxx:146
bool operator>(const TransactionTimer &rhs) const
Definition Timer.hxx:167
bool operator<(const TransactionTimer &rhs) const
Definition Timer.hxx:162
const Data & getTransactionId() const
Definition Timer.hxx:152
uint64_t getWhen() const
Definition Timer.hxx:156
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream
void list()
Definition userAdmin.cxx:66