[asterisk-commits] kmoore: branch kmoore/bridge_construction-cel_bridging r389076 - in /team/kmo...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat May 18 15:42:36 CDT 2013


Author: kmoore
Date: Sat May 18 15:42:33 2013
New Revision: 389076

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389076
Log:
init svnmerge and automerge and commit current work

Modified:
    team/kmoore/bridge_construction-cel_bridging/   (props changed)
    team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_bridging.h
    team/kmoore/bridge_construction-cel_bridging/main/asterisk.c
    team/kmoore/bridge_construction-cel_bridging/main/cel.c
    team/kmoore/bridge_construction-cel_bridging/main/stasis_bridging.c

Propchange: team/kmoore/bridge_construction-cel_bridging/
------------------------------------------------------------------------------
    automerge-propname = bc-cel_bridging-integrated

Propchange: team/kmoore/bridge_construction-cel_bridging/
------------------------------------------------------------------------------
--- bc-cel_bridging-integrated (added)
+++ bc-cel_bridging-integrated Sat May 18 15:42:33 2013
@@ -1,0 +1,1 @@
+/team/kmoore/bridge_construction-cel_channels:1-389074

Propchange: team/kmoore/bridge_construction-cel_bridging/
            ('svnmerge-integrated' removed)

Modified: team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_bridging.h?view=diff&rev=389076&r1=389075&r2=389076
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_bridging.h (original)
+++ team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_bridging.h Sat May 18 15:42:33 2013
@@ -45,6 +45,8 @@
 	struct ao2_container *channels;
 	/*! Bridge flags to tweak behavior */
 	struct ast_flags feature_flags;
+	/*! Bridge capabilities */
+	uint32_t capabilities;
 	/*! Number of channels participating in the bridge */
 	unsigned int num_channels;
 	/*! Number of active channels in the bridge. */

Modified: team/kmoore/bridge_construction-cel_bridging/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/asterisk.c?view=diff&rev=389076&r1=389075&r2=389076
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/asterisk.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/asterisk.c Sat May 18 15:42:33 2013
@@ -4282,11 +4282,6 @@
 		exit(1);
 	}
 
-	if (ast_cel_engine_init()) {
-		printf("%s", term_quit());
-		exit(1);
-	}
-
 	if (ast_device_state_engine_init()) {
 		printf("%s", term_quit());
 		exit(1);
@@ -4326,6 +4321,11 @@
 	}
 
 	if (ast_bridging_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
+	if (ast_cel_engine_init()) {
 		printf("%s", term_quit());
 		exit(1);
 	}

Modified: team/kmoore/bridge_construction-cel_bridging/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/cel.c?view=diff&rev=389076&r1=389075&r2=389076
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/cel.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/cel.c Sat May 18 15:42:33 2013
@@ -57,6 +57,8 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_bridging.h"
+#include "asterisk/bridging.h"
 
 /*! Message router for state that CEL needs to know about */
 static struct stasis_message_router *cel_state_router;
@@ -66,6 +68,15 @@
 
 /*! Subscription for forwarding the channel caching topic */
 static struct stasis_subscription *cel_channel_forwarder;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_bridge_forwarder;
+
+/*! Container for primary channel listing for 2 party bridges */
+static struct ao2_container *bridge_primaries;
+
+/*! The number of buckets into which primary channel uniqueids will be hashed */
+#define BRIDGE_PRIMARY_BUCKETS 251
 
 /*! Container for dial end multichannel blobs for holding on to dial statuses */
 static struct ao2_container *cel_dialstatus_store;
@@ -419,11 +430,21 @@
 
 static int report_event_snapshot(struct ast_channel_snapshot *snapshot,
 		enum ast_cel_event_type event_type, const char *userdefevname,
-		const char *extra)
+		const char *extra, const char *peer2_id)
 {
 	struct timeval eventtime;
 	struct ast_event *ev;
 	char *linkedid = ast_strdupa(snapshot->linkedid);
+	const char *peer_name = snapshot->bridged_name;
+
+	if (ast_strlen_zero(peer_name) && peer2_id) {
+		RAII_VAR(struct ast_channel_snapshot *, peer2_snapshot, NULL /* XXX ast_channel_snapshot_get_latest(peer2_id)*/, ao2_cleanup);
+		if (!peer2_snapshot) {
+			return -1;
+		}
+
+		peer_name = ast_strdupa(peer2_snapshot->name);
+	}
 
 	if (!cel_enabled) {
 		return 0;
@@ -483,7 +504,7 @@
 		AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
 		AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
 		AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra, ""),
-		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, snapshot->bridged_name,
+		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peer_name,
 		AST_EVENT_IE_END);
 
 	if (ev && ast_event_queue(ev)) {
@@ -492,6 +513,17 @@
 	}
 
 	return 0;
+}
+
+static int report_event_id(const char *channel_id,
+		enum ast_cel_event_type event_type, const char *userdefevname,
+		const char *extra, const char *peer2_id)
+{
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL /* XXX ast_channel_snapshot_get_latest(channel_id)*/, ao2_cleanup);
+	if (!snapshot) {
+		return -1;
+	}
+	return report_event_snapshot(snapshot, event_type, userdefevname, extra, peer2_id);
 }
 
 /* called whenever a channel is destroyed or a linkedid is changed to
@@ -515,7 +547,7 @@
 	 * before unreffing the channel we have a refcount of 3, we're done. Unlink and report. */
 	if (ao2_ref(lid, -1) == 3) {
 		ast_str_container_remove(linkedids, lid);
-		report_event_snapshot(snapshot, AST_CEL_LINKEDID_END, NULL, NULL);
+		report_event_snapshot(snapshot, AST_CEL_LINKEDID_END, NULL, NULL, NULL);
 	}
 	ao2_ref(lid, -1);
 }
@@ -858,13 +890,13 @@
 	int is_hungup, was_hungup;
 
 	if (!new_snapshot) {
-		report_event_snapshot(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL);
+		report_event_snapshot(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL, NULL);
 		check_retire_linkedid(old_snapshot);
 		return;
 	}
 
 	if (!old_snapshot) {
-		report_event_snapshot(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL);
+		report_event_snapshot(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL, NULL);
 		return;
 	}
 
@@ -882,12 +914,12 @@
 			new_snapshot->hangupcause,
 			new_snapshot->hangupsource,
 			dialstatus);
-		report_event_snapshot(new_snapshot, AST_CEL_HANGUP, NULL, ast_str_buffer(extra_str));
+		report_event_snapshot(new_snapshot, AST_CEL_HANGUP, NULL, ast_str_buffer(extra_str), NULL);
 		return;
 	}
 
 	if (old_snapshot->state != new_snapshot->state && new_snapshot->state == AST_STATE_UP) {
-		report_event_snapshot(new_snapshot, AST_CEL_ANSWER, NULL, NULL);
+		report_event_snapshot(new_snapshot, AST_CEL_ANSWER, NULL, NULL, NULL);
 		return;
 	}
 }
@@ -916,12 +948,12 @@
 
 	/* old snapshot has an application, end it */
 	if (old_snapshot && !ast_strlen_zero(old_snapshot->appl)) {
-		report_event_snapshot(old_snapshot, AST_CEL_APP_END, NULL, NULL);
+		report_event_snapshot(old_snapshot, AST_CEL_APP_END, NULL, NULL, NULL);
 	}
 
 	/* new snapshot has an application, start it */
 	if (new_snapshot && !ast_strlen_zero(new_snapshot->appl)) {
-		report_event_snapshot(new_snapshot, AST_CEL_APP_START, NULL, NULL);
+		report_event_snapshot(new_snapshot, AST_CEL_APP_START, NULL, NULL, NULL);
 	}
 }
 
@@ -931,12 +963,21 @@
 	cel_channel_linkedid_change,
 };
 
+static int snapshots_share_capability(
+	struct ast_bridge_snapshot *old_snapshot,
+	struct ast_bridge_snapshot *new_snapshot,
+	uint32_t capability)
+{
+	return ((old_snapshot->capabilities | capability)
+		&& (new_snapshot->capabilities | capability));
+}
+
 static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_topic *topic,
 	struct stasis_message *message)
 {
 	struct stasis_cache_update *update = stasis_message_data(message);
-	if (ast_channel_snapshot_type() == update->type) {
+	if (update->type == ast_channel_snapshot_type()) {
 		struct ast_channel_snapshot *old_snapshot;
 		struct ast_channel_snapshot *new_snapshot;
 		size_t i;
@@ -947,6 +988,106 @@
 		for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
 			cel_channel_monitors[i](old_snapshot, new_snapshot);
 		}
+	} else if (update->type == ast_bridge_snapshot_type()) {
+		struct ast_bridge_snapshot *old_snapshot;
+		struct ast_bridge_snapshot *new_snapshot;
+
+		update = stasis_message_data(message);
+
+		old_snapshot = stasis_message_data(update->old_snapshot);
+		new_snapshot = stasis_message_data(update->new_snapshot);
+
+		if (old_snapshot->capabilities == new_snapshot->capabilities) {
+			return;
+		}
+
+		if (snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_1TO1MIX)
+			|| snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_NATIVE)
+			|| snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_HOLDING)
+			|| snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_MULTIMIX)) {
+			return;
+		}
+
+		/* Produce bridge capability change event */
+	}
+}
+
+static void cel_bridge_enter_cb(
+	void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	struct ast_bridge_blob *blob = stasis_message_data(message);
+	struct ast_bridge_snapshot *snapshot = blob->bridge;
+	struct ast_channel_snapshot *chan_snapshot = blob->channel;
+
+	if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX || snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE) {
+		if (ao2_container_count(snapshot->channels) == 2) {
+			struct ao2_iterator i;
+			RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
+
+			/* get the name of the channel in the container we don't already know the name of */
+			i = ao2_iterator_init(snapshot->channels, 0);
+			while ((channel_id = ao2_iterator_next(&i))) {
+				if (strcmp(channel_id, chan_snapshot->uniqueid)) {
+					break;
+				}
+				ao2_cleanup(channel_id);
+				channel_id = NULL;
+			}
+			ao2_iterator_destroy(&i);
+
+			ast_str_container_add(bridge_primaries, channel_id);
+			report_event_id(channel_id, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->uniqueid);
+		}
+	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
+		report_event_id(chan_snapshot->uniqueid, AST_CEL_CONF_ENTER, NULL, NULL, NULL);
+	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_HOLDING) {
+		/* XXX AST_CEL_PARK_START refactor to parking subscription */
+	}
+}
+
+static void cel_bridge_leave_cb(
+	void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	struct ast_bridge_blob *blob = stasis_message_data(message);
+	struct ast_bridge_snapshot *snapshot = blob->bridge;
+	struct ast_channel_snapshot *chan_snapshot = blob->channel;
+
+	if ((snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX)
+		|| (snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE)) {
+		if (ao2_container_count(snapshot->channels) == 1) {
+			RAII_VAR(char *, ao2_primary, ao2_find(bridge_primaries, chan_snapshot->uniqueid, OBJ_KEY), ao2_cleanup);
+			RAII_VAR(char *, channel_id_in_bridge, NULL, ao2_cleanup);
+			char *primary, *secondary;
+			struct ao2_iterator i;
+
+			/* get the only item in the container */
+			i = ao2_iterator_init(snapshot->channels, 0);
+			while ((channel_id_in_bridge = ao2_iterator_next(&i))) {
+				break;
+			}
+			ao2_iterator_destroy(&i);
+
+			if (ao2_primary) {
+				primary = ao2_primary;
+				secondary = channel_id_in_bridge;
+			} else {
+				primary = channel_id_in_bridge;
+				secondary = ao2_primary;
+			}
+
+			ast_str_container_remove(bridge_primaries, primary);
+
+			report_event_id(primary, AST_CEL_BRIDGE_END, NULL, NULL, secondary);
+		}
+		/* AST_CEL_BRIDGE_END when all parties have left */
+	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
+		report_event_id(chan_snapshot->uniqueid, AST_CEL_CONF_EXIT, NULL, NULL, NULL);
+	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_HOLDING) {
+		/* XXX AST_CEL_PARK_END refactor to parking subscription */
 	}
 }
 
@@ -979,11 +1120,16 @@
 	ao2_cleanup(cel_state_topic);
 	cel_state_topic = NULL;
 	cel_channel_forwarder = stasis_unsubscribe(cel_channel_forwarder);
+	cel_bridge_forwarder = stasis_unsubscribe(cel_bridge_forwarder);
 	ao2_cleanup(appset);
 	appset = NULL;
 	ao2_cleanup(linkedids);
 	linkedids = NULL;
 	ast_cli_unregister(&cli_status);
+	stasis_message_router_unsubscribe(cel_state_router);
+	cel_state_router = NULL;
+	ao2_cleanup(bridge_primaries);
+	bridge_primaries = NULL;
 }
 
 int ast_cel_engine_init(void)
@@ -992,6 +1138,7 @@
 	if (!(appset = ast_str_container_alloc(NUM_APP_BUCKETS))) {
 		return -1;
 	}
+
 	if (!(linkedids = ast_str_container_alloc(NUM_APP_BUCKETS))) {
 		return -1;
 	}
@@ -999,6 +1146,7 @@
 	if (!(cel_dialstatus_store = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS, dialstatus_hash, dialstatus_cmp))) {
 		return -1;
 	}
+
 
 	if (do_reload() || ast_cli_register(&cli_status)) {
 		return -1;
@@ -1009,8 +1157,17 @@
 		return -1;
 	}
 
-	cel_channel_forwarder = stasis_forward_all(stasis_caching_get_topic(ast_channel_topic_all_cached()), cel_state_topic);
+	cel_channel_forwarder = stasis_forward_all(
+		stasis_caching_get_topic(ast_channel_topic_all_cached()),
+		cel_state_topic);
 	if (!cel_channel_forwarder) {
+		return -1;
+	}
+
+	cel_bridge_forwarder = stasis_forward_all(
+		stasis_caching_get_topic(ast_bridge_topic_all_cached()),
+		cel_state_topic);
+	if (!cel_bridge_forwarder) {
 		return -1;
 	}
 
@@ -1037,6 +1194,29 @@
 		return -1;
 	}
 
+	bridge_primaries = ast_str_container_alloc(BRIDGE_PRIMARY_BUCKETS);
+	if (!bridge_primaries) {
+		return -1;
+	}
+
+	ret |= stasis_message_router_add(cel_state_router,
+		ast_channel_entered_bridge_type(),
+		cel_bridge_enter_cb,
+		NULL);
+
+	ret |= stasis_message_router_add(cel_state_router,
+		ast_channel_left_bridge_type(),
+		cel_bridge_leave_cb,
+		NULL);
+
+	/* If somehow we failed to add any routes, just shut down the whole
+	 * thing and fail it.
+	 */
+	if (ret) {
+		ast_cel_engine_term();
+		return -1;
+	}
+
 	ast_register_atexit(ast_cel_engine_term);
 
 	return 0;

Modified: team/kmoore/bridge_construction-cel_bridging/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/stasis_bridging.c?view=diff&rev=389076&r1=389075&r2=389076
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/stasis_bridging.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/stasis_bridging.c Sat May 18 15:42:33 2013
@@ -94,6 +94,7 @@
 	ast_string_field_set(snapshot, technology, bridge->technology->name);
 
 	snapshot->feature_flags = bridge->feature_flags;
+	snapshot->capabilities = bridge->technology->capabilities;
 	snapshot->num_channels = bridge->num_channels;
 	snapshot->num_active = bridge->num_active;
 




More information about the asterisk-commits mailing list