Wed Jan 8 2020 09:49:57

Asterisk developer's documentation


app_waituntil.c File Reference

Sleep until the given epoch. More...

#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int load_module (void)
 
static int unload_module (void)
 
static int waituntil_exec (struct ast_channel *chan, const char *data)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Wait until specified time" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app = "WaitUntil"
 
static struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Sleep until the given epoch.

Author
Philip Prindeville phili.nosp@m.pp@r.nosp@m.edfis.nosp@m.h-so.nosp@m.lutio.nosp@m.ns.c.nosp@m.om

Definition in file app_waituntil.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 122 of file app_waituntil.c.

static void __unreg_module ( void  )
static

Definition at line 122 of file app_waituntil.c.

static int load_module ( void  )
static

Definition at line 117 of file app_waituntil.c.

References ast_register_application_xml, and waituntil_exec().

118 {
120 }
static char * app
Definition: app_waituntil.c:72
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int waituntil_exec(struct ast_channel *chan, const char *data)
Definition: app_waituntil.c:74
static int unload_module ( void  )
static

Definition at line 112 of file app_waituntil.c.

References ast_unregister_application().

113 {
115 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static char * app
Definition: app_waituntil.c:72
static int waituntil_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 74 of file app_waituntil.c.

References ast_log(), ast_safe_sleep(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), LOG_NOTICE, LOG_WARNING, and pbx_builtin_setvar_helper().

Referenced by load_module().

75 {
76  int res;
77  double fraction;
78  long seconds;
79  struct timeval future = { 0, };
80  struct timeval now = ast_tvnow();
81  int msec;
82 
83  if (ast_strlen_zero(data)) {
84  ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n");
85  pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
86  return 0;
87  }
88 
89  if (sscanf(data, "%30ld%30lf", &seconds, &fraction) == 0) {
90  ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n");
91  pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
92  return 0;
93  }
94 
95  future.tv_sec = seconds;
96  future.tv_usec = fraction * 1000000;
97 
98  if ((msec = ast_tvdiff_ms(future, now)) < 0) {
99  ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)now.tv_sec, (long)future.tv_sec);
100  pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST");
101  return 0;
102  }
103 
104  if ((res = ast_safe_sleep(chan, msec)))
105  pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP");
106  else
107  pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK");
108 
109  return res;
110 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
#define LOG_WARNING
Definition: logger.h:144
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Wait until specified time" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 122 of file app_waituntil.c.

char* app = "WaitUntil"
static

Definition at line 72 of file app_waituntil.c.

Definition at line 122 of file app_waituntil.c.