RTS API Documentation  1.10.11
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

◆ switch_interval_time_t

typedef int64_t switch_interval_time_t

number of microseconds in the interval

Definition at line 191 of file switch_apr.h.

◆ switch_time_exp_t

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)

◆ switch_time_t

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

◆ switch_micro_sleep()

void switch_micro_sleep ( switch_interval_time_t  t)

Definition at line 635 of file switch_time.c.

References do_sleep().

636 {
637  do_sleep(t);
638 }
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:151

◆ switch_rfc822_date()

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 361 of file switch_apr.c.

Referenced by switch_event_prep_for_delivery_detailed().

362 {
363  return fspr_rfc822_date(date_str, t);
364 }

◆ switch_sleep()

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 640 of file switch_time.c.

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

Referenced by fst_init_core_and_modload(), main(), and switch_msleep().

641 {
642 
643  if (globals.RUNNING != 1 || t < 1000 || t >= 10000) {
644  do_sleep(t);
645  return;
646  }
647 #ifndef DISABLE_1MS_COND
648  if (globals.use_cond_yield == 1) {
650  return;
651  }
652 #endif
653 
654  do_sleep(t);
655 }
void switch_cond_yield(switch_interval_time_t t)
Definition: switch_time.c:677
static struct @9 globals
static void do_sleep(switch_interval_time_t t)
Definition: switch_time.c:151

◆ switch_strftime()

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 150 of file switch_apr.c.

References format, and SWITCH_STATUS_FALSE.

Referenced by switch_xml_std_datetime_check().

151 {
152  const char *p = format;
153 
154  if (!p)
155  return SWITCH_STATUS_FALSE;
156 
157  while (*p) {
158  if (*p == '%') {
159  switch (*(++p)) {
160  case 'C':
161  case 'D':
162  case 'r':
163  case 'R':
164  case 'T':
165  case 'e':
166  case 'a':
167  case 'A':
168  case 'b':
169  case 'B':
170  case 'c':
171  case 'd':
172  case 'H':
173  case 'I':
174  case 'j':
175  case 'm':
176  case 'M':
177  case 'p':
178  case 'S':
179  case 'U':
180  case 'w':
181  case 'W':
182  case 'x':
183  case 'X':
184  case 'y':
185  case 'Y':
186  case 'z':
187  case 'Z':
188  case '%':
189  p++;
190  continue;
191  case '\0':
192  default:
193  return SWITCH_STATUS_FALSE;
194  }
195  }
196  p++;
197  }
198 
199  return fspr_strftime(s, retsize, max, format, (fspr_time_exp_t *) tm);
200 }
char const int const cJSON_bool format
Definition: switch_cJSON.h:153

◆ switch_strftime_nocheck()

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 202 of file switch_apr.c.

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

203 {
204  return fspr_strftime(s, retsize, max, format, (fspr_time_exp_t *) tm);
205 }
char const int const cJSON_bool format
Definition: switch_cJSON.h:153

◆ switch_time_exp_get()

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 fspr_time_t e.g. elapsed usec since epoch

Parameters
resultthe resulting imploded time
inputthe input exploded time

Definition at line 341 of file switch_apr.c.

Referenced by switch_str_time().

342 {
343  return fspr_time_exp_get((fspr_time_t *) result, (fspr_time_exp_t *) input);
344 }

◆ switch_time_exp_gmt()

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 356 of file switch_apr.c.

Referenced by process_rtcp_report(), and rtcp_generate_sender_info().

357 {
358  return fspr_time_exp_gmt((fspr_time_exp_t *) result, input);
359 }

◆ switch_time_exp_gmt_get()

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 fspr_time_t that always represents GMT

Parameters
resultthe resulting imploded time
inputthe input exploded time

Definition at line 336 of file switch_apr.c.

Referenced by switch_str_time().

337 {
338  return fspr_time_exp_gmt_get((fspr_time_t *) result, (fspr_time_exp_t *) input);
339 }

◆ switch_time_exp_lt()

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 346 of file switch_apr.c.

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

347 {
348  return fspr_time_exp_lt((fspr_time_exp_t *) result, input);
349 }

◆ switch_time_exp_tz()

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 351 of file switch_apr.c.

Referenced by switch_xml_std_datetime_check().

352 {
353  return fspr_time_exp_tz((fspr_time_exp_t *) result, input, (fspr_int32_t) offs);
354 }

◆ switch_time_make()

switch_time_t switch_time_make ( switch_time_t  sec,
int32_t  usec 
)

Definition at line 366 of file switch_apr.c.

367 {
368  return ((switch_time_t) (sec) * APR_USEC_PER_SEC + (switch_time_t) (usec));
369 }
int64_t switch_time_t
Definition: switch_apr.h:188

◆ switch_time_now()

switch_time_t switch_time_now ( void  )
Returns
the current time

Definition at line 325 of file switch_apr.c.

Referenced by record_callback(), 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_send_rtcp_event(), switch_time_sync(), and time_now().

326 {
327 #if defined(HAVE_CLOCK_GETTIME) && defined(SWITCH_USE_CLOCK_FUNCS)
328  struct timespec ts;
329  clock_gettime(CLOCK_REALTIME, &ts);
330  return ts.tv_sec * APR_USEC_PER_SEC + (ts.tv_nsec / 1000);
331 #else
332  return (switch_time_t) fspr_time_now();
333 #endif
334 }
int64_t switch_time_t
Definition: switch_apr.h:188