Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
Functions | Variables
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"
Include dependency graph for app_waituntil.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app = "WaitUntil"
 
static const 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

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 123 of file app_waituntil.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 123 of file app_waituntil.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 123 of file app_waituntil.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 118 of file app_waituntil.c.

119{
121}
static int waituntil_exec(struct ast_channel *chan, const char *data)
static char * app
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640

References app, ast_register_application_xml, and waituntil_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 113 of file app_waituntil.c.

114{
116}
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392

References app, and ast_unregister_application().

◆ waituntil_exec()

static int waituntil_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 75 of file app_waituntil.c.

76{
77 int res;
78 double fraction;
79 long seconds;
80 struct timeval future = { 0, };
81 struct timeval now = ast_tvnow();
82 int msec;
83
84 if (ast_strlen_zero(data)) {
85 ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n");
86 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
87 return 0;
88 }
89
90 if (sscanf(data, "%30ld%30lf", &seconds, &fraction) == 0) {
91 ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n");
92 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
93 return 0;
94 }
95
96 future.tv_sec = seconds;
97 future.tv_usec = fraction * 1000000;
98
99 if ((msec = ast_tvdiff_ms(future, now)) < 0) {
100 ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)now.tv_sec, (long)future.tv_sec);
101 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST");
102 return 0;
103 }
104
105 if ((res = ast_safe_sleep(chan, msec)))
106 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP");
107 else
108 pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK");
109
110 return res;
111}
#define ast_log
Definition astobj2.c:42
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition channel.c:1542
#define LOG_NOTICE
#define LOG_WARNING
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

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().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Wait until specified time" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 123 of file app_waituntil.c.

◆ app

char* app = "WaitUntil"
static

Definition at line 73 of file app_waituntil.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 123 of file app_waituntil.c.