[svn-commits] jrose: branch jrose/bridge_projects r381279 - in /team/jrose/bridge_projects:...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 12 13:46:17 CST 2013


Author: jrose
Date: Tue Feb 12 13:46:13 2013
New Revision: 381279

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381279
Log:
bridge construction: Interval Hooks continue some more

The exciting conclusion to r381253 ---
Limit structures are now copied to and used from the bridge_channel
feature set for the channel they are set to. File names for the various
sounds played by the limits feature now use string fields and are no
longer limited to 256 characters. The interval strict flag is removed
from interval hooks, so all interval hooks are treated as strict now.
(strict means that hooks which execute repetitively will execute every
<frequency> instead of waiting <frequency> between executions).
Still to go: test events



Modified:
    team/jrose/bridge_projects/include/asterisk/bridging_features.h
    team/jrose/bridge_projects/main/bridging.c
    team/jrose/bridge_projects/main/features.c

Modified: team/jrose/bridge_projects/include/asterisk/bridging_features.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/include/asterisk/bridging_features.h?view=diff&rev=381279&r1=381278&r2=381279
==============================================================================
--- team/jrose/bridge_projects/include/asterisk/bridging_features.h (original)
+++ team/jrose/bridge_projects/include/asterisk/bridging_features.h Tue Feb 12 13:46:13 2013
@@ -148,8 +148,6 @@
 	AST_LIST_ENTRY(ast_bridge_features_hook) entry;
 	/*! Heap index for interval hooks */
 	ssize_t __heap_index;
-	/*! TRUE if we should take into account the time spent executing the callback when rescheduling the interval hook */
-	unsigned int interval_strict:1;
 };
 
 #define BRIDGE_FEATURES_INTERVAL_RATE 10
@@ -172,6 +170,8 @@
 	void *talker_pvt_data;
 	/*! Feature flags that are enabled */
 	struct ast_flags feature_flags;
+	/*! Limits feature data */
+	struct ast_bridge_features_limits *limits;
 	/*! Used to assign the sequence number to the next interval hook added. */
 	unsigned int interval_sequence;
 	/*! Bit to indicate that the feature_flags and hook list is setup */
@@ -216,12 +216,15 @@
 	unsigned int warning;
 	/*! Interval between the warnings (specified in milliseconds or 0 to disable) */
 	unsigned int frequency;
-	/*! 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];
-	/*! Sound file to play when the call is first entered (if empty, then the remaining time will be played) */
-	char connect_sound[256];
+
+	AST_DECLARE_STRING_FIELDS(
+		/*! Sound file to play when the maximum duration is reached (if empty, then nothing will be played) */
+		AST_STRING_FIELD(duration_sound);
+		/*! Sound file to play when the warning time is reached (if empty, then the remaining time will be played) */
+		AST_STRING_FIELD(warning_sound);
+		/*! Sound file to play when the call is first entered (if empty, then the remaining time will be played) */
+		AST_STRING_FIELD(connect_sound);
+	);
 	/*! Time when the bridge will be terminated by the limits feature */
 	struct timeval quitting_time;
 };
@@ -392,6 +395,9 @@
  * \param features Bridge features structure
  * \param limits Configured limits applicable to the channel
  *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
  * Example usage:
  *
  * \code
@@ -406,7 +412,7 @@
  * \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);
+int 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

Modified: team/jrose/bridge_projects/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/bridging.c?view=diff&rev=381279&r1=381278&r2=381279
==============================================================================
--- team/jrose/bridge_projects/main/bridging.c (original)
+++ team/jrose/bridge_projects/main/bridging.c Tue Feb 12 13:46:13 2013
@@ -50,6 +50,7 @@
 #include "asterisk/heap.h"
 #include "asterisk/say.h"
 #include "asterisk/timing.h"
+#include "asterisk/stringfields.h"
 #include "asterisk/musiconhold.h"
 
 static AST_RWLIST_HEAD_STATIC(bridge_technologies, ast_bridge_technology);
@@ -1086,9 +1087,7 @@
 
 		ast_debug(1, "Updating hook '%p' and adding it back to '%p'\n", hook, bridge_channel);
 
-		if (hook->interval_strict) {
-			execution_time = ast_tvdiff_ms(ast_tvnow(), start);
-		}
+		execution_time = ast_tvdiff_ms(ast_tvnow(), start);
 
 		/* resetting start */
 		start = ast_tvnow();
@@ -1964,7 +1963,6 @@
 	hook->callback = callback;
 	hook->destructor = destructor;
 	hook->hook_pvt = hook_pvt;
-	hook->interval_strict = strict ? 1 : 0;
 
 	ast_debug(1, "Putting interval hook '%p' in the interval hooks heap on features '%p'\n",
 		hook, features);
@@ -2037,7 +2035,7 @@
 	return -1;
 }
 
-static void limits_interval_playback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, char *file)
+static void limits_interval_playback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
 {
 	if (!strcasecmp(file, "timeleft")) {
 
@@ -2110,26 +2108,62 @@
 	return !limits->frequency ? -1 : 0;
 }
 
-void ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits)
-{
+static void copy_bridge_features_limits(struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
+{
+	dst->duration = src->duration;
+	dst->warning = src->warning;
+	dst->frequency = src->frequency;
+	dst->quitting_time = src->quitting_time;
+
+	ast_string_field_set(dst, duration_sound, src->duration_sound);
+	ast_string_field_set(dst, warning_sound, src->warning_sound);
+	ast_string_field_set(dst, connect_sound, src->connect_sound);
+}
+
+/* XXX This should probably be changed to include failure conditions so that the consumers can know if it failed. */
+int ast_bridge_features_set_limits(struct ast_bridge_features *features, struct ast_bridge_features_limits *limits)
+{
+	struct ast_bridge_features_limits *feature_limits;
+
 	if (!limits->duration) {
-		return;
-	}
-
-	ast_bridge_features_interval_hook(features, limits->duration, 0,
-		bridge_features_duration_callback, limits, NULL);
-
-	limits->quitting_time = ast_tvadd(ast_tvnow(), ast_samp2tv(limits->duration, 1000));
-
-	if (!ast_strlen_zero(limits->connect_sound)) {
-		ast_bridge_features_interval_hook(features, 1, 1, bridge_features_connect_callback, limits, NULL);
-	}
-
-	if (limits->warning && limits->warning < limits->duration) {
-		ast_bridge_features_interval_hook(features, limits->warning, 1,
+		return -1;
+	}
+
+	if (features->limits) {
+		ast_log(LOG_ERROR, "Tried to apply limits to a feature set that already has limits.\n");
+		return -1;
+	}
+
+	feature_limits = ast_malloc(sizeof(*feature_limits));
+
+	if (!feature_limits) {
+		return -1;
+	}
+
+	if (ast_string_field_init(feature_limits, 256)) {
+		ast_free(feature_limits);
+		return -1;
+	}
+
+	copy_bridge_features_limits(feature_limits, limits);
+	features->limits = feature_limits;
+
+	ast_bridge_features_interval_hook(features, feature_limits->duration, 0,
+		bridge_features_duration_callback, feature_limits, NULL);
+
+	feature_limits->quitting_time = ast_tvadd(ast_tvnow(), ast_samp2tv(feature_limits->duration, 1000));
+
+	if (!ast_strlen_zero(feature_limits->connect_sound)) {
+		ast_bridge_features_interval_hook(features, 1, 1, bridge_features_connect_callback, feature_limits, NULL);
+	}
+
+	if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
+		ast_bridge_features_interval_hook(features, feature_limits->warning, 1,
 			bridge_features_warning_callback,
-			limits, NULL);
-	}
+			feature_limits, NULL);
+	}
+
+	return 0;
 }
 
 void ast_bridge_features_set_flag(struct ast_bridge_features *features, enum ast_bridge_feature_flags flag)
@@ -2190,6 +2224,13 @@
 		features->interval_timer = NULL;
 	}
 
+	/* If the features contains a limits pvt, destroy that as well. */
+	if (features->limits) {
+		ast_string_field_free_memory(features->limits);
+		ast_free(features->limits);
+		features->limits = NULL;
+	}
+
 	/* Destroy each DTMF feature hook. */
 	while ((hook = AST_LIST_REMOVE_HEAD(&features->hooks, entry))) {
 		if (hook->destructor) {
@@ -2202,6 +2243,7 @@
 		features->talker_destructor_cb(features->talker_pvt_data);
 		features->talker_pvt_data = NULL;
 	}
+
 }
 
 struct ast_bridge_features *ast_bridge_features_new(void)

Modified: team/jrose/bridge_projects/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/features.c?view=diff&rev=381279&r1=381278&r2=381279
==============================================================================
--- team/jrose/bridge_projects/main/features.c (original)
+++ team/jrose/bridge_projects/main/features.c Tue Feb 12 13:46:13 2013
@@ -4368,17 +4368,17 @@
 static void bridge_config_set_limits_warning_values(struct ast_bridge_config *config, struct ast_bridge_features_limits *limits)
 {
 	if (config->end_sound) {
-		ast_copy_string(limits->duration_sound, config->end_sound, sizeof(limits->duration_sound));
+		ast_string_field_set(limits, duration_sound, config->end_sound);
 	}
 
 	if (config->warning_sound) {
-		ast_copy_string(limits->warning_sound, config->warning_sound, sizeof(limits->warning_sound));
+		ast_string_field_set(limits, warning_sound, config->warning_sound);
 	}
 
 	if (config->start_sound) {
-		ast_copy_string(limits->connect_sound, config->start_sound, sizeof(limits->connect_sound));
+		ast_string_field_set(limits, connect_sound, config->start_sound);
 	} else {
-		ast_copy_string(limits->connect_sound, "timeleft", sizeof(limits->connect_sound));
+		ast_string_field_set(limits, connect_sound, "timeleft");
 	}
 
 	limits->frequency = config->warning_freq;
@@ -4636,6 +4636,7 @@
 
 	/* Setup DTMF features. */
 	ast_bridge_features_init(&chan_features);
+
 	peer_features = ast_bridge_features_new();
 	if (!peer_features
 		|| setup_bridge_channel_features(peer_features, &config->features_callee)
@@ -4650,9 +4651,36 @@
 	}
 
 	if (config->timelimit) {
+		if (ast_string_field_init(&call_duration_limits_chan, 256)) {
+			ast_log(LOG_ERROR, "Could not allocate caller duration limits string field. Bridge canceled.\n");
+
+			ast_bridge_features_destroy(peer_features);
+			ast_bridge_features_cleanup(&chan_features);
+			if (bridge_cdr) {
+				ast_cdr_discard(bridge_cdr);
+			}
+			return -1;
+		}
+
+		if (ast_string_field_init(&call_duration_limits_peer, 256)) {
+			ast_log(LOG_ERROR, "Could not allocate callee duration limits string field. Bridge canceled.\n");
+			ast_string_field_free_memory(&call_duration_limits_chan);
+
+			ast_bridge_features_destroy(peer_features);
+			ast_bridge_features_cleanup(&chan_features);
+			if (bridge_cdr) {
+				ast_cdr_discard(bridge_cdr);
+			}
+			return -1;
+		}
+
 		bridge_config_set_limits(config, &call_duration_limits_chan, &call_duration_limits_peer);
 		ast_bridge_features_set_limits(&chan_features, &call_duration_limits_chan);
 		ast_bridge_features_set_limits(peer_features, &call_duration_limits_peer);
+
+		/* At this point we are done with the limits structs since they have been copied to the individual feature sets. */
+		ast_string_field_free_memory(&call_duration_limits_chan);
+		ast_string_field_free_memory(&call_duration_limits_peer);
 	}
 
 	ast_cel_report_event(chan, AST_CEL_BRIDGE_START, NULL, NULL, peer);/* BUGBUG expected to go away. */




More information about the svn-commits mailing list