Loading...
Searching...
No Matches
su_time.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SU_TIME_H
#define SU_TIME_H
#ifndef SU_TYPES_H
#include "sofia-sip/su_types.h"
#endif
SOFIA_BEGIN_DECLS
typedef uint64_t su_time64_t;
typedef su_time64_t su_nanotime_t;
typedef int64_t su_dur64_t;
struct su_time_s {
unsigned long tv_sec;
unsigned long tv_usec;
};
typedef struct su_time_s su_time_t;
typedef long su_duration_t;
enum {
SU_DURATION_MAX = 0x7fffffffL
};
#define SU_DURATION_MAX SU_DURATION_MAX
typedef uint64_t su_ntp_t;
#define SU_NTP_C(x) SU_U64_C(x)
#define SU_TIME_CMP(t1, t2) su_time_cmp(t1, t2)
#define SU_TIME_EPOCH 2208988800UL
#define SU_E9 (1000000000U)
#define SU_TIME64_MAX ((su_time64_t)(su_dur64_t)-1)
SOFIAPUBFUN su_time64_t su_nanotime(su_time64_t *return_time);
SOFIAPUBFUN su_time64_t su_monotime(su_time64_t *return_time);
SOFIAPUBFUN su_time64_t su_now64(void);
SOFIAPUBFUN su_time64_t su_stamp64(void);
SOFIAPUBFUN su_time_t su_time64_to_time(su_time64_t t);
SOFIAPUBFUN su_time64_t su_time_to_time64(su_time_t tv);
SOFIAPUBFUN su_duration_t su_duration64(su_time64_t t1, su_time64_t t2);
SOFIAPUBFUN su_time_t su_now(void);
SOFIAPUBFUN void su_time(su_time_t *tv);
SOFIAPUBFUN long su_time_cmp(su_time_t const t1, su_time_t const t2);
SOFIAPUBFUN double su_time_diff(su_time_t const t1, su_time_t const t2);
SOFIAPUBFUN su_duration_t su_duration(su_time_t const t1, su_time_t const t2);
SOFIAPUBFUN su_time_t su_time_add(su_time_t t, su_duration_t dur);
SOFIAPUBFUN su_time_t su_time_dadd(su_time_t t, double dur);
SOFIAPUBFUN int su_time_print(char *s, int n, su_time_t const *tv);
#define SU_SEC_TO_DURATION(sec) ((su_duration_t)(1000 * (sec)))
SOFIAPUBFUN su_ntp_t su_ntp_now(void);
SOFIAPUBFUN uint32_t su_ntp_sec(void);
SOFIAPUBFUN uint32_t su_ntp_hi(su_ntp_t);
SOFIAPUBFUN uint32_t su_ntp_lo(su_ntp_t);
SOFIAPUBFUN uint32_t su_ntp_mw(su_ntp_t ntp);
#if !SU_HAVE_INLINE
SOFIAPUBFUN uint32_t su_ntp_fraq(su_time_t t);
SOFIAPUBFUN uint32_t su_time_ms(su_time_t t);
SOFIAPUBFUN su_time64_t su_time64_add(su_time64_t t, su_duration_t dur);
#else
su_inline uint32_t su_ntp_fraq(su_time_t t);
su_inline uint32_t su_time_ms(su_time_t t);
su_inline su_time64_t su_time64_add(su_time64_t t, su_duration_t dur);
#endif
SOFIAPUBFUN su_ntp_t su_ntp_hilo(uint32_t hi, uint32_t lo);
SOFIAPUBFUN uint64_t su_counter(void);
SOFIAPUBFUN uint64_t su_nanocounter(void);
SOFIAPUBFUN uint32_t su_random(void);
#if SU_HAVE_INLINE
su_inline uint32_t su_ntp_fraq(su_time_t t)
{
/*
* Multiply usec by 0.065536 (ie. 2**16 / 1E6)
*
* Utilize fact that 0.065536 == 1024 / 15625
*/
return (t.tv_sec << 16) + (1024 * t.tv_usec + 7812) / 15625;
}
su_inline uint32_t su_time_ms(su_time_t t)
{
return t.tv_sec * 1000 + (t.tv_usec + 500) / 1000;
}
su_inline su_time64_t su_time64_add(su_time64_t t, su_duration_t offset)
{
return t + 1000000 * (su_dur64_t)offset;
}
#endif
SOFIA_END_DECLS
#endif /* !defined(SU_TIME_H) */
su_time_s
Time in seconds and microsecondcs.
Definition su_time.h:57
su_time_s::tv_usec
unsigned long tv_usec
Microseconds.
Definition su_time.h:59
su_time_s::tv_sec
unsigned long tv_sec
Seconds.
Definition su_time.h:58
SOFIAPUBFUN
#define SOFIAPUBFUN
SOFIAPUBFUN declares an exported function.
Definition su_config.h:66
su_inline
#define su_inline
Define as suitable declarator static inline functions.
Definition su_configure.h:90
su_now64
su_time64_t su_now64(void)
Get current time as nanoseconds since epoch.
Definition su_time0.c:194
su_dur64_t
int64_t su_dur64_t
Time offset (duration) in nanoseconds.
Definition su_time.h:50
su_ntp_now
su_ntp_t su_ntp_now(void)
Get NTP timestamp.
Definition su_time.c:264
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_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_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_ntp_hi
uint32_t su_ntp_hi(su_ntp_t)
High 32 bit of NTP timestamp.
Definition su_time.c:319
su_duration_t
long su_duration_t
Time difference in microseconds.
Definition su_time.h:70
su_ntp_fraq
uint32_t su_ntp_fraq(su_time_t t)
Middle 32 bit of NTP timestamp.
Definition su_time.h:148
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_now
su_time_t su_now(void)
Get current time.
Definition su_time.c:170
su_ntp_sec
uint32_t su_ntp_sec(void)
Get NTP seconds.
Definition su_time.c:306
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_t
struct su_time_s su_time_t
Time in seconds and microsecondcs.
Definition su_time.h:62
su_stamp64
su_time64_t su_stamp64(void)
Get current monotonic timestamp as nanoseconds.
Definition su_time0.c:271
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_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_time
void su_time(su_time_t *tv)
Get current time.
Definition su_time0.c:88
su_ntp_t
uint64_t su_ntp_t
NTP timestamp.
Definition su_time.h:83
su_time64_t
uint64_t su_time64_t
Time in nanoseconds.
Definition su_time.h:44
su_random
uint32_t su_random(void)
Generate a random 32-bit unsigned integer.
Definition su_uniqueid.c:421
su_time_ms
uint32_t su_time_ms(su_time_t t)
Time as milliseconds.
Definition su_time.h:159
su_nanotime_t
su_time64_t su_nanotime_t
Time in nanoseconds.
Definition su_time.h:47
su_ntp_mw
uint32_t su_ntp_mw(su_ntp_t ntp)
Middle 32 bit of NTP timestamp.
Definition su_time.c:347
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_ntp_lo
uint32_t su_ntp_lo(su_ntp_t)
Low 32 bit of NTP timestamp.
Definition su_time.c:335
su_monotime
su_time64_t su_monotime(su_time64_t *return_time)
Get current monotonic time as nanoseconds.
Definition su_time0.c:246
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
su_types.h
Basic integer types for su library.
uint32_t
SU_U32_T uint32_t
32-bit unsigned integer
Definition su_types.h:87
int64_t
SU_S64_T int64_t
64-bit signed integer
Definition su_types.h:85
uint64_t
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.