Data Structures | Defines | Typedefs | Enumerations | Functions

sofia-sip/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...

Defines

#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.

Typedefs

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_nanotime_t su_nanotime (su_nanotime_t *return_time)
 Get current time as nanoseconds since epoch.
su_nanotime_t su_monotime (su_nanotime_t *return_time)
 Get current time as nanoseconds.
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.
uint32_t su_random (void)
 Get random 32-bit unsigned number.

Detailed Description

Time types and functions.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>
Date:
Created: Thu Mar 18 19:40:51 1999 pessi

Define Documentation

#define SU_TIME_CMP (   t1,
  t2 
)

Compare two timestamps.

The macro SU_TIME_CMP() compares two su_time_t timestamps.

Parameters:
t1 first NTP timestamp in su_time_t structure
t2 second NTP timestamp in su_time_t structure
Return values:
negative,if t1 is before t2,
zero,if t1 is same as t2, or
positive,if t1 is after t2.
#define SU_TIME_EPOCH

Seconds from 1.1.1900 to 1.1.1970.

Since:
New in 1.12.4.
#define SU_TIME_H

Defined when <sofia-sip/su_time.h> has been included.


Typedef Documentation

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.

typedef uint64_t su_ntp_t

NTP timestamp.

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

typedef struct su_time_s su_time_t

Time in seconds and microsecondcs.


Enumeration Type Documentation

anonymous enum
Enumerator:
SU_DURATION_MAX 

Maximum duration in milliseconds.


Function Documentation

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:
t1 after time
t2 before 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_nanotime_t su_monotime ( su_nanotime_t *  return_time  ) 

Get current 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_time optional pointer to return the current time
Returns:
Current time as nanoseconds
su_nanotime_t su_nanotime ( su_nanotime_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_time optional pointer to current time to return
Returns:
Nanoseconds since epoch
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.
uint32_t su_ntp_fraq ( su_time_t  t  )  [inline]

Middle 32 bit of NTP timestamp.

uint32_t su_ntp_hi ( su_ntp_t  ntp  ) 

High 32 bit of NTP timestamp.

Parameters:
ntp 64bit NTP timestamp.
Returns:
The function su_ntp_hi() returns high 32 bits of NTP timestamp.
uint32_t su_ntp_lo ( su_ntp_t  ntp  ) 

Low 32 bit of NTP timestamp.

Parameters:
ntp 64bit NTP timestamp.
Returns:
The function su_ntp_hi() returns low 32 bits of NTP timestamp.
uint32_t su_ntp_mw ( su_ntp_t  ntp  ) 

Middle 32 bit of NTP timestamp.

Parameters:
ntp 64bit NTP timestamp.
Returns:
The function su_ntp_mw() returns bits 48..16 (middle word) of NTP timestamp.
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.
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.
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:
tv pointer to the timeval object
su_time_t su_time_add ( su_time_t  t0,
su_duration_t  dur 
)

Add milliseconds to the time.

Parameters:
t0 time in seconds and microseconds as su_time_t
dur milliseconds to be added
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:
t1 first NTP timestamp in su_time_t structure
t2 second NTP timestamp in su_time_t structure
Return values:
Negative,if t1 is before t2,
Zero,if t1 is same as t2, or
Positive,if t1 is after t2.
su_time_t su_time_dadd ( su_time_t  t0,
double  sec 
)

Add seconds to the time.

Parameters:
t0 time in seconds and microseconds as su_time_t
sec seconds to be added
Returns:
New time as su_time_t.
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:
t1 first timeval
t2 second timeval
Returns:
The difference between two timestamps in seconds as a double.
uint32_t su_time_ms ( su_time_t  t  )  [inline]

Time as milliseconds.

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:
s pointer to buffer
n buffer size
tv pointer to the timeval object
Returns:
The number of characters printed, excluding the final NUL.
 All Data Structures Files Functions Variables Typedefs Enumerator Defines

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