Tue Aug 24 20:35:06 2010

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"
Include dependency graph for app_waituntil.c:

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, void *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 113 of file app_waituntil.c.

References ast_register_application_xml, and waituntil_exec().

00114 {
00115    return ast_register_application_xml(app, waituntil_exec);
00116 }

static int unload_module ( void   )  [static]

Definition at line 108 of file app_waituntil.c.

References ast_unregister_application().

00109 {
00110    return ast_unregister_application(app);
00111 }

static int waituntil_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 70 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().

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


Variable Documentation

char* app = "WaitUntil" [static]

Definition at line 68 of file app_waituntil.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1