Tue Aug 24 20:34:34 2010

Asterisk developer's documentation


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 (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"

Detailed Description

Wait for Ring Application.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_waitforring.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Waits until first ring after time"   
)
static int load_module ( void   )  [static]

Definition at line 129 of file app_waitforring.c.

References ast_register_application_xml, and waitforring_exec().

00130 {
00131    return ast_register_application_xml(app, waitforring_exec);
00132 }

static int unload_module ( void   )  [static]

Definition at line 124 of file app_waitforring.c.

References ast_unregister_application().

00125 {
00126    return ast_unregister_application(app);
00127 }

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

Definition at line 56 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_verb, ast_waitfor(), f, ast_frame::frametype, LOG_WARNING, s, and ast_frame::subclass.

Referenced by load_module().

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


Variable Documentation

char* app = "WaitForRing" [static]

Definition at line 54 of file app_waitforring.c.


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