Asterisk - The Open Source Telephony Project  18.5.0
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"   
)

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 136 of file app_waitforring.c.

References app, AST_MODULE_INFO_STANDARD_EXTENDED(), ast_register_application_xml, ASTERISK_GPL_KEY, and waitforring_exec().

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 131 of file app_waitforring.c.

References app, and ast_unregister_application().

132 {
134 }
static char * app
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

◆ waitforring_exec()

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

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

Referenced by load_module().

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 LOG_WARNING
Definition: logger.h:274
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_opt_transmit_silence
Definition: options.h:124
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
struct ast_frame_subclass subclass
#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:8266
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2033
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:8312
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ast_frfree(fr)
Data structure associated with a single frame of data.
enum ast_frame_type frametype

Variable Documentation

◆ app

char* app = "WaitForRing"
static

Definition at line 56 of file app_waitforring.c.

Referenced by load_module(), and unload_module().