Sat Aug 6 00:39:38 2011

Asterisk developer's documentation


app_waitforring.c File Reference

Wait for Ring Application. More...

#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

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int unload_module (void)
static int waitforring_exec (struct ast_channel *chan, void *data)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Waits until first ring after time" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static char * app = "WaitForRing"
static const struct ast_module_infoast_module_info = &__mod_info
static char * desc
static char * synopsis = "Wait for Ring Application"


Detailed Description

Wait for Ring Application.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_waitforring.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 145 of file app_waitforring.c.

static void __unreg_module ( void   )  [static]

Definition at line 145 of file app_waitforring.c.

static int load_module ( void   )  [static]

Definition at line 140 of file app_waitforring.c.

References ast_register_application(), and waitforring_exec().

00141 {
00142    return ast_register_application(app, waitforring_exec, synopsis, desc);
00143 }

static int unload_module ( void   )  [static]

Definition at line 129 of file app_waitforring.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00130 {
00131    int res;
00132 
00133    res = ast_unregister_application(app);
00134 
00135    ast_module_user_hangup_all();
00136 
00137    return res; 
00138 }

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_module_user_add, ast_module_user_remove, ast_opt_transmit_silence, ast_read(), ast_verbose(), ast_waitfor(), f, LOG_WARNING, option_verbose, and VERBOSE_PREFIX_3.

Referenced by load_module().

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


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Waits until first ring after time" , .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 145 of file app_waitforring.c.

char* app = "WaitForRing" [static]

Definition at line 53 of file app_waitforring.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 145 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.


Generated on Sat Aug 6 00:39:38 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7