|
reSIProcate/rutil
9694
|
00001 #if !defined(RESIP_TIMER_HXX) 00002 #define RESIP_TIMER_HXX 00003 00004 #ifdef HAVE_CONFIG_H 00005 #include "config.h" 00006 #endif 00007 00008 #include "rutil/Data.hxx" 00009 #include "rutil/HeapInstanceCounter.hxx" 00010 #include <iostream> 00011 #include "rutil/Time.hxx" 00012 00013 namespace resip 00014 { 00015 00016 class Message; 00017 00024 class Timer 00025 { 00026 public: 00027 RESIP_HeapCount(Timer); 00028 typedef enum 00029 { 00030 TimerA, // doubling 00031 TimerB, 00032 TimerC, 00033 TimerD, 00034 TimerE1,// doubling 00035 TimerE2,// doubling 00036 TimerF, 00037 TimerG, // doubling 00038 TimerH, 00039 TimerI, 00040 TimerJ, 00041 TimerK, 00042 TimerTrying, 00043 TimerStaleClient, 00044 TimerStaleServer, 00045 TimerStateless, 00046 TimerCleanUp, 00047 ApplicationTimer // .dlb. Fifo, so no thread issues 00048 } Type; 00049 00050 static Data toData(Type timer); 00051 00054 static void setupTimeOffsets() 00055 {} 00056 00059 static UInt64 getTimeMicroSec() 00060 { 00061 return ResipClock::getTimeMicroSec(); 00062 } 00065 static UInt64 getTimeMs() 00066 { 00067 return ResipClock::getTimeMs(); 00068 } 00071 static UInt64 getTimeSecs() 00072 { 00073 return ResipClock::getTimeSecs(); 00074 } 00078 static UInt64 getRandomFutureTimeMs(UInt64 futureMs) 00079 { 00080 return ResipClock::getRandomFutureTimeMs(futureMs); 00081 } 00084 static UInt64 getForever() 00085 { 00086 return ResipClock::getForever(); 00087 } 00088 00097 static unsigned getMaxSystemTimeWaitMs(void) 00098 { 00099 return ResipClock::getMaxSystemTimeWaitMs(); 00100 } 00101 00102 static void resetT1(unsigned long t1); 00103 00104 // These values can be changed but it is not recommended to do so after a 00105 // stack is up and running since they are not mutexed 00106 // These times are all in ms 00107 static unsigned long T1; 00108 static unsigned long T2; 00109 static unsigned long T4; 00110 static unsigned long T100; 00111 00112 static unsigned long TB; // default 64*T1 00113 static unsigned long TC; 00114 static unsigned long TF; // default 64*T1 00115 static unsigned long TH; // default 64*T1 00116 00117 static unsigned long TD; 00118 static unsigned long TS; 00119 }; 00120 00121 // !bwc! There is some duplicated code between TransactionTimer and 00122 // TimerWithPayload. Should eventually create a single template class like the 00123 // following, and use it with Payload=Message* and Payload=TransactionTimer 00124 // template <typename Payload> 00125 // class Timestamped 00126 // { 00127 // // blah blah blah 00128 // private: 00129 // UInt64 mTimestamp; 00130 // Payload mPayload; 00131 // }; 00132 class TransactionTimer 00133 { 00134 public: 00135 RESIP_HeapCount(TransactionTimer); 00136 00137 TransactionTimer(unsigned long ms, 00138 Timer::Type type, 00139 const Data& transactionId); 00140 00141 ~TransactionTimer(){} 00142 00143 const Data& getTransactionId() const {return mTransactionId;} 00144 Timer::Type getType() const { return mType; } 00145 unsigned long getDuration() const { return mDuration;} 00146 00147 UInt64 getWhen() const {return mWhen;} 00148 #ifndef RESIP_USE_STL_STREAMS 00149 EncodeStream& encode(EncodeStream& str) const; 00150 #endif 00151 std::ostream& encode(std::ostream& str) const; 00152 00153 inline bool operator<(const TransactionTimer& rhs) const 00154 { 00155 return mWhen < rhs.mWhen; 00156 } 00157 00158 inline bool operator>(const TransactionTimer& rhs) const 00159 { 00160 return mWhen > rhs.mWhen; 00161 } 00162 00163 protected: 00164 UInt64 mWhen; 00165 Timer::Type mType; 00166 Data mTransactionId; 00167 unsigned long mDuration; // duration of time in ms 00168 00169 private: 00170 // disabled 00171 TransactionTimer(); 00172 }; 00173 00174 class TimerWithPayload 00175 { 00176 public: 00177 RESIP_HeapCount(TimerWithPayload); 00178 00179 TimerWithPayload(unsigned long ms, Message* message); 00180 00181 ~TimerWithPayload(){} 00182 00183 // return the message to queue, possibly null 00184 Message* getMessage() const { return mMessage;} 00185 00186 UInt64 getWhen() const {return mWhen;} 00187 #ifndef RESIP_USE_STL_STREAMS 00188 EncodeStream& encode(EncodeStream& str) const; 00189 #endif 00190 std::ostream& encode(std::ostream& str) const; 00191 00192 inline bool operator<(const TimerWithPayload& rhs) const 00193 { 00194 return mWhen < rhs.mWhen; 00195 } 00196 00197 inline bool operator>(const TimerWithPayload& rhs) const 00198 { 00199 return mWhen > rhs.mWhen; 00200 } 00201 00202 protected: 00203 UInt64 mWhen; 00204 Message* mMessage; // message to queue on timeout 00205 00206 private: 00207 // disabled 00208 TimerWithPayload(); 00209 }; 00210 00211 00212 inline std::ostream& operator<<(std::ostream& str, const TransactionTimer& t) 00213 { 00214 return t.encode(str); 00215 } 00216 00217 inline std::ostream& operator<<(std::ostream& str, const TimerWithPayload& t) 00218 { 00219 return t.encode(str); 00220 } 00221 00222 #ifndef RESIP_USE_STL_STREAMS 00223 inline EncodeStream& operator<<(EncodeStream& str, const TransactionTimer& t) 00224 { 00225 return t.encode(str); 00226 } 00227 00228 inline EncodeStream& operator<<(EncodeStream& str, const TimerWithPayload& t) 00229 { 00230 return t.encode(str); 00231 } 00232 #endif 00233 00234 } 00235 00236 #if 0 00237 Timer Value Section Meaning 00238 ---------------------------------------------------------------------- 00239 T1 500ms default Section 17.1.1.1 RTT Estimate 00240 T2 4s Section 17.1.2.2 The maximum retransmit 00241 interval for non-INVITE 00242 requests and INVITE 00243 responses 00244 T4 5s Section 17.1.2.2 Maximum duration a 00245 message will 00246 remain in the network 00247 Timer A initially T1 Section 17.1.1.2 INVITE request retransmit 00248 interval, for UDP only 00249 Timer B 64*T1 Section 17.1.1.2 INVITE transaction 00250 timeout timer 00251 Timer C > 3min Section 16.6 proxy INVITE transaction 00252 bullet 11 timeout 00253 Timer D > 32s for UDP Section 17.1.1.2 Wait time for response 00254 0s for TCP/SCTP retransmits 00255 Timer E initially T1 Section 17.1.2.2 non-INVITE request 00256 retransmit interval, 00257 UDP only 00258 Timer F 64*T1 Section 17.1.2.2 non-INVITE transaction 00259 timeout timer 00260 Timer G initially T1 Section 17.2.1 INVITE response 00261 retransmit interval 00262 Timer H 64*T1 Section 17.2.1 Wait time for 00263 ACK receipt 00264 Timer I T4 for UDP Section 17.2.1 Wait time for 00265 0s for TCP/SCTP ACK retransmits 00266 Timer J 64*T1 for UDP Section 17.2.2 Wait time for 00267 0s for TCP/SCTP non-INVITE request 00268 retransmits 00269 Timer K T4 for UDP Section 17.1.2.2 Wait time for 00270 0s for TCP/SCTP response retransmits 00271 00272 Table 4: Summary of timers 00273 #endif 00274 00275 #endif 00276 00277 /* ==================================================================== 00278 * The Vovida Software License, Version 1.0 00279 * 00280 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00281 * 00282 * Redistribution and use in source and binary forms, with or without 00283 * modification, are permitted provided that the following conditions 00284 * are met: 00285 * 00286 * 1. Redistributions of source code must retain the above copyright 00287 * notice, this list of conditions and the following disclaimer. 00288 * 00289 * 2. Redistributions in binary form must reproduce the above copyright 00290 * notice, this list of conditions and the following disclaimer in 00291 * the documentation and/or other materials provided with the 00292 * distribution. 00293 * 00294 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00295 * and "Vovida Open Communication Application Library (VOCAL)" must 00296 * not be used to endorse or promote products derived from this 00297 * software without prior written permission. For written 00298 * permission, please contact vocal@vovida.org. 00299 * 00300 * 4. Products derived from this software may not be called "VOCAL", nor 00301 * may "VOCAL" appear in their name, without prior written 00302 * permission of Vovida Networks, Inc. 00303 * 00304 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00305 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00306 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00307 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00308 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00309 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00310 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00311 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00312 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00313 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00314 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00315 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00316 * DAMAGE. 00317 * 00318 * ==================================================================== 00319 * 00320 * This software consists of voluntary contributions made by Vovida 00321 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00322 * Inc. For more information on Vovida Networks, Inc., please see 00323 * <http://www.vovida.org/>. 00324 * 00325 */
1.7.5.1