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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 8 18:27:36 CDT 2009


Author: file
Date: Fri May  8 18:27:33 2009
New Revision: 193458

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=193458
Log:
Finish cleaning up the higher level warnings/limits API.

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=193458&r1=193457&r2=193458
==============================================================================
--- team/file/bridging-phase2/include/asterisk/bridging_features.h (original)
+++ team/file/bridging-phase2/include/asterisk/bridging_features.h Fri May  8 18:27:33 2009
@@ -20,7 +20,6 @@
  * \brief Channel Bridging API
  * \author Joshua Colp <jcolp at digium.com>
  *
- * \todo Add a higher level warnings/lifetime feature API
  * \todo Add ability to disable certain completion options of attended transfer
  */
 
@@ -138,12 +137,12 @@
 	/*! 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 warning;
+	/*! Interval between the warnings (specified in milliseconds or 0 to disable) */
 	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 */
+	/*! Sound file to play when the maximum duration is reached (if empty then nothing will be played) */
+	char duration_sound[256];
+	/*! Sound file to play when the warning time is reached (if empty then the remaining time will be played) */
 	char warning_sound[256];
 };
 
@@ -286,10 +285,8 @@
 /*! \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)
- *
+ * \param limits Configured limits applicable to the channel
+  *
  * Example usage:
  *
  * \code

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=193458&r1=193457&r2=193458
==============================================================================
--- team/file/bridging-phase2/main/bridging.c (original)
+++ team/file/bridging-phase2/main/bridging.c Fri May  8 18:27:33 2009
@@ -1527,55 +1527,75 @@
 
 static int bridge_features_duration_callback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 {
+	struct ast_bridge_features_limits *limits = hook_pvt;
+
+	if (!ast_strlen_zero(limits->duration_sound)) {
+		ast_streamfile(bridge_channel->chan, limits->duration_sound, bridge_channel->chan->language);
+	}
+
 	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)
+
+	return -1;
+}
+
+static int bridge_features_warning_sound_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_streamfile(bridge_channel->chan, limits->warning_sound, bridge_channel->chan->language);
+
+	if (limits->frequency) {
+		ast_bridge_features_interval_update(bridge_channel, limits->frequency);
+	}
+
 	ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);
 
-	return 0;
+	return !limits->frequency ? -1 : 0;
+}
+
+static int bridge_features_warning_time_left_callback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
+{
+	struct ast_bridge_features_limits *limits = hook_pvt;
+	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", "");
+		}
+	}
+
+	if (limits->frequency) {
+		ast_bridge_features_interval_update(bridge_channel, limits->frequency);
+	}
+
+	ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_WAIT);
+
+	return !limits->frequency ? -1 : 0;
 }
 
 void ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits)
@@ -1584,10 +1604,12 @@
 		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);
+	ast_bridge_features_interval_hook(features, limits->duration, 0, bridge_features_duration_callback, limits);
+
+	if (limits->warning && limits->warning < limits->duration) {
+		ast_bridge_features_interval_hook(features, limits->warning, 1,
+						  !ast_strlen_zero(limits->warning_sound) ? bridge_features_warning_sound_callback : bridge_features_warning_time_left_callback,
+						  limits);
 	}
 }
 




More information about the asterisk-commits mailing list