[asterisk-commits] kmoore: branch kmoore/stasis-cel_bridging r388928 - /team/kmoore/stasis-cel_b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 16 08:33:14 CDT 2013


Author: kmoore
Date: Thu May 16 08:33:13 2013
New Revision: 388928

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388928
Log:
Compilation fixes, cleanup, introduction of a helper function, and implementation of the first replaced event

Modified:
    team/kmoore/stasis-cel_bridging/main/cel.c
    team/kmoore/stasis-cel_bridging/main/stasis_bridging.c

Modified: team/kmoore/stasis-cel_bridging/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/main/cel.c?view=diff&rev=388928&r1=388927&r2=388928
==============================================================================
--- team/kmoore/stasis-cel_bridging/main/cel.c (original)
+++ team/kmoore/stasis-cel_bridging/main/cel.c Thu May 16 08:33:13 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 channel state */
 static struct stasis_message_router *cel_channel_state_router;
@@ -382,11 +384,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);
+	}
 
 	/* Make sure a reload is not occurring while we're checking to see if this
 	 * is an event that we care about.  We could lose an important event in this
@@ -450,7 +462,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, 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)) {
@@ -459,6 +471,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
@@ -482,7 +505,7 @@
 	 * before unreffing the channel we have a refcount of 3, we're done. Unlink and report. */
 	if (ao2_ref(lid, -1) == 3) {
 		ao2_unlink(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);
 }
@@ -820,13 +843,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;
 	}
 
@@ -836,12 +859,12 @@
 	if (!was_hungup && is_hungup) {
 		RAII_VAR(struct ast_str *, extra_str, ast_str_create(128), ast_free);
 		ast_str_set(&extra_str, 0, "%d,%s,%s", new_snapshot->hangupcause, new_snapshot->hangupsource, new_snapshot->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;
 	}
 }
@@ -870,12 +893,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);
 	}
 }
 
@@ -913,10 +936,27 @@
 	struct stasis_topic *topic,
 	struct stasis_message *message)
 {
-	struct ast_bridge_snapshot *snapshot = stasis_message_data(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) {
 		/* AST_CEL_BRIDGE_START when second party enters */
+		if (ao2_container_count(snapshot->channels) == 2) {
+			struct ao2_iterator i;
+			RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
+			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);
+
+			report_event_id(channel_id, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->uniqueid);
+		}
 	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
 		/* AST_CEL_CONF_START */
 	} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_HOLDING) {
@@ -947,7 +987,7 @@
 	uint32_t capability)
 {
 	return ((old_snapshot->capabilities | capability)
-		&& (new_snapshot->capabilities | capability))
+		&& (new_snapshot->capabilities | capability));
 }
 
 static void cel_bridge_snapshot_update_cb(void *data, struct stasis_subscription *sub,
@@ -957,7 +997,6 @@
 	struct stasis_cache_update *update;
 	struct ast_bridge_snapshot *old_snapshot;
 	struct ast_bridge_snapshot *new_snapshot;
-	size_t i;
 
 	update = stasis_message_data(message);
 

Modified: team/kmoore/stasis-cel_bridging/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/main/stasis_bridging.c?view=diff&rev=388928&r1=388927&r2=388928
==============================================================================
--- team/kmoore/stasis-cel_bridging/main/stasis_bridging.c (original)
+++ team/kmoore/stasis-cel_bridging/main/stasis_bridging.c Thu May 16 08:33:13 2013
@@ -94,7 +94,7 @@
 	ast_string_field_set(snapshot, technology, bridge->technology->name);
 
 	snapshot->feature_flags = bridge->feature_flags;
-	snapshot->capabilites = bridge->technology->capabilities;
+	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