[asterisk-commits] mmichelson: branch group/ari-greedy-atxfer r419683 - in /team/group/ari-greed...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 28 13:14:23 CDT 2014


Author: mmichelson
Date: Mon Jul 28 13:14:21 2014
New Revision: 419683

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419683
Log:
Commit the content of review 3857 to this branch.

The content of this changeset ensures that channels that
move from a Stasis bridge to a non-Stasis bridge are booted
from Stasis in the process. This means that after leaving
the Stasis bridge, a ChannelLeftBridge event is sent, followed
by a StasisEnd event. No futher events are issued for the
channel since the application is then unsubscribed from
that channel's events.


Modified:
    team/group/ari-greedy-atxfer/include/asterisk/bridge_channel.h
    team/group/ari-greedy-atxfer/res/stasis/stasis_bridge.c

Modified: team/group/ari-greedy-atxfer/include/asterisk/bridge_channel.h
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/include/asterisk/bridge_channel.h?view=diff&rev=419683&r1=419682&r2=419683
==============================================================================
--- team/group/ari-greedy-atxfer/include/asterisk/bridge_channel.h (original)
+++ team/group/ari-greedy-atxfer/include/asterisk/bridge_channel.h Mon Jul 28 13:14:21 2014
@@ -162,6 +162,8 @@
 		/*! Digit currently sending into the bridge. (zero if not sending) */
 		char dtmf_digit;
 	} owed;
+	/*! Callback to call if the bridge channel is being moved from one bridge to another. */
+	void (*bein_moved)(struct ast_bridge_channel *bridge_channel, struct ast_bridge *src, struct ast_bridge *dst);
 };
 
 /*!

Modified: team/group/ari-greedy-atxfer/res/stasis/stasis_bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/stasis/stasis_bridge.c?view=diff&rev=419683&r1=419682&r2=419683
==============================================================================
--- team/group/ari-greedy-atxfer/res/stasis/stasis_bridge.c (original)
+++ team/group/ari-greedy-atxfer/res/stasis/stasis_bridge.c Mon Jul 28 13:14:21 2014
@@ -34,6 +34,8 @@
 #include "asterisk/bridge.h"
 #include "asterisk/bridge_after.h"
 #include "asterisk/bridge_internal.h"
+#include "asterisk/stasis_app.h"
+#include "asterisk/stasis_channels.h"
 #include "stasis_bridge.h"
 #include "control.h"
 #include "command.h"
@@ -42,6 +44,8 @@
 #include "asterisk/pbx.h"
 
 /* ------------------------------------------------------------------- */
+
+static struct ast_bridge_methods bridge_stasis_v_table;
 
 static void bridge_stasis_run_cb(struct ast_channel *chan, void *data)
 {
@@ -138,6 +142,57 @@
 	return ast_bridge_base_v_table.push(self, bridge_channel, swap);
 }
 
+static void bridge_stasis_bein_moved(struct ast_bridge_channel *bridge_channel,
+		struct ast_bridge *src, struct ast_bridge *dst)
+{
+	if (src->v_table == &bridge_stasis_v_table &&
+			dst->v_table != &bridge_stasis_v_table) {
+		/* Send the stasis end here. Need the app name for that... */
+		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+		RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+		RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+		struct stasis_message_sanitizer *sanitize = stasis_app_get_sanitizer();
+		struct stasis_app *app;
+		struct ast_channel *chan;
+
+		chan = bridge_channel->chan;
+		ast_assert(chan != NULL);
+
+		control = stasis_app_control_find_by_channel(chan);
+		if (!control) {
+			return;
+		}
+		app = control_app(control);
+		if (!app) {
+			return;
+		}
+
+		/* Set channel info */
+		ast_channel_lock(chan);
+		snapshot = ast_channel_snapshot_create(chan);
+		ast_channel_unlock(chan);
+		if (snapshot == NULL) {
+			return;
+		}
+
+		if (sanitize && sanitize->channel_snapshot
+			&& sanitize->channel_snapshot(snapshot)) {
+			return;
+		}
+
+		msg = ast_json_pack("{s: s, s: o, s: o}",
+			"type", "StasisEnd",
+			"timestamp", ast_json_timeval(ast_tvnow(), NULL),
+			"channel", ast_channel_snapshot_to_json(snapshot, NULL));
+		if (!msg) {
+			return;
+		}
+
+		app_send(app, msg);
+		return;
+	}
+}
+
 /*!
  * \internal
  * \brief Pull this channel from the Stasis bridge.
@@ -157,10 +212,10 @@
 		ast_bridge_channel_update_accountcodes(NULL, bridge_channel);
 	}
 
+	bridge_channel->bein_moved = bridge_stasis_bein_moved;
+
 	ast_bridge_base_v_table.pull(self, bridge_channel);
 }
-
-static struct ast_bridge_methods bridge_stasis_v_table;
 
 struct ast_bridge *bridge_stasis_new(uint32_t capabilities, unsigned int flags, const char *name, const char *id)
 {




More information about the asterisk-commits mailing list