su  1.12.11devel
 All Data Structures Files Functions Variables Typedefs Enumerator Macros Groups Pages
su_time.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef SU_TIME_H
26 
27 #define SU_TIME_H
28 
37 #ifndef SU_TYPES_H
38 #include "sofia-sip/su_types.h"
39 #endif
40 
41 SOFIA_BEGIN_DECLS
42 
45 
48 
51 
57 struct su_time_s {
58  unsigned long tv_sec;
59  unsigned long tv_usec;
60 };
62 typedef struct su_time_s su_time_t;
63 
70 typedef long su_duration_t;
71 
72 enum {
74  SU_DURATION_MAX = 0x7fffffffL
75 };
76 #define SU_DURATION_MAX SU_DURATION_MAX
77 
84 
86 #define SU_NTP_C(x) SU_U64_C(x)
87 
88 #define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2)
89 
91 #define SU_TIME_EPOCH 2208988800UL
92 
93 #define SU_E9 (1000000000U)
94 
96 #define SU_TIME64_MAX ((su_time64_t)(su_dur64_t)-1)
97 
100 
103 
104 SOFIAPUBFUN su_time_t su_time64_to_time(su_time64_t t);
105 SOFIAPUBFUN su_time64_t su_time_to_time64(su_time_t tv);
106 
108 
110 SOFIAPUBFUN void su_time(su_time_t *tv);
111 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
112 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
114 
117 
118 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
119 
120 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
121 
127 
128 #if !SU_HAVE_INLINE
132 #else
136 #endif
137 
138 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
139 
140 SOFIAPUBFUN uint64_t su_counter(void);
141 
142 SOFIAPUBFUN uint64_t su_nanocounter(void);
143 
145 
146 #if SU_HAVE_INLINE
147 
149 {
150  /*
151  * Multiply usec by 0.065536 (ie. 2**16 / 1E6)
152  *
153  * Utilize fact that 0.065536 == 1024 / 15625
154  */
155  return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
156 }
157 
160 {
161  return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
162 }
163 
166 {
167  return t + 1000000 * (su_dur64_t)offset;
168 }
169 
170 #endif
171 
172 SOFIA_END_DECLS
173 
174 #endif /* !defined(SU_TIME_H) */

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