[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r385817 - in /team/kmoore/stasis-b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 15 15:08:50 CDT 2013


Author: kmoore
Date: Mon Apr 15 15:08:46 2013
New Revision: 385817

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385817
Log:
Rebase changes on top of the merge debris

Modified:
    team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
    team/kmoore/stasis-bridge_events/main/stasis_bridging.c
    team/kmoore/stasis-bridge_events/res/res_stasis.c

Modified: team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h?view=diff&rev=385817&r1=385816&r2=385817
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h Mon Apr 15 15:08:46 2013
@@ -203,6 +203,13 @@
 void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan);
 
 /*!
+ * \brief Build a JSON object from a \ref ast_bridge_snapshot.
+ * \return JSON object representing bridge snapshot.
+ * \return \c NULL on error
+ */
+struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot);
+
+/*!
  * \brief Dispose of the stasis bridging topics and message types
  */
 void ast_stasis_bridging_shutdown(void);

Modified: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/stasis_bridging.c?view=diff&rev=385817&r1=385816&r2=385817
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/stasis_bridging.c Mon Apr 15 15:08:46 2013
@@ -311,6 +311,26 @@
 	}
 
 	stasis_publish(ast_bridge_topic(bridge), msg);
+}
+
+struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot)
+{
+	RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
+	int r = 0;
+
+	if (snapshot == NULL) {
+		return NULL;
+	}
+
+	json_chan = ast_json_object_create();
+	if (!json_chan) { ast_log(LOG_ERROR, "Error creating channel json object\n"); return NULL; }
+
+	r = ast_json_object_set(json_chan, "bridge-uniqueid", ast_json_string_create(snapshot->uniqueid));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "bridge-technology", ast_json_string_create(snapshot->technology));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+
+	return ast_json_ref(json_chan);
 }
 
 void ast_stasis_bridging_shutdown(void)

Modified: team/kmoore/stasis-bridge_events/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/res/res_stasis.c?view=diff&rev=385817&r1=385816&r2=385817
==============================================================================
--- team/kmoore/stasis-bridge_events/res/res_stasis.c (original)
+++ team/kmoore/stasis-bridge_events/res/res_stasis.c Mon Apr 15 15:08:46 2013
@@ -41,6 +41,7 @@
 #include "asterisk/strings.h"
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/callerid.h"
+#include "asterisk/stasis_bridging.h"
 
 /*!
  * \brief Number of buckets for the Stasis application hash table.  Remember to
@@ -66,6 +67,9 @@
  */
 #define BLOB_HANDLER_BUCKETS 7
 
+/*! \brief Number of buckets for the global bridges container */
+#define APP_BRIDGES_BUCKETS 57
+
 /*!
  * \brief Stasis application container. Please call apps_registry() instead of
  * directly accessing.
@@ -79,6 +83,10 @@
 
 /*! \brief Message router for the channel caching topic */
 struct stasis_message_router *app_channel_router;
+
+struct stasis_message_router *app_bridge_router;
+
+struct ao2_container *app_bridges;
 
 /*! Ref-counting accessor for the stasis applications container */
 static struct ao2_container *apps_registry(void)
@@ -167,25 +175,147 @@
 	}
 }
 
+struct bridge_info {
+	/*! List of channel identifiers that stasis apps are interested in for this bridge */
+	struct ao2_container *channels;
+	/*! uniqueid of the bridge */
+	char uniqueid[];
+};
+
+/*! AO2 destructor for \ref bridge_info */
+static void bridge_info_dtor(void *obj)
+{
+	struct bridge_info *info = obj;
+
+	ao2_cleanup(info->channels);
+	info->channels = NULL;
+}
+
+/*! AO2 hash function for \ref bridge_info */
+static int bridge_info_hash(const void *obj, const int flags)
+{
+	const struct bridge_info *info = obj;
+	const char *uniqueid = flags & OBJ_KEY ? obj : info->uniqueid;
+
+	return ast_str_hash(uniqueid);
+}
+
+/*! AO2 comparison function for \ref bridge_info */
+static int bridge_info_cmp(void *lhs, void *rhs, int flags)
+{
+	const struct bridge_info *lhs_info = lhs;
+	const struct bridge_info *rhs_info = rhs;
+	const char *rhs_uniqueid = flags & OBJ_KEY ? rhs : rhs_info->uniqueid;
+
+	if (strcmp(lhs_info->uniqueid, rhs_uniqueid) == 0) {
+		return CMP_MATCH;
+	} else {
+		return 0;
+	}
+}
+
+static int check_bridge_snapshot_cb(void *obj, void *arg, int flags)
+{
+	struct ast_bridge_snapshot *snapshot = stasis_message_data(obj);
+	char *chan_uniqueid = arg;
+	RAII_VAR(struct bridge_info *, info, NULL, ao2_cleanup);
+	RAII_VAR(char *, channel_in_snapshot, NULL, ao2_cleanup);
+	RAII_VAR(char *, channel_in_info, NULL, ao2_cleanup);
+
+	channel_in_snapshot = ao2_find(snapshot->channels, chan_uniqueid, OBJ_KEY);
+	if (!channel_in_snapshot) {
+		return 0;
+	}
+
+	info = ao2_find(app_bridges, snapshot->uniqueid, OBJ_KEY);
+	if (!info) {
+		/* bridge not yet in list of bridges of interest */
+		info = ao2_alloc(sizeof(*info) + strlen(snapshot->uniqueid) + 1, bridge_info_dtor);
+		if (!info) {
+			return CMP_STOP;
+		}
+		ao2_link(app_bridges, info);
+	}
+
+	channel_in_info = ao2_find(info->channels, chan_uniqueid, OBJ_KEY);
+	if (channel_in_info) {
+		return CMP_STOP;
+	}
+
+	/* since there is already an ao2 copy of the channel uniqueid
+	 * available, just link that in */
+	ao2_link(info->channels, channel_in_snapshot);
+
+	/* Assumes a given channel will only be in one bridge */
+	return CMP_STOP;
+}
+
+/*!
+ * Handles adding and updating bridge_info structs upon interest
+ * in a channel from app_stasis */
+static void add_bridge_for_chan(char *uniqueid)
+{
+	RAII_VAR(struct ao2_container *, bridge_states, NULL, ao2_cleanup);
+
+	bridge_states = stasis_cache_dump(ast_bridge_topic_all_cached(),
+		ast_bridge_snapshot_type());
+
+	if (!bridge_states) {
+		return;
+	}
+
+	ao2_callback(bridge_states, OBJ_NODATA, check_bridge_snapshot_cb, uniqueid);
+}
+
 static int app_add_channel(struct app* app, const struct ast_channel *chan)
 {
-	const char *uniqueid;
+	char *uniqueid;
 	ast_assert(chan != NULL);
 	ast_assert(app != NULL);
 
-	uniqueid = ast_channel_uniqueid(chan);
-	if (!ast_str_container_add(app->channels, uniqueid)) {
+	uniqueid = ast_strdupa(ast_channel_uniqueid(chan));
+	if (ast_str_container_add(app->channels, uniqueid)) {
 		return -1;
 	}
+
+	add_bridge_for_chan(uniqueid);
 	return 0;
 }
 
+static int check_bridge_info_removal_cb(void *obj, void *arg, int flags)
+{
+	struct bridge_info *info = obj;
+	char *chan_uniqueid = arg;
+	RAII_VAR(char *, chan_in_info, NULL, ao2_cleanup);
+
+	chan_in_info = ao2_find(info->channels, chan_uniqueid, OBJ_KEY | OBJ_UNLINK);
+	if (!chan_in_info) {
+		return 0;
+	}
+
+	if (ao2_container_count(info->channels)) {
+		return CMP_STOP;
+	}
+	/* no channels left in this bridge_info to be interested in,
+	 * so have it removed from the container */
+	return CMP_MATCH | CMP_STOP;
+}
+
+static void remove_bridge_for_chan(char *uniqueid)
+{
+	ao2_callback(app_bridges, OBJ_NODATA | OBJ_UNLINK, check_bridge_info_removal_cb, uniqueid);
+}
+
 static void app_remove_channel(struct app* app, const struct ast_channel *chan)
 {
+	char *uniqueid;
 	ast_assert(chan != NULL);
 	ast_assert(app != NULL);
 
-	ao2_find(app->channels, ast_channel_uniqueid(chan), OBJ_KEY | OBJ_NODATA | OBJ_UNLINK);
+	uniqueid = ast_strdupa(ast_channel_uniqueid(chan));
+	ao2_find(app->channels, uniqueid, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK);
+
+	remove_bridge_for_chan(uniqueid);
 }
 
 /*!
@@ -301,7 +431,7 @@
 	handler->type = NULL;
 }
 
-static struct ast_json *app_event_create(
+static struct ast_json *app_channel_event_create(
 	const char *event_name,
 	const struct ast_channel_snapshot *snapshot,
 	const struct ast_json *extra_info)
@@ -390,7 +520,7 @@
 	if (snapshot == NULL) {
 		return -1;
 	}
-	msg = app_event_create("stasis-end", snapshot, NULL);
+	msg = app_channel_event_create("stasis-end", snapshot, NULL);
 	if (!msg) {
 		return -1;
 	}
@@ -403,21 +533,24 @@
 {
 	RAII_VAR(char *, uniqueid, NULL, ao2_cleanup);
 	struct app *app = obj;
-	struct ast_channel_snapshot *snapshot = arg;
-
-	uniqueid = ao2_find(app->channels, snapshot->uniqueid, OBJ_KEY);
+	char *chan_uniqueid = arg;
+
+	uniqueid = ao2_find(app->channels, chan_uniqueid, OBJ_KEY);
 	return uniqueid ? CMP_MATCH : 0;
 }
 
-static struct ao2_container *get_watching_apps(struct ast_channel_snapshot *snapshot)
+static struct ao2_container *get_watching_apps(const char *uniqueid)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
 	struct ao2_container *watching_apps;
+	char *uniqueid_dup;
 	RAII_VAR(struct ao2_iterator *,watching_apps_iter, NULL, ao2_iterator_destroy);
-	ast_assert(snapshot != NULL);
+	ast_assert(uniqueid != NULL);
 	ast_assert(apps != NULL);
 
-	watching_apps_iter = ao2_callback(apps, OBJ_MULTIPLE, app_watching_channel_cb, snapshot);
+	uniqueid_dup = ast_strdupa(uniqueid);
+
+	watching_apps_iter = ao2_callback(apps, OBJ_MULTIPLE, app_watching_channel_cb, uniqueid_dup);
 	watching_apps = watching_apps_iter->c;
 
 	if (!ao2_container_count(watching_apps)) {
@@ -429,7 +562,7 @@
 }
 
 /*! \brief Typedef for callbacks that get called on channel snapshot updates */
-typedef struct ast_json *(*snapshot_monitor)(
+typedef struct ast_json *(*channel_snapshot_monitor)(
 	struct ast_channel_snapshot *old_snapshot,
 	struct ast_channel_snapshot *new_snapshot);
 
@@ -459,7 +592,7 @@
 		return NULL;
 	}
 
-	return app_event_create(event_name, new_snapshot ? new_snapshot : old_snapshot, json);
+	return app_channel_event_create(event_name, new_snapshot ? new_snapshot : old_snapshot, json);
 }
 
 /*!
@@ -517,7 +650,7 @@
 		return NULL;
 	}
 
-	return app_event_create("channel-event-dialplan", new_snapshot, json);
+	return app_channel_event_create("channel-event-dialplan", new_snapshot, json);
 }
 
 /*!
@@ -559,7 +692,7 @@
 		return NULL;
 	}
 
-	return app_event_create("channel-event-callerid", new_snapshot, json);
+	return app_channel_event_create("channel-event-callerid", new_snapshot, json);
 }
 
 static struct ast_json *channel_snapshot(
@@ -570,10 +703,10 @@
 		return NULL;
 	}
 
-	return app_event_create("channel-snapshot", new_snapshot, NULL);
-}
-
-snapshot_monitor monitors[] = {
+	return app_channel_event_create("channel-snapshot", new_snapshot, NULL);
+}
+
+channel_snapshot_monitor channel_monitors[] = {
 	channel_snapshot,
 	channel_state,
 	channel_dialplan,
@@ -600,15 +733,15 @@
 	struct ast_channel_snapshot *old_snapshot = stasis_message_data(update->old_snapshot);
 	int i;
 
-	watching_apps = get_watching_apps(new_snapshot ? new_snapshot : old_snapshot);
+	watching_apps = get_watching_apps(new_snapshot ? new_snapshot->uniqueid : old_snapshot->uniqueid);
 	if (!watching_apps) {
 		return;
 	}
 
-	for (i = 0; i < ARRAY_LEN(monitors); ++i) {
+	for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
 		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 
-		msg = monitors[i](old_snapshot, new_snapshot);
+		msg = channel_monitors[i](old_snapshot, new_snapshot);
 		if (msg) {
 			ao2_callback(watching_apps, OBJ_NODATA, app_send_cb, msg);
 		}
@@ -646,7 +779,7 @@
 		return;
 	}
 
-	watching_apps = get_watching_apps(obj->snapshot);
+	watching_apps = get_watching_apps(obj->snapshot->uniqueid);
 	if (!watching_apps) {
 		return;
 	}
@@ -657,6 +790,257 @@
 	}
 
 	distribute_message(watching_apps, msg);
+}
+
+static int find_diff(void *uniqueid, void *arg, int flags)
+{
+	struct ao2_container *secondary = arg;
+	RAII_VAR(char *, ao2_uniqueid, NULL, ao2_cleanup);
+
+	ao2_uniqueid = ao2_find(secondary, uniqueid, OBJ_KEY);
+	if (!ao2_uniqueid) {
+		return CMP_MATCH | CMP_STOP;
+	}
+
+	return 0;
+}
+static struct bridge_info *bridge_info_create_or_update(char *bridge_uniqueid, char *entering_chan)
+{
+	RAII_VAR(struct ao2_container *, entering_apps, NULL, ao2_cleanup);
+	struct bridge_info *info = ao2_find(app_bridges, bridge_uniqueid, OBJ_KEY);
+	RAII_VAR(char *, channel_in_info, NULL, ao2_cleanup);
+
+	if (!entering_chan) {
+		return info;
+	}
+
+	entering_apps = get_watching_apps(entering_chan);
+	if (!entering_apps || ao2_container_count(entering_apps)) {
+		return info;
+	}
+
+	if (!info) {
+		/* bridge not yet in list of bridges of interest */
+		info = ao2_alloc(sizeof(*info) + strlen(bridge_uniqueid) + 1, bridge_info_dtor);
+		if (!info) {
+			return NULL;
+		}
+		ao2_link(app_bridges, info);
+	}
+
+	channel_in_info = ao2_find(info->channels, entering_chan, OBJ_KEY);
+	if (!channel_in_info) {
+		/* since there is already an ao2 copy of the channel uniqueid
+		 * available, just link that in */
+		ao2_link(info->channels, entering_chan);
+	}
+
+	return info;
+}
+
+static int chan_list_intersect_cb(void *obj, void *arg, int flags)
+{
+	struct ao2_container *bridge_channels = arg;
+	RAII_VAR(char *, bridge_chan, ao2_find(bridge_channels, obj, OBJ_KEY), ao2_cleanup);
+
+	if (bridge_chan) {
+		return CMP_MATCH;
+	}
+	return 0;
+}
+
+static int check_app_intersect_cb(void *obj, void *arg, int flags)
+{
+	struct app *app = obj;
+	struct ao2_container *bridge_channels = arg;
+	RAII_VAR(char *, match, NULL, ao2_cleanup);
+
+	match = ao2_callback(app->channels, 0, chan_list_intersect_cb, bridge_channels);
+	/* if intersection, match app */
+	if (match) {
+		return CMP_MATCH;
+	}
+
+	return 0;
+}
+
+/* find all apps where the intersection of the app channels of interest
+ * set and the bridge stasis channels set results in a non-empty set */
+static struct ao2_container *get_bridge_watching_apps(struct bridge_info *info)
+{
+	RAII_VAR(struct ao2_container *, out, NULL, ao2_cleanup);
+	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
+	RAII_VAR(struct ao2_iterator *,callback_iter, NULL, ao2_iterator_destroy);
+
+	callback_iter = ao2_callback(apps, OBJ_MULTIPLE, check_app_intersect_cb, info->channels);
+	out = callback_iter->c;
+
+	if (!ao2_container_count(out)) {
+		return NULL;
+	}
+
+	ao2_ref(out, +1);
+	return out;
+}
+
+static struct ast_json *app_bridge_event_create(
+	const char *event_name,
+	const struct ast_bridge_snapshot *snapshot,
+	const struct ast_json *extra_info)
+{
+	RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, event, NULL, ast_json_unref);
+
+	if (extra_info) {
+		event = ast_json_deep_copy(extra_info);
+	} else {
+		event = ast_json_object_create();
+	}
+
+	if (snapshot) {
+		int ret;
+
+		/* Mustn't already have a bridge field */
+		ast_assert(ast_json_object_get(event, "bridge") == NULL);
+
+		ret = ast_json_object_set(
+			event,
+			"bridge", ast_bridge_snapshot_to_json(snapshot));
+		if (ret != 0) {
+			return NULL;
+		}
+	}
+
+	message = ast_json_pack("{s: o}", event_name, ast_json_ref(event));
+
+	return ast_json_ref(message);
+}
+
+/*! \brief Typedef for callbacks that get called on channel snapshot updates */
+typedef struct ast_json *(*bridge_snapshot_monitor)(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot);
+
+static struct ast_json *bridge_snapshot(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot)
+{
+	if (!new_snapshot) {
+		return NULL;
+	}
+
+	return app_bridge_event_create("bridge-snapshot", new_snapshot, NULL);
+}
+
+/*! \brief Handle bridge creation */
+static struct ast_json *bridge_create(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot)
+{
+	if (!new_snapshot || old_snapshot) {
+		return NULL;
+	}
+
+	return app_bridge_event_create("bridge-event-create", new_snapshot, NULL);
+}
+
+/*! \brief Handle bridge destruction */
+static struct ast_json *bridge_destroy(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot)
+{
+	if (new_snapshot || !old_snapshot) {
+		return NULL;
+	}
+
+	return app_bridge_event_create("bridge-event-destroy", old_snapshot, NULL);
+}
+
+/*! \brief Handle channels entering and leaving */
+static struct ast_json *bridge_channel_diff(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot)
+{
+	RAII_VAR(char *, new_diff, NULL, ao2_cleanup);
+	RAII_VAR(char *, old_diff, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, uniqueid_json, NULL, ast_json_unref);
+	char *event;
+
+	if (!new_snapshot || !old_snapshot
+		|| ao2_container_count(new_snapshot->channels)
+			== ao2_container_count(old_snapshot->channels)) {
+		return NULL;
+	}
+
+	/* get the diff channel for new and old snapshot */
+	new_diff = ao2_callback(new_snapshot->channels, OBJ_NODATA, find_diff, old_snapshot->channels);
+	old_diff = ao2_callback(old_snapshot->channels, OBJ_NODATA, find_diff, new_snapshot->channels);
+	if (new_diff) {
+		event = "bridge-event-enter";
+		uniqueid_json = ast_json_pack("s: s", "uniqueid", new_diff);
+	} else if (old_diff) {
+		event = "bridge-event-leave";
+		uniqueid_json = ast_json_pack("s: s", "uniqueid", old_diff);
+	} else {
+		return NULL;
+	}
+
+	return app_bridge_event_create(event, old_snapshot, uniqueid_json);
+}
+
+bridge_snapshot_monitor bridge_monitors[] = {
+	bridge_snapshot,
+	bridge_create,
+	bridge_destroy,
+	bridge_channel_diff,
+};
+
+static void sub_bridge_handler(void *data,
+		struct stasis_subscription *sub,
+		struct stasis_topic *topic,
+		struct stasis_message *message)
+{
+	RAII_VAR(struct ao2_container *, watching_apps, NULL, ao2_cleanup);
+	struct stasis_cache_update *update = stasis_message_data(message);
+	struct ast_bridge_snapshot *new_snapshot = stasis_message_data(update->new_snapshot);
+	struct ast_bridge_snapshot *old_snapshot = stasis_message_data(update->old_snapshot);
+	RAII_VAR(char *, entering_chan, NULL, ao2_cleanup);
+	RAII_VAR(char *, leaving_chan, NULL, ao2_cleanup);
+	RAII_VAR(struct bridge_info *, info, NULL, ao2_cleanup);
+	char *bridge_uniqueid = ast_strdupa(new_snapshot ? new_snapshot->uniqueid : old_snapshot->uniqueid);
+	int i;
+
+	/* update bridge_info for added channels if there is interest */ 
+	if (new_snapshot && old_snapshot) {
+		entering_chan = ao2_callback(new_snapshot->channels, 0, find_diff, old_snapshot->channels);
+	}
+	info = bridge_info_create_or_update(bridge_uniqueid, entering_chan);
+	if (!info) {
+		/* no interest in this bridge */
+		return;
+	}
+
+	/* get list of apps that are interested in this bridge event */
+	watching_apps = get_bridge_watching_apps(info);
+	if (!watching_apps) {
+		goto bridge_handler_cleanup;
+	}
+
+	for (i = 0; i < ARRAY_LEN(bridge_monitors); ++i) {
+		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+
+		msg = bridge_monitors[i](old_snapshot, new_snapshot);
+		if (msg) {
+			ao2_callback(watching_apps, OBJ_NODATA, app_send_cb, msg);
+		}
+	}
+
+bridge_handler_cleanup:
+	/* update bridge_info for removed channels if there is interest */ 
+	if (new_snapshot && old_snapshot) {
+		leaving_chan = ao2_callback(old_snapshot->channels, 0, find_diff, new_snapshot->channels);
+		ao2_find(info->channels, leaving_chan, OBJ_UNLINK | OBJ_NODATA);
+	}
 }
 
 /*!
@@ -784,7 +1168,7 @@
 		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 		SCOPED_LOCK(app_lock, app, ao2_lock, ao2_unlock);
 
-		msg = app_event_create("application-replaced", NULL, NULL);
+		msg = app_channel_event_create("application-replaced", NULL, NULL);
 		app->handler(app->data, app_name, msg);
 
 		app->handler = handler;
@@ -835,7 +1219,7 @@
 		return NULL;
 	}
 
-	return app_event_create("channel-event-dtmf-received", obj->snapshot, extra);
+	return app_channel_event_create("channel-event-dtmf-received", obj->snapshot, extra);
 }
 
 static struct ast_json *handle_blob_generic(struct ast_channel_blob *obj)
@@ -844,7 +1228,7 @@
 
 	ast_str_set(&event_name, 0, "channel-event-%s", ast_channel_blob_json_type(obj));
 
-	return app_event_create(ast_str_buffer(event_name), obj->snapshot, obj->blob);
+	return app_channel_event_create(ast_str_buffer(event_name), obj->snapshot, obj->blob);
 }
 
 static void register_blob_handler(const char *blob_type, blob_handler_cb blob_type_handler_cb)
@@ -908,7 +1292,22 @@
 	r |= stasis_message_router_add(app_channel_router, stasis_cache_update_type(), sub_snapshot_handler, NULL);
 	r |= stasis_message_router_add(app_channel_router, ast_channel_blob_type(), sub_blob_handler, NULL);
 
-	return r;
+	app_bridges = ao2_container_alloc(APP_BRIDGES_BUCKETS, bridge_info_hash, bridge_info_cmp);
+	if (!app_bridges) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	app_bridge_router = stasis_message_router_create(stasis_caching_get_topic(ast_bridge_topic_all_cached()));
+	if (!app_bridge_router) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	r |= stasis_message_router_add(app_bridge_router, stasis_cache_update_type(), sub_bridge_handler, NULL);
+	if (r) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)
@@ -921,11 +1320,17 @@
 	ao2_cleanup(blob_handlers);
 	blob_handlers = NULL;
 
+	stasis_message_router_unsubscribe(app_bridge_router);
+	app_bridge_router = NULL;
+
 	ao2_cleanup(__apps_registry);
 	__apps_registry = NULL;
 
 	ao2_cleanup(__app_controls);
 	__app_controls = NULL;
+
+	ao2_cleanup(app_bridges);
+	app_bridges = NULL;
 
 	return r;
 }




More information about the asterisk-commits mailing list