[asterisk-commits] file: branch file/bridging-phase2 r192928 - in /team/file/bridging-phase2: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 6 22:24:05 CDT 2009


Author: file
Date: Wed May  6 22:24:01 2009
New Revision: 192928

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=192928
Log:
Add a higher level API call to limit the amount of time a channel can be in a bridge and also provide warnings.

Modified:
    team/file/bridging-phase2/include/asterisk/bridging_features.h
    team/file/bridging-phase2/main/bridging.c

Modified: team/file/bridging-phase2/include/asterisk/bridging_features.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/file/bridging-phase2/include/asterisk/bridging_features.h?view=diff&rev=192928&r1=192927&r2=192928
==============================================================================
--- team/file/bridging-phase2/include/asterisk/bridging_features.h (original)
+++ team/file/bridging-phase2/include/asterisk/bridging_features.h Wed May  6 22:24:01 2009
@@ -131,6 +131,22 @@
 	char context[AST_MAX_CONTEXT];
 };
 
+/*!
+ * \brief Structure that contains configuration information for the limits feature
+ */
+struct ast_bridge_features_limits {
+	/*! Maximum duration that the channel is allowed to be in the bridge (specified in milliseconds) */
+	unsigned int duration;
+	/*! Duration into the call when warnings should begin (specified in milliseconds or 0 to disable) */
+	unsigned int warnings;
+	/*! Interval between the warnings */
+	unsigned int frequency;
+	/*! Bit to indicate that the built in warning calculation and prompts should be used */
+	unsigned int warning_prompts:1;
+	/*! Sound file to play for the warning */
+	char warning_sound[256];
+};
+
 /*! \brief Register a handler for a built in feature
  *
  * \param feature The feature that the handler will be responsible for
@@ -267,6 +283,29 @@
  */
 int ast_bridge_features_enable(struct ast_bridge_features *features, enum ast_bridge_builtin_feature feature, const char *dtmf, void *config);
 
+/*! \brief Limit the amount of time a channel may stay in the bridge and optionally play warning messages as time runs out
+ *
+ * \param features Bridge features structure
+ * \param lifetime Maximum duration the channel may stay in the bridge (specified in milliseconds)
+ * \param warning The amount of time into the call that warning messages will start (specified in milliseconds or 0 to disable)
+ * \param frequency Amount of time in between each warning message (specified in milliseconds or 0 to disable)
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_bridge_features features;
+ * struct ast_bridge_features_limits limits = { .duration = 10000, };
+ * ast_bridge_features_init(&features);
+ * ast_bridge_features_set_limits(&features, &limits);
+ * \endcode
+ *
+ * This sets the maximum time the channel can be in the bridge to 10 seconds and does not play any warnings.
+ *
+ * \note This API call can only be used on a features structure that will be used in association with a bridge channel.
+ * \note The ast_bridge_features_limits structure must remain accessible for the lifetime of the features structure.
+ */
+void ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits);
+
 /*! \brief Set a flag on a bridge features structure
  *
  * \param features Bridge features structure

Modified: team/file/bridging-phase2/main/bridging.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/file/bridging-phase2/main/bridging.c?view=diff&rev=192928&r1=192927&r2=192928
==============================================================================
--- team/file/bridging-phase2/main/bridging.c (original)
+++ team/file/bridging-phase2/main/bridging.c Wed May  6 22:24:01 2009
@@ -41,6 +41,7 @@
 #include "asterisk/file.h"
 #include "asterisk/module.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/say.h"
 
 static AST_RWLIST_HEAD_STATIC(bridge_technologies, ast_bridge_technology);
 
@@ -1084,6 +1085,7 @@
 
 		ast_debug(1, "Updating timeout on bridge '%p' since a channel that may change it has entered\n", bridge_channel->bridge);
 		bridge_channel->bridge->timeout = bridge_timeout(bridge_channel->bridge);
+		ast_debug(1, "Timeout on bridge '%p' is now %d\n", bridge_channel->bridge, bridge_channel->bridge->timeout);
 	}
 
 	/* Tell the bridge technology we are joining so they set us up */
@@ -1523,6 +1525,72 @@
 	return ast_bridge_features_hook(features, dtmf, builtin_features_handlers[feature], config);
 }
 
+static int bridge_features_duration_callback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
+{
+	ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_END);
+	return 0;
+}
+
+static int bridge_features_warning_callback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
+{
+	struct ast_bridge_features_limits *limits = hook_pvt;
+
+	if (limits->warning_prompts) {
+		struct ast_bridge_features_hook *interval_hook;
+		unsigned int remaining = 0;
+
+		AST_LIST_TRAVERSE(&bridge_channel->features->interval_hooks, interval_hook, entry) {
+			if (interval_hook->callback == bridge_features_duration_callback) {
+				remaining = ast_tvdiff_ms(interval_hook->interval_trip_time, ast_tvnow()) / 1000;
+				break;
+			}
+		}
+
+		if (remaining > 0) {
+			unsigned int min = 0, sec = 0;
+
+			if ((remaining / 60) > 1) {
+				min = remaining / 60;
+				sec = remaining % 60;
+			} else {
+				sec = remaining;
+			}
+
+			ast_stream_and_wait(bridge_channel->chan, "vm-youhave", "");
+
+			if (min) {
+				ast_say_number(bridge_channel->chan, min, AST_DIGIT_ANY, bridge_channel->chan->language, NULL);
+				ast_stream_and_wait(bridge_channel->chan, "queue-minutes", "");
+			}
+
+			if (sec) {
+				ast_say_number(bridge_channel->chan, sec, AST_DIGIT_ANY, bridge_channel->chan->language, NULL);
+				ast_stream_and_wait(bridge_channel->chan, "queue-seconds", "");
+			}
+		}
+	} else {
+		ast_streamfile(bridge_channel->chan, limits->warning_sound, bridge_channel->chan->language);
+	}
+
+	ast_bridge_features_interval_update(bridge_channel, limits->frequency);
+	ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);
+
+	return 0;
+}
+
+void ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits)
+{
+	if (!limits->duration) {
+		return;
+	}
+
+	ast_bridge_features_interval_hook(features, limits->duration, 0, bridge_features_duration_callback, NULL);
+
+	if (limits->warnings && limits->warnings < limits->duration && (limits->warning_prompts || !ast_strlen_zero(limits->warning_sound))) {
+		ast_bridge_features_interval_hook(features, limits->warnings, 1, bridge_features_warning_callback, limits);
+	}
+}
+
 int ast_bridge_features_set_flag(struct ast_bridge_features *features, enum ast_bridge_feature_flags flag)
 {
 	ast_set_flag(&features->feature_flags, flag);




More information about the asterisk-commits mailing list