Asterisk - The Open Source Telephony Project GIT-master-5782b03
Functions | Variables
bridge_builtin_interval_features.c File Reference

Built in bridging interval features. More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/bridge.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/astobj2.h"
#include "asterisk/test.h"
#include "asterisk/say.h"
#include "asterisk/stringfields.h"
#include "asterisk/musiconhold.h"
#include "asterisk/causes.h"
Include dependency graph for bridge_builtin_interval_features.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int bridge_builtin_set_limits (struct ast_bridge_features *features, struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)
 
static int bridge_features_connect_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static int bridge_features_duration_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static void bridge_features_limits_copy (struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
 
static void bridge_features_limits_dtor (void *vdoomed)
 
static int bridge_features_warning_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static void limits_interval_playback (struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Built in bridging interval features" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Built in bridging interval features.

Author
Jonathan Rose jrose.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file bridge_builtin_interval_features.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ bridge_builtin_set_limits()

static int bridge_builtin_set_limits ( struct ast_bridge_features features,
struct ast_bridge_features_limits limits,
enum ast_bridge_hook_remove_flags  remove_flags 
)
static

Definition at line 148 of file bridge_builtin_interval_features.c.

151{
152 RAII_VAR(struct ast_bridge_features_limits *, feature_limits, NULL, ao2_cleanup);
153
154 if (!limits->duration) {
155 return -1;
156 }
157
158 /* Create limits hook_pvt data. */
160 feature_limits = ao2_alloc_options(sizeof(*feature_limits),
162 if (!feature_limits) {
164 return -1;
165 }
166 if (ast_bridge_features_limits_construct(feature_limits)) {
167 return -1;
168 }
169 bridge_features_limits_copy(feature_limits, limits);
170 feature_limits->quitting_time = ast_tvadd(ast_tvnow(),
171 ast_samp2tv(feature_limits->duration, 1000));
172
173 /* Install limit hooks. */
174 ao2_ref(feature_limits, +1);
176 feature_limits->duration,
177 bridge_features_duration_callback, feature_limits, __ao2_cleanup, remove_flags)) {
178 ast_log(LOG_ERROR, "Failed to schedule the duration limiter to the bridge channel.\n");
179 ao2_ref(feature_limits, -1);
180 return -1;
181 }
182 if (!ast_strlen_zero(feature_limits->connect_sound)) {
183 ao2_ref(feature_limits, +1);
185 bridge_features_connect_callback, feature_limits, __ao2_cleanup, remove_flags)) {
186 ast_log(LOG_WARNING, "Failed to schedule connect sound to the bridge channel.\n");
187 ao2_ref(feature_limits, -1);
188 }
189 }
190 if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
191 ao2_ref(feature_limits, +1);
193 feature_limits->duration - feature_limits->warning,
194 bridge_features_warning_callback, feature_limits, __ao2_cleanup, remove_flags)) {
195 ast_log(LOG_WARNING, "Failed to schedule warning sound playback to the bridge channel.\n");
196 ao2_ref(feature_limits, -1);
197 }
198 }
199
200 return 0;
201}
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
void __ao2_cleanup(void *obj)
Definition: astobj2.c:677
static void bridge_features_limits_copy(struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
static int bridge_features_warning_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
static int bridge_features_duration_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
static int bridge_features_connect_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
static void bridge_features_limits_dtor(void *vdoomed)
int ast_bridge_features_limits_construct(struct ast_bridge_features_limits *limits)
Constructor function for ast_bridge_features_limits.
Definition: bridge.c:3396
int ast_bridge_interval_hook(struct ast_bridge_features *features, enum ast_bridge_hook_timer_option flags, unsigned int interval, ast_bridge_hook_callback callback, void *hook_pvt, ast_bridge_hook_pvt_destructor destructor, enum ast_bridge_hook_remove_flags remove_flags)
Attach an interval hook to a bridge features structure.
Definition: bridge.c:3319
@ AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA
#define LOG_ERROR
#define LOG_WARNING
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:483
#define ast_module_ref(mod)
Hold a reference to the module.
Definition: module.h:457
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure that contains configuration information for the limits feature.
struct ast_module * self
Definition: module.h:356
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:282
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References __ao2_cleanup(), AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_ref, ast_bridge_features_limits_construct(), AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA, ast_bridge_interval_hook(), ast_log, ast_module_ref, ast_module_unref, ast_samp2tv(), ast_strlen_zero(), ast_tvadd(), ast_tvnow(), bridge_features_connect_callback(), bridge_features_duration_callback(), bridge_features_limits_copy(), bridge_features_limits_dtor(), bridge_features_warning_callback(), LOG_ERROR, LOG_WARNING, NULL, RAII_VAR, and ast_module_info::self.

Referenced by load_module().

◆ bridge_features_connect_callback()

static int bridge_features_connect_callback ( struct ast_bridge_channel bridge_channel,
void *  hook_pvt 
)
static

Definition at line 115 of file bridge_builtin_interval_features.c.

116{
117 struct ast_bridge_features_limits *limits = hook_pvt;
118
119 limits_interval_playback(bridge_channel, limits, limits->connect_sound);
120 return -1;
121}
static void limits_interval_playback(struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)

References limits_interval_playback().

Referenced by bridge_builtin_set_limits().

◆ bridge_features_duration_callback()

static int bridge_features_duration_callback ( struct ast_bridge_channel bridge_channel,
void *  hook_pvt 
)
static

Definition at line 51 of file bridge_builtin_interval_features.c.

52{
53 struct ast_bridge_features_limits *limits = hook_pvt;
54
55 if (!ast_strlen_zero(limits->duration_sound)) {
56 ast_stream_and_wait(bridge_channel->chan, limits->duration_sound, AST_DIGIT_NONE);
57 }
58
61
62 ast_test_suite_event_notify("BRIDGE_TIMELIMIT", "Channel1: %s",
63 ast_channel_name(bridge_channel->chan));
64 return -1;
65}
@ BRIDGE_CHANNEL_STATE_END
void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:106
const char * ast_channel_name(const struct ast_channel *chan)
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1878
#define AST_DIGIT_NONE
Definition: file.h:47
struct ast_channel * chan
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189

References ast_bridge_channel_leave_bridge(), AST_CAUSE_NORMAL_CLEARING, ast_channel_name(), AST_DIGIT_NONE, ast_stream_and_wait(), ast_strlen_zero(), ast_test_suite_event_notify, BRIDGE_CHANNEL_STATE_END, and ast_bridge_channel::chan.

Referenced by bridge_builtin_set_limits().

◆ bridge_features_limits_copy()

static void bridge_features_limits_copy ( struct ast_bridge_features_limits dst,
struct ast_bridge_features_limits src 
)
static

Definition at line 131 of file bridge_builtin_interval_features.c.

132{
133 ast_string_fields_copy(dst, src);
134 dst->quitting_time = src->quitting_time;
135 dst->duration = src->duration;
136 dst->warning = src->warning;
137 dst->frequency = src->frequency;
138}
#define ast_string_fields_copy(copy, orig)
Copy all string fields from one instance to another of the same structure.
Definition: stringfields.h:630

References ast_string_fields_copy, ast_bridge_features_limits::duration, ast_bridge_features_limits::frequency, ast_bridge_features_limits::quitting_time, and ast_bridge_features_limits::warning.

Referenced by bridge_builtin_set_limits().

◆ bridge_features_limits_dtor()

static void bridge_features_limits_dtor ( void *  vdoomed)
static

Definition at line 140 of file bridge_builtin_interval_features.c.

141{
142 struct ast_bridge_features_limits *doomed = vdoomed;
143
146}
void ast_bridge_features_limits_destroy(struct ast_bridge_features_limits *limits)
Destructor function for ast_bridge_features_limits.
Definition: bridge.c:3407

References ast_bridge_features_limits_destroy(), ast_module_unref, and ast_module_info::self.

Referenced by bridge_builtin_set_limits().

◆ bridge_features_warning_callback()

static int bridge_features_warning_callback ( struct ast_bridge_channel bridge_channel,
void *  hook_pvt 
)
static

Definition at line 123 of file bridge_builtin_interval_features.c.

124{
125 struct ast_bridge_features_limits *limits = hook_pvt;
126
127 limits_interval_playback(bridge_channel, limits, limits->warning_sound);
128 return limits->frequency ?: -1;
129}

References limits_interval_playback().

Referenced by bridge_builtin_set_limits().

◆ limits_interval_playback()

static void limits_interval_playback ( struct ast_bridge_channel bridge_channel,
struct ast_bridge_features_limits limits,
const char *  file 
)
static

Definition at line 67 of file bridge_builtin_interval_features.c.

68{
69 if (!strcasecmp(file, "timeleft")) {
70 unsigned int remaining = ast_tvdiff_ms(limits->quitting_time, ast_tvnow()) / 1000;
71 unsigned int min;
72 unsigned int sec;
73
74 if (remaining <= 0) {
75 return;
76 }
77
78 if ((remaining / 60) > 1) {
79 min = remaining / 60;
80 sec = remaining % 60;
81 } else {
82 min = 0;
83 sec = remaining;
84 }
85
86 ast_stream_and_wait(bridge_channel->chan, "vm-youhave", AST_DIGIT_NONE);
87 if (min) {
88 ast_say_number(bridge_channel->chan, min, AST_DIGIT_NONE,
89 ast_channel_language(bridge_channel->chan), NULL);
90 ast_stream_and_wait(bridge_channel->chan, "queue-minutes", AST_DIGIT_NONE);
91 }
92 if (sec) {
93 ast_say_number(bridge_channel->chan, sec, AST_DIGIT_NONE,
94 ast_channel_language(bridge_channel->chan), NULL);
95 ast_stream_and_wait(bridge_channel->chan, "queue-seconds", AST_DIGIT_NONE);
96 }
97 } else {
99 }
100
101 /*
102 * It may be necessary to resume music on hold after we finish
103 * playing the announcment.
104 */
105 if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_MOH)) {
106 const char *latest_musicclass;
107
108 ast_channel_lock(bridge_channel->chan);
109 latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(bridge_channel->chan));
110 ast_channel_unlock(bridge_channel->chan);
111 ast_moh_start(bridge_channel->chan, latest_musicclass, NULL);
112 }
113}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
const char * ast_channel_latest_musicclass(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2968
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
@ AST_FLAG_MOH
Definition: channel.h:1011
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#define min(a, b)
Definition: f2c.h:197
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7788
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
Definition: channel.c:8257
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
#define ast_test_flag(p, flag)
Definition: utils.h:63

References ast_channel_flags(), ast_channel_language(), ast_channel_latest_musicclass(), ast_channel_lock, ast_channel_unlock, AST_DIGIT_NONE, AST_FLAG_MOH, ast_moh_start(), ast_say_number(), ast_strdupa, ast_stream_and_wait(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_bridge_channel::chan, make_ari_stubs::file, min, and NULL.

Referenced by bridge_features_connect_callback(), and bridge_features_warning_callback().

◆ load_module()

static int load_module ( void  )
static

Definition at line 209 of file bridge_builtin_interval_features.c.

210{
213}
static int bridge_builtin_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)
int ast_bridge_interval_register(enum ast_bridge_builtin_interval interval, ast_bridge_builtin_set_limits_fn callback)
Register a handler for a built in interval feature.
Definition: bridge.c:3107
@ AST_BRIDGE_BUILTIN_INTERVAL_LIMITS

References AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, ast_bridge_interval_register(), and bridge_builtin_set_limits().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 203 of file bridge_builtin_interval_features.c.

204{
206 return 0;
207}
int ast_bridge_interval_unregister(enum ast_bridge_builtin_interval interval)
Unregisters a handler for a built in interval feature.
Definition: bridge.c:3119

References AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, and ast_bridge_interval_unregister().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Built in bridging interval features" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 215 of file bridge_builtin_interval_features.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 215 of file bridge_builtin_interval_features.c.