su 1.12.11devel
Loading...
Searching...
No Matches
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
27#define SU_TIME_H
37#ifndef SU_TYPES_H
38#include "sofia-sip/su_types.h"
39#endif
40
41SOFIA_BEGIN_DECLS
42
45
48
51
57struct su_time_s {
58 unsigned long tv_sec;
59 unsigned long tv_usec;
60};
62typedef struct su_time_s su_time_t;
63
70typedef long su_duration_t;
71
72enum {
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
104SOFIAPUBFUN su_time_t su_time64_to_time(su_time64_t t);
105SOFIAPUBFUN su_time64_t su_time_to_time64(su_time_t tv);
106
108
111SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
112SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
114
117
118SOFIAPUBFUN 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
138SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
139
140SOFIAPUBFUN uint64_t su_counter(void);
141
142SOFIAPUBFUN uint64_t su_nanocounter(void);
143
145
146#if SU_HAVE_INLINE
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
172SOFIA_END_DECLS
173
174#endif /* !defined(SU_TIME_H) */
Time in seconds and microsecondcs.
Definition su_time.h:57
unsigned long tv_usec
Microseconds
Definition su_time.h:59
unsigned long tv_sec
Seconds.
Definition su_time.h:58
#define SOFIAPUBFUN
SOFIAPUBFUN declares an exported function.
Definition su_config.h:66
#define su_inline
Define as suitable declarator static inline functions.
Definition su_configure.h:90
su_time64_t su_now64(void)
Get current time as nanoseconds since epoch.
Definition su_time0.c:194
int64_t su_dur64_t
Time offset (duration) in nanoseconds.
Definition su_time.h:50
su_ntp_t su_ntp_now(void)
Get NTP timestamp.
Definition su_time.c:264
su_duration_t su_duration64(su_time64_t t1, su_time64_t t2)
Time difference in milliseconds.
Definition su_time.c:243
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_time_t su_time_add(su_time_t t, su_duration_t dur)
Add milliseconds to the time.
Definition su_time.c:358
uint32_t su_ntp_hi(su_ntp_t)
High 32 bit of NTP timestamp.
Definition su_time.c:319
long su_duration_t
Time difference in microseconds.
Definition su_time.h:70
uint32_t su_ntp_fraq(su_time_t t)
Middle 32 bit of NTP timestamp.
Definition su_time.h:148
int su_time_print(char *s, int n, su_time_t const *tv)
Print su_time_t timestamp.
Definition su_time.c:189
su_time_t su_now(void)
Get current time.
Definition su_time.c:170
uint32_t su_ntp_sec(void)
Get NTP seconds.
Definition su_time.c:306
su_time_t su_time_dadd(su_time_t t, double dur)
Add seconds to the time.
Definition su_time.c:372
su_time64_t su_stamp64(void)
Get current monotonic timestamp as nanoseconds.
Definition su_time0.c:271
long su_time_cmp(su_time_t const t1, su_time_t const t2)
Compare two timestamps.
Definition su_time.c:111
su_duration_t su_duration(su_time_t const t1, su_time_t const t2)
Time difference in milliseconds.
Definition su_time.c:211
void su_time(su_time_t *tv)
Get current time.
Definition su_time0.c:88
uint64_t su_ntp_t
NTP timestamp.
Definition su_time.h:83
uint64_t su_time64_t
Time in nanoseconds.
Definition su_time.h:44
uint32_t su_random(void)
Generate a random 32-bit unsigned integer.
Definition su_uniqueid.c:421
uint32_t su_time_ms(su_time_t t)
Time as milliseconds.
Definition su_time.h:159
su_time64_t su_nanotime_t
Time in nanoseconds.
Definition su_time.h:47
uint32_t su_ntp_mw(su_ntp_t ntp)
Middle 32 bit of NTP timestamp.
Definition su_time.c:347
su_time64_t su_nanotime(su_time64_t *return_time)
Get current time as nanoseconds since epoch.
Definition su_time0.c:170
uint32_t su_ntp_lo(su_ntp_t)
Low 32 bit of NTP timestamp.
Definition su_time.c:335
su_time64_t su_monotime(su_time64_t *return_time)
Get current monotonic time as nanoseconds.
Definition su_time0.c:246
double su_time_diff(su_time_t const t1, su_time_t const t2)
Difference between two timestamps.
Definition su_time.c:156
Basic integer types for su library.
SU_U32_T uint32_t
32-bit unsigned integer
Definition su_types.h:87
SU_S64_T int64_t
64-bit signed integer
Definition su_types.h:85
SU_U64_T uint64_t
64-bit unsigned integer
Definition su_types.h:83

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