[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r385264 - /team/kmoore/stasis-brid...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 10 13:58:22 CDT 2013


Author: kmoore
Date: Wed Apr 10 13:58:19 2013
New Revision: 385264

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385264
Log:
Add manager actions for querying bridge information

Modified:
    team/kmoore/stasis-bridge_events/main/manager_bridging.c

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=385264&r1=385263&r2=385264
==============================================================================
--- team/kmoore/stasis-bridge_events/main/manager_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/manager_bridging.c Wed Apr 10 13:58:19 2013
@@ -102,6 +102,34 @@
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
+	<manager name="BridgeList" language="en_US">
+		<synopsis>
+			Get a list of bridges in the system.
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+			<parameter name="BridgeType">
+				<para>Optional type for filtering the resulting list of bridges.</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Returns a list of bridges, optionally filtering on a bridge type.</para>
+		</description>
+	</manager>
+	<manager name="BridgeInfo" language="en_US">
+		<synopsis>
+			Get information about a bridge.
+		</synopsis>
+		<syntax>
+			<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
+			<parameter name="BridgeUniqueid" required="true">
+				<para>The unique ID of the bridge about which to retreive information.</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Returns detailed information about a bridge and the channels in it.</para>
+		</description>
+	</manager>
  ***/
 
 /*!
@@ -352,10 +380,134 @@
 		ast_str_buffer(from_text));
 }
 
+static int filter_bridge_type_cb(void *obj, void *arg, int flags)
+{
+	char *bridge_type = arg;
+	struct ast_bridge_snapshot *snapshot = stasis_message_data(obj);
+	/* unlink all the snapshots that do not match the bridge type */
+	return strcmp(bridge_type, snapshot->technology) ? CMP_MATCH : 0;
+}
+
+static int send_bridge_list_item_cb(void *obj, void *arg, void *data, int flags)
+{
+	struct ast_bridge_snapshot *snapshot = stasis_message_data(obj);
+	struct mansession *s = arg;
+	char *id_text = data;
+	RAII_VAR(struct ast_str *, bridge_info, manager_build_bridge_state_string(snapshot, ""), ast_free);
+
+	astman_append(s,
+		"Event: BridgeListItem\r\n"
+		"%s"
+		"%s"
+		"\r\n",
+		ast_str_buffer(bridge_info),
+		id_text);
+	return 0;
+}
+
+static int manager_bridges_list(struct mansession *s, const struct message *m)
+{
+	const char *id = astman_get_header(m, "ActionID");
+	const char *type_filter = astman_get_header(m, "BridgeType");
+	RAII_VAR(struct ast_str *, id_text, ast_str_create(128), ast_free);
+	RAII_VAR(struct ao2_container *, bridges, NULL, ao2_cleanup);
+
+	if (!id_text) {
+		astman_send_error(s, m, "Internal error");
+		return -1;
+	}
+
+	if (!ast_strlen_zero(id)) {
+		ast_str_set(&id_text, 0, "ActionID: %s\r\n", id);
+	}
+
+	bridges = stasis_cache_dump(ast_bridge_topic_all_cached(), ast_bridge_snapshot_type());
+	if (!bridges) {
+		astman_send_error(s, m, "Internal error");
+		return -1;
+	}
+
+	if (!ast_strlen_zero(type_filter)) {
+		char *type_filter_dup = ast_strdupa(type_filter);
+		ao2_callback(bridges, OBJ_MULTIPLE | OBJ_NODATA | OBJ_UNLINK, filter_bridge_type_cb, type_filter_dup);
+	}
+
+	ao2_callback_data(bridges, OBJ_NODATA, send_bridge_list_item_cb, s, ast_str_buffer(id_text));
+
+	astman_append(s,
+		"Event: BridgeListComplete\r\n"
+		"%s"
+		"\r\n",
+		ast_str_buffer(id_text));
+
+	return 0;
+}
+
+static int send_bridge_info_item_cb(void *obj, void *arg, void *data, int flags)
+{
+	char *uniqueid = obj;
+	struct mansession *s = arg;
+	char *id_text = data;
+
+	astman_append(s,
+		"Event: BridgeInfoChannel\r\n"
+		"Uniqueid: %s\r\n"
+		"%s"
+		"\r\n",
+		uniqueid,
+		id_text);
+	return 0;
+}
+
+static int manager_bridge_info(struct mansession *s, const struct message *m)
+{
+	const char *id = astman_get_header(m, "ActionID");
+	const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid");
+	RAII_VAR(struct ast_str *, id_text, ast_str_create(128), ast_free);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_str *, bridge_info, NULL, ast_free);
+	struct ast_bridge_snapshot *snapshot;
+
+	if (!id_text) {
+		astman_send_error(s, m, "Internal error");
+		return -1;
+	}
+
+	if (!bridge_uniqueid) {
+	}
+
+	if (!ast_strlen_zero(id)) {
+		ast_str_set(&id_text, 0, "ActionID: %s\r\n", id);
+	}
+
+	msg = stasis_cache_get(ast_bridge_topic_all_cached(), ast_bridge_snapshot_type(), bridge_uniqueid);
+	if (!msg) {
+		astman_send_error(s, m, "BridgeUniqueid not found");
+		return -1;
+	}
+
+	snapshot = stasis_message_data(msg);
+	bridge_info = manager_build_bridge_state_string(snapshot, "");
+
+	ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, ast_str_buffer(id_text));
+
+	astman_append(s,
+		"Event: BridgeInfoComplete\r\n"
+		"%s"
+		"%s"
+		"\r\n",
+		ast_str_buffer(bridge_info),
+		ast_str_buffer(id_text));
+
+	return 0;
+}
+
 static void manager_bridging_shutdown(void)
 {
 	stasis_message_router_unsubscribe(bridge_state_router);
 	bridge_state_router = NULL;
+	ast_manager_unregister("BridgeList");
+	ast_manager_unregister("BridgeInfo");
 }
 
 int manager_bridging_init(void)
@@ -385,6 +537,9 @@
 					 ast_bridge_merge_message_type(),
 					 bridge_merge_cb,
 					 NULL);
+
+	ret |= ast_manager_register_xml_core("BridgeList", 0, manager_bridges_list);
+	ret |= ast_manager_register_xml_core("BridgeInfo", 0, manager_bridge_info);
 
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.




More information about the asterisk-commits mailing list