[svn-commits] dlee: branch dlee/ari-async-bridge r395885 - /team/dlee/ari-async-bridge/res/...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 31 11:12:59 CDT 2013


Author: dlee
Date: Wed Jul 31 11:12:57 2013
New Revision: 395885

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395885
Log:
Hangup works while in an async bridge

Modified:
    team/dlee/ari-async-bridge/res/stasis/control.c

Modified: team/dlee/ari-async-bridge/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/res/stasis/control.c?view=diff&rev=395885&r1=395884&r2=395885
==============================================================================
--- team/dlee/ari-async-bridge/res/stasis/control.c (original)
+++ team/dlee/ari-async-bridge/res/stasis/control.c Wed Jul 31 11:12:57 2013
@@ -33,6 +33,7 @@
 #include "control.h"
 #include "asterisk/dial.h"
 #include "asterisk/bridge.h"
+#include "asterisk/bridge_after.h"
 #include "asterisk/bridge_basic.h"
 #include "asterisk/bridge_features.h"
 #include "asterisk/frame.h"
@@ -101,11 +102,20 @@
 	return control;
 }
 
+static void *noop_cb(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	return NULL;
+}
+
+
 static struct stasis_app_command *exec_command(
 	struct stasis_app_control *control, stasis_app_command_cb command_fn,
 	void *data)
 {
 	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
+
+	command_fn = command_fn ? : noop_cb;
 
 	command = command_create(command_fn, data);
 
@@ -453,12 +463,56 @@
 	return control->bridge;
 }
 
+
+static void bridge_after_cb(struct ast_channel *chan, void *data)
+{
+	struct stasis_app_control *control = data;
+
+	ast_debug(3, "%s, %s: Channel leaving bridge\n",
+		ast_channel_uniqueid(chan), control->bridge->uniqueid);
+
+	ast_assert(chan == control->channel);
+
+	ast_channel_pbx_set(control->channel, control->pbx);
+	control->pbx = NULL;
+
+	control->bridge = NULL;
+}
+
+static void bridge_after_cb_failed(enum ast_bridge_after_cb_reason reason,
+	void *data)
+{
+	struct stasis_app_control *control = data;
+
+	bridge_after_cb(control->channel, data);
+
+	ast_debug(3, "  reason: %s\n",
+		ast_bridge_after_cb_reason_string(reason));
+
+	/* Wakeup the command_queue loop */
+	exec_command(control, NULL, NULL);
+}
+
 void stasis_app_add_to_bridge(struct stasis_app_control *control,
 	struct ast_bridge *bridge)
 {
 	int res;
 
 	if (!control || !bridge) {
+		return;
+	}
+
+	ast_assert(control->channel != NULL);
+
+	/* Depart whatever Stasis bridge we're currently in */
+	if (control->bridge) {
+		ast_bridge_depart(control->channel);
+	}
+
+	res = ast_bridge_set_after_callback(control->channel, bridge_after_cb,
+		bridge_after_cb_failed, control);
+	if (res != 0) {
+		ast_log(LOG_ERROR, "Error setting after-bridge callback\n");
 		return;
 	}
 
@@ -491,9 +545,9 @@
 		return;
 	}
 
+	ast_assert(control->channel != NULL);
+
 	ast_bridge_depart(control->channel);
-	ast_channel_pbx_set(control->channel, control->pbx);
-	control->pbx = NULL;
 }
 
 const char *stasis_app_control_get_channel_id(




More information about the svn-commits mailing list