su 1.12.11devel
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
su_time.h File Reference

Time types and functions. More...

#include "sofia-sip/su_types.h"
Include dependency graph for su_time.h:

Go to the source code of this file.

Data Structures

struct  su_time_s
 Time in seconds and microsecondcs. More...
 

Macros

#define SU_TIME_H
 Defined when <sofia-sip/su_time.h> has been included.
 
#define SU_NTP_C(x)
 Represent NTP constant.
 
#define SU_TIME_CMP(t1, t2)
 Compare two timestamps.
 
#define SU_TIME_EPOCH
 Seconds from 1.1.1900 to 1.1.1970.
 
#define SU_TIME64_MAX
 Maximum value of su_time64_t type.
 

Typedefs

typedef uint64_t su_time64_t
 Time in nanoseconds.
 
typedef su_time64_t su_nanotime_t
 Time in nanoseconds.
 
typedef int64_t su_dur64_t
 Time offset (duration) in nanoseconds.
 
typedef struct su_time_s su_time_t
 Time in seconds and microsecondcs.
 
typedef long su_duration_t
 Time difference in microseconds.
 
typedef uint64_t su_ntp_t
 NTP timestamp.
 

Enumerations

enum  { SU_DURATION_MAX }
 

Functions

su_time64_t su_nanotime (su_time64_t *return_time)
 Get current time as nanoseconds since epoch.
 
su_time64_t su_monotime (su_time64_t *return_time)
 Get current monotonic time as nanoseconds.
 
su_time64_t su_now64 (void)
 Get current time as nanoseconds since epoch.
 
su_time64_t su_stamp64 (void)
 Get current monotonic timestamp as nanoseconds.
 
su_duration_t su_duration64 (su_time64_t t1, su_time64_t t2)
 Time difference in milliseconds.
 
su_time_t su_now (void)
 Get current time.
 
void su_time (su_time_t *tv)
 Get current time.
 
long su_time_cmp (su_time_t const t1, su_time_t const t2)
 Compare two timestamps.
 
double su_time_diff (su_time_t const t1, su_time_t const t2)
 Difference between two timestamps.
 
su_duration_t su_duration (su_time_t const t1, su_time_t const t2)
 Time difference in milliseconds.
 
su_time_t su_time_add (su_time_t t, su_duration_t dur)
 Add milliseconds to the time.
 
su_time_t su_time_dadd (su_time_t t, double dur)
 Add seconds to the time.
 
int su_time_print (char *s, int n, su_time_t const *tv)
 Print su_time_t timestamp.
 
su_ntp_t su_ntp_now (void)
 Get NTP timestamp.
 
uint32_t su_ntp_sec (void)
 Get NTP seconds.
 
uint32_t su_ntp_hi (su_ntp_t)
 High 32 bit of NTP timestamp.
 
uint32_t su_ntp_lo (su_ntp_t)
 Low 32 bit of NTP timestamp.
 
uint32_t su_ntp_mw (su_ntp_t ntp)
 Middle 32 bit of NTP timestamp.
 
uint32_t su_ntp_fraq (su_time_t t)
 Middle 32 bit of NTP timestamp.
 
uint32_t su_time_ms (su_time_t t)
 Time as milliseconds.
 
su_time64_t su_time64_add (su_time64_t t, su_duration_t offset)
 Add offset in milliseconds to 64-bit nanosecond time.
 
uint32_t su_random (void)
 Generate a random 32-bit unsigned integer.
 

Detailed Description

Time types and functions.

Author
Pekka Pessi Pekka.nosp@m..Pes.nosp@m.si@no.nosp@m.kia..nosp@m.com
Date
Created: Thu Mar 18 19:40:51 1999 pessi

Macro Definition Documentation

◆ SU_TIME64_MAX

#define SU_TIME64_MAX

Maximum value of su_time64_t type.

Since
Not yet released

◆ SU_TIME_CMP

#define SU_TIME_CMP (   t1,
  t2 
)

Compare two timestamps.

The macro SU_TIME_CMP() compares two su_time_t timestamps.

Parameters
t1first NTP timestamp in su_time_t structure
t2second NTP timestamp in su_time_t structure
Return values
negative,ift1 is before t2,
zero,ift1 is same as t2, or
positive,ift1 is after t2.

◆ SU_TIME_EPOCH

#define SU_TIME_EPOCH

Seconds from 1.1.1900 to 1.1.1970.

Since
New in 1.12.4.

Typedef Documentation

◆ su_dur64_t

Time offset (duration) in nanoseconds.

Since
Not yet released

◆ su_duration_t

typedef long su_duration_t

Time difference in microseconds.

The type su_duration_t is used to present small time differences (24 days), usually calculated between two su_time_t timestamps. Note that the su_duration_t is signed.

◆ su_ntp_t

typedef uint64_t su_ntp_t

NTP timestamp.

NTP timestamp is defined as microseconds since epoch (1-Jan-1900) with 64-bit resolution.

◆ su_time64_t

Time in nanoseconds.

Since
Not yet released

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SU_DURATION_MAX 

Maximum duration in milliseconds.

Function Documentation

◆ su_duration()

su_duration_t su_duration ( su_time_t const  t1,
su_time_t const  t2 
)

Time difference in milliseconds.

Calculates the duration from t2 to t1 in milliseconds.

Parameters
t1after time
t2before time
Returns
The duration in milliseconds between the two times. If the difference is bigger than SU_DURATION_MAX, return SU_DURATION_MAX instead. If the difference is smaller than -SU_DURATION_MAX, return -SU_DURATION_MAX.

◆ su_duration64()

su_duration_t su_duration64 ( su_time64_t  t1,
su_time64_t  t2 
)

Time difference in milliseconds.

Calculates the duration from t2 to t1 in milliseconds.

Parameters
t1after time
t2before time
Returns
The duration in milliseconds between the two times.

If the difference is bigger than SU_DURATION_MAX, return SU_DURATION_MAX instead.

If the difference is smaller than -SU_DURATION_MAX, return -SU_DURATION_MAX instead.

◆ su_monotime()

su_time64_t su_monotime ( su_time64_t return_time)

Get current monotonic time as nanoseconds.

Return the current time expressed as nanoseconds. The time returned is monotonic and never goes back - if the underlying system supports such a clock.

Parameters
return_timeoptional pointer to return the current time
Returns
Current time as nanoseconds

◆ su_nanotime()

su_time64_t su_nanotime ( su_time64_t return_time)

Get current time as nanoseconds since epoch.

Return the current NTP timestamp expressed as nanoseconds since epoch (January 1st 1900).

Parameters
return_timeoptional pointer to current time to return
Returns
Nanoseconds since epoch

◆ su_now()

su_time_t su_now ( void  )

Get current time.

Return the current timestamp in su_time_t structure.

Returns
The structure containing the current NTP timestamp.

◆ su_now64()

su_time64_t su_now64 ( void  )

Get current time as nanoseconds since epoch.

Return the current NTP timestamp expressed as nanoseconds since epoch (January 1st 1900).

Returns
Nanoseconds since epoch
Since
Not yet released

◆ su_ntp_hi()

uint32_t su_ntp_hi ( su_ntp_t  ntp)

High 32 bit of NTP timestamp.

Parameters
ntp64bit NTP timestamp.
Returns
The function su_ntp_hi() returns high 32 bits of NTP timestamp.

◆ su_ntp_lo()

uint32_t su_ntp_lo ( su_ntp_t  ntp)

Low 32 bit of NTP timestamp.

Parameters
ntp64bit NTP timestamp.
Returns
The function su_ntp_hi() returns low 32 bits of NTP timestamp.

◆ su_ntp_mw()

uint32_t su_ntp_mw ( su_ntp_t  ntp)

Middle 32 bit of NTP timestamp.

Parameters
ntp64bit NTP timestamp.
Returns
The function su_ntp_mw() returns bits 48..16 (middle word) of NTP timestamp.

◆ su_ntp_now()

su_ntp_t su_ntp_now ( void  )

Get NTP timestamp.

The function su_ntp_now() returns the current NTP timestamp. NTP timestamp is seconds elapsed since January 1st, 1900.

Returns
The current time as NTP timestamp is returned.

◆ su_ntp_sec()

uint32_t su_ntp_sec ( void  )

Get NTP seconds.

The function su_ntp_sec() returns the seconds elapsed since January 1st, 1900.

Returns
The current time as NTP seconds is returned.

◆ su_stamp64()

su_time64_t su_stamp64 ( void  )

Get current monotonic timestamp as nanoseconds.

Return the current timestamp expressed as nanoseconds. The time returned is monotonic and never goes back - if the underlying system supports such a clock.

Returns
Current timestamp as nanoseconds
Since
Not yet released

◆ su_time()

void su_time ( su_time_t tv)

Get current time.

The function su_time() fills its argument with the current NTP timestamp expressed as a su_time_t structure.

Parameters
tvpointer to the timeval object

◆ su_time64_add()

su_time64_t su_time64_add ( su_time64_t  t,
su_duration_t  offset 
)
inline

Add offset in milliseconds to 64-bit nanosecond time.

Since
Not yet released

◆ su_time_add()

su_time_t su_time_add ( su_time_t  t0,
su_duration_t  dur 
)

Add milliseconds to the time.

Parameters
t0time in seconds and microseconds as su_time_t
durmilliseconds to be added

◆ su_time_cmp()

long su_time_cmp ( su_time_t const  t1,
su_time_t const  t2 
)

Compare two timestamps.

The function su_time_cmp() compares two su_time_t timestamps.

Parameters
t1first NTP timestamp in su_time_t structure
t2second NTP timestamp in su_time_t structure
Return values
Negative,ift1 is before t2,
Zero,ift1 is same as t2, or
Positive,ift1 is after t2.

◆ su_time_dadd()

su_time_t su_time_dadd ( su_time_t  t0,
double  sec 
)

Add seconds to the time.

Parameters
t0time in seconds and microseconds as su_time_t
secseconds to be added
Returns
New time as su_time_t.

◆ su_time_diff()

double su_time_diff ( su_time_t const  t1,
su_time_t const  t2 
)

Difference between two timestamps.

The function returns difference between two timestamps in seconds (t1 - t2).

Parameters
t1first timeval
t2second timeval
Returns
The difference between two timestamps in seconds as a double.

◆ su_time_print()

int su_time_print ( char *  s,
int  n,
su_time_t const *  tv 
)

Print su_time_t timestamp.

This function prints a su_time_t timestamp as a decimal number to the given buffer.

Parameters
spointer to buffer
nbuffer size
tvpointer to the timeval object
Returns
The number of characters printed, excluding the final NUL.

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