Fri Jun 19 12:10:37 2009

Asterisk developer's documentation


func_timeout.c File Reference

Channel timeout related dialplan functions. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.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 timeout_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int timeout_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel timeout dialplan functions" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_custom_function timeout_function


Detailed Description

Channel timeout related dialplan functions.

Author:
Mark Spencer <markster@digium.com>

Definition in file func_timeout.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 194 of file func_timeout.c.

static void __unreg_module ( void   )  [static]

Definition at line 194 of file func_timeout.c.

static int load_module ( void   )  [static]

Definition at line 189 of file func_timeout.c.

References ast_custom_function_register, and timeout_function.

00190 {
00191    return ast_custom_function_register(&timeout_function);
00192 }

static int timeout_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 37 of file func_timeout.c.

References ast_copy_string(), ast_log(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), chan, ast_pbx::dtimeoutms, LOG_ERROR, ast_channel::pbx, ast_pbx::rtimeoutms, and ast_channel::whentohangup.

00039 {
00040    struct timeval myt;
00041 
00042    if (!chan)
00043       return -1;
00044 
00045    if (!data) {
00046       ast_log(LOG_ERROR, "Must specify type of timeout to get.\n");
00047       return -1;
00048    }
00049 
00050    switch (*data) {
00051    case 'a':
00052    case 'A':
00053       if (ast_tvzero(chan->whentohangup)) {
00054          ast_copy_string(buf, "0", len);
00055       } else {
00056          myt = ast_tvnow();
00057          snprintf(buf, len, "%.3f", ast_tvdiff_ms(myt, chan->whentohangup) / 1000.0);
00058       }
00059       break;
00060 
00061    case 'r':
00062    case 'R':
00063       if (chan->pbx) {
00064          snprintf(buf, len, "%.3f", chan->pbx->rtimeoutms / 1000.0);
00065       }
00066       break;
00067 
00068    case 'd':
00069    case 'D':
00070       if (chan->pbx) {
00071          snprintf(buf, len, "%.3f", chan->pbx->dtimeoutms / 1000.0);
00072       }
00073       break;
00074 
00075    default:
00076       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00077       return -1;
00078    }
00079 
00080    return 0;
00081 }

static int timeout_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 83 of file func_timeout.c.

References ast_channel_setwhentohangup_tv(), ast_localtime(), ast_log(), ast_strftime(), ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_verbose, chan, LOG_ERROR, sec, and VERBOSITY_ATLEAST.

00085 {
00086    double x = 0.0;
00087    long sec = 0L;
00088    char timestr[64];
00089    struct ast_tm myt;
00090    struct timeval when = {0,};
00091    int res;
00092 
00093    if (!chan)
00094       return -1;
00095 
00096    if (!data) {
00097       ast_log(LOG_ERROR, "Must specify type of timeout to set.\n");
00098       return -1;
00099    }
00100 
00101    if (!value)
00102       return -1;
00103 
00104    res = sscanf(value, "%ld%lf", &sec, &x);
00105    if (res == 0 || sec < 0) {
00106       when.tv_sec = 0;
00107       when.tv_usec = 0;
00108    } else if (res == 1) {
00109       when.tv_sec = sec;
00110    } else if (res == 2) {
00111       when.tv_sec = sec;
00112       when.tv_usec = x * 1000000;
00113    }
00114 
00115    switch (*data) {
00116    case 'a':
00117    case 'A':
00118       ast_channel_setwhentohangup_tv(chan, when);
00119       if (VERBOSITY_ATLEAST(3)) {
00120          if (!ast_tvzero(chan->whentohangup)) {
00121             when = ast_tvadd(when, ast_tvnow());
00122             ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
00123                ast_localtime(&when, &myt, NULL));
00124             ast_verbose("Channel will hangup at %s.\n", timestr);
00125          } else {
00126             ast_verbose("Channel hangup cancelled.\n");
00127          }
00128       }
00129       break;
00130 
00131    case 'r':
00132    case 'R':
00133       if (chan->pbx) {
00134          chan->pbx->rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000.0;
00135          ast_verb(3, "Response timeout set to %.3f\n", chan->pbx->rtimeoutms / 1000.0);
00136       }
00137       break;
00138 
00139    case 'd':
00140    case 'D':
00141       if (chan->pbx) {
00142          chan->pbx->dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000.0;
00143          ast_verb(3, "Digit timeout set to %.3f\n", chan->pbx->dtimeoutms / 1000.0);
00144       }
00145       break;
00146 
00147    default:
00148       ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
00149       break;
00150    }
00151 
00152    return 0;
00153 }

static int unload_module ( void   )  [static]

Definition at line 184 of file func_timeout.c.

References ast_custom_function_unregister(), and timeout_function.

00185 {
00186    return ast_custom_function_unregister(&timeout_function);
00187 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Channel timeout dialplan functions" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 194 of file func_timeout.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 194 of file func_timeout.c.

struct ast_custom_function timeout_function [static]

Definition at line 155 of file func_timeout.c.

Referenced by load_module(), and unload_module().


Generated on Fri Jun 19 12:10:37 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7