su_time.c File Reference


Detailed Description

Implementation of OS-independent time functions.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>

Jari Selin <Jari.Selin@nokia-email.address.hidden>

Kai Vehmanen <first.surname@nokia-email.address.hidden>

Date:
Created: Thu Mar 18 19:40:51 1999 pessi

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "sofia-sip/su_types.h"
#include "su_module_debug.h"
#include "sofia-sip/su_time.h"

Include dependency graph for su_time.c:

Functions

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_time_t su_now (void)
 Get current time.
int su_time_print (char *s, int n, su_time_t const *tv)
 Print su_time_t timestamp.
su_duration_t su_duration (su_time_t const t1, su_time_t const t2)
 Time difference in milliseconds.
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 ntp)
 High 32 bit of NTP timestamp.
uint32_t su_ntp_lo (su_ntp_t ntp)
 Low 32 bit of NTP timestamp.
uint32_t su_ntp_mw (su_ntp_t ntp)
 Middle 32 bit of NTP timestamp.
su_time_t su_time_add (su_time_t t0, su_duration_t dur)
 Add milliseconds to the time.
su_time_t su_time_dadd (su_time_t t0, double sec)
 Add seconds to the time.


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

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.

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.


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