[asterisk-commits] kmoore: branch kmoore/cel_local r394385 - in /team/kmoore/cel_local: include/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 15 10:20:27 CDT 2013


Author: kmoore
Date: Mon Jul 15 10:20:21 2013
New Revision: 394385

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394385
Log:
Add LOCAL_OPTIMIZE CEL event type, supporting code, and test

Modified:
    team/kmoore/cel_local/include/asterisk/cel.h
    team/kmoore/cel_local/main/asterisk.c
    team/kmoore/cel_local/main/cel.c
    team/kmoore/cel_local/tests/test_cel.c

Modified: team/kmoore/cel_local/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_local/include/asterisk/cel.h?view=diff&rev=394385&r1=394384&r2=394385
==============================================================================
--- team/kmoore/cel_local/include/asterisk/cel.h (original)
+++ team/kmoore/cel_local/include/asterisk/cel.h Mon Jul 15 10:20:21 2013
@@ -87,6 +87,8 @@
 	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,
+	/*! \brief A local channel optimization occurred */
+	AST_CEL_LOCAL_OPTIMIZE = 27,
 };
 
 /*! 

Modified: team/kmoore/cel_local/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_local/main/asterisk.c?view=diff&rev=394385&r1=394384&r2=394385
==============================================================================
--- team/kmoore/cel_local/main/asterisk.c (original)
+++ team/kmoore/cel_local/main/asterisk.c Mon Jul 15 10:20:21 2013
@@ -4341,12 +4341,12 @@
 		exit(1);
 	}
 
-	if (ast_cel_engine_init()) {
+	if (ast_local_init()) {
 		printf("%s", term_quit());
 		exit(1);
 	}
 
-	if (ast_local_init()) {
+	if (ast_cel_engine_init()) {
 		printf("%s", term_quit());
 		exit(1);
 	}

Modified: team/kmoore/cel_local/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_local/main/cel.c?view=diff&rev=394385&r1=394384&r2=394385
==============================================================================
--- team/kmoore/cel_local/main/cel.c (original)
+++ team/kmoore/cel_local/main/cel.c Mon Jul 15 10:20:21 2013
@@ -62,6 +62,7 @@
 #include "asterisk/bridging.h"
 #include "asterisk/parking.h"
 #include "asterisk/features.h"
+#include "asterisk/core_local.h"
 
 /*** DOCUMENTATION
 	<configInfo name="cel" language="en_US">
@@ -102,7 +103,6 @@
 						<enum name="CONF_END"/>
 						<enum name="PARK_START"/>
 						<enum name="PARK_END"/>
-						<enum name="TRANSFER"/>
 						<enum name="USER_DEFINED"/>
 						<enum name="CONF_ENTER"/>
 						<enum name="CONF_EXIT"/>
@@ -114,7 +114,7 @@
 						<enum name="3WAY_END"/>
 						<enum name="HOOKFLASH"/>
 						<enum name="LINKEDID_END"/>
-
+						<enum name="LOCAL_OPTIMIZE"/>
 					</enumlist>
 					</description>
 				</configOption>
@@ -320,6 +320,7 @@
 	[AST_CEL_3WAY_END]         = "3WAY_END",
 	[AST_CEL_HOOKFLASH]        = "HOOKFLASH",
 	[AST_CEL_LINKEDID_END]     = "LINKEDID_END",
+	[AST_CEL_LOCAL_OPTIMIZE]   = "LOCAL_OPTIMIZE",
 };
 
 struct bridge_assoc {
@@ -1445,6 +1446,22 @@
 	cel_report_event(target, AST_CEL_PICKUP, NULL, NULL, channel->name);
 }
 
+static void cel_local_cb(
+	void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	struct ast_multi_channel_blob *obj = stasis_message_data(message);
+	struct ast_channel_snapshot *localone = ast_multi_channel_blob_get_channel(obj, "1");
+	struct ast_channel_snapshot *localtwo = ast_multi_channel_blob_get_channel(obj, "2");
+
+	if (!localone || !localtwo) {
+		return;
+	}
+
+	cel_report_event(localone, AST_CEL_LOCAL_OPTIMIZE, NULL, NULL, localtwo->name);
+}
+
 static void ast_cel_engine_term(void)
 {
 	aco_info_destroy(&cel_cfg_info);
@@ -1581,6 +1598,11 @@
 		cel_pickup_cb,
 		NULL);
 
+	ret |= stasis_message_router_add(cel_state_router,
+		ast_local_optimization_end_type(),
+		cel_local_cb,
+		NULL);
+
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.
 	 */

Modified: team/kmoore/cel_local/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_local/tests/test_cel.c?view=diff&rev=394385&r1=394384&r2=394385
==============================================================================
--- team/kmoore/cel_local/tests/test_cel.c (original)
+++ team/kmoore/cel_local/tests/test_cel.c Mon Jul 15 10:20:21 2013
@@ -49,6 +49,7 @@
 #include "asterisk/stasis_bridging.h"
 #include "asterisk/json.h"
 #include "asterisk/features.h"
+#include "asterisk/core_local.h"
 
 #define TEST_CATEGORY "/main/cel/"
 
@@ -1499,6 +1500,63 @@
 
 	HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
 	HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(test_cel_local_optimize)
+{
+	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
+	struct ast_party_caller alice_caller = ALICE_CALLERID;
+	struct ast_party_caller bob_caller = BOB_CALLERID;
+	RAII_VAR(struct ast_multi_channel_blob *, mc_blob, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_channel_snapshot *, alice_snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_channel_snapshot *, bob_snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, local_opt_begin, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, local_opt_end, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = TEST_CATEGORY;
+		info->summary = "Test local channel optimization record generation";
+		info->description =
+			"Test CEL records for two local channels being optimized\n"
+			"out by sending a messages indicating local optimization\n"
+			"begin and end\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	mc_blob = ast_multi_channel_blob_create(ast_json_null());
+	ast_test_validate(test, mc_blob != NULL);
+
+	CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
+	CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
+
+	alice_snapshot = ast_channel_snapshot_create(chan_alice);
+	ast_test_validate(test, alice_snapshot != NULL);
+
+	bob_snapshot = ast_channel_snapshot_create(chan_bob);
+	ast_test_validate(test, bob_snapshot != NULL);
+
+	ast_multi_channel_blob_add_channel(mc_blob, "1", alice_snapshot);
+	ast_multi_channel_blob_add_channel(mc_blob, "2", bob_snapshot);
+
+	local_opt_begin = stasis_message_create(ast_local_optimization_begin_type(), mc_blob);
+	ast_test_validate(test, local_opt_begin != NULL);
+
+	local_opt_end = stasis_message_create(ast_local_optimization_end_type(), mc_blob);
+	ast_test_validate(test, local_opt_end != NULL);
+
+	stasis_publish(ast_channel_topic(chan_alice), local_opt_begin);
+	stasis_publish(ast_channel_topic(chan_alice), local_opt_end);
+	APPEND_EVENT_SNAPSHOT(alice_snapshot, AST_CEL_LOCAL_OPTIMIZE, NULL, NULL, bob_snapshot->name);
+
+	HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL, "");
+	HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL, "");
 
 	return AST_TEST_PASS;
 }
@@ -1916,6 +1974,8 @@
 
 	AST_TEST_UNREGISTER(test_cel_dial_pickup);
 
+	AST_TEST_UNREGISTER(test_cel_local_optimize);
+
 	ast_channel_unregister(&test_cel_chan_tech);
 
 	ao2_cleanup(cel_test_config);
@@ -1954,6 +2014,7 @@
 	cel_test_config->events |= 1<<AST_CEL_BLINDTRANSFER;
 	cel_test_config->events |= 1<<AST_CEL_ATTENDEDTRANSFER;
 	cel_test_config->events |= 1<<AST_CEL_PICKUP;
+	cel_test_config->events |= 1<<AST_CEL_LOCAL_OPTIMIZE;
 
 	ast_channel_register(&test_cel_chan_tech);
 
@@ -1986,6 +2047,8 @@
 
 	AST_TEST_REGISTER(test_cel_dial_pickup);
 
+	AST_TEST_REGISTER(test_cel_local_optimize);
+
 	/* ast_test_register_* has to happen after AST_TEST_REGISTER */
 	/* Verify received vs expected events and clean things up after every test */
 	ast_test_register_init(TEST_CATEGORY, test_cel_init_cb);




More information about the asterisk-commits mailing list