[asterisk-commits] kmoore: branch kmoore/bridge_construction-cel_bridging r389476 - /team/kmoore...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 22 07:58:33 CDT 2013


Author: kmoore
Date: Wed May 22 07:58:29 2013
New Revision: 389476

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389476
Log:
Hold on to channel snapshots that might be important after the cache has been cleared

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

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=389476&r1=389475&r2=389476
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/cel.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/cel.c Wed May 22 07:58:29 2013
@@ -321,36 +321,40 @@
 
 struct bridge_assoc {
 	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(channel_id);	/*!< UniqueID of the primary/dialing 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;
 };
 
 static void bridge_assoc_dtor(void *obj)
 {
 	struct bridge_assoc *assoc = obj;
 	ast_string_field_free_memory(assoc);
-}
-
-static struct bridge_assoc *bridge_assoc_alloc(const char *channel_id, const char *bridge_id, const char *secondary_name)
+	ao2_cleanup(assoc->primary_snapshot);
+	assoc->primary_snapshot = NULL;
+}
+
+static struct bridge_assoc *bridge_assoc_alloc(struct ast_channel_snapshot *primary, const char *bridge_id, const char *secondary_name)
 {
 	RAII_VAR(struct bridge_assoc *, assoc, ao2_alloc(sizeof(*assoc), bridge_assoc_dtor), ao2_cleanup);
-	if (!assoc || ast_string_field_init(assoc, 64)) {
-		return NULL;
-	}
-
-	ast_string_field_set(assoc, channel_id, channel_id);
+	if (!primary || !assoc || ast_string_field_init(assoc, 64)) {
+		return NULL;
+	}
+
 	ast_string_field_set(assoc, bridge_id, bridge_id);
 	ast_string_field_set(assoc, secondary_name, secondary_name);
 
+	assoc->primary_snapshot = primary;
+	ao2_ref(primary, +1);
+
 	ao2_ref(assoc, +1);
 	return assoc;
 }
 
-static int add_bridge_primary(const char *channel_id, const char *bridge_id, const char *secondary_name)
-{
-	RAII_VAR(struct bridge_assoc *, assoc, bridge_assoc_alloc(channel_id, bridge_id, secondary_name), ao2_cleanup);
+static int add_bridge_primary(struct ast_channel_snapshot *primary, const char *bridge_id, const char *secondary_name)
+{
+	RAII_VAR(struct bridge_assoc *, assoc, bridge_assoc_alloc(primary, bridge_id, secondary_name), ao2_cleanup);
 	if (!assoc) {
 		return -1;
 	}
@@ -370,7 +374,7 @@
 	const struct bridge_assoc *assoc = obj;
 	const char *uniqueid = obj;
 	if (!(flags & OBJ_KEY)) {
-		uniqueid = assoc->channel_id;
+		uniqueid = assoc->primary_snapshot->uniqueid;
 	}
 
 	return ast_str_hash(uniqueid);
@@ -380,9 +384,9 @@
 static int bridge_assoc_cmp(void *obj, void *arg, int flags)
 {
 	struct bridge_assoc *assoc1 = obj, *assoc2 = arg;
-	const char *assoc2_id = arg, *assoc1_id = assoc1->channel_id;
+	const char *assoc2_id = arg, *assoc1_id = assoc1->primary_snapshot->uniqueid;
 	if (!(flags & OBJ_KEY)) {
-		assoc2_id = assoc2->channel_id;
+		assoc2_id = assoc2->primary_snapshot->uniqueid;
 	}
 
 	return !strcmp(assoc1_id, assoc2_id) ? CMP_MATCH | CMP_STOP : 0;
@@ -729,6 +733,7 @@
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, ast_channel_snapshot_get_latest(channel_id), ao2_cleanup);
 	if (!snapshot) {
+		ast_log(LOG_ERROR, "COULDN'T FIND SNAPSHOT RAAAA\n");
 		return -1;
 	}
 	return report_event_snapshot(snapshot, event_type, userdefevname, extra, peer2_id);
@@ -1176,6 +1181,24 @@
 		&& (new_snapshot->capabilities | capability));
 }
 
+static void update_bridge_primary(struct ast_channel_snapshot *snapshot)
+{
+	RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
+
+	if (!snapshot) {
+		return;
+	}
+
+	assoc = ao2_find(bridge_primaries, snapshot->uniqueid, OBJ_KEY);
+	if (!assoc) {
+		return;
+	}
+
+	ao2_cleanup(assoc->primary_snapshot);
+	ao2_ref(snapshot, +1);
+	assoc->primary_snapshot = snapshot;
+}
+
 static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
 	struct stasis_topic *topic,
 	struct stasis_message *message)
@@ -1189,6 +1212,8 @@
 		old_snapshot = stasis_message_data(update->old_snapshot);
 		new_snapshot = stasis_message_data(update->new_snapshot);
 
+		update_bridge_primary(new_snapshot);
+
 		for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
 			cel_channel_monitors[i](old_snapshot, new_snapshot);
 		}
@@ -1229,6 +1254,7 @@
 		if (ao2_container_count(snapshot->channels) == 2) {
 			struct ao2_iterator i;
 			RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
+			RAII_VAR(struct ast_channel_snapshot *, latest_primary, 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);
@@ -1241,8 +1267,9 @@
 			}
 			ao2_iterator_destroy(&i);
 
-			add_bridge_primary(channel_id, snapshot->uniqueid, chan_snapshot->name);
-			report_event_id(channel_id, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->name);
+			latest_primary = ast_channel_snapshot_get_latest(channel_id);
+			add_bridge_primary(latest_primary, snapshot->uniqueid, chan_snapshot->name);
+			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);
@@ -1263,7 +1290,7 @@
 	if ((snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX)
 		|| (snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE)) {
 		if (ao2_container_count(snapshot->channels) == 1) {
-			RAII_VAR(struct bridge_assoc *, ao2_primary, ao2_find(bridge_primaries, chan_snapshot->uniqueid, OBJ_KEY), ao2_cleanup);
+			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;
@@ -1275,15 +1302,15 @@
 			}
 			ao2_iterator_destroy(&i);
 
-			if (ao2_primary) {
+			if (assoc) {
 				primary = chan_snapshot->uniqueid;
 			} else {
 				primary = channel_id_in_bridge;
-				ao2_primary = ao2_find(bridge_primaries, primary, OBJ_KEY);
+				assoc = ao2_find(bridge_primaries, primary, OBJ_KEY);
 			}
 
 			remove_bridge_primary(primary);
-			report_event_id(primary, AST_CEL_BRIDGE_END, NULL, NULL, ao2_primary->secondary_name);
+			report_event_snapshot(assoc->primary_snapshot, AST_CEL_BRIDGE_END, NULL, NULL, assoc->secondary_name);
 		}
 		/* AST_CEL_BRIDGE_END when all parties have left */
 	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {




More information about the asterisk-commits mailing list