su 1.12.11devel
/build/buildd/sofia-sip-1.12.11+20110422/libsofia-sip-ua/su/sofia-sip/su_time.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef SU_TIME_H
00026 
00027 #define SU_TIME_H
00028 
00037 #ifndef SU_TYPES_H
00038 #include "sofia-sip/su_types.h"
00039 #endif
00040 
00041 SOFIA_BEGIN_DECLS
00042 
00044 typedef uint64_t su_time64_t;
00045 
00047 typedef su_time64_t su_nanotime_t;
00048 
00050 typedef int64_t su_dur64_t;
00051 
00057 struct su_time_s {
00058   unsigned long tv_sec;         
00059   unsigned long tv_usec;        
00060 };
00062 typedef struct su_time_s su_time_t;
00063 
00070 typedef long su_duration_t;
00071 
00072 enum {
00074   SU_DURATION_MAX = 0x7fffffffL
00075 };
00076 #define SU_DURATION_MAX SU_DURATION_MAX
00077 
00083 typedef uint64_t su_ntp_t;
00084 
00086 #define SU_NTP_C(x) SU_U64_C(x)
00087 
00088 #define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2)
00089 
00091 #define SU_TIME_EPOCH 2208988800UL
00092 
00093 #define SU_E9 (1000000000U)
00094 
00096 #define SU_TIME64_MAX ((su_time64_t)(su_dur64_t)-1)
00097 
00098 SOFIAPUBFUN su_time64_t su_nanotime(su_time64_t *return_time);
00099 SOFIAPUBFUN su_time64_t su_monotime(su_time64_t *return_time);
00100 
00101 SOFIAPUBFUN su_time64_t su_now64(void);
00102 SOFIAPUBFUN su_time64_t su_stamp64(void);
00103 
00104 SOFIAPUBFUN su_time_t su_time64_to_time(su_time64_t t);
00105 SOFIAPUBFUN su_time64_t su_time_to_time64(su_time_t tv);
00106 
00107 SOFIAPUBFUN su_duration_t su_duration64(su_time64_t t1, su_time64_t t2);
00108 
00109 SOFIAPUBFUN su_time_t su_now(void);
00110 SOFIAPUBFUN void su_time(su_time_t *tv);
00111 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
00112 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
00113 SOFIAPUBFUN su_duration_t su_duration(su_time_t const t1, su_time_t const t2);
00114 
00115 SOFIAPUBFUN su_time_t su_time_add(su_time_t t, su_duration_t dur);
00116 SOFIAPUBFUN su_time_t su_time_dadd(su_time_t t, double dur);
00117 
00118 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
00119 
00120 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
00121 
00122 SOFIAPUBFUN su_ntp_t su_ntp_now(void);
00123 SOFIAPUBFUN uint32_t su_ntp_sec(void);
00124 SOFIAPUBFUN uint32_t su_ntp_hi(su_ntp_t);
00125 SOFIAPUBFUN uint32_t su_ntp_lo(su_ntp_t);
00126 SOFIAPUBFUN uint32_t su_ntp_mw(su_ntp_t ntp);
00127 
00128 #if !SU_HAVE_INLINE
00129 SOFIAPUBFUN uint32_t su_ntp_fraq(su_time_t t);
00130 SOFIAPUBFUN uint32_t su_time_ms(su_time_t t);
00131 SOFIAPUBFUN su_time64_t su_time64_add(su_time64_t t, su_duration_t dur);
00132 #else
00133 su_inline uint32_t su_ntp_fraq(su_time_t t);
00134 su_inline uint32_t su_time_ms(su_time_t t);
00135 su_inline su_time64_t su_time64_add(su_time64_t t, su_duration_t dur);
00136 #endif
00137 
00138 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
00139 
00140 SOFIAPUBFUN uint64_t su_counter(void);
00141 
00142 SOFIAPUBFUN uint64_t su_nanocounter(void);
00143 
00144 SOFIAPUBFUN uint32_t su_random(void);
00145 
00146 #if SU_HAVE_INLINE
00147 
00148 su_inline uint32_t su_ntp_fraq(su_time_t t)
00149 {
00150   /*
00151    * Multiply usec by 0.065536 (ie. 2**16 / 1E6)
00152    *
00153    * Utilize fact that 0.065536 == 1024 / 15625
00154    */
00155   return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
00156 }
00157 
00159 su_inline uint32_t su_time_ms(su_time_t t)
00160 {
00161   return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
00162 }
00163 
00165 su_inline su_time64_t su_time64_add(su_time64_t t, su_duration_t offset)
00166 {
00167   return t + 1000000 * (su_dur64_t)offset;
00168 }
00169 
00170 #endif
00171 
00172 SOFIA_END_DECLS
00173 
00174 #endif /* !defined(SU_TIME_H) */
 All Data Structures Files Functions Variables Typedefs Enumerator Defines

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.