Wed Jan 8 2020 09:49:57

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"

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, const char *data)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app = "WaitForRing"
 
static struct ast_module_infoast_module_info = &__mod_info
 

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

static void __reg_module ( void  )
static

Definition at line 143 of file app_waitforring.c.

static void __unreg_module ( void  )
static

Definition at line 143 of file app_waitforring.c.

static int load_module ( void  )
static

Definition at line 138 of file app_waitforring.c.

References ast_register_application_xml, and waitforring_exec().

139 {
141 }
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:437
static int unload_module ( void  )
static

Definition at line 133 of file app_waitforring.c.

References ast_unregister_application().

134 {
136 }
static char * app
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static int waitforring_exec ( struct ast_channel chan,
const char *  data 
)
static

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

Referenced by load_module().

61 {
62  struct ast_frame *f;
63  struct ast_silence_generator *silgen = NULL;
64  int res = 0;
65  double s;
66  int timeout_ms;
67  int ms;
68  struct timeval start = ast_tvnow();
69 
70  if (!data || (sscanf(data, "%30lg", &s) != 1)) {
71  ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
72  return 0;
73  }
74 
75  if (s < 0.0) {
76  ast_log(LOG_WARNING, "Invalid timeout provided for WaitForRing (%lg)\n", s);
77  return 0;
78  }
79 
82  }
83 
84  timeout_ms = s * 1000.0;
85  while ((ms = ast_remaining_ms(start, timeout_ms))) {
86  ms = ast_waitfor(chan, ms);
87  if (ms < 0) {
88  res = -1;
89  break;
90  }
91  if (ms > 0) {
92  f = ast_read(chan);
93  if (!f) {
94  res = -1;
95  break;
96  }
98  ast_verb(3, "Got a ring but still waiting for timeout\n");
99  }
100  ast_frfree(f);
101  }
102  }
103  /* Now we're really ready for the ring */
104  if (!res) {
105  for (;;) {
106  int wait_res = ast_waitfor(chan, -1);
107  if (wait_res < 0) {
108  res = -1;
109  break;
110  } else {
111  f = ast_read(chan);
112  if (!f) {
113  res = -1;
114  break;
115  }
117  ast_verb(3, "Got a ring after the timeout\n");
118  ast_frfree(f);
119  break;
120  }
121  ast_frfree(f);
122  }
123  }
124  }
125 
126  if (silgen) {
128  }
129 
130  return res;
131 }
union ast_frame_subclass subclass
Definition: frame.h:146
#define LOG_WARNING
Definition: logger.h:144
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define ast_opt_transmit_silence
Definition: options.h:120
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8309
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: utils.c:1615
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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:8355
static struct ast_format f[]
Definition: format_g726.c:181
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3539
Data structure associated with a single frame of data.
Definition: frame.h:142
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_frfree(fr)
Definition: frame.h:583

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 143 of file app_waitforring.c.

char* app = "WaitForRing"
static

Definition at line 58 of file app_waitforring.c.

Definition at line 143 of file app_waitforring.c.