[asterisk-commits] irroot: branch irroot/distrotech-customers-trunk r345021 - in /team/irroot/di...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Nov 13 02:57:02 CST 2011


Author: irroot
Date: Sun Nov 13 02:56:58 2011
New Revision: 345021

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=345021
Log:
Change pickup macro to use datastore adding a bridge callback to datastore

Modified:
    team/irroot/distrotech-customers-trunk/include/asterisk/datastore.h
    team/irroot/distrotech-customers-trunk/main/channel.c
    team/irroot/distrotech-customers-trunk/main/features.c
    team/irroot/distrotech-customers-trunk/main/global_datastores.c

Modified: team/irroot/distrotech-customers-trunk/include/asterisk/datastore.h
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/include/asterisk/datastore.h?view=diff&rev=345021&r1=345020&r2=345021
==============================================================================
--- team/irroot/distrotech-customers-trunk/include/asterisk/datastore.h (original)
+++ team/irroot/distrotech-customers-trunk/include/asterisk/datastore.h Sun Nov 13 02:56:58 2011
@@ -48,6 +48,17 @@
 	 * \return nothing.
 	 */
 	void (*chan_fixup)(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan);
+
+	/*!
+	 * \brief Callback to operate on bridge channel before entring bridge loop
+	 *
+	 * \arg data The datastore data
+	 * \arg chan channel owning the datastore (locked and running autoservice)
+	 * \arg bridge channel
+	 *
+	 * \return nothing.
+	 */
+	void (*bridge_fixup)(void *data, struct ast_channel *chan, struct ast_channel *bridge);
 };
 
 /*! \brief Structure for a data store object */

Modified: team/irroot/distrotech-customers-trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/main/channel.c?view=diff&rev=345021&r1=345020&r2=345021
==============================================================================
--- team/irroot/distrotech-customers-trunk/main/channel.c (original)
+++ team/irroot/distrotech-customers-trunk/main/channel.c Sun Nov 13 02:56:58 2011
@@ -7444,9 +7444,6 @@
 	long time_left_ms=0;
 	char caller_warning = 0;
 	char callee_warning = 0;
-	const char *bridge_macro;
-	const char *bridge_macro_args;
-	struct ast_datastore *ds_bridge_macro;
 
 	*fo = NULL;
 
@@ -7526,31 +7523,6 @@
 	/* Before we enter in and bridge these two together tell them both the source of audio has changed */
 	ast_indicate(c0, AST_CONTROL_SRCUPDATE);
 	ast_indicate(c1, AST_CONTROL_SRCUPDATE);
-
-	if ((ds_bridge_macro = ast_channel_datastore_find(c0, &pickup_target_info, NULL))) {
-		bridge_macro = pbx_builtin_getvar_helper(c0, "PICKUP_BRIDGE_MACRO");
-		if (!ast_strlen_zero(bridge_macro)) {
-			bridge_macro_args = pbx_builtin_getvar_helper(c0, "PICKUP_BRIDGE_MACRO_ARGS");
-			ast_app_run_macro(c0, c1, bridge_macro, bridge_macro_args);
-		}
-		ast_channel_lock(c0);
-		if (!ast_channel_datastore_remove(c0, ds_bridge_macro)) {
-			ast_datastore_free(ds_bridge_macro);
-		}
-		ast_channel_unlock(c0);
-	}
-	if ((ds_bridge_macro = ast_channel_datastore_find(c1, &pickup_target_info, NULL))) {
-		bridge_macro = pbx_builtin_getvar_helper(c1, "PICKUP_BRIDGE_MACRO");
-		if (!ast_strlen_zero(bridge_macro)) {
-			bridge_macro_args = pbx_builtin_getvar_helper(c1, "PICKUP_BRIDGE_MACRO_ARGS");
-			ast_app_run_macro(c1, c0, bridge_macro, bridge_macro_args);
-		}
-		ast_channel_lock(c1);
-		if (!ast_channel_datastore_remove(c1, ds_bridge_macro)) {
-			ast_datastore_free(ds_bridge_macro);
-		}
-		ast_channel_unlock(c1);
-	}
 
 	for (/* ever */;;) {
 		struct timeval now = { 0, };

Modified: team/irroot/distrotech-customers-trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/main/features.c?view=diff&rev=345021&r1=345020&r2=345021
==============================================================================
--- team/irroot/distrotech-customers-trunk/main/features.c (original)
+++ team/irroot/distrotech-customers-trunk/main/features.c Sun Nov 13 02:56:58 2011
@@ -3856,6 +3856,7 @@
 	struct ast_cdr *new_peer_cdr = NULL; /* the proper chan cdr, if there are forked cdrs */
 	struct ast_silence_generator *silgen = NULL;
 	const char *h_context;
+	struct ast_datastore *ds;
 
 	if (chan && peer) {
 		pbx_builtin_setvar_helper(chan, "BRIDGEPEER", peer->name);
@@ -4012,6 +4013,29 @@
 	 * don't, well, what can we do about that? */
 	clear_dialed_interfaces(chan);
 	clear_dialed_interfaces(peer);
+
+	/*put channel in autoservice and lock while we run any bridging callbacks*/
+	ast_autoservice_start(chan);
+	ast_channel_lock(chan);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->datastores, ds, entry) {
+		if (ds->info->bridge_fixup) {
+			ds->info->bridge_fixup(ds->data, chan, peer);
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	ast_channel_unlock(chan);
+	ast_autoservice_stop(chan);
+
+	ast_autoservice_start(peer);
+	ast_channel_lock(peer);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&peer->datastores, ds, entry) {
+		if (ds->info->bridge_fixup) {
+			ds->info->bridge_fixup(ds->data, peer, chan);
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	ast_channel_unlock(peer);
+	ast_autoservice_stop(peer);
 
 	for (;;) {
 		struct ast_channel *other;	/* used later */
@@ -7194,6 +7218,23 @@
 	return res;
 }
 
+static void ast_pickup_bridge_fixup(void *data, struct ast_channel *chan, struct ast_channel *bridge)
+{
+	const char *bridge_macro;
+	const char *bridge_macro_args;
+
+	if ((bridge_macro = pbx_builtin_getvar_helper(chan, "PICKUP_BRIDGE_MACRO")) &&
+	    !ast_strlen_zero(bridge_macro)) {
+		bridge_macro_args = pbx_builtin_getvar_helper(chan, "PICKUP_BRIDGE_MACRO_ARGS");
+		ast_app_run_macro(NULL, bridge, bridge_macro, bridge_macro_args);
+	}
+}
+
+const struct ast_datastore_info pickup_target_info = {
+	.type = "pickup-call",
+	.bridge_fixup = ast_pickup_bridge_fixup,
+};
+
 int ast_do_pickup(struct ast_channel *chan, struct ast_channel *target)
 {
 	struct ast_party_connected_line connected_caller;
@@ -7216,10 +7257,11 @@
 	}
 	ast_channel_datastore_add(target, ds_pickup);
 
-	/* Mark the target so a macro can be run on it if needed. */
-	ds_bridge_macro = ast_datastore_alloc(&pickup_target_info, NULL);
-	if (ds_bridge_macro) {
-		ast_channel_datastore_add(target, ds_bridge_macro);
+	/* Mark the channel so a macro can be run when about to be bridged
+	 * the datastore is left so a pickup can be detected.
+	 */
+	if ((ds_bridge_macro = ast_datastore_alloc(&pickup_target_info, NULL))) {
+		ast_channel_datastore_add(chan, ds_bridge_macro);
 	} else {
 		ast_log(LOG_WARNING,
 			"Unable to create channel datastore on '%s' for running macro\n", target_name);
@@ -7278,7 +7320,7 @@
 	if (!ast_channel_datastore_remove(target, ds_pickup)) {
 		ast_datastore_free(ds_pickup);
 	}
-	if (res && ds_bridge_macro && !ast_channel_datastore_remove(target, ds_bridge_macro)) {
+	if (res && ds_bridge_macro && !ast_channel_datastore_remove(chan, ds_bridge_macro)) {
 		ast_datastore_free(ds_bridge_macro);
 	}
 

Modified: team/irroot/distrotech-customers-trunk/main/global_datastores.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-trunk/main/global_datastores.c?view=diff&rev=345021&r1=345020&r2=345021
==============================================================================
--- team/irroot/distrotech-customers-trunk/main/global_datastores.c (original)
+++ team/irroot/distrotech-customers-trunk/main/global_datastores.c Sun Nov 13 02:56:58 2011
@@ -110,7 +110,3 @@
 	.destroy = secure_call_store_destroy,
 	.duplicate = secure_call_store_duplicate,
 };
-
-const struct ast_datastore_info pickup_target_info = {
-	.type = "pickup-call",
-};




More information about the asterisk-commits mailing list