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 
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 SOFIAPUBFUN su_time_t su_now(void);
00085 SOFIAPUBFUN void su_time(su_time_t *tv);
00086 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
00087 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
00088 SOFIAPUBFUN su_duration_t su_duration(su_time_t const t1, su_time_t const t2);
00089 
00090 SOFIAPUBFUN su_time_t su_time_add(su_time_t t, su_duration_t dur);
00091 SOFIAPUBFUN su_time_t su_time_dadd(su_time_t t, double dur);
00092 
00093 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
00094 
00095 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
00096 
00097 SOFIAPUBFUN su_ntp_t su_ntp_now(void);
00098 SOFIAPUBFUN uint32_t su_ntp_sec(void);
00099 SOFIAPUBFUN uint32_t su_ntp_hi(su_ntp_t);
00100 SOFIAPUBFUN uint32_t su_ntp_lo(su_ntp_t);
00101 SOFIAPUBFUN uint32_t su_ntp_mw(su_ntp_t ntp);
00102 
00103 #if !SU_HAVE_INLINE
00104 SOFIAPUBFUN uint32_t su_ntp_fraq(su_time_t t);
00105 SOFIAPUBFUN uint32_t su_time_ms(su_time_t t);
00106 #else
00107 
00108 su_inline uint32_t su_ntp_fraq(su_time_t t)
00109 {
00110   /*
00111    * Multiply usec by 0.065536 (ie. 2**16 / 1E6)
00112    * 
00113    * Utilize fact that 0.065536 == 1024 / 15625
00114    */
00115   return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
00116 }
00117 
00119 su_inline uint32_t su_time_ms(su_time_t t)
00120 {
00121   return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
00122 }
00123 #endif
00124 
00125 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
00126 
00127 SOFIAPUBFUN uint64_t su_counter(void);
00128 
00129 SOFIAPUBFUN uint64_t su_nanocounter(void);
00130 
00131 SOFIAPUBFUN uint32_t su_random();
00132 
00133 SOFIA_END_DECLS
00134 
00135 #endif /* !defined(SU_TIME_H) */

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