FreeSWITCH API Documentation  1.7.0
Data Structures | Typedefs | Functions
+ Collaboration diagram for Time Routines:

Data Structures

struct  switch_time_exp_t
 

Typedefs

typedef int64_t switch_time_t
 
typedef int64_t switch_interval_time_t
 
typedef struct switch_time_exp_t switch_time_exp_t
 

Functions

switch_time_t switch_time_make (switch_time_t sec, int32_t usec)
 
switch_time_t switch_time_now (void)
 
switch_status_t switch_time_exp_gmt_get (switch_time_t *result, switch_time_exp_t *input)
 
switch_status_t switch_strftime (char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
 
switch_status_t switch_strftime_nocheck (char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
 
switch_status_t switch_rfc822_date (char *date_str, switch_time_t t)
 
switch_status_t switch_time_exp_gmt (switch_time_exp_t *result, switch_time_t input)
 
switch_status_t switch_time_exp_get (switch_time_t *result, switch_time_exp_t *input)
 
switch_status_t switch_time_exp_lt (switch_time_exp_t *result, switch_time_t input)
 
switch_status_t switch_time_exp_tz (switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
 
void switch_sleep (switch_interval_time_t t)
 
void switch_micro_sleep (switch_interval_time_t t)
 

Detailed Description

Typedef Documentation

typedef int64_t switch_interval_time_t

number of microseconds in the interval

Definition at line 191 of file switch_apr.h.

a structure similar to ANSI struct tm with the following differences:

  • tm_usec isn't an ANSI field
  • tm_gmtoff isn't an ANSI field (it's a bsdism)
typedef int64_t switch_time_t

number of microseconds since 00:00:00 january 1, 1970 UTC

Definition at line 188 of file switch_apr.h.

Function Documentation

void switch_micro_sleep ( switch_interval_time_t  t)

Definition at line 615 of file switch_time.c.

References do_sleep().

616 {
617  do_sleep(t);
618 }
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:150
switch_status_t switch_rfc822_date ( char *  date_str,
switch_time_t  t 
)

switch_rfc822_date formats dates in the RFC822 format in an efficient manner. It is a fixed length format which requires the indicated amount of storage, including the trailing NUL terminator.

Parameters
date_strString to write to.
tthe time to convert

Definition at line 338 of file switch_apr.c.

Referenced by switch_event_prep_for_delivery_detailed().

339 {
340  return apr_rfc822_date(date_str, t);
341 }
void switch_sleep ( switch_interval_time_t  t)

Sleep for the specified number of micro-seconds.

Parameters
tdesired amount of time to sleep.
Warning
May sleep for longer than the specified time.

Definition at line 620 of file switch_time.c.

References do_sleep(), globals, and switch_cond_yield().

Referenced by main(), and switch_msleep().

621 {
622 
623  if (globals.RUNNING != 1 || t < 1000 || t >= 10000) {
624  do_sleep(t);
625  return;
626  }
627 #ifndef DISABLE_1MS_COND
628  if (globals.use_cond_yield == 1) {
630  return;
631  }
632 #endif
633 
634  do_sleep(t);
635 }
void switch_cond_yield(switch_interval_time_t t)
Definition: switch_time.c:657
static struct @7 globals
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:150
switch_status_t switch_strftime ( char *  s,
switch_size_t retsize,
switch_size_t  max,
const char *  format,
switch_time_exp_t tm 
)

formats the exploded time according to the format specified

Parameters
sstring to write to
retsizeThe length of the returned string
maxThe maximum length of the string
formatThe format for the time string
tmThe time to convert

Definition at line 127 of file switch_apr.c.

References SWITCH_STATUS_FALSE.

Referenced by switch_xml_std_datetime_check().

128 {
129  const char *p = format;
130 
131  if (!p)
132  return SWITCH_STATUS_FALSE;
133 
134  while (*p) {
135  if (*p == '%') {
136  switch (*(++p)) {
137  case 'C':
138  case 'D':
139  case 'r':
140  case 'R':
141  case 'T':
142  case 'e':
143  case 'a':
144  case 'A':
145  case 'b':
146  case 'B':
147  case 'c':
148  case 'd':
149  case 'H':
150  case 'I':
151  case 'j':
152  case 'm':
153  case 'M':
154  case 'p':
155  case 'S':
156  case 'U':
157  case 'w':
158  case 'W':
159  case 'x':
160  case 'X':
161  case 'y':
162  case 'Y':
163  case 'z':
164  case 'Z':
165  case '%':
166  p++;
167  continue;
168  case '\0':
169  default:
170  return SWITCH_STATUS_FALSE;
171  }
172  }
173  p++;
174  }
175 
176  return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
177 }
switch_status_t switch_strftime_nocheck ( char *  s,
switch_size_t retsize,
switch_size_t  max,
const char *  format,
switch_time_exp_t tm 
)

formats the exploded time according to the format specified (does not validate format string)

Parameters
sstring to write to
retsizeThe length of the returned string
maxThe maximum length of the string
formatThe format for the time string
tmThe time to convert

Definition at line 179 of file switch_apr.c.

Referenced by switch_channel_set_timestamps(), switch_console_printf(), switch_event_prep_for_delivery_detailed(), and switch_strftime_tz().

180 {
181  return apr_strftime(s, retsize, max, format, (apr_time_exp_t *) tm);
182 }
switch_status_t switch_time_exp_get ( switch_time_t result,
switch_time_exp_t input 
)

Convert time value from human readable format to a numeric apr_time_t e.g. elapsed usec since epoch

Parameters
resultthe resulting imploded time
inputthe input exploded time

Definition at line 318 of file switch_apr.c.

Referenced by switch_str_time().

319 {
320  return apr_time_exp_get((apr_time_t *) result, (apr_time_exp_t *) input);
321 }
switch_status_t switch_time_exp_gmt ( switch_time_exp_t result,
switch_time_t  input 
)

convert a time to its human readable components in GMT timezone

Parameters
resultthe exploded time
inputthe time to explode

Definition at line 333 of file switch_apr.c.

Referenced by process_rtcp_report(), and rtcp_generate_sender_info().

334 {
335  return apr_time_exp_gmt((apr_time_exp_t *) result, input);
336 }
switch_status_t switch_time_exp_gmt_get ( switch_time_t result,
switch_time_exp_t input 
)

Convert time value from human readable format to a numeric apr_time_t that always represents GMT

Parameters
resultthe resulting imploded time
inputthe input exploded time

Definition at line 313 of file switch_apr.c.

Referenced by switch_str_time().

314 {
315  return apr_time_exp_gmt_get((apr_time_t *) result, (apr_time_exp_t *) input);
316 }
switch_status_t switch_time_exp_lt ( switch_time_exp_t result,
switch_time_t  input 
)

convert a time to its human readable components in local timezone

Parameters
resultthe exploded time
inputthe time to explode

Definition at line 323 of file switch_apr.c.

Referenced by switch_channel_set_timestamps(), switch_console_printf(), switch_event_prep_for_delivery_detailed(), switch_log_vprintf(), switch_str_time(), and switch_xml_std_datetime_check().

324 {
325  return apr_time_exp_lt((apr_time_exp_t *) result, input);
326 }
switch_status_t switch_time_exp_tz ( switch_time_exp_t result,
switch_time_t  input,
switch_int32_t  offs 
)

convert a time to its human readable components in a specific timezone with offset

Parameters
resultthe exploded time
inputthe time to explode

Definition at line 328 of file switch_apr.c.

Referenced by switch_xml_std_datetime_check().

329 {
330  return apr_time_exp_tz((apr_time_exp_t *) result, input, (apr_int32_t) offs);
331 }
switch_time_t switch_time_make ( switch_time_t  sec,
int32_t  usec 
)

Definition at line 343 of file switch_apr.c.

344 {
345  return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
346 }
int64_t switch_time_t
Definition: switch_apr.h:188
switch_time_t switch_time_now ( void  )
Returns
the current time

Definition at line 302 of file switch_apr.c.

Referenced by process_rtcp_report(), record_callback(), rtcp_generate_report_block(), rtcp_generate_sender_info(), rtp_common_write(), switch_channel_clear_flag(), switch_channel_perform_hangup(), switch_channel_set_flag_value(), switch_core_media_read_frame(), switch_core_session_exec(), switch_core_session_request_xml(), switch_ivr_dmachine_check_timeout(), switch_ivr_dmachine_feed(), switch_jb_pop_nack(), switch_micro_time_now(), SWITCH_MODULE_RUNTIME_FUNCTION(), switch_rtp_create(), switch_rtp_enable_vad(), switch_time_sync(), time_now(), and timer_generic_sync().

303 {
304 #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
305  struct timespec ts;
306  clock_gettime(CLOCK_REALTIME, &ts);
307  return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
308 #else
309  return (switch_time_t) apr_time_now();
310 #endif
311 }
int64_t switch_time_t
Definition: switch_apr.h:188