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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 22 13:37:47 CDT 2013


Author: kmoore
Date: Wed May 22 13:37:43 2013
New Revision: 389517

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389517
Log:
Do a bit of cleanup and allow CEL to handle a bridge changing capabilities

Modified:
    team/kmoore/bridge_construction-cel_bridging/include/asterisk/cel.h
    team/kmoore/bridge_construction-cel_bridging/main/cel.c

Modified: team/kmoore/bridge_construction-cel_bridging/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/include/asterisk/cel.h?view=diff&rev=389517&r1=389516&r2=389517
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/include/asterisk/cel.h (original)
+++ team/kmoore/bridge_construction-cel_bridging/include/asterisk/cel.h Wed May 22 13:37:43 2013
@@ -103,6 +103,8 @@
 	AST_CEL_PICKUP = 24,
 	/*! \brief this call was forwarded somewhere else  */
 	AST_CEL_FORWARD = 25,
+	/*! \brief a bridge turned into a conference and will be treated as such until it is torn down */
+	AST_CEL_BRIDGE_TO_CONF = 26,
 };
 
 /*! 

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=389517&r1=389516&r2=389517
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/cel.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/cel.c Wed May 22 13:37:43 2013
@@ -97,6 +97,7 @@
 						<enum name="BRIDGE_START"/>
 						<enum name="BRIDGE_END"/>
 						<enum name="BRIDGE_UPDATE"/>
+						<enum name="BRIDGE_TO_CONF"/>
 						<enum name="CONF_START"/>
 						<enum name="CONF_END"/>
 						<enum name="PARK_START"/>
@@ -305,6 +306,7 @@
 	[AST_CEL_BRIDGE_START]     = "BRIDGE_START",
 	[AST_CEL_BRIDGE_END]       = "BRIDGE_END",
 	[AST_CEL_BRIDGE_UPDATE]    = "BRIDGE_UPDATE",
+	[AST_CEL_BRIDGE_TO_CONF]   = "BRIDGE_TO_CONF",
 	[AST_CEL_CONF_START]       = "CONF_START",
 	[AST_CEL_CONF_END]         = "CONF_END",
 	[AST_CEL_PARK_START]       = "PARK_START",
@@ -325,10 +327,11 @@
 
 struct bridge_assoc {
 	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(bridge_id);	/*!< UniqueID of the bridge */
-		AST_STRING_FIELD(secondary_name);	/*!< UniqueID of the secondary/dialed channel */
+		AST_STRING_FIELD(bridge_id);           /*!< UniqueID of the bridge */
+		AST_STRING_FIELD(secondary_name);      /*!< UniqueID of the secondary/dialed channel */
 	);
-	struct ast_channel_snapshot *primary_snapshot;
+	struct ast_channel_snapshot *primary_snapshot; /*!< The snapshot for the initiating channel in the bridge */
+	int track_as_conf;                             /*!< Whether this bridge will be treated like a conference in CEL terms */
 };
 
 static void bridge_assoc_dtor(void *obj)
@@ -658,7 +661,7 @@
 	struct timeval eventtime;
 	struct ast_event *ev;
 	char *linkedid = ast_strdupa(snapshot->linkedid);
-	const char *peer_name = "";
+	const char *peer_name = peer2_name;
 	RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
 	RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
 
@@ -670,13 +673,11 @@
 		return 0;
 	}
 
-	assoc = ao2_find(bridge_primaries, snapshot->uniqueid, OBJ_KEY);
-	if (assoc) {
-		peer_name = assoc->secondary_name;
-	}
-
-	if (ast_strlen_zero(peer_name) && peer2_name) {
-		peer_name = peer2_name;
+	if (ast_strlen_zero(peer_name)) {
+		assoc = ao2_find(bridge_primaries, snapshot->uniqueid, OBJ_KEY);
+		if (assoc) {
+			peer_name = assoc->secondary_name;
+		}
 	}
 
 	/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
@@ -720,7 +721,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, peer_name,
+		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, S_OR(peer_name, ""),
 		AST_EVENT_IE_END);
 
 	if (ev && ast_event_queue(ev)) {
@@ -729,17 +730,6 @@
 	}
 
 	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, 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
@@ -1212,6 +1202,12 @@
 	return 0;
 }
 
+static struct bridge_assoc *find_bridge_primary_by_bridge_id(const char *bridge_id)
+{
+	char *dup_id = ast_strdupa(bridge_id);
+	return ao2_callback(bridge_primaries, 0, bridge_match_cb, dup_id);
+}
+
 static void clear_bridge_primary(const char *bridge_id)
 {
 	char *dup_id = ast_strdupa(bridge_id);
@@ -1237,6 +1233,7 @@
 			cel_channel_monitors[i](old_snapshot, new_snapshot);
 		}
 	} else if (update->type == ast_bridge_snapshot_type()) {
+		RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
 		struct ast_bridge_snapshot *old_snapshot;
 		struct ast_bridge_snapshot *new_snapshot;
 
@@ -1258,14 +1255,56 @@
 			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)) {
+		if (snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_HOLDING)
+			|| snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_MULTIMIX)
+			|| snapshots_share_capability(old_snapshot, new_snapshot, AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE)
+			) {
 			return;
 		}
 
-		/* Produce bridge capability change event */
+		/* handle 1:1/native -> multimix */
+		if ((old_snapshot->capabilities & (AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE))
+			&& (new_snapshot->capabilities & AST_BRIDGE_CAPABILITY_MULTIMIX)) {
+			assoc = find_bridge_primary_by_bridge_id(new_snapshot->uniqueid);
+
+			/* this bridge will no longer be treated like a bridge, so mark the bridge_assoc as such */
+			assoc->track_as_conf = 1;
+			report_event_snapshot(assoc->primary_snapshot, AST_CEL_BRIDGE_TO_CONF, NULL, NULL, assoc->secondary_name);
+			return;
+		}
+
+		/* handle multimix -> 1:1/native */
+		if ((old_snapshot->capabilities & AST_BRIDGE_CAPABILITY_MULTIMIX)
+			&& (new_snapshot->capabilities & (AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE))) {
+			struct ao2_iterator i;
+			RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
+			RAII_VAR(struct ast_channel_snapshot *, chan_snapshot, NULL, ao2_cleanup);
+
+			assoc = find_bridge_primary_by_bridge_id(new_snapshot->uniqueid);
+			if (assoc) {
+				assoc->track_as_conf = 1;
+				return;
+			}
+
+			/* get the first item in the container */
+			i = ao2_iterator_init(new_snapshot->channels, 0);
+			while ((channel_id = ao2_iterator_next(&i))) {
+				break;
+			}
+			ao2_iterator_destroy(&i);
+
+			/* create a bridge_assoc for this bridge and mark it as being tracked appropriately */
+			chan_snapshot = ast_channel_snapshot_get_latest(channel_id);
+			ast_assert(chan_snapshot != NULL);
+			assoc = bridge_assoc_alloc(chan_snapshot, new_snapshot->uniqueid, chan_snapshot->name);
+			if (!assoc) {
+				return;
+			}
+			assoc->track_as_conf = 1;
+	
+			ao2_link(bridge_primaries, assoc);
+			return;
+		}
 	}
 }
 
@@ -1279,6 +1318,12 @@
 	struct ast_channel_snapshot *chan_snapshot = blob->channel;
 
 	if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX || snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE) {
+		RAII_VAR(struct bridge_assoc *, assoc, find_bridge_primary_by_bridge_id(snapshot->uniqueid), ao2_cleanup);
+		if (assoc && assoc->track_as_conf) {
+			report_event_snapshot(chan_snapshot, AST_CEL_CONF_ENTER, NULL, NULL, NULL);
+			return;
+		}
+		
 		if (ao2_container_count(snapshot->channels) == 2) {
 			struct ao2_iterator i;
 			RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
@@ -1300,7 +1345,7 @@
 			report_event_snapshot(latest_primary, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->name);
 		}
 	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
-		report_event_id(chan_snapshot->uniqueid, AST_CEL_CONF_ENTER, NULL, NULL, NULL);
+		report_event_snapshot(chan_snapshot, AST_CEL_CONF_ENTER, NULL, NULL, NULL);
 	}
 }
 
@@ -1315,31 +1360,26 @@
 
 	if ((snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX)
 		|| (snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE)) {
+		RAII_VAR(struct bridge_assoc *, assoc,
+			find_bridge_primary_by_bridge_id(snapshot->uniqueid),
+			ao2_cleanup);
+
+		if (!assoc) {
+			return;
+		}
+
+		if (assoc->track_as_conf) {
+			report_event_snapshot(chan_snapshot, AST_CEL_CONF_EXIT, NULL, NULL, NULL);
+			return;
+		}
+
 		if (ao2_container_count(snapshot->channels) == 1) {
-			RAII_VAR(struct bridge_assoc *, assoc, ao2_find(bridge_primaries, chan_snapshot->uniqueid, OBJ_KEY), ao2_cleanup);
-			RAII_VAR(char *, channel_id_in_bridge, NULL, ao2_cleanup);
-			const char *primary;
-			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 (assoc) {
-				primary = chan_snapshot->uniqueid;
-			} else {
-				primary = channel_id_in_bridge;
-				assoc = ao2_find(bridge_primaries, primary, OBJ_KEY);
-			}
-
-			remove_bridge_primary(primary);
 			report_event_snapshot(assoc->primary_snapshot, AST_CEL_BRIDGE_END, NULL, NULL, assoc->secondary_name);
+			remove_bridge_primary(assoc->primary_snapshot->uniqueid);
+			return;
 		}
 	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
-		report_event_id(chan_snapshot->uniqueid, AST_CEL_CONF_EXIT, NULL, NULL, NULL);
+		report_event_snapshot(chan_snapshot, AST_CEL_CONF_EXIT, NULL, NULL, NULL);
 	}
 }
 




More information about the asterisk-commits mailing list