[asterisk-commits] kmoore: branch kmoore/peer-field-restoration r398692 - in /team/kmoore/peer-f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 9 16:10:52 CDT 2013


Author: kmoore
Date: Mon Sep  9 16:10:50 2013
New Revision: 398692

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398692
Log:
Initial work, two tests still failing

Modified:
    team/kmoore/peer-field-restoration/include/asterisk/cel.h
    team/kmoore/peer-field-restoration/main/cel.c
    team/kmoore/peer-field-restoration/tests/test_cel.c

Modified: team/kmoore/peer-field-restoration/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/peer-field-restoration/include/asterisk/cel.h?view=diff&rev=398692&r1=398691&r2=398692
==============================================================================
--- team/kmoore/peer-field-restoration/include/asterisk/cel.h (original)
+++ team/kmoore/peer-field-restoration/include/asterisk/cel.h Mon Sep  9 16:10:50 2013
@@ -273,6 +273,7 @@
  * \param userdefevname Custom name for the call event. (optional)
  * \param extra An event-specific opaque JSON blob to be rendered and placed
  *        in the "CEL_EXTRA" information element of the call event. (optional)
+ * \param peer_str A list of comma-separated peer channel names. (optional)
  *
  * \since 12
  *
@@ -281,7 +282,7 @@
  */
 struct ast_event *ast_cel_create_event(struct ast_channel_snapshot *snapshot,
 		enum ast_cel_event_type event_type, const char *userdefevname,
-		struct ast_json *extra);
+		struct ast_json *extra, const char *peer_str);
 
 /*!
  * \brief CEL backend callback

Modified: team/kmoore/peer-field-restoration/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/peer-field-restoration/main/cel.c?view=diff&rev=398692&r1=398691&r2=398692
==============================================================================
--- team/kmoore/peer-field-restoration/main/cel.c (original)
+++ team/kmoore/peer-field-restoration/main/cel.c Mon Sep  9 16:10:50 2013
@@ -293,8 +293,8 @@
 	[AST_CEL_PARK_START]       = "PARK_START",
 	[AST_CEL_PARK_END]         = "PARK_END",
 	[AST_CEL_USER_DEFINED]     = "USER_DEFINED",
-	[AST_CEL_BRIDGE_ENTER]       = "BRIDGE_ENTER",
-	[AST_CEL_BRIDGE_EXIT]        = "BRIDGE_EXIT",
+	[AST_CEL_BRIDGE_ENTER]     = "BRIDGE_ENTER",
+	[AST_CEL_BRIDGE_EXIT]      = "BRIDGE_EXIT",
 	[AST_CEL_BLINDTRANSFER]    = "BLINDTRANSFER",
 	[AST_CEL_ATTENDEDTRANSFER] = "ATTENDEDTRANSFER",
 	[AST_CEL_PICKUP]           = "PICKUP",
@@ -585,7 +585,7 @@
 static int cel_linkedid_ref(const char *linkedid);
 struct ast_event *ast_cel_create_event(struct ast_channel_snapshot *snapshot,
 		enum ast_cel_event_type event_type, const char *userdefevname,
-		struct ast_json *extra)
+		struct ast_json *extra, const char *peer)
 {
 	struct timeval eventtime = ast_tvnow();
 	RAII_VAR(char *, extra_txt, NULL, ast_json_free);
@@ -614,7 +614,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_txt, ""),
-		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, "",
+		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, S_OR(peer, ""),
 		AST_EVENT_IE_END);
 }
 
@@ -628,7 +628,7 @@
 
 static int cel_report_event(struct ast_channel_snapshot *snapshot,
 		enum ast_cel_event_type event_type, const char *userdefevname,
-		struct ast_json *extra)
+		struct ast_json *extra, const char *peer_str)
 {
 	struct ast_event *ev;
 	char *linkedid = ast_strdupa(snapshot->linkedid);
@@ -659,7 +659,7 @@
 		return 0;
 	}
 
-	ev = ast_cel_create_event(snapshot, event_type, userdefevname, extra);
+	ev = ast_cel_create_event(snapshot, event_type, userdefevname, extra, peer_str);
 	if (!ev) {
 		return -1;
 	}
@@ -692,7 +692,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);
-		cel_report_event(snapshot, AST_CEL_LINKEDID_END, NULL, NULL);
+		cel_report_event(snapshot, AST_CEL_LINKEDID_END, NULL, NULL, NULL);
 	}
 	ao2_ref(lid, -1);
 }
@@ -928,13 +928,13 @@
 	int is_hungup, was_hungup;
 
 	if (!new_snapshot) {
-		cel_report_event(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL);
+		cel_report_event(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL, NULL);
 		check_retire_linkedid(old_snapshot);
 		return;
 	}
 
 	if (!old_snapshot) {
-		cel_report_event(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL);
+		cel_report_event(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL, NULL);
 		return;
 	}
 
@@ -952,12 +952,12 @@
 			"hangupcause", new_snapshot->hangupcause,
 			"hangupsource", new_snapshot->hangupsource,
 			"dialstatus", dialstatus);
-		cel_report_event(new_snapshot, AST_CEL_HANGUP, NULL, extra);
+		cel_report_event(new_snapshot, AST_CEL_HANGUP, NULL, extra, NULL);
 		return;
 	}
 
 	if (old_snapshot->state != new_snapshot->state && new_snapshot->state == AST_STATE_UP) {
-		cel_report_event(new_snapshot, AST_CEL_ANSWER, NULL, NULL);
+		cel_report_event(new_snapshot, AST_CEL_ANSWER, NULL, NULL, NULL);
 		return;
 	}
 }
@@ -990,12 +990,12 @@
 
 	/* old snapshot has an application, end it */
 	if (old_snapshot && !ast_strlen_zero(old_snapshot->appl)) {
-		cel_report_event(old_snapshot, AST_CEL_APP_END, NULL, NULL);
+		cel_report_event(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)) {
-		cel_report_event(new_snapshot, AST_CEL_APP_START, NULL, NULL);
+		cel_report_event(new_snapshot, AST_CEL_APP_START, NULL, NULL, NULL);
 	}
 }
 
@@ -1041,6 +1041,49 @@
 	}
 }
 
+static struct ast_str *cel_generate_peer_str(
+	struct ast_bridge_snapshot *bridge,
+	struct ast_channel_snapshot *chan)
+{
+	struct ast_str *peer_str = ast_str_create(32);
+	struct ao2_iterator i;
+	char *current_chan = NULL;
+
+	if (!peer_str) {
+		return NULL;
+	}
+
+	for (i = ao2_iterator_init(bridge->channels, 0);
+		(current_chan = ao2_iterator_next(&i));
+		ao2_cleanup(current_chan)) {
+		RAII_VAR(struct ast_channel_snapshot *, current_snapshot,
+			NULL,
+			ao2_cleanup);
+
+		/* Don't add the channel for which this message is being generated */
+		if (!strcmp(current_chan, chan->uniqueid)) {
+			continue;
+		}
+
+		current_snapshot = ast_channel_snapshot_get_latest(current_chan);
+		if (!current_snapshot) {
+			
+			ast_free(peer_str);
+			ao2_cleanup(current_chan);
+			ao2_iterator_destroy(&i);
+			return NULL;
+		}
+
+		ast_str_append(&peer_str, 0, "%s,", current_snapshot->name);
+	}
+	ao2_iterator_destroy(&i);
+
+	/* Rip off the trailing comma */
+	ast_str_truncate(peer_str, -1);
+
+	return peer_str;
+}
+
 static void cel_bridge_enter_cb(
 	void *data, struct stasis_subscription *sub,
 	struct stasis_topic *topic,
@@ -1050,6 +1093,7 @@
 	struct ast_bridge_snapshot *snapshot = blob->bridge;
 	struct ast_channel_snapshot *chan_snapshot = blob->channel;
 	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
+	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free);
 
 	if (cel_filter_channel_snapshot(chan_snapshot)) {
 		return;
@@ -1060,7 +1104,12 @@
 		return;
 	}
 
-	cel_report_event(chan_snapshot, AST_CEL_BRIDGE_ENTER, NULL, extra);
+	peer_str = cel_generate_peer_str(snapshot, chan_snapshot);
+	if (!peer_str) {
+		return;
+	}
+
+	cel_report_event(chan_snapshot, AST_CEL_BRIDGE_ENTER, NULL, extra, ast_str_buffer(peer_str));
 }
 
 static void cel_bridge_leave_cb(
@@ -1072,6 +1121,7 @@
 	struct ast_bridge_snapshot *snapshot = blob->bridge;
 	struct ast_channel_snapshot *chan_snapshot = blob->channel;
 	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
+	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free);
 
 	if (cel_filter_channel_snapshot(chan_snapshot)) {
 		return;
@@ -1082,7 +1132,12 @@
 		return;
 	}
 
-	cel_report_event(chan_snapshot, AST_CEL_BRIDGE_EXIT, NULL, extra);
+	peer_str = cel_generate_peer_str(snapshot, chan_snapshot);
+	if (!peer_str) {
+		return;
+	}
+
+	cel_report_event(chan_snapshot, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str));
 }
 
 static void cel_parking_cb(
@@ -1100,7 +1155,7 @@
 			"parker_dial_string", parked_payload->parker_dial_string,
 			"parking_lot", parked_payload->parkinglot);
 		if (extra) {
-			cel_report_event(parked_payload->parkee, AST_CEL_PARK_START, NULL, extra);
+			cel_report_event(parked_payload->parkee, AST_CEL_PARK_START, NULL, extra, NULL);
 		}
 		return;
 	case PARKED_CALL_TIMEOUT:
@@ -1122,7 +1177,7 @@
 
 	extra = ast_json_pack("{s: s}", "reason", reason);
 	if (extra) {
-		cel_report_event(parked_payload->parkee, AST_CEL_PARK_END, NULL, extra);
+		cel_report_event(parked_payload->parkee, AST_CEL_PARK_END, NULL, extra, NULL);
 	}
 }
 
@@ -1154,7 +1209,7 @@
 
 		extra = ast_json_pack("{s: s}", "forward", get_blob_variable(blob, "forward"));
 		if (extra) {
-			cel_report_event(caller, AST_CEL_FORWARD, NULL, extra);
+			cel_report_event(caller, AST_CEL_FORWARD, NULL, extra, NULL);
 		}
 	}
 
@@ -1179,7 +1234,7 @@
 		{
 			const char *event = ast_json_string_get(ast_json_object_get(event_details, "event"));
 			struct ast_json *extra = ast_json_object_get(event_details, "extra");
-			cel_report_event(obj->snapshot, event_type, event, extra);
+			cel_report_event(obj->snapshot, event_type, event, extra, NULL);
 			break;
 		}
 	default:
@@ -1232,7 +1287,7 @@
 		"bridge_id", bridge_snapshot->uniqueid);
 
 	if (extra) {
-		cel_report_event(chan_snapshot, AST_CEL_BLINDTRANSFER, NULL, extra);
+		cel_report_event(chan_snapshot, AST_CEL_BLINDTRANSFER, NULL, extra, NULL);
 	}
 }
 
@@ -1286,7 +1341,7 @@
 		}
 		break;
 	}
-	cel_report_event(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra);
+	cel_report_event(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra, NULL);
 }
 
 static void cel_pickup_cb(
@@ -1308,7 +1363,7 @@
 		return;
 	}
 
-	cel_report_event(target, AST_CEL_PICKUP, NULL, extra);
+	cel_report_event(target, AST_CEL_PICKUP, NULL, extra, NULL);
 }
 
 static void cel_local_cb(
@@ -1330,7 +1385,7 @@
 		return;
 	}
 
-	cel_report_event(localone, AST_CEL_LOCAL_OPTIMIZE, NULL, extra);
+	cel_report_event(localone, AST_CEL_LOCAL_OPTIMIZE, NULL, extra, NULL);
 }
 
 static void ast_cel_engine_term(void)

Modified: team/kmoore/peer-field-restoration/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/peer-field-restoration/tests/test_cel.c?view=diff&rev=398692&r1=398691&r2=398692
==============================================================================
--- team/kmoore/peer-field-restoration/tests/test_cel.c (original)
+++ team/kmoore/peer-field-restoration/tests/test_cel.c Mon Sep  9 16:10:50 2013
@@ -91,13 +91,19 @@
 }
 
 #define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
-	if (append_expected_event(chan, ev_type, userevent, extra)) { \
+	if (append_expected_event(chan, ev_type, userevent, extra, NULL)) { \
 		return AST_TEST_FAIL; \
 	} \
 	} while (0)
 
-#define APPEND_EVENT_SNAPSHOT(snapshot, ev_type, userevent, extra) do { \
-	if (append_expected_event_snapshot(snapshot, ev_type, userevent, extra)) { \
+#define APPEND_EVENT_PEER(chan, ev_type, userevent, extra, peer) do { \
+	if (append_expected_event(chan, ev_type, userevent, extra, peer)) { \
+		return AST_TEST_FAIL; \
+	} \
+	} while (0)
+
+#define APPEND_EVENT_SNAPSHOT(snapshot, ev_type, userevent, extra, peer) do { \
+	if (append_expected_event_snapshot(snapshot, ev_type, userevent, extra, peer)) { \
 		return AST_TEST_FAIL; \
 	} \
 	} while (0)
@@ -116,16 +122,26 @@
 
 #define BRIDGE_EXIT_EVENT(channel, bridge) do { \
 	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
+	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
+	stasis_topic_wait(ast_channel_topic_all()); \
+	stasis_topic_wait(ast_bridge_topic_all()); \
+	peer_str = test_cel_generate_peer_str(channel, bridge); \
+	ast_test_validate(test, peer_str != NULL); \
 	extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
 	ast_test_validate(test, extra != NULL); \
-	APPEND_EVENT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra); \
+	APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str)); \
 	} while (0)
 
 #define BRIDGE_EXIT_SNAPSHOT(channel, bridge) do { \
 	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
+	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
+	stasis_topic_wait(ast_channel_topic_all()); \
+	stasis_topic_wait(ast_bridge_topic_all()); \
+	peer_str = test_cel_generate_peer_str_snapshot(channel, bridge); \
+	ast_test_validate(test, peer_str != NULL); \
 	extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
 	ast_test_validate(test, extra != NULL); \
-	APPEND_EVENT_SNAPSHOT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra); \
+	APPEND_EVENT_SNAPSHOT(channel, AST_CEL_BRIDGE_EXIT, NULL, extra, ast_str_buffer(peer_str)); \
 	} while (0)
 
 #define BRIDGE_ENTER(channel, bridge) do { \
@@ -137,9 +153,14 @@
 
 #define BRIDGE_ENTER_EVENT(channel, bridge) do { \
 	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
+	RAII_VAR(struct ast_str *, peer_str, NULL, ast_free); \
+	stasis_topic_wait(ast_channel_topic_all()); \
+	stasis_topic_wait(ast_bridge_topic_all()); \
+	peer_str = test_cel_generate_peer_str(channel, bridge); \
+	ast_test_validate(test, peer_str != NULL); \
 	extra = ast_json_pack("{s: s}", "bridge_id", bridge->uniqueid); \
 	ast_test_validate(test, extra != NULL); \
-	APPEND_EVENT(channel, AST_CEL_BRIDGE_ENTER, NULL, extra); \
+	APPEND_EVENT_PEER(channel, AST_CEL_BRIDGE_ENTER, NULL, extra, ast_str_buffer(peer_str)); \
 	} while (0)
 
 #define BLINDTRANSFER_EVENT(channel, bridge, extension, context) do { \
@@ -248,15 +269,84 @@
 	struct ast_channel *chan,
 	enum ast_cel_event_type type,
 	const char *userdefevname,
-	struct ast_json *extra);
+	struct ast_json *extra,
+	const char *peer);
 
 static int append_expected_event_snapshot(
 	struct ast_channel_snapshot *snapshot,
 	enum ast_cel_event_type type,
 	const char *userdefevname,
-	struct ast_json *extra);
+	struct ast_json *extra,
+	const char *peer);
 
 static int append_dummy_event(void);
+
+static struct ast_str *__test_cel_generate_peer_str(struct ast_channel_snapshot *chan, struct ast_bridge_snapshot *bridge)
+{
+	struct ast_str *peer_str = ast_str_create(32);
+	struct ao2_iterator i;
+	char *current_chan = NULL;
+
+	if (!peer_str) {
+		return NULL;
+	}
+
+	for (i = ao2_iterator_init(bridge->channels, 0);
+		(current_chan = ao2_iterator_next(&i));
+		ao2_cleanup(current_chan)) {
+		RAII_VAR(struct ast_channel_snapshot *, current_snapshot,
+			NULL,
+			ao2_cleanup);
+
+		/* Don't add the channel for which this message is being generated */
+		if (!strcmp(current_chan, chan->uniqueid)) {
+			continue;
+		}
+
+		current_snapshot = ast_channel_snapshot_get_latest(current_chan);
+		if (!current_snapshot) {
+			
+			ast_free(peer_str);
+			ao2_cleanup(current_chan);
+			ao2_iterator_destroy(&i);
+			return NULL;
+		}
+
+		ast_str_append(&peer_str, 0, "%s,", current_snapshot->name);
+	}
+	ao2_iterator_destroy(&i);
+
+	/* Rip off the trailing comma */
+	ast_str_truncate(peer_str, -1);
+
+	return peer_str;
+}
+
+static struct ast_str *test_cel_generate_peer_str_snapshot(struct ast_channel_snapshot *chan, struct ast_bridge *bridge)
+{
+	RAII_VAR(struct ast_bridge_snapshot *, snapshot,
+		ast_bridge_snapshot_get_latest(bridge->uniqueid),
+		ao2_cleanup);
+	
+	if (!snapshot) {
+		return NULL;
+	}
+
+	return __test_cel_generate_peer_str(chan, snapshot);
+}
+
+static struct ast_str *test_cel_generate_peer_str(struct ast_channel *chan, struct ast_bridge *bridge)
+{
+	RAII_VAR(struct ast_channel_snapshot *, snapshot,
+		ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan)),
+		ao2_cleanup);
+	
+	if (!snapshot) {
+		return NULL;
+	}
+
+	return test_cel_generate_peer_str_snapshot(snapshot, bridge);
+}
 
 static void safe_channel_release(struct ast_channel *chan)
 {
@@ -620,7 +710,7 @@
 
 #define EMULATE_DIAL(channel, dialstring) do { \
 	EMULATE_APP_DATA(channel, 1, "Dial", dialstring); \
-	if (append_expected_event(channel, AST_CEL_APP_START, NULL, NULL)) { \
+	if (append_expected_event(channel, AST_CEL_APP_START, NULL, NULL, NULL)) { \
 		return AST_TEST_FAIL; \
 	} \
 	} while (0)
@@ -630,7 +720,7 @@
 
 #define START_DIALED_FULL(caller, callee, number, name) do { \
 	callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, number, NULL, NULL, ast_channel_linkedid(caller), 0, CHANNEL_TECH_NAME "/" name); \
-	if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL)) { \
+	if (append_expected_event(callee, AST_CEL_CHANNEL_START, NULL, NULL, NULL)) { \
 		return AST_TEST_FAIL; \
 	} \
 	ast_set_flag(ast_channel_flags(callee), AST_FLAG_OUTGOING); \
@@ -1485,7 +1575,7 @@
 	extra = ast_json_pack("{s: s}", "local_two", bob_snapshot->name);
 	ast_test_validate(test, extra != NULL);
 
-	APPEND_EVENT_SNAPSHOT(alice_snapshot, AST_CEL_LOCAL_OPTIMIZE, NULL, extra);
+	APPEND_EVENT_SNAPSHOT(alice_snapshot, AST_CEL_LOCAL_OPTIMIZE, NULL, extra, NULL);
 
 	HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
 	HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
@@ -1568,10 +1658,11 @@
 	struct ast_channel_snapshot *snapshot,
 	enum ast_cel_event_type type,
 	const char *userdefevname,
-	struct ast_json *extra)
+	struct ast_json *extra,
+	const char *peer)
 {
 	RAII_VAR(struct ast_event *, ev, NULL, ast_free);
-	ev = ast_cel_create_event(snapshot, type, userdefevname, extra);
+	ev = ast_cel_create_event(snapshot, type, userdefevname, extra, peer);
 	if (!ev) {
 		return -1;
 	}
@@ -1583,7 +1674,8 @@
 	struct ast_channel *chan,
 	enum ast_cel_event_type type,
 	const char *userdefevname,
-	struct ast_json *extra)
+	struct ast_json *extra,
+	const char *peer)
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 	snapshot = ast_channel_snapshot_create(chan);
@@ -1591,7 +1683,7 @@
 		return -1;
 	}
 
-	return append_expected_event_snapshot(snapshot, type, userdefevname, extra);
+	return append_expected_event_snapshot(snapshot, type, userdefevname, extra, peer);
 }
 
 static void test_sub(struct ast_event *event)




More information about the asterisk-commits mailing list