75 static int timeout_read(
struct ast_channel *chan,
const char *cmd,
char *data,
76 char *buf,
size_t len)
84 ast_log(LOG_ERROR,
"Must specify type of timeout to get.\n");
91 if (
ast_tvzero(*ast_channel_whentohangup(chan))) {
95 snprintf(buf, len,
"%.3f",
ast_tvdiff_ms(*ast_channel_whentohangup(chan), myt) / 1000.0);
101 if (ast_channel_pbx(chan)) {
102 snprintf(buf, len,
"%.3f", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
108 if (ast_channel_pbx(chan)) {
109 snprintf(buf, len,
"%.3f", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
114 ast_log(LOG_ERROR,
"Unknown timeout type specified.\n");
121 static int timeout_write(
struct ast_channel *chan,
const char *cmd,
char *data,
128 struct timeval when = {0,};
135 ast_log(LOG_ERROR,
"Must specify type of timeout to set.\n");
142 res = sscanf(value,
"%30ld%30lf", &sec, &x);
143 if (res == 0 || sec < 0) {
146 }
else if (res == 1) {
148 }
else if (res == 2) {
150 when.tv_usec = x * 1000000;
156 ast_channel_lock(chan);
158 ast_channel_unlock(chan);
159 if (VERBOSITY_ATLEAST(3)) {
160 if (!
ast_tvzero(*ast_channel_whentohangup(chan))) {
162 ast_strftime(timestr,
sizeof(timestr),
"%Y-%m-%d %H:%M:%S.%3q %Z",
164 ast_verb(3,
"Channel will hangup at %s.\n", timestr);
166 ast_verb(3,
"Channel hangup cancelled.\n");
173 if (ast_channel_pbx(chan)) {
174 ast_channel_pbx(chan)->
rtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
175 ast_verb(3,
"Response timeout set to %.3f\n", ast_channel_pbx(chan)->rtimeoutms / 1000.0);
181 if (ast_channel_pbx(chan)) {
182 ast_channel_pbx(chan)->
dtimeoutms = when.tv_sec * 1000 + when.tv_usec / 1000;
183 ast_verb(3,
"Digit timeout set to %.3f\n", ast_channel_pbx(chan)->dtimeoutms / 1000.0);
188 ast_log(LOG_ERROR,
"Unknown timeout type specified.\n");
197 .read = timeout_read,
199 .write = timeout_write,
202 static int unload_module(
void)
207 static int load_module(
void)
212 AST_MODULE_INFO_STANDARD(
ASTERISK_GPL_KEY,
"Channel timeout dialplan functions");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset)
Set when to hang a channel up.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
General Asterisk PBX channel definitions.
Data structure associated with a custom dialplan function.
Core PBX routines and definitions.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_custom_function_register(acf)
Register a custom function.