[asterisk-commits] dlee: branch dlee/ASTERISK-21969 r396407 - in /team/dlee/ASTERISK-21969: main...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 8 13:20:49 CDT 2013


Author: dlee
Date: Thu Aug  8 13:20:48 2013
New Revision: 396407

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396407
Log:
org

Modified:
    team/dlee/ASTERISK-21969/main/stasis_bridges.c
    team/dlee/ASTERISK-21969/res/stasis/app.c

Modified: team/dlee/ASTERISK-21969/main/stasis_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21969/main/stasis_bridges.c?view=diff&rev=396407&r1=396406&r2=396407
==============================================================================
--- team/dlee/ASTERISK-21969/main/stasis_bridges.c (original)
+++ team/dlee/ASTERISK-21969/main/stasis_bridges.c Thu Aug  8 13:20:48 2013
@@ -134,6 +134,7 @@
 static struct ast_manager_event_blob *blind_transfer_to_ami(struct stasis_message *message);
 static struct ast_json *ast_channel_entered_bridge_to_json(struct stasis_message *msg);
 static struct ast_json *ast_channel_left_bridge_to_json(struct stasis_message *msg);
+static struct ast_json *ast_bridge_merge_message_to_json(struct stasis_message *msg);
 
 static struct stasis_cp_all *bridge_cache_all;
 
@@ -141,7 +142,8 @@
  * @{ \brief Define bridge message types.
  */
 STASIS_MESSAGE_TYPE_DEFN(ast_bridge_snapshot_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_bridge_merge_message_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_bridge_merge_message_type,
+	.to_json = ast_bridge_merge_message_to_json);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_entered_bridge_type,
 	.to_json = ast_channel_entered_bridge_to_json);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_left_bridge_type,
@@ -309,6 +311,19 @@
 
 	ao2_ref(msg, +1);
 	return msg;
+}
+
+static struct ast_json *ast_bridge_merge_message_to_json(struct stasis_message *msg)
+{
+	struct ast_bridge_merge_message *merge;
+
+	merge = stasis_message_data(msg);
+
+        return ast_json_pack("{s: s, s: o, s: o, s: o}",
+                "type", "BridgeMerged",
+                "timestamp", ast_json_timeval(*stasis_message_timestamp(msg), NULL),
+                "bridge", ast_bridge_snapshot_to_json(merge->to),
+                "bridge_from", ast_bridge_snapshot_to_json(merge->from));
 }
 
 void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from)

Modified: team/dlee/ASTERISK-21969/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21969/res/stasis/app.c?view=diff&rev=396407&r1=396406&r2=396407
==============================================================================
--- team/dlee/ASTERISK-21969/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-21969/res/stasis/app.c Thu Aug  8 13:20:48 2013
@@ -39,6 +39,8 @@
 	struct stasis_topic *topic;
 	/*! Router for handling messages forwarded to \a topic. */
 	struct stasis_message_router *router;
+	/*! Subscription to watch for bridge merge messages */
+	struct stasis_subscription *bridge_merge_sub;
 	/*! Container of the channel forwards to this app's topic. */
 	struct ao2_container *forwards;
 	/*! Callback function for this application. */
@@ -268,6 +270,35 @@
         app_send(app, json);
 }
 
+static void bridge_merge_handler(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct app *app = data;
+	struct ast_bridge_merge_message *merge;
+	RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
+
+	if (stasis_message_type(message) != ast_bridge_merge_message_type()) {
+		return;
+	}
+
+	merge = stasis_message_data(message);
+
+	/* Find out if we're subscribed to either bridge */
+	forwards = ao2_find(app->forwards, merge->from->uniqueid,
+		OBJ_SEARCH_KEY);
+	if (!forwards) {
+		forwards = ao2_find(app->forwards, merge->to->uniqueid,
+			OBJ_SEARCH_KEY);
+	}
+
+	if (!forwards) {
+		return;
+	}
+
+	/* Forward the message to the app */
+	stasis_forward_message(app->topic, topic, message);
+}
+
 struct app *app_create(const char *name, stasis_app_cb handler, void *data)
 {
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
@@ -295,6 +326,12 @@
 		return NULL;
 	}
 
+	app->bridge_merge_sub = stasis_subscribe(ast_bridge_topic_all(),
+		bridge_merge_handler, app);
+	if (!app->bridge_merge_sub) {
+		return NULL;
+	}
+
 	app->router = stasis_message_router_create(app->topic);
 	if (!app->router) {
 		return NULL;
@@ -303,11 +340,6 @@
         res |= stasis_message_router_add_cache_update(app->router,
 		ast_bridge_snapshot_type(), sub_bridge_update_handler, app);
 
-	/*
-        res |= stasis_message_router_add(app->router,
-		ast_bridge_merge_message_type(), sub_bridge_merge_handler,
-		app);
-	*/
 	res |= stasis_message_router_set_default(app->router,
 		sub_default_handler, app);
 




More information about the asterisk-commits mailing list