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)
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 struct ast_module_infoast_module_info = &__mod_info


Detailed Description

Built in bridging interval features.

Author:
Jonathan Rose <jrose@digium.com>

Definition in file bridge_builtin_interval_features.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 217 of file bridge_builtin_interval_features.c.

static void __unreg_module ( void   )  [static]

Definition at line 217 of file bridge_builtin_interval_features.c.

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 150 of file bridge_builtin_interval_features.c.

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(), ast_bridge_features_limits::duration, LOG_ERROR, LOG_WARNING, NULL, and RAII_VAR.

Referenced by load_module().

00153 {
00154    RAII_VAR(struct ast_bridge_features_limits *, feature_limits, NULL, ao2_cleanup);
00155 
00156    if (!limits->duration) {
00157       return -1;
00158    }
00159 
00160    /* Create limits hook_pvt data. */
00161    ast_module_ref(ast_module_info->self);
00162    feature_limits = ao2_alloc_options(sizeof(*feature_limits),
00163       bridge_features_limits_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
00164    if (!feature_limits) {
00165       ast_module_unref(ast_module_info->self);
00166       return -1;
00167    }
00168    if (ast_bridge_features_limits_construct(feature_limits)) {
00169       return -1;
00170    }
00171    bridge_features_limits_copy(feature_limits, limits);
00172    feature_limits->quitting_time = ast_tvadd(ast_tvnow(),
00173       ast_samp2tv(feature_limits->duration, 1000));
00174 
00175    /* Install limit hooks. */
00176    ao2_ref(feature_limits, +1);
00177    if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA,
00178       feature_limits->duration,
00179       bridge_features_duration_callback, feature_limits, __ao2_cleanup, remove_flags)) {
00180       ast_log(LOG_ERROR, "Failed to schedule the duration limiter to the bridge channel.\n");
00181       ao2_ref(feature_limits, -1);
00182       return -1;
00183    }
00184    if (!ast_strlen_zero(feature_limits->connect_sound)) {
00185       ao2_ref(feature_limits, +1);
00186       if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA, 1,
00187          bridge_features_connect_callback, feature_limits, __ao2_cleanup, remove_flags)) {
00188          ast_log(LOG_WARNING, "Failed to schedule connect sound to the bridge channel.\n");
00189          ao2_ref(feature_limits, -1);
00190       }
00191    }
00192    if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
00193       ao2_ref(feature_limits, +1);
00194       if (ast_bridge_interval_hook(features, AST_BRIDGE_HOOK_TIMER_OPTION_MEDIA,
00195          feature_limits->duration - feature_limits->warning,
00196          bridge_features_warning_callback, feature_limits, __ao2_cleanup, remove_flags)) {
00197          ast_log(LOG_WARNING, "Failed to schedule warning sound playback to the bridge channel.\n");
00198          ao2_ref(feature_limits, -1);
00199       }
00200    }
00201 
00202    return 0;
00203 }

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

Definition at line 117 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits::connect_sound, and limits_interval_playback().

Referenced by bridge_builtin_set_limits().

00118 {
00119    struct ast_bridge_features_limits *limits = hook_pvt;
00120 
00121    limits_interval_playback(bridge_channel, limits, limits->connect_sound);
00122    return -1;
00123 }

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

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

static void bridge_features_limits_dtor ( void *  vdoomed  )  [static]

Definition at line 142 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits_destroy(), and ast_module_unref.

Referenced by bridge_builtin_set_limits().

00143 {
00144    struct ast_bridge_features_limits *doomed = vdoomed;
00145 
00146    ast_bridge_features_limits_destroy(doomed);
00147    ast_module_unref(ast_module_info->self);
00148 }

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

Definition at line 125 of file bridge_builtin_interval_features.c.

References ast_bridge_features_limits::frequency, limits_interval_playback(), and ast_bridge_features_limits::warning_sound.

Referenced by bridge_builtin_set_limits().

00126 {
00127    struct ast_bridge_features_limits *limits = hook_pvt;
00128 
00129    limits_interval_playback(bridge_channel, limits, limits->warning_sound);
00130    return limits->frequency ?: -1;
00131 }

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

Definition at line 69 of file bridge_builtin_interval_features.c.

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, min, NULL, and ast_bridge_features_limits::quitting_time.

Referenced by bridge_features_connect_callback(), and bridge_features_warning_callback().

00070 {
00071    if (!strcasecmp(file, "timeleft")) {
00072       unsigned int remaining = ast_tvdiff_ms(limits->quitting_time, ast_tvnow()) / 1000;
00073       unsigned int min;
00074       unsigned int sec;
00075 
00076       if (remaining <= 0) {
00077          return;
00078       }
00079 
00080       if ((remaining / 60) > 1) {
00081          min = remaining / 60;
00082          sec = remaining % 60;
00083       } else {
00084          min = 0;
00085          sec = remaining;
00086       }
00087 
00088       ast_stream_and_wait(bridge_channel->chan, "vm-youhave", AST_DIGIT_NONE);
00089       if (min) {
00090          ast_say_number(bridge_channel->chan, min, AST_DIGIT_NONE,
00091             ast_channel_language(bridge_channel->chan), NULL);
00092          ast_stream_and_wait(bridge_channel->chan, "queue-minutes", AST_DIGIT_NONE);
00093       }
00094       if (sec) {
00095          ast_say_number(bridge_channel->chan, sec, AST_DIGIT_NONE,
00096             ast_channel_language(bridge_channel->chan), NULL);
00097          ast_stream_and_wait(bridge_channel->chan, "queue-seconds", AST_DIGIT_NONE);
00098       }
00099    } else {
00100       ast_stream_and_wait(bridge_channel->chan, file, AST_DIGIT_NONE);
00101    }
00102 
00103    /*
00104     * It may be necessary to resume music on hold after we finish
00105     * playing the announcment.
00106     */
00107    if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_MOH)) {
00108       const char *latest_musicclass;
00109 
00110       ast_channel_lock(bridge_channel->chan);
00111       latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(bridge_channel->chan));
00112       ast_channel_unlock(bridge_channel->chan);
00113       ast_moh_start(bridge_channel->chan, latest_musicclass, NULL);
00114    }
00115 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]


Variable Documentation

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 217 of file bridge_builtin_interval_features.c.

Definition at line 217 of file bridge_builtin_interval_features.c.


Generated on Thu Apr 16 06:29:09 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6