Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 136 of file app_waitforring.c.

137{
139}
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 131 of file app_waitforring.c.

132{
134}
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 58 of file app_waitforring.c.

59{
60 struct ast_frame *f;
61 struct ast_silence_generator *silgen = NULL;
62 int res = 0;
63 double s;
64 int timeout_ms;
65 int ms;
66 struct timeval start = ast_tvnow();
67
68 if (!data || (sscanf(data, "%30lg", &s) != 1)) {
69 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
70 return 0;
71 }
72
73 if (s < 0.0) {
74 ast_log(LOG_WARNING, "Invalid timeout provided for WaitForRing (%lg)\n", s);
75 return 0;
76 }
77
80 }
81
82 timeout_ms = s * 1000.0;
83 while ((ms = ast_remaining_ms(start, timeout_ms))) {
84 ms = ast_waitfor(chan, ms);
85 if (ms < 0) {
86 res = -1;
87 break;
88 }
89 if (ms > 0) {
90 f = ast_read(chan);
91 if (!f) {
92 res = -1;
93 break;
94 }
96 ast_verb(3, "Got a ring but still waiting for timeout\n");
97 }
98 ast_frfree(f);
99 }
100 }
101 /* Now we're really ready for the ring */
102 if (!res) {
103 for (;;) {
104 int wait_res = ast_waitfor(chan, -1);
105 if (wait_res < 0) {
106 res = -1;
107 break;
108 } else {
109 f = ast_read(chan);
110 if (!f) {
111 res = -1;
112 break;
113 }
115 ast_verb(3, "Got a ring after the timeout\n");
116 ast_frfree(f);
117 break;
118 }
119 ast_frfree(f);
120 }
121 }
122 }
123
124 if (silgen) {
126 }
127
128 return res;
129}
#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:8186
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3181
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:8232
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4276
#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:124
#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 56 of file app_waitforring.c.

Referenced by load_module(), and unload_module().