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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 11 12:13:12 CDT 2013


Author: kmoore
Date: Thu Apr 11 12:13:09 2013
New Revision: 385316

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385316
Log:
Add bridge blob type
Remove video elements from the bridge snapshot and remove their associated events
Convert BridgeEnter and BridgeLeave events to use the bridge blob

Modified:
    team/kmoore/stasis-bridge_events/apps/app_stasis.c
    team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
    team/kmoore/stasis-bridge_events/main/bridging.c
    team/kmoore/stasis-bridge_events/main/manager_bridging.c
    team/kmoore/stasis-bridge_events/main/stasis_bridging.c

Modified: team/kmoore/stasis-bridge_events/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/apps/app_stasis.c?view=diff&rev=385316&r1=385315&r2=385316
==============================================================================
--- team/kmoore/stasis-bridge_events/apps/app_stasis.c (original)
+++ team/kmoore/stasis-bridge_events/apps/app_stasis.c Thu Apr 11 12:13:09 2013
@@ -970,73 +970,11 @@
 	return app_bridge_event_create(event, old_snapshot, uniqueid_json);
 }
 
-/*! \brief Handle bridge video source change */
-static struct ast_json *bridge_video_source(
-	struct ast_bridge_snapshot *old_snapshot,
-	struct ast_bridge_snapshot *new_snapshot)
-{
-	RAII_VAR(struct ast_json *, uniqueid_json, NULL, ast_json_unref);
-
-	if (!new_snapshot || !old_snapshot) {
-		return NULL;
-	}
-
-	if (!strcmp(new_snapshot->video_source, old_snapshot->video_source)) {
-		return NULL;
-	}
-
-	uniqueid_json = ast_json_pack("s: s", "uniqueid", new_snapshot->video_source);
-	if (!uniqueid_json) {
-		return NULL;
-	}
-
-	return app_bridge_event_create("bridge-event-video-source-change", new_snapshot, uniqueid_json);
-}
-
-static const char *video_mode_to_str(enum ast_bridge_video_mode_type video_mode)
-{
-	switch (video_mode) {
-	case AST_BRIDGE_VIDEO_MODE_NONE:
-		return "none";
-	case AST_BRIDGE_VIDEO_MODE_SINGLE_SRC:
-		return "single";
-	case AST_BRIDGE_VIDEO_MODE_TALKER_SRC:
-		return "talker";
-	}
-	return NULL;
-}
-
-/*! \brief Handle bridge video mode change */
-static struct ast_json *bridge_video_mode(
-	struct ast_bridge_snapshot *old_snapshot,
-	struct ast_bridge_snapshot *new_snapshot)
-{
-	RAII_VAR(struct ast_json *, mode_json, NULL, ast_json_unref);
-
-	if (!new_snapshot || !old_snapshot) {
-		return NULL;
-	}
-
-	if (new_snapshot->video_mode == old_snapshot->video_mode) {
-		return NULL;
-	}
-
-	mode_json = ast_json_pack("s: s", "bridge-video-mode", video_mode_to_str(new_snapshot->video_mode));
-	if (!mode_json) {
-		return NULL;
-	}
-
-	return app_bridge_event_create("bridge-event-video-mode-change", new_snapshot, mode_json);
-}
-
-
 bridge_snapshot_monitor bridge_monitors[] = {
 	bridge_snapshot,
 	bridge_create,
 	bridge_destroy,
 	bridge_channel_diff,
-	bridge_video_mode,
-	bridge_video_source,
 };
 
 static void sub_bridge_handler(void *data,

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=385316&r1=385315&r2=385316
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h Thu Apr 11 12:13:09 2013
@@ -39,13 +39,9 @@
 		AST_STRING_FIELD(uniqueid);
 		/*! Bridge technology that is handling the bridge */
 		AST_STRING_FIELD(technology);
-		/*! The current source for video if any */
-		AST_STRING_FIELD(video_source);
 	);
 	/*! Linked list of channels participating in the bridge */
 	struct ao2_container *channels;
-	/*! Video mode currently set on the bridge */
-	enum ast_bridge_video_mode_type video_mode;
 	/*! Bridge flags to tweak behavior */
 	struct ast_flags feature_flags;
 	/*! Number of channels participating in the bridge */
@@ -111,6 +107,7 @@
  */
 void ast_bridge_publish_state(struct ast_bridge *bridge);
 
+/*! \brief Message representing the merge of two bridges */
 struct ast_bridge_merge_message {
 	struct ast_bridge_snapshot *from;	/*!< Bridge from which channels will be removed during the merge */
 	struct ast_bridge_snapshot *to;		/*!< Bridge to which channels will be added during the merge */
@@ -134,6 +131,78 @@
 void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from);
 
 /*!
+ * \since 12
+ * \brief Blob of data associated with a bridge.
+ *
+ * The \c blob is actually a JSON object of structured data. It has a "type" field
+ * which contains the type string describing this blob.
+ */
+struct ast_bridge_blob {
+	/*! Bridge blob is associated with (or NULL for global/all bridges) */
+	struct ast_bridge_snapshot *bridge;
+	/*! Channel blob is associated with (may be NULL for some messages) */
+	struct ast_channel_snapshot *channel;
+	/*! JSON blob of data */
+	struct ast_json *blob;
+};
+
+/*!
+ * \since 12
+ * \brief Message type for \ref ast_bridge_blob messages.
+ *
+ * \retval Message type for \ref ast_bridge_blob messages.
+ */
+struct stasis_message_type *ast_bridge_blob_type(void);
+
+/*!
+ * \since 12
+ * \brief Creates a \ref ast_bridge_blob message.
+ *
+ * The \a blob JSON object requires a \c "type" field describing the blob. It
+ * should also be treated as immutable and not modified after it is put into the
+ * message.
+ *
+ * \param bridge Channel blob is associated with, or NULL for global/all bridges.
+ * \param blob JSON object representing the data.
+ * \return \ref ast_bridge_blob message.
+ * \return \c NULL on error
+ */
+struct stasis_message *ast_bridge_blob_create(struct ast_bridge *bridge,
+					struct ast_channel *chan,
+					struct ast_json *blob);
+
+/*!
+ * \since 12
+ * \brief Extracts the type field from a \ref ast_bridge_blob.
+ *
+ * Returned \c char* is still owned by \a obj
+ *
+ * \param obj Channel blob object.
+ *
+ * \retval Type field value from the blob.
+ * \retval \c NULL on error.
+ */
+const char *ast_bridge_blob_json_type(struct ast_bridge_blob *obj);
+
+/*!
+ * \since 12
+ * \brief Publish a bridge channel enter event
+ *
+ * \param bridge The bridge a channel entered
+ * \param chan The channel that entered the bridge
+ */
+void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan);
+
+/*!
+ * \since 12
+ * \brief Publish a bridge channel leave event
+ *
+ * \param bridge The bridge a channel left
+ * \param chan The channel that left the bridge
+ */
+void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan);
+
+/*!
  * \brief Dispose of the stasis bridging topics and message types
  */
 void ast_stasis_bridging_shutdown(void);

Modified: team/kmoore/stasis-bridge_events/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/bridging.c?view=diff&rev=385316&r1=385315&r2=385316
==============================================================================
--- team/kmoore/stasis-bridge_events/main/bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/bridging.c Thu Apr 11 12:13:09 2013
@@ -436,7 +436,7 @@
 	bridge->v_table->pull(bridge, bridge_channel);
 
 	bridge->reconfigured = 1;
-	ast_bridge_publish_state(bridge);
+	ast_bridge_publish_leave(bridge, bridge_channel->chan);
 }
 
 /*!
@@ -508,7 +508,7 @@
 	}
 
 	bridge->reconfigured = 1;
-	ast_bridge_publish_state(bridge);
+	ast_bridge_publish_enter(bridge, bridge_channel->chan);
 }
 
 /*!
@@ -3787,7 +3787,6 @@
 	bridge->video_mode.mode_data.single_src_data.chan_vsrc = ast_channel_ref(video_src_chan);
 	ast_test_suite_event_notify("BRIDGE_VIDEO_MODE", "Message: video mode set to single source\r\nVideo Mode: %d\r\nVideo Channel: %s", bridge->video_mode.mode, ast_channel_name(video_src_chan));
 	ast_indicate(video_src_chan, AST_CONTROL_VIDUPDATE);
-	ast_bridge_publish_state(bridge);
 	ast_bridge_unlock(bridge);
 }
 
@@ -3797,7 +3796,6 @@
 	cleanup_video_mode(bridge);
 	bridge->video_mode.mode = AST_BRIDGE_VIDEO_MODE_TALKER_SRC;
 	ast_test_suite_event_notify("BRIDGE_VIDEO_MODE", "Message: video mode set to talker source\r\nVideo Mode: %d", bridge->video_mode.mode);
-	ast_bridge_publish_state(bridge);
 	ast_bridge_unlock(bridge);
 }
 
@@ -3826,7 +3824,6 @@
 		data->average_talking_energy = talker_energy;
 		ast_test_suite_event_notify("BRIDGE_VIDEO_SRC", "Message: video source updated\r\nVideo Channel: %s", ast_channel_name(data->chan_vsrc));
 		ast_indicate(data->chan_vsrc, AST_CONTROL_VIDUPDATE);
-		ast_bridge_publish_state(bridge);
 	} else if ((data->average_talking_energy < talker_energy) && !is_keyframe) {
 		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
 	} else if (!data->chan_vsrc && is_keyframe) {
@@ -3834,7 +3831,6 @@
 		data->average_talking_energy = talker_energy;
 		ast_test_suite_event_notify("BRIDGE_VIDEO_SRC", "Message: video source updated\r\nVideo Channel: %s", ast_channel_name(data->chan_vsrc));
 		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
-		ast_bridge_publish_state(bridge);
 	} else if (!data->chan_old_vsrc && is_keyframe) {
 		data->chan_old_vsrc = ast_channel_ref(chan);
 		ast_indicate(chan, AST_CONTROL_VIDUPDATE);
@@ -3921,7 +3917,6 @@
 			bridge->video_mode.mode_data.talker_src_data.chan_old_vsrc = NULL;
 		}
 	}
-	ast_bridge_publish_state(bridge);
 	ast_bridge_unlock(bridge);
 }
 

Modified: team/kmoore/stasis-bridge_events/main/manager_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/manager_bridging.c?view=diff&rev=385316&r1=385315&r2=385316
==============================================================================
--- team/kmoore/stasis-bridge_events/main/manager_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/manager_bridging.c Thu Apr 11 12:13:09 2013
@@ -28,9 +28,11 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/stasis_bridging.h"
+#include "asterisk/stasis_channels.h"
 #include "asterisk/manager.h"
 #include "asterisk/stasis_message_router.h"
 
+/*! \brief Message router for cached bridge state snapshot updates */
 static struct stasis_message_router *bridge_state_router;
 
 /*** DOCUMENTATION
@@ -72,32 +74,6 @@
 				<xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
 				<parameter name="Uniqueid">
 					<para>The uniqueid of the channel leaving the bridge</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
-	<managerEvent language="en_US" name="BridgeVideoSourceChange">
-		<managerEventInstance class="EVENT_FLAG_CALL">
-			<synopsis>Raised when the video source for a bridge changes.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-				<parameter name="Uniqueid">
-					<para>The uniqueid of the channel that is the current video source</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
-	<managerEvent language="en_US" name="BridgeVideoModeChange">
-		<managerEventInstance class="EVENT_FLAG_CALL">
-			<synopsis>Raised when the video mode for a bridge changes.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-				<parameter name="BridgeVideoMode">
-					<enumlist>
-						<enum name="none"/>
-						<enum name="single"/>
-						<enum name="talker"/>
-					</enumlist>
 				</parameter>
 			</syntax>
 		</managerEventInstance>
@@ -195,98 +171,10 @@
 		EVENT_FLAG_CALL, "BridgeDestroy", NO_EXTRA_FIELDS);
 }
 
-static int find_diff(void *uniqueid, void *arg, void *data, int flags)
-{
-	struct ao2_container *secondary = arg;
-	char **out = data;
-	RAII_VAR(char *, ao2_uniqueid, NULL, ao2_cleanup);
-
-	ao2_uniqueid = ao2_find(secondary, uniqueid, OBJ_KEY);
-	if (!ao2_uniqueid) {
-		*out = uniqueid;
-		return CMP_STOP;
-	}
-
-	return 0;
-}
-
-/*! \brief Handle channels entering and leaving */
-static struct ast_manager_event_blob *bridge_channel_diff(
-	struct ast_bridge_snapshot *old_snapshot,
-	struct ast_bridge_snapshot *new_snapshot)
-{
-	char *new_diff = NULL;
-	char *old_diff = NULL;
-
-	if (!new_snapshot || !old_snapshot
-		|| ao2_container_count(new_snapshot->channels)
-			== ao2_container_count(old_snapshot->channels)) {
-		return NULL;
-	}
-
-	/* get the diff channel on the new snapshot */
-	ao2_callback_data(new_snapshot->channels, OBJ_NODATA, find_diff, old_snapshot->channels, &new_diff);
-
-	if (new_diff) {
-		return ast_manager_event_blob_create(
-			EVENT_FLAG_CALL, "BridgeEnter",
-			"Uniqueid: %s\r\n", new_diff);
-	}
-
-	/* get the diff channel on the old snapshot */
-	ao2_callback_data(old_snapshot->channels, OBJ_NODATA, find_diff, new_snapshot->channels, &old_diff);
-
-	if (old_diff) {
-		return ast_manager_event_blob_create(
-			EVENT_FLAG_CALL, "BridgeLeave",
-			"Uniqueid: %s\r\n", old_diff);
-	}
-
-	return NULL;
-}
-
-/*! \brief Handle bridge video source change */
-static struct ast_manager_event_blob *bridge_video_source(
-	struct ast_bridge_snapshot *old_snapshot,
-	struct ast_bridge_snapshot *new_snapshot)
-{
-	if (!new_snapshot || !old_snapshot) {
-		return NULL;
-	}
-
-	if (!strcmp(new_snapshot->video_source, old_snapshot->video_source)) {
-		return NULL;
-	}
-
-	return ast_manager_event_blob_create(
-		EVENT_FLAG_CALL, "BridgeVideoSourceChange",
-		"Uniqueid: %s\r\n", new_snapshot->video_source);
-}
-
-/*! \brief Handle bridge video mode change */
-static struct ast_manager_event_blob *bridge_video_mode(
-	struct ast_bridge_snapshot *old_snapshot,
-	struct ast_bridge_snapshot *new_snapshot)
-{
-	if (!new_snapshot || !old_snapshot) {
-		return NULL;
-	}
-
-	if (new_snapshot->video_mode == old_snapshot->video_mode) {
-		return NULL;
-	}
-
-	return ast_manager_event_blob_create(
-		EVENT_FLAG_CALL, "BridgeVideoModeChange",
-		"BridgeVideoMode: %s\r\n", ast_bridge_video_mode_type2str(new_snapshot->video_mode));
-}
 
 bridge_snapshot_monitor bridge_monitors[] = {
 	bridge_create,
 	bridge_destroy,
-	bridge_channel_diff,
-	bridge_video_mode,
-	bridge_video_source,
 };
 
 static void bridge_snapshot_update(void *data, struct stasis_subscription *sub,
@@ -367,6 +255,32 @@
 		ast_str_buffer(from_text));
 }
 
+static void bridge_blob_cb(void *data, struct stasis_subscription *sub,
+				    struct stasis_topic *topic,
+				    struct stasis_message *message)
+{
+	struct ast_bridge_blob *blob = stasis_message_data(message);
+	const char *type = ast_bridge_blob_json_type(blob);
+	RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
+	char *event;
+
+	if (!strcmp("leave", type)) {
+		event = "BridgeLeave";
+	} else if (!strcmp("enter", type)) {
+		event = "BridgeEnter";
+	} else {
+		return;
+	}
+
+	bridge_text = manager_build_bridge_state_string(blob->bridge, "");
+
+	manager_event(EVENT_FLAG_CALL, event,
+		"%s"
+		"Uniqueid: %s\r\n",
+		ast_str_buffer(bridge_text),
+		blob->channel->uniqueid);
+}
+
 static int filter_bridge_type_cb(void *obj, void *arg, int flags)
 {
 	char *bridge_type = arg;
@@ -527,6 +441,11 @@
 					 bridge_merge_cb,
 					 NULL);
 
+	ret |= stasis_message_router_add(bridge_state_router,
+					 ast_bridge_blob_type(),
+					 bridge_blob_cb,
+					 NULL);
+
 	ret |= ast_manager_register_xml_core("BridgeList", 0, manager_bridges_list);
 	ret |= ast_manager_register_xml_core("BridgeInfo", 0, manager_bridge_info);
 

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=385316&r1=385315&r2=385316
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/stasis_bridging.c Thu Apr 11 12:13:09 2013
@@ -35,21 +35,31 @@
 #include "asterisk/stasis.h"
 #include "asterisk/channel.h"
 #include "asterisk/stasis_bridging.h"
+#include "asterisk/stasis_channels.h"
 #include "asterisk/bridging.h"
 #include "asterisk/bridging_technology.h"
 
 #define SNAPSHOT_CHANNELS_BUCKETS 13
 
+/*! \brief Message type for bridge snapshot messages */
 static struct stasis_message_type *bridge_snapshot_type;
 
+/*! \brief Message type for bridge blob messages */
+static struct stasis_message_type *bridge_blob_type;
+
+/*! \brief Message type for bridge merge messages */
+static struct stasis_message_type *bridge_merge_message_type;
+
+/*! \brief Aggregate topic for bridge messages */
 static struct stasis_topic *bridge_topic_all;
 
+/*! \brief Caching aggregate topic for bridge snapshots */
 static struct stasis_caching_topic *bridge_topic_all_cached;
 
+/*! \brief Topic pool for individual bridge topics */
 static struct stasis_topic_pool *bridge_topic_pool;
 
-static struct stasis_message_type *bridge_merge_message_type;
-
+/*! \brief Destructor for bridge snapshots */
 static void bridge_snapshot_dtor(void *obj)
 {
 	struct ast_bridge_snapshot *snapshot = obj;
@@ -62,7 +72,6 @@
 {
 	RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
 	struct ast_bridge_channel *bridge_channel;
-	enum ast_bridge_video_mode_type video_mode;
 
 	snapshot = ao2_alloc(sizeof(*snapshot), bridge_snapshot_dtor);
 	if (!snapshot || ast_string_field_init(snapshot, 128)) {
@@ -84,14 +93,6 @@
 	ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);
 	ast_string_field_set(snapshot, technology, bridge->technology->name);
 
-	video_mode = bridge->video_mode.mode;
-	if ((video_mode == AST_BRIDGE_VIDEO_MODE_SINGLE_SRC
-		|| video_mode == AST_BRIDGE_VIDEO_MODE_TALKER_SRC)
-		&& bridge->video_mode.mode_data.talker_src_data.chan_vsrc) {
-		ast_string_field_set(snapshot, video_source, ast_channel_uniqueid(bridge->video_mode.mode_data.talker_src_data.chan_vsrc));
-	}
-
-	snapshot->video_mode = video_mode;
 	snapshot->feature_flags = bridge->feature_flags;
 	snapshot->num_channels = bridge->num_channels;
 	snapshot->num_active = bridge->num_active;
@@ -149,6 +150,7 @@
 	return bridge_merge_message_type;
 }
 
+/*! \brief Destructor for bridge merge messages */
 static void bridge_merge_message_dtor(void *obj)
 {
 	struct ast_bridge_merge_message *msg = obj;
@@ -159,6 +161,7 @@
 	msg->from = NULL;
 }
 
+/*! \brief Bridge merge message creation helper */
 static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_bridge *to, struct ast_bridge *from)
 {
 	RAII_VAR(struct ast_bridge_merge_message *, msg, NULL, ao2_cleanup);
@@ -203,19 +206,129 @@
 	stasis_publish(ast_bridge_topic_all(), msg);
 }
 
+struct stasis_message_type *ast_bridge_blob_type(void)
+{
+	return bridge_blob_type;
+}
+
+static void bridge_blob_dtor(void *obj)
+{
+	struct ast_bridge_blob *event = obj;
+	ao2_cleanup(event->bridge);
+	event->bridge = NULL;
+	ao2_cleanup(event->channel);
+	event->channel = NULL;
+	ast_json_unref(event->blob);
+	event->blob = NULL;
+}
+
+struct stasis_message *ast_bridge_blob_create(struct ast_bridge *bridge,
+					struct ast_channel *chan,
+					struct ast_json *blob)
+{
+	RAII_VAR(struct ast_bridge_blob *, obj, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct ast_json *type;
+
+	ast_assert(blob != NULL);
+
+	type = ast_json_object_get(blob, "type");
+	if (type == NULL) {
+		ast_log(LOG_ERROR, "Invalid ast_bridge_blob; missing type field\n");
+		return NULL;
+	}
+
+	obj = ao2_alloc(sizeof(*obj), bridge_blob_dtor);
+	if (!obj) {
+		return NULL;
+	}
+
+	if (bridge) {
+		obj->bridge = ast_bridge_snapshot_create(bridge);
+		if (obj->bridge == NULL) {
+			return NULL;
+		}
+	}
+
+	if (chan) {
+		obj->channel = ast_channel_snapshot_create(chan);
+		if (obj->channel == NULL) {
+			return NULL;
+		}
+	}
+
+	obj->blob = ast_json_ref(blob);
+
+	msg = stasis_message_create(ast_bridge_blob_type(), obj);
+	if (!msg) {
+		return NULL;
+	}
+
+	ao2_ref(msg, +1);
+	return msg;
+}
+
+const char *ast_bridge_blob_json_type(struct ast_bridge_blob *obj)
+{
+	if (obj == NULL) {
+		return NULL;
+	}
+
+	return ast_json_string_get(ast_json_object_get(obj->blob, "type"));
+}
+
+void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan)
+{
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, enter_json, NULL, ast_json_unref);
+
+	ast_bridge_publish_state(bridge);
+	
+	enter_json = ast_json_pack("{s: s}",
+			"type", "enter");
+
+	msg = ast_bridge_blob_create(bridge, chan, enter_json);
+	if (!msg) {
+		return;
+	}
+
+	stasis_publish(ast_bridge_topic(bridge), msg);
+}
+
+void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan)
+{
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, leave_json, NULL, ast_json_unref);
+
+	ast_bridge_publish_state(bridge);
+	
+	leave_json = ast_json_pack("{s: s}",
+			"type", "leave");
+
+	msg = ast_bridge_blob_create(bridge, chan, leave_json);
+	if (!msg) {
+		return;
+	}
+
+	stasis_publish(ast_bridge_topic(bridge), msg);
+}
+
 void ast_stasis_bridging_shutdown(void)
 {
 	ao2_cleanup(bridge_snapshot_type);
 	bridge_snapshot_type = NULL;
+	ao2_cleanup(bridge_blob_type);
+	bridge_blob_type = NULL;
+	ao2_cleanup(bridge_merge_message_type);
+	bridge_merge_message_type = NULL;
 	ao2_cleanup(bridge_topic_all);
 	bridge_topic_all = NULL;
 	bridge_topic_all_cached = stasis_caching_unsubscribe(bridge_topic_all_cached);
 	ao2_cleanup(bridge_topic_pool);
 	bridge_topic_pool = NULL;
-	ao2_cleanup(bridge_merge_message_type);
-	bridge_merge_message_type = NULL;
-}
-
+}
+
+/*! \brief snapshot ID getter for caching topic */
 static const char *bridge_snapshot_get_id(struct stasis_message *msg)
 {
 	struct ast_bridge_snapshot *snapshot;
@@ -229,8 +342,9 @@
 void ast_stasis_bridging_init(void)
 {
 	bridge_snapshot_type = stasis_message_type_create("ast_bridge_snapshot");
+	bridge_blob_type = stasis_message_type_create("ast_bridge_blob");
+	bridge_merge_message_type = stasis_message_type_create("ast_bridge_merge_message");
 	bridge_topic_all = stasis_topic_create("ast_bridge_topic_all");
 	bridge_topic_all_cached = stasis_caching_topic_create(bridge_topic_all, bridge_snapshot_get_id);
 	bridge_topic_pool = stasis_topic_pool_create(bridge_topic_all);
-	bridge_snapshot_type = stasis_message_type_create("ast_bridge_merge_message");
-}
+}




More information about the asterisk-commits mailing list