Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Functions | Variables
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 marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_waitforring.c.

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

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

◆ load_module()

static int load_module ( void  )
static

Definition at line 139 of file app_waitforring.c.

140{
142}
static int waitforring_exec(struct ast_channel *chan, const char *data)
static char * app
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References app, ast_register_application_xml, and waitforring_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 134 of file app_waitforring.c.

135{
137}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, and ast_unregister_application().

◆ waitforring_exec()

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

Definition at line 61 of file app_waitforring.c.

62{
63 struct ast_frame *f;
64 struct ast_silence_generator *silgen = NULL;
65 int res = 0;
66 double s;
67 int timeout_ms;
68 int ms;
69 struct timeval start = ast_tvnow();
70
71 if (!data || (sscanf(data, "%30lg", &s) != 1)) {
72 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
73 return 0;
74 }
75
76 if (s < 0.0) {
77 ast_log(LOG_WARNING, "Invalid timeout provided for WaitForRing (%lg)\n", s);
78 return 0;
79 }
80
83 }
84
85 timeout_ms = s * 1000.0;
86 while ((ms = ast_remaining_ms(start, timeout_ms))) {
87 ms = ast_waitfor(chan, ms);
88 if (ms < 0) {
89 res = -1;
90 break;
91 }
92 if (ms > 0) {
93 f = ast_read(chan);
94 if (!f) {
95 res = -1;
96 break;
97 }
99 ast_verb(3, "Got a ring but still waiting for timeout\n");
100 }
101 ast_frfree(f);
102 }
103 }
104 /* Now we're really ready for the ring */
105 if (!res) {
106 for (;;) {
107 int wait_res = ast_waitfor(chan, -1);
108 if (wait_res < 0) {
109 res = -1;
110 break;
111 } else {
112 f = ast_read(chan);
113 if (!f) {
114 res = -1;
115 break;
116 }
118 ast_verb(3, "Got a ring after the timeout\n");
119 ast_frfree(f);
120 break;
121 }
122 ast_frfree(f);
123 }
124 }
125 }
126
127 if (silgen) {
129 }
130
131 return res;
132}
#define ast_log
Definition: astobj2.c:42
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8169
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3130
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8215
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4214
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
@ AST_CONTROL_RING
#define ast_verb(level,...)
#define LOG_WARNING
#define ast_opt_transmit_silence
Definition: options.h:125
#define NULL
Definition: resample.c:96
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: utils.c:2281
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

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(), ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, NULL, and ast_frame::subclass.

Referenced by load_module().

Variable Documentation

◆ app

char* app = "WaitForRing"
static

Definition at line 59 of file app_waitforring.c.

Referenced by load_module(), and unload_module().