su  1.12.11devel
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) */
su_monotime
su_time64_t su_monotime(su_time64_t *return_time)
Get current monotonic time as nanoseconds.
Definition: su_time0.c:246
su_types.h
su_now64
su_time64_t su_now64(void)
Get current time as nanoseconds since epoch.
Definition: su_time0.c:194
su_time_diff
double su_time_diff(su_time_t const t1, su_time_t const t2)
Difference between two timestamps.
Definition: su_time.c:156
uint32_t
SU_U32_T uint32_t
32-bit unsigned integer
Definition: su_types.h:87
su_time_s
Time in seconds and microsecondcs.
Definition: su_time.h:57
su_inline
#define su_inline
Define as suitable declarator static inline functions.
Definition: su_configure.h:90
su_time_print
int su_time_print(char *s, int n, su_time_t const *tv)
Print su_time_t timestamp.
Definition: su_time.c:189
su_ntp_hi
uint32_t su_ntp_hi(su_ntp_t)
High 32 bit of NTP timestamp.
Definition: su_time.c:319
su_time_cmp
long su_time_cmp(su_time_t const t1, su_time_t const t2)
Compare two timestamps.
Definition: su_time.c:111
su_stamp64
su_time64_t su_stamp64(void)
Get current monotonic timestamp as nanoseconds.
Definition: su_time0.c:271
su_nanotime_t
su_time64_t su_nanotime_t
Time in nanoseconds.
Definition: su_time.h:47
su_time64_add
su_time64_t su_time64_add(su_time64_t t, su_duration_t dur)
Add offset in milliseconds to 64-bit nanosecond time.
Definition: su_time.h:165
su_ntp_fraq
uint32_t su_ntp_fraq(su_time_t t)
Middle 32 bit of NTP timestamp.
Definition: su_time.h:148
su_ntp_now
su_ntp_t su_ntp_now(void)
Get NTP timestamp.
Definition: su_time.c:264
su_dur64_t
int64_t su_dur64_t
Time offset (duration) in nanoseconds.
Definition: su_time.h:50
su_time_add
su_time_t su_time_add(su_time_t t, su_duration_t dur)
Add milliseconds to the time.
Definition: su_time.c:358
su_time_s::tv_usec
unsigned long tv_usec
Microseconds
Definition: su_time.h:59
su_time_dadd
su_time_t su_time_dadd(su_time_t t, double dur)
Add seconds to the time.
Definition: su_time.c:372
su_time
void su_time(su_time_t *tv)
Get current time.
Definition: su_time0.c:88
int64_t
SU_S64_T int64_t
64-bit signed integer
Definition: su_types.h:85
su_time_ms
uint32_t su_time_ms(su_time_t t)
Time as milliseconds.
Definition: su_time.h:159
su_duration_t
long su_duration_t
Time difference in microseconds.
Definition: su_time.h:70
SOFIAPUBFUN
#define SOFIAPUBFUN
SOFIAPUBFUN declares an exported function.
Definition: su_config.h:66
su_random
uint32_t su_random(void)
Generate a random 32-bit unsigned integer.
Definition: su_uniqueid.c:421
su_duration
su_duration_t su_duration(su_time_t const t1, su_time_t const t2)
Time difference in milliseconds.
Definition: su_time.c:211
su_time64_t
uint64_t su_time64_t
Time in nanoseconds.
Definition: su_time.h:44
su_nanotime
su_time64_t su_nanotime(su_time64_t *return_time)
Get current time as nanoseconds since epoch.
Definition: su_time0.c:170
su_now
su_time_t su_now(void)
Get current time.
Definition: su_time.c:170
su_duration64
su_duration_t su_duration64(su_time64_t t1, su_time64_t t2)
Time difference in milliseconds.
Definition: su_time.c:243
SU_DURATION_MAX
@ SU_DURATION_MAX
Maximum duration in milliseconds.
Definition: su_time.h:74
su_ntp_sec
uint32_t su_ntp_sec(void)
Get NTP seconds.
Definition: su_time.c:306
su_ntp_mw
uint32_t su_ntp_mw(su_ntp_t ntp)
Middle 32 bit of NTP timestamp.
Definition: su_time.c:347
su_time_s::tv_sec
unsigned long tv_sec
Seconds.
Definition: su_time.h:58
uint64_t
SU_U64_T uint64_t
64-bit unsigned integer
Definition: su_types.h:83
su_ntp_t
uint64_t su_ntp_t
NTP timestamp.
Definition: su_time.h:83
su_ntp_lo
uint32_t su_ntp_lo(su_ntp_t)
Low 32 bit of NTP timestamp.
Definition: su_time.c:335

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