[asterisk-commits] dlee: branch dlee/ASTERISK-22451-ari-subscribe r399015 - /team/dlee/ASTERISK-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 12 16:27:34 CDT 2013


Author: dlee
Date: Thu Sep 12 16:27:33 2013
New Revision: 399015

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399015
Log:
Subscribe to bridges

Modified:
    team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c?view=diff&rev=399015&r1=399014&r2=399015
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c Thu Sep 12 16:27:33 2013
@@ -822,13 +822,27 @@
 }
 
 #define CHANNEL_SCHEME "channel:"
+#define BRIDGE_SCHEME "bridge:"
+
+struct event_source {
+	enum {
+		EVENT_SOURCE_CHANNEL,
+		EVENT_SOURCE_BRIDGE,
+		EVENT_SOURCE_ENDPOINT,
+	} event_source_type;
+	union {
+		struct ast_channel *channel;
+		struct ast_bridge *bridge;
+		struct ast_endpoint *endpoint;
+	};
+};
 
 enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name,
-	const char **event_sources, int event_sources_count,
+	const char **event_source_names, int event_sources_count,
 	struct ast_json **json)
 {
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_channel **, channels, NULL, ast_free);
+	RAII_VAR(struct event_source *, event_sources, NULL, ast_free);
 	enum stasis_app_subscribe_res res = STASIS_ASR_OK;
 	int i;
 
@@ -840,16 +854,26 @@
 		return STASIS_ASR_APP_NOT_FOUND;
 	}
 
-	channels = ast_calloc(event_sources_count, sizeof(*channels));
-	if (!channels) {
+	event_sources = ast_calloc(event_sources_count, sizeof(*event_sources));
+	if (!event_sources) {
 		return STASIS_ASR_INTERNAL_ERROR;
 	}
 
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
-		if (ast_begins_with(event_sources[i], CHANNEL_SCHEME)) {
-			channels[i] = ast_channel_get_by_name(event_sources[i] +
-					strlen(CHANNEL_SCHEME));
-			if (!channels[i]) {
+		if (ast_begins_with(event_source_names[i], CHANNEL_SCHEME)) {
+			event_sources[i].event_source_type =
+				EVENT_SOURCE_CHANNEL;
+			event_sources[i].channel = ast_channel_get_by_name(
+				event_source_names[i] + strlen(CHANNEL_SCHEME));
+			if (!event_sources[i].channel) {
+				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
+			}
+		} else if (ast_begins_with(event_source_names[i], BRIDGE_SCHEME)) {
+			event_sources[i].event_source_type =
+				EVENT_SOURCE_BRIDGE;
+			event_sources[i].bridge = ast_bridge_get_id(
+				event_source_names[i] + strlen(BRIDGE_SCHEME));
+			if (!event_sources[i].bridge) {
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
 		} else {
@@ -858,11 +882,22 @@
 	}
 
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
-		int sub_res = app_subscribe_channel(app, channels[i]);
+		int sub_res = -1;
+		switch (event_sources[i].event_source_type) {
+		case EVENT_SOURCE_CHANNEL:
+			sub_res = app_subscribe_channel(app, event_sources[i].channel);
+			break;
+		case EVENT_SOURCE_BRIDGE:
+			sub_res = app_subscribe_bridge(app. event_sources[i].bridge)
+			break;
+		case EVENT_SOURCE_ENDPOINT:
+			break;
+		}
+
 		if (sub_res != 0) {
 			ast_log(LOG_ERROR,
-				"Error subscribing app '%s' to channel '%s'\n",
-				app_name, ast_channel_name(channels[i]));
+				"Error subscribing app '%s' to '%s'\n",
+				app_name, event_source_names[i]);
 			res = STASIS_ASR_INTERNAL_ERROR;
 		}
 	}
@@ -872,7 +907,18 @@
 	}
 
 	for (i = 0; i < event_sources_count; ++i) {
-		channels[i] = ast_channel_cleanup(channels[i]);
+		switch (event_sources[i].event_source_type) {
+		case EVENT_SOURCE_CHANNEL:
+			event_sources[i].channel =
+				ast_channel_cleanup(event_sources[i].channel);
+			break;
+		case EVENT_SOURCE_BRIDGE:
+			ao2_cleanup(event_sources[i].bridge);
+			event_sources[i].bridge = NULL;
+			break;
+		case EVENT_SOURCE_ENDPOINT:
+			break;
+		}
 	}
 
 	return res;




More information about the asterisk-commits mailing list