#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/lock.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Waits until first ring after time") | |
static int | load_module (void) |
static int | unload_module (void) |
static int | waitforring_exec (struct ast_channel *chan, void *data) |
Variables | |
static char * | app = "WaitForRing" |
static char * | desc |
static char * | synopsis = "Wait for Ring Application" |
Definition in file app_waitforring.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Waits until first ring after time" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 131 of file app_waitforring.c.
References ast_register_application(), and waitforring_exec().
00132 { 00133 return ast_register_application(app, waitforring_exec, synopsis, desc); 00134 }
static int unload_module | ( | void | ) | [static] |
Definition at line 120 of file app_waitforring.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00121 { 00122 int res; 00123 00124 res = ast_unregister_application(app); 00125 00126 ast_module_user_hangup_all(); 00127 00128 return res; 00129 }
static int waitforring_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 56 of file app_waitforring.c.
References AST_CONTROL_RING, AST_FRAME_CONTROL, ast_frfree, ast_log(), ast_module_user_add, ast_module_user_remove, ast_read(), ast_verbose(), ast_waitfor(), f, ast_frame::frametype, LOG_WARNING, option_verbose, ast_frame::subclass, and VERBOSE_PREFIX_3.
Referenced by load_module().
00057 { 00058 struct ast_module_user *u; 00059 struct ast_frame *f; 00060 int res = 0; 00061 int ms; 00062 00063 if (!data || (sscanf(data, "%d", &ms) != 1)) { 00064 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n"); 00065 return 0; 00066 } 00067 00068 u = ast_module_user_add(chan); 00069 00070 ms *= 1000; 00071 while(ms > 0) { 00072 ms = ast_waitfor(chan, ms); 00073 if (ms < 0) { 00074 res = ms; 00075 break; 00076 } 00077 if (ms > 0) { 00078 f = ast_read(chan); 00079 if (!f) { 00080 res = -1; 00081 break; 00082 } 00083 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) { 00084 if (option_verbose > 2) 00085 ast_verbose(VERBOSE_PREFIX_3 "Got a ring but still waiting for timeout\n"); 00086 } 00087 ast_frfree(f); 00088 } 00089 } 00090 /* Now we're really ready for the ring */ 00091 if (!res) { 00092 ms = 99999999; 00093 while(ms > 0) { 00094 ms = ast_waitfor(chan, ms); 00095 if (ms < 0) { 00096 res = ms; 00097 break; 00098 } 00099 if (ms > 0) { 00100 f = ast_read(chan); 00101 if (!f) { 00102 res = -1; 00103 break; 00104 } 00105 if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_RING)) { 00106 if (option_verbose > 2) 00107 ast_verbose(VERBOSE_PREFIX_3 "Got a ring after the timeout\n"); 00108 ast_frfree(f); 00109 break; 00110 } 00111 ast_frfree(f); 00112 } 00113 } 00114 } 00115 ast_module_user_remove(u); 00116 00117 return res; 00118 }
char* app = "WaitForRing" [static] |
Definition at line 53 of file app_waitforring.c.
char* desc [static] |
Initial value:
" WaitForRing(timeout)\n" "Returns 0 after waiting at least timeout seconds. and\n" "only after the next ring has completed. Returns 0 on\n" "success or -1 on hangup\n"
Definition at line 48 of file app_waitforring.c.
char* synopsis = "Wait for Ring Application" [static] |
Definition at line 46 of file app_waitforring.c.