[asterisk-commits] mmichelson: branch mmichelson/queue_bugbug r394790 - in /team/mmichelson/queu...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 19 09:37:35 CDT 2013


Author: mmichelson
Date: Fri Jul 19 09:37:31 2013
New Revision: 394790

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394790
Log:
Commit some progress.

This contains two things
1) A bunch of debugging that will eventually be removed due to some
local optimization problems I encountered.
2) Handling for agent login and logoff events.


Modified:
    team/mmichelson/queue_bugbug/apps/app_queue.c
    team/mmichelson/queue_bugbug/main/bridging.c
    team/mmichelson/queue_bugbug/main/core_local.c

Modified: team/mmichelson/queue_bugbug/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/queue_bugbug/apps/app_queue.c?view=diff&rev=394790&r1=394789&r2=394790
==============================================================================
--- team/mmichelson/queue_bugbug/apps/app_queue.c (original)
+++ team/mmichelson/queue_bugbug/apps/app_queue.c Fri Jul 19 09:37:31 2013
@@ -1920,6 +1920,12 @@
 	if (!payload) {
 		return;
 	}
+	if (!caller_snapshot) {
+		ast_log(LOG_NOTICE, "I'm sending a NULL CALLER snapshot\n");
+	} 
+	if (!agent_snapshot) {
+		ast_log(LOG_NOTICE, "I'm sending a NULL AGENT snapshot\n");
+	}
 
 	ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
 	ast_multi_channel_blob_add_channel(payload, "agent", agent_snapshot);
@@ -5142,6 +5148,29 @@
 			queue_agent_complete_type(), blob);
 }
 
+static void queue_agent_cb(void *userdata, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *msg)
+{
+	struct ast_channel_blob *agent_blob;
+
+	if (stasis_subscription_final_message(sub, msg)) {
+		return;
+	}
+
+	agent_blob = stasis_message_data(msg);
+
+	if (ast_channel_agent_login_type() == stasis_message_type(msg)) {
+		ast_queue_log("NONE", agent_blob->snapshot->uniqueid,
+			ast_json_string_get(ast_json_object_get(agent_blob->blob, "agent")),
+			"AGENTLOGIN", "%s", agent_blob->snapshot->name);
+	} else if (ast_channel_agent_logoff_type() == stasis_message_type(msg)) {
+		ast_queue_log("NONE", agent_blob->snapshot->uniqueid,
+			ast_json_string_get(ast_json_object_get(agent_blob->blob, "agent")),
+			"AGENTLOGOFF", "%s|%ld", agent_blob->snapshot->name,
+			(long) ast_json_integer_get(ast_json_object_get(agent_blob->blob, "logintime")));
+	}
+}
+
 struct local_optimization {
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(dest_bridge_uniqueid);
@@ -5212,7 +5241,9 @@
 	}
 
 	ast_string_field_set(queue_data, caller_uniqueid, ast_channel_uniqueid(qe->chan));
+	ast_log(LOG_NOTICE, "Initial caller uniqueid is %s\n", queue_data->caller_uniqueid);
 	ast_string_field_set(queue_data, agent_uniqueid, ast_channel_uniqueid(peer));
+	ast_log(LOG_NOTICE, "Initial agent uniqueid is %s\n", queue_data->agent_uniqueid);
 	queue_data->queue = queue_ref(qe->parent);
 	queue_data->starttime = starttime;
 	queue_data->holdstart = holdstart;
@@ -5286,6 +5317,7 @@
 		RAII_VAR(struct ast_channel_snapshot *, caller, NULL, ao2_cleanup);
 		RAII_VAR(struct ast_channel_snapshot *, agent, NULL, ao2_cleanup);
 
+		ast_log(LOG_NOTICE, "Getting a transfer event...\n");
 		/* BUGBUG Once atxfer_features is merged, we need to also return when
 		 * atxfer_msg->dest == AST_ATTENDED_TRANSFER_THREEWAY
 		 */
@@ -5294,11 +5326,16 @@
 		}
 
 		ao2_lock(queue_data);
-		if (ast_strlen_zero(queue_data->bridge_uniqueid) ||
-				((atxfer_msg->to_transferee.bridge_snapshot && strcmp(queue_data->bridge_uniqueid,
+		ast_log(LOG_NOTICE, "queue bridge id is %s\n", queue_data->bridge_uniqueid);
+		ast_log(LOG_NOTICE, "to_transferee bridge id is %s\n", atxfer_msg->to_transferee.bridge_snapshot ?
+				atxfer_msg->to_transferee.bridge_snapshot->uniqueid : "NULL");
+		ast_log(LOG_NOTICE, "to_transfer_target bridge id is %s\n", atxfer_msg->to_transfer_target.bridge_snapshot ?
+				atxfer_msg->to_transfer_target.bridge_snapshot->uniqueid : "NULL");
+
+		if ((!atxfer_msg->to_transferee.bridge_snapshot || strcmp(queue_data->bridge_uniqueid,
 						atxfer_msg->to_transferee.bridge_snapshot->uniqueid)) &&
-				 (atxfer_msg->to_transfer_target.bridge_snapshot && strcmp(queue_data->bridge_uniqueid,
-					 atxfer_msg->to_transfer_target.bridge_snapshot->uniqueid)))) {
+				 (!atxfer_msg->to_transfer_target.bridge_snapshot || strcmp(queue_data->bridge_uniqueid,
+					 atxfer_msg->to_transfer_target.bridge_snapshot->uniqueid))) {
 			ao2_unlock(queue_data);
 			return;
 		}
@@ -5349,6 +5386,8 @@
 
 	dest = ast_json_integer_get(ast_json_object_get(ast_multi_channel_blob_get_json(optimization_blob), "dest"));
 
+	ast_log(LOG_NOTICE, "dest is %s\n", dest == AST_UNREAL_OWNER ? "OWNER" : "CHAN");
+
 	ast_log(LOG_NOTICE, "Destination bridge is %s\n",
 			dest == AST_UNREAL_OWNER ? local_one->bridgeid : local_two->bridgeid);
 
@@ -5399,8 +5438,12 @@
 
 	ast_string_field_set(queue_data, bridge_uniqueid, optimization->dest_bridge_uniqueid);
 	if (is_caller) {
+		ast_log(LOG_NOTICE, "Changing caller uniqueid from %s to %s\n",
+				queue_data->caller_uniqueid, optimization->source_chan_uniqueid);
 		ast_string_field_set(queue_data, caller_uniqueid, optimization->source_chan_uniqueid);
 	} else {
+		ast_log(LOG_NOTICE, "Changing agent uniqueid from %s to %s\n",
+				queue_data->agent_uniqueid, optimization->source_chan_uniqueid);
 		ast_string_field_set(queue_data, agent_uniqueid, optimization->source_chan_uniqueid);
 	}
 
@@ -9990,6 +10033,8 @@
 static const struct ast_data_entry queue_data_providers[] = {
 	AST_DATA_ENTRY("asterisk/application/queue/list", &queues_data_provider),
 };
+	
+static struct stasis_message_router *agent_router;
 
 static int unload_module(void)
 {
@@ -10016,6 +10061,7 @@
 		stasis_message_router_remove(message_router, queue_agent_dump_type());
 		stasis_message_router_remove(message_router, queue_agent_ringnoanswer_type());
 	}
+	stasis_message_router_unsubscribe_and_join(agent_router);
 
 	STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_join_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_leave_type);
@@ -10093,7 +10139,7 @@
 	int res;
 	struct ast_flags mask = {AST_FLAGS_ALL, };
 	struct ast_config *member_config;
-	struct stasis_message_router *message_router;
+	struct stasis_message_router *manager_router;
 
 	queues = ao2_container_alloc(MAX_QUEUE_BUCKETS, queue_hash_cb, queue_cmp_cb);
 
@@ -10164,8 +10210,13 @@
 		res = -1;
 	}
 
-	message_router = ast_manager_get_message_router();
-	if (!message_router) {
+	manager_router = ast_manager_get_message_router();
+	if (!manager_router) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	agent_router = stasis_message_router_create(ast_channel_topic_all());
+	if (!agent_router) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
@@ -10186,75 +10237,85 @@
 	STASIS_MESSAGE_TYPE_INIT(queue_agent_dump_type);
 	STASIS_MESSAGE_TYPE_INIT(queue_agent_ringnoanswer_type);
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_caller_join_type(),
 				  queue_channel_manager_event,
 				  "QueueCallerJoin");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_caller_leave_type(),
 				  queue_channel_manager_event,
 				  "QueueCallerLeave");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_caller_abandon_type(),
 				  queue_channel_manager_event,
 				  "QueueCallerAbandon");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_status_type(),
 				  queue_member_manager_event,
 				  "QueueMemberStatus");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_added_type(),
 				  queue_member_manager_event,
 				  "QueueMemberAdded");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_removed_type(),
 				  queue_member_manager_event,
 				  "QueueMemberRemoved");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_pause_type(),
 				  queue_member_manager_event,
 				  "QueueMemberPause");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_penalty_type(),
 				  queue_member_manager_event,
 				  "QueueMemberPenalty");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_member_ringinuse_type(),
 				  queue_member_manager_event,
 				  "QueueMemberRinginuse");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_agent_called_type(),
 				  queue_multi_channel_manager_event,
 				  "AgentCalled");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_agent_connect_type(),
 				  queue_multi_channel_manager_event,
 				  "AgentConnect");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_agent_complete_type(),
 				  queue_multi_channel_manager_event,
 				  "AgentComplete");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_agent_dump_type(),
 				  queue_multi_channel_manager_event,
 				  "AgentDump");
 
-	stasis_message_router_add(message_router,
+	stasis_message_router_add(manager_router,
 				  queue_agent_ringnoanswer_type(),
 				  queue_multi_channel_manager_event,
 				  "AgentRingNoAnswer");
+
+	stasis_message_router_add(agent_router,
+			ast_channel_agent_login_type(),
+			queue_agent_cb,
+			NULL);
+
+	stasis_message_router_add(agent_router,
+			ast_channel_agent_logoff_type(),
+			queue_agent_cb,
+			NULL);
 
 	ast_extension_state_add(NULL, NULL, extension_state_cb, NULL);
 

Modified: team/mmichelson/queue_bugbug/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/queue_bugbug/main/bridging.c?view=diff&rev=394790&r1=394789&r2=394790
==============================================================================
--- team/mmichelson/queue_bugbug/main/bridging.c (original)
+++ team/mmichelson/queue_bugbug/main/bridging.c Fri Jul 19 09:37:31 2013
@@ -4907,6 +4907,16 @@
  * write it into the bridge yet because optimization has the
  * bridge locked.
  */
+
+	ast_log(LOG_NOTICE, "Optimization bridge dump\n");
+	ast_log(LOG_NOTICE, "dst_channel is %s\n", ast_channel_name(dst_bridge_channel->chan));
+	ast_log(LOG_NOTICE, "src_channel is %s\n", ast_channel_name(src_bridge_channel->chan));
+	ast_log(LOG_NOTICE, "pvt->owner is %s\n", ast_channel_name(pvt->owner));
+	ast_log(LOG_NOTICE, "pvt->chan is %s\n", ast_channel_name(pvt->chan));
+	ast_log(LOG_NOTICE, "dst_bridge is %s\n", dst_bridge->uniqueid);
+	ast_log(LOG_NOTICE, "pvt->owner bridge is %s\n", ast_channel_internal_bridge(pvt->owner)->uniqueid);
+	ast_log(LOG_NOTICE, "pvt->chan bridge is %s\n", ast_channel_internal_bridge(pvt->chan)->uniqueid);
+
 	other = ast_bridge_channel_peer(src_bridge_channel);
 	if (other && other->state == AST_BRIDGE_CHANNEL_STATE_WAIT) {
 		unsigned int id = ast_atomic_fetchadd_int((int *) &optimization_id, +1);

Modified: team/mmichelson/queue_bugbug/main/core_local.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/queue_bugbug/main/core_local.c?view=diff&rev=394790&r1=394789&r2=394790
==============================================================================
--- team/mmichelson/queue_bugbug/main/core_local.c (original)
+++ team/mmichelson/queue_bugbug/main/core_local.c Fri Jul 19 09:37:31 2013
@@ -385,14 +385,9 @@
 		struct ast_json *json_object)
 {
 	struct ast_multi_channel_blob *payload;
-	RAII_VAR(struct ast_json *, blob, ast_json_null(), ast_json_unref);
 	RAII_VAR(struct ast_channel_snapshot *, local_one_snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_channel_snapshot *, local_two_snapshot, NULL, ao2_cleanup);
 
-	if (!blob) {
-		return NULL;
-	}
-
 	local_one_snapshot = ast_channel_snapshot_create(p->base.owner);
 	if (!local_one_snapshot) {
 		return NULL;
@@ -403,7 +398,7 @@
 		return NULL;
 	}
 
-	payload = ast_multi_channel_blob_create(blob);
+	payload = ast_multi_channel_blob_create(json_object);
 	if (!payload) {
 		return NULL;
 	}
@@ -417,10 +412,12 @@
 static void local_optimization_started_cb(struct ast_unreal_pvt *base, struct ast_channel *source,
 		enum ast_unreal_channel_indicator dest, unsigned int id)
 {
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, json_object, ast_json_null(), ast_json_unref);
 	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct local_pvt *p = (struct local_pvt *)base;
+
+	ast_log(LOG_NOTICE, "Publishing dest of %s\n", dest == AST_UNREAL_OWNER ? "OWNER" : "CHAN");
 
 	json_object = ast_json_pack("{s: i, s: i}",
 			"dest", dest, "id", id);
@@ -452,7 +449,7 @@
 /*! \brief Callback for \ref ast_unreal_pvt_callbacks \ref optimization_finished_cb */
 static void local_optimization_finished_cb(struct ast_unreal_pvt *base, int success, unsigned int id)
 {
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, json_object, ast_json_null(), ast_json_unref);
 	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct local_pvt *p = (struct local_pvt *)base;




More information about the asterisk-commits mailing list