su 1.12.10
|
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 00048 struct su_time_s { 00049 unsigned long tv_sec; 00050 unsigned long tv_usec; 00051 }; 00053 typedef struct su_time_s su_time_t; 00054 00061 typedef long su_duration_t; 00062 00063 enum { 00065 SU_DURATION_MAX = 0x7fffffffL 00066 }; 00067 #define SU_DURATION_MAX SU_DURATION_MAX 00068 00074 typedef uint64_t su_ntp_t; 00075 00077 #define SU_NTP_C(x) SU_U64_C(x) 00078 00079 #define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2) 00080 00082 #define SU_TIME_EPOCH 2208988800UL 00083 00084 typedef uint64_t su_nanotime_t; 00085 00086 #define SU_E9 (1000000000U) 00087 00088 SOFIAPUBFUN su_nanotime_t su_nanotime(su_nanotime_t *return_time); 00089 SOFIAPUBFUN su_nanotime_t su_monotime(su_nanotime_t *return_time); 00090 00091 SOFIAPUBFUN su_time_t su_now(void); 00092 SOFIAPUBFUN void su_time(su_time_t *tv); 00093 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2); 00094 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2); 00095 SOFIAPUBFUN su_duration_t su_duration(su_time_t const t1, su_time_t const t2); 00096 00097 SOFIAPUBFUN su_time_t su_time_add(su_time_t t, su_duration_t dur); 00098 SOFIAPUBFUN su_time_t su_time_dadd(su_time_t t, double dur); 00099 00100 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv); 00101 00102 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec))) 00103 00104 SOFIAPUBFUN su_ntp_t su_ntp_now(void); 00105 SOFIAPUBFUN uint32_t su_ntp_sec(void); 00106 SOFIAPUBFUN uint32_t su_ntp_hi(su_ntp_t); 00107 SOFIAPUBFUN uint32_t su_ntp_lo(su_ntp_t); 00108 SOFIAPUBFUN uint32_t su_ntp_mw(su_ntp_t ntp); 00109 00110 #if !SU_HAVE_INLINE 00111 SOFIAPUBFUN uint32_t su_ntp_fraq(su_time_t t); 00112 SOFIAPUBFUN uint32_t su_time_ms(su_time_t t); 00113 #else 00114 00115 su_inline uint32_t su_ntp_fraq(su_time_t t) 00116 { 00117 /* 00118 * Multiply usec by 0.065536 (ie. 2**16 / 1E6) 00119 * 00120 * Utilize fact that 0.065536 == 1024 / 15625 00121 */ 00122 return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625; 00123 } 00124 00126 su_inline uint32_t su_time_ms(su_time_t t) 00127 { 00128 return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000; 00129 } 00130 #endif 00131 00132 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo); 00133 00134 SOFIAPUBFUN uint64_t su_counter(void); 00135 00136 SOFIAPUBFUN uint64_t su_nanocounter(void); 00137 00138 SOFIAPUBFUN uint32_t su_random(); 00139 00140 SOFIA_END_DECLS 00141 00142 #endif /* !defined(SU_TIME_H) */