su  1.13.17
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 
41 SOFIA_BEGIN_DECLS
42 
48 struct su_time_s {
49  unsigned long tv_sec;
50  unsigned long tv_usec;
51 };
53 typedef struct su_time_s su_time_t;
54 
61 typedef long su_duration_t;
62 
63 enum {
65  SU_DURATION_MAX = 0x7fffffffL
66 };
67 #define SU_DURATION_MAX SU_DURATION_MAX
68 
75 
77 #define SU_NTP_C(x) SU_U64_C(x)
78 
79 #define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2)
80 
82 #define SU_TIME_EPOCH 2208988800UL
83 
84 typedef uint64_t su_nanotime_t;
85 
86 #define SU_E9 (1000000000U)
87 
88 typedef void (*su_time_func_t)(su_time_t *tv);
89 
90 
91 SOFIAPUBFUN void su_set_time_func(su_time_func_t func);
92 
93 SOFIAPUBFUN su_nanotime_t su_nanotime(su_nanotime_t *return_time);
94 SOFIAPUBFUN su_nanotime_t su_monotime(su_nanotime_t *return_time);
95 
97 SOFIAPUBFUN void su_time(su_time_t *tv);
98 SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
99 SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
101 
104 
105 SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
106 
107 #define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
108 
114 
115 #if !SU_HAVE_INLINE
118 #else
121 #endif
122 
123 SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
124 
125 SOFIAPUBFUN uint64_t su_counter(void);
126 
127 SOFIAPUBFUN uint64_t su_nanocounter(void);
128 
130 
131 #if SU_HAVE_INLINE
134 {
135  /*
136  * Multiply usec by 0.065536 (ie. 2**16 / 1E6)
137  *
138  * Utilize fact that 0.065536 == 1024 / 15625
139  */
140  return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
141 }
142 
145 {
146  return (t.tv_sec * 1000) + ((t.tv_usec + 500) / 1000);
147 }
148 #endif
149 
150 SOFIA_END_DECLS
151 
152 #endif /* !defined(SU_TIME_H) */
Time in seconds and microsecondcs.
Definition: su_time.h:48
unsigned long tv_usec
Microseconds
Definition: su_time.h:50
unsigned long tv_sec
Seconds.
Definition: su_time.h:49
#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_ntp_t su_ntp_now(void)
Get NTP timestamp.
Definition: su_time.c:224
su_nanotime_t su_nanotime(su_nanotime_t *return_time)
Get current time as nanoseconds since epoch.
Definition: su_time0.c:140
su_time_t su_time_add(su_time_t t, su_duration_t dur)
Add milliseconds to the time.
Definition: su_time.c:329
uint32_t su_ntp_hi(su_ntp_t)
High 32 bit of NTP timestamp.
Definition: su_time.c:279
long su_duration_t
Time difference in microseconds.
Definition: su_time.h:61
uint32_t su_ntp_fraq(su_time_t t)
Middle 32 bit of NTP timestamp.
Definition: su_time.h:133
int su_time_print(char *s, int n, su_time_t const *tv)
Print su_time_t timestamp.
Definition: su_time.c:164
su_time_t su_now(void)
Get current time.
Definition: su_time.c:145
uint32_t su_ntp_sec(void)
Get NTP seconds.
Definition: su_time.c:266
su_time_t su_time_dadd(su_time_t t, double dur)
Add seconds to the time.
Definition: su_time.c:343
long su_time_cmp(su_time_t const t1, su_time_t const t2)
Compare two timestamps.
Definition: su_time.c:86
su_duration_t su_duration(su_time_t const t1, su_time_t const t2)
Time difference in milliseconds.
Definition: su_time.c:186
void su_time(su_time_t *tv)
Get current time.
Definition: su_time0.c:86
uint64_t su_ntp_t
NTP timestamp.
Definition: su_time.h:74
uint32_t su_random(void)
Get random 32-bit unsigned number.
Definition: su_uniqueid.c:427
uint32_t su_time_ms(su_time_t t)
Time as milliseconds.
Definition: su_time.h:144
@ SU_DURATION_MAX
Maximum duration in milliseconds.
Definition: su_time.h:65
uint32_t su_ntp_mw(su_ntp_t ntp)
Middle 32 bit of NTP timestamp.
Definition: su_time.c:307
su_nanotime_t su_monotime(su_nanotime_t *return_time)
Get current time as nanoseconds.
Definition: su_time0.c:205
uint32_t su_ntp_lo(su_ntp_t)
Low 32 bit of NTP timestamp.
Definition: su_time.c:295
double su_time_diff(su_time_t const t1, su_time_t const t2)
Difference between two timestamps.
Definition: su_time.c:131
Basic integer types for su library.
SU_U32_T uint32_t
32-bit unsigned integer
Definition: su_types.h:87
SU_U64_T uint64_t
64-bit unsigned integer
Definition: su_types.h:83

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