app_waitforring.c File Reference

Wait for Ring Application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"

Include dependency graph for app_waitforring.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (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, const char *data)

Variables

static char * app = "WaitForRing"


Detailed Description

Wait for Ring Application.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_waitforring.c.


Function Documentation

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Waits until first ring after time"   
)

static int load_module ( void   )  [static]

Definition at line 138 of file app_waitforring.c.

References ast_register_application_xml, and waitforring_exec().

00139 {
00140    return ast_register_application_xml(app, waitforring_exec);
00141 }

static int unload_module ( void   )  [static]

Definition at line 133 of file app_waitforring.c.

References ast_unregister_application().

00134 {
00135    return ast_unregister_application(app);
00136 }

static int waitforring_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 60 of file app_waitforring.c.

References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), AST_CONTROL_RING, AST_FRAME_CONTROL, ast_frfree, ast_log, ast_opt_transmit_silence, ast_read(), ast_remaining_ms(), ast_tvnow(), ast_verb, ast_waitfor(), f, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, NULL, and ast_frame::subclass.

Referenced by load_module().

00061 {
00062    struct ast_frame *f;
00063    struct ast_silence_generator *silgen = NULL;
00064    int res = 0;
00065    double s;
00066    int timeout_ms;
00067    int ms;
00068    struct timeval start = ast_tvnow();
00069 
00070    if (!data || (sscanf(data, "%30lg", &s) != 1)) {
00071       ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
00072       return 0;
00073    }
00074 
00075    if (s < 0.0) {
00076       ast_log(LOG_WARNING, "Invalid timeout provided for WaitForRing (%lg)\n", s);
00077       return 0;
00078    }
00079 
00080    if (ast_opt_transmit_silence) {
00081       silgen = ast_channel_start_silence_generator(chan);
00082    }
00083 
00084    timeout_ms = s * 1000.0;
00085    while ((ms = ast_remaining_ms(start, timeout_ms))) {
00086       ms = ast_waitfor(chan, ms);
00087       if (ms < 0) {
00088          res = -1;
00089          break;
00090       }
00091       if (ms > 0) {
00092          f = ast_read(chan);
00093          if (!f) {
00094             res = -1;
00095             break;
00096          }
00097          if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_RING)) {
00098             ast_verb(3, "Got a ring but still waiting for timeout\n");
00099          }
00100          ast_frfree(f);
00101       }
00102    }
00103    /* Now we're really ready for the ring */
00104    if (!res) {
00105       for (;;) {
00106          int wait_res = ast_waitfor(chan, -1);
00107          if (wait_res < 0) {
00108             res = -1;
00109             break;
00110          } else {
00111             f = ast_read(chan);
00112             if (!f) {
00113                res = -1;
00114                break;
00115             }
00116             if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_RING)) {
00117                ast_verb(3, "Got a ring after the timeout\n");
00118                ast_frfree(f);
00119                break;
00120             }
00121             ast_frfree(f);
00122          }
00123       }
00124    }
00125 
00126    if (silgen) {
00127       ast_channel_stop_silence_generator(chan, silgen);
00128    }
00129 
00130    return res;
00131 }


Variable Documentation

char* app = "WaitForRing" [static]

Definition at line 58 of file app_waitforring.c.


Generated on Thu Apr 16 06:28:50 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6