Fri Aug 17 00:17:25 2018

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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Wait until specified time")
static int load_module (void)
static int unload_module (void)
static int waituntil_exec (struct ast_channel *chan, const char *data)

Variables

static char * app = "WaitUntil"

Detailed Description

Sleep until the given epoch.

Author:
Philip Prindeville <philipp@redfish-solutions.com>

Definition in file app_waituntil.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Wait until specified time"   
)
static int load_module ( void   )  [static]

Definition at line 117 of file app_waituntil.c.

References ast_register_application_xml, and waituntil_exec().

00118 {
00119    return ast_register_application_xml(app, waituntil_exec);
00120 }

static int unload_module ( void   )  [static]

Definition at line 112 of file app_waituntil.c.

References ast_unregister_application().

00113 {
00114    return ast_unregister_application(app);
00115 }

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

00075 {
00076    int res;
00077    double fraction;
00078    long seconds;
00079    struct timeval future = { 0, };
00080    struct timeval now = ast_tvnow();
00081    int msec;
00082 
00083    if (ast_strlen_zero(data)) {
00084       ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n");
00085       pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
00086       return 0;
00087    }
00088 
00089    if (sscanf(data, "%30ld%30lf", &seconds, &fraction) == 0) {
00090       ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n");
00091       pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE");
00092       return 0;
00093    }
00094 
00095    future.tv_sec = seconds;
00096    future.tv_usec = fraction * 1000000;
00097 
00098    if ((msec = ast_tvdiff_ms(future, now)) < 0) {
00099       ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)now.tv_sec, (long)future.tv_sec);
00100       pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST");
00101       return 0;
00102    }
00103 
00104    if ((res = ast_safe_sleep(chan, msec)))
00105       pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP");
00106    else
00107       pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK");
00108 
00109    return res;
00110 }


Variable Documentation

char* app = "WaitUntil" [static]

Definition at line 72 of file app_waituntil.c.


Generated on 17 Aug 2018 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1