[svn-commits] kmoore: branch kmoore/cel_transfers r393893 - in /team/kmoore/cel_transfers: ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 9 14:17:56 CDT 2013


Author: kmoore
Date: Tue Jul  9 14:17:54 2013
New Revision: 393893

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393893
Log:
Add CEL pickup message support

Modified:
    team/kmoore/cel_transfers/main/cel.c
    team/kmoore/cel_transfers/main/features.c
    team/kmoore/cel_transfers/tests/test_cel.c

Modified: team/kmoore/cel_transfers/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_transfers/main/cel.c?view=diff&rev=393893&r1=393892&r2=393893
==============================================================================
--- team/kmoore/cel_transfers/main/cel.c (original)
+++ team/kmoore/cel_transfers/main/cel.c Tue Jul  9 14:17:54 2013
@@ -61,6 +61,7 @@
 #include "asterisk/stasis_bridging.h"
 #include "asterisk/bridging.h"
 #include "asterisk/parking.h"
+#include "asterisk/features.h"
 
 /*** DOCUMENTATION
 	<configInfo name="cel" language="en_US">
@@ -1531,6 +1532,18 @@
 	report_event_snapshot(channel1, AST_CEL_ATTENDEDTRANSFER, NULL, extra, NULL);
 }
 
+static void cel_pickup_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 *channel = ast_multi_channel_blob_get_channel(obj, "channel");
+	struct ast_channel_snapshot *target = ast_multi_channel_blob_get_channel(obj, "target");
+
+	report_event_snapshot(target, AST_CEL_PICKUP, NULL, NULL, channel->name);
+}
+
 static void ast_cel_engine_term(void)
 {
 	aco_info_destroy(&cel_cfg_info);
@@ -1662,6 +1675,11 @@
 		cel_attended_transfer_cb,
 		NULL);
 
+	ret |= stasis_message_router_add(cel_state_router,
+		ast_call_pickup_type(),
+		cel_pickup_cb,
+		NULL);
+
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.
 	 */

Modified: team/kmoore/cel_transfers/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_transfers/main/features.c?view=diff&rev=393893&r1=393892&r2=393893
==============================================================================
--- team/kmoore/cel_transfers/main/features.c (original)
+++ team/kmoore/cel_transfers/main/features.c Tue Jul  9 14:17:54 2013
@@ -70,7 +70,6 @@
 #include "asterisk/audiohook.h"
 #include "asterisk/global_datastores.h"
 #include "asterisk/astobj2.h"
-#include "asterisk/cel.h"
 #include "asterisk/test.h"
 #include "asterisk/bridging.h"
 #include "asterisk/bridging_basic.h"
@@ -4745,8 +4744,6 @@
 	ast_channel_unlock(chan);
 	connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
 
-	ast_cel_report_event(target, AST_CEL_PICKUP, NULL, NULL, chan);
-
 	if (ast_answer(chan)) {
 		ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan_name);
 		goto pickup_failed;

Modified: team/kmoore/cel_transfers/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_transfers/tests/test_cel.c?view=diff&rev=393893&r1=393892&r2=393893
==============================================================================
--- team/kmoore/cel_transfers/tests/test_cel.c (original)
+++ team/kmoore/cel_transfers/tests/test_cel.c Tue Jul  9 14:17:54 2013
@@ -48,6 +48,7 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_bridging.h"
 #include "asterisk/json.h"
+#include "asterisk/features.h"
 
 #define TEST_CATEGORY "/main/cel/"
 
@@ -222,28 +223,32 @@
 
 /*! \brief Hang up a test channel safely */
 #define HANGUP_CHANNEL(channel, cause, dialstatus) do { \
-	RAII_VAR(struct ast_json *, hangup_extra, NULL, ast_json_unref); \
-	hangup_extra = ast_json_pack("{s: i, s: s, s: s}", \
-		"hangupcause", cause, \
-		"hangupsource", "", \
-		"dialstatus", dialstatus); \
-	ast_test_validate(test, hangup_extra != NULL); \
 	ast_channel_hangupcause_set((channel), (cause)); \
 	ao2_ref(channel, +1); \
 	if (!ast_hangup((channel))) { \
-		APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, hangup_extra, NULL); \
+		HANGUP_EVENT(channel, cause, dialstatus); \
 		APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL, NULL); \
 		ao2_cleanup(stasis_cache_get_extended(ast_channel_topic_all_cached(), \
 			ast_channel_snapshot_type(), ast_channel_uniqueid(channel), 1)); \
 		ao2_cleanup(channel); \
 		channel = NULL; \
 	} else { \
-		APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, hangup_extra, NULL); \
+		HANGUP_EVENT(channel, cause, dialstatus); \
 		APPEND_EVENT(channel, AST_CEL_CHANNEL_END, NULL, NULL, NULL); \
 		ao2_cleanup(stasis_cache_get_extended(ast_channel_topic_all_cached(), \
 			ast_channel_snapshot_type(), ast_channel_uniqueid(channel), 1)); \
 		ao2_cleanup(channel); \
 	} \
+	} while (0)
+
+#define HANGUP_EVENT(channel, cause, dialstatus) do { \
+	RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref); \
+	extra = ast_json_pack("{s: i, s: s, s: s}", \
+		"hangupcause", cause, \
+		"hangupsource", "", \
+		"dialstatus", dialstatus); \
+	ast_test_validate(test, extra != NULL); \
+	APPEND_EVENT(channel, AST_CEL_HANGUP, NULL, extra, NULL); \
 	} while (0)
 
 static int append_expected_event(
@@ -1445,6 +1450,55 @@
 	HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
 	HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL, "");
 	HANGUP_CHANNEL(chan_eve, AST_CAUSE_NORMAL, "");
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(test_cel_dial_pickup)
+{
+	RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
+	RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
+	struct ast_party_caller caller = ALICE_CALLERID;
+	struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = TEST_CATEGORY;
+		info->summary = "Test call pickup";
+		info->description =
+			"Test CEL records for a call that is\n"
+			"inbound to Asterisk, executes some dialplan, and\n"
+			"is picked up.\n";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	CREATE_ALICE_CHANNEL(chan_caller, &caller);
+
+	EMULATE_DIAL(chan_caller, CHANNEL_TECH_NAME "/Bob");
+
+	START_DIALED(chan_caller, chan_callee);
+
+	ast_channel_state_set(chan_caller, AST_STATE_RINGING);
+
+	CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller);
+
+	{
+		SCOPED_CHANNELLOCK(lock, chan_callee);
+		APPEND_EVENT(chan_callee, AST_CEL_PICKUP, NULL, NULL, ast_channel_name(chan_charlie));
+		ast_test_validate(test, 0 == ast_do_pickup(chan_charlie, chan_callee));
+	}
+
+	/* Hang up the masqueraded zombie */
+	HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL, "");
+
+	ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
+
+	HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL, "ANSWER");
+	HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL, "");
 
 	return AST_TEST_PASS;
 }
@@ -1856,6 +1910,8 @@
 	AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_merge);
 	AST_TEST_UNREGISTER(test_cel_attended_transfer_bridges_link);
 
+	AST_TEST_UNREGISTER(test_cel_dial_pickup);
+
 	ast_channel_unregister(&test_cel_chan_tech);
 
 	ao2_cleanup(cel_test_config);
@@ -1893,6 +1949,7 @@
 	cel_test_config->events |= 1<<AST_CEL_CONF_EXIT;
 	cel_test_config->events |= 1<<AST_CEL_BLINDTRANSFER;
 	cel_test_config->events |= 1<<AST_CEL_ATTENDEDTRANSFER;
+	cel_test_config->events |= 1<<AST_CEL_PICKUP;
 
 	AST_TEST_REGISTER(test_cel_channel_creation);
 	AST_TEST_REGISTER(test_cel_unanswered_inbound_call);
@@ -1921,6 +1978,8 @@
 	AST_TEST_REGISTER(test_cel_attended_transfer_bridges_merge);
 	AST_TEST_REGISTER(test_cel_attended_transfer_bridges_link);
 
+	AST_TEST_REGISTER(test_cel_dial_pickup);
+
 	ast_test_register_init(TEST_CATEGORY, test_cel_init_cb);
 	ast_test_register_cleanup(TEST_CATEGORY, test_cel_cleanup_cb);
 




More information about the svn-commits mailing list