[asterisk-commits] qwell: branch qwell/queue_events r390315 - in /team/qwell/queue_events: apps/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 31 12:33:49 CDT 2013


Author: qwell
Date: Fri May 31 12:33:47 2013
New Revision: 390315

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390315
Log:
Move queue member AMI messages away from ast_manager_publish_event().

Modified:
    team/qwell/queue_events/apps/app_queue.c
    team/qwell/queue_events/main/manager.c

Modified: team/qwell/queue_events/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/queue_events/apps/app_queue.c?view=diff&rev=390315&r1=390314&r2=390315
==============================================================================
--- team/qwell/queue_events/apps/app_queue.c (original)
+++ team/qwell/queue_events/apps/app_queue.c Fri May 31 12:33:47 2013
@@ -1822,9 +1822,23 @@
 struct stasis_message_type *queue_caller_leave_type(void);
 struct stasis_message_type *queue_caller_abandon_type(void);
 
+struct stasis_message_type *queue_member_status_type(void);
+struct stasis_message_type *queue_member_added_type(void);
+struct stasis_message_type *queue_member_removed_type(void);
+struct stasis_message_type *queue_member_pause_type(void);
+struct stasis_message_type *queue_member_penalty_type(void);
+struct stasis_message_type *queue_member_ringinuse_type(void);
+
 STASIS_MESSAGE_TYPE_DEFN(queue_caller_join_type);
 STASIS_MESSAGE_TYPE_DEFN(queue_caller_leave_type);
 STASIS_MESSAGE_TYPE_DEFN(queue_caller_abandon_type);
+
+STASIS_MESSAGE_TYPE_DEFN(queue_member_status_type);
+STASIS_MESSAGE_TYPE_DEFN(queue_member_added_type);
+STASIS_MESSAGE_TYPE_DEFN(queue_member_removed_type);
+STASIS_MESSAGE_TYPE_DEFN(queue_member_pause_type);
+STASIS_MESSAGE_TYPE_DEFN(queue_member_penalty_type);
+STASIS_MESSAGE_TYPE_DEFN(queue_member_ringinuse_type);
 
 static void queue_caller_join_cb(void *data,
 	struct stasis_subscription *sub, struct stasis_topic *topic,
@@ -1914,6 +1928,81 @@
 	}
 
 	stasis_publish(ast_channel_topic(chan), msg);
+}
+
+static void queue_member_manager_event(const char *type, struct stasis_message *message)
+{
+	struct ast_json_payload *payload = stasis_message_data(message);
+	struct ast_json *event = payload->json;
+	RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
+
+	event_string = ast_manager_str_from_json_object(event, NULL);
+	if (!event_string) {
+		return;
+	}
+
+	manager_event(EVENT_FLAG_AGENT, type,
+		"%s", ast_str_buffer(event_string));
+}
+
+static void queue_member_status_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberStatus", message);
+}
+
+static void queue_member_added_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberAdded", message);
+}
+
+static void queue_member_removed_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberRemoved", message);
+}
+
+static void queue_member_pause_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberPause", message);
+}
+
+static void queue_member_penalty_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberPenalty", message);
+}
+
+static void queue_member_ringinuse_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	queue_member_manager_event("QueueMemberRinginuse", message);
+}
+
+static void queue_publish_member_blob(struct stasis_message_type *type, struct ast_json *blob)
+{
+	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+	payload = ast_json_payload_create(blob);
+	if (!payload) {
+		return;
+	}
+
+	msg = stasis_message_create(type, payload);
+	if (!msg) {
+		return;
+	}
+
+	stasis_publish(ast_manager_get_topic(), msg);
 }
 
 static struct ast_json *queue_member_blob_create(struct call_queue *q, struct member *mem)
@@ -2021,7 +2110,7 @@
 		return;
 	}
 
-	ast_manager_publish_event("QueueMemberStatus", EVENT_FLAG_AGENT, queue_member_blob_create(q, m));
+	queue_publish_member_blob(queue_member_status_type(), queue_member_blob_create(q, m));
 }
 
 /*!
@@ -6214,7 +6303,7 @@
 				queue_t_unref(q, "Interface wasn't dynamic, expiring temporary reference");
 				return RES_NOT_DYNAMIC;
 			}
-			ast_manager_publish_event("QueueMemberAdded", EVENT_FLAG_AGENT, queue_member_blob_create(q, mem));
+			queue_publish_member_blob(queue_member_removed_type(), queue_member_blob_create(q, mem));
 
 			member_remove_from_queue(q, mem);
 			ao2_ref(mem, -1);
@@ -6263,7 +6352,7 @@
 			new_member->ringinuse = q->ringinuse;
 			new_member->dynamic = 1;
 			member_add_to_queue(q, new_member);
-			ast_manager_publish_event("QueueMemberAdded", EVENT_FLAG_AGENT, queue_member_blob_create(q, new_member));
+			queue_publish_member_blob(queue_member_added_type(), queue_member_blob_create(q, new_member));
 
 			if (is_member_available(new_member)) {
 				ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Queue:%s_avail", q->name);
@@ -6301,7 +6390,7 @@
 		ast_json_object_set(json_blob, "Reason", ast_json_string_create(reason));
 	}
 
-	ast_manager_publish_event("QueueMemberPause", EVENT_FLAG_AGENT, json_blob);
+	queue_publish_member_blob(queue_member_pause_type(), json_blob);
 
 	return 0;
 }
@@ -6404,7 +6493,7 @@
 		mem->penalty = penalty;
 
 		ast_queue_log(q->name, "NONE", interface, "PENALTY", "%d", penalty);
-		ast_manager_publish_event("QueueMemberPenalty", EVENT_FLAG_AGENT, queue_member_blob_create(q, mem));
+		queue_publish_member_blob(queue_member_penalty_type(), queue_member_blob_create(q, mem));
 		ao2_ref(mem, -1);
 	}
 	ao2_unlock(q);
@@ -6430,7 +6519,7 @@
 		mem->ringinuse = ringinuse;
 
 		ast_queue_log(q->name, "NONE", interface, "RINGINUSE", "%d", ringinuse);
-		ast_manager_publish_event("QueueMemberRinginuse", EVENT_FLAG_AGENT, queue_member_blob_create(q, mem));
+		queue_publish_member_blob(queue_member_ringinuse_type(), queue_member_blob_create(q, mem));
 		ao2_ref(mem, -1);
 	}
 	ao2_unlock(q);
@@ -9873,6 +9962,13 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_leave_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(queue_caller_abandon_type);
 
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_status_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_added_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_removed_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_pause_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_penalty_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(queue_member_ringinuse_type);
+
 	ast_cli_unregister_multiple(cli_queue, ARRAY_LEN(cli_queue));
 	res = ast_manager_unregister("QueueStatus");
 	res |= ast_manager_unregister("Queues");
@@ -10012,6 +10108,13 @@
 	STASIS_MESSAGE_TYPE_INIT(queue_caller_leave_type);
 	STASIS_MESSAGE_TYPE_INIT(queue_caller_abandon_type);
 
+	STASIS_MESSAGE_TYPE_INIT(queue_member_status_type);
+	STASIS_MESSAGE_TYPE_INIT(queue_member_added_type);
+	STASIS_MESSAGE_TYPE_INIT(queue_member_removed_type);
+	STASIS_MESSAGE_TYPE_INIT(queue_member_pause_type);
+	STASIS_MESSAGE_TYPE_INIT(queue_member_penalty_type);
+	STASIS_MESSAGE_TYPE_INIT(queue_member_ringinuse_type);
+
 	stasis_message_router_add(message_router,
 				  queue_caller_join_type(),
 				  queue_caller_join_cb,
@@ -10025,6 +10128,36 @@
 	stasis_message_router_add(message_router,
 				  queue_caller_abandon_type(),
 				  queue_caller_abandon_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_status_type(),
+				  queue_member_status_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_added_type(),
+				  queue_member_added_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_removed_type(),
+				  queue_member_removed_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_pause_type(),
+				  queue_member_pause_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_penalty_type(),
+				  queue_member_penalty_cb,
+				  NULL);
+
+	stasis_message_router_add(message_router,
+				  queue_member_ringinuse_type(),
+				  queue_member_ringinuse_cb,
 				  NULL);
 
 	ast_extension_state_add(NULL, NULL, extension_state_cb, NULL);

Modified: team/qwell/queue_events/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/queue_events/main/manager.c?view=diff&rev=390315&r1=390314&r2=390315
==============================================================================
--- team/qwell/queue_events/main/manager.c (original)
+++ team/qwell/queue_events/main/manager.c Fri May 31 12:33:47 2013
@@ -1285,7 +1285,24 @@
 		if (exclusion_cb && exclusion_cb(key)) {
 			continue;
 		}
-		ast_str_append(&output_str, 0, "%s: %s\r\n", key, ast_json_string_get(value));
+		switch (ast_json_typeof(value)) {
+		case AST_JSON_STRING:
+			ast_str_append(&output_str, 0, "%s: %s\r\n", key, ast_json_string_get(value));
+			break;
+		case AST_JSON_INTEGER:
+			ast_str_append(&output_str, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
+			break;
+		case AST_JSON_TRUE:
+			ast_str_append(&output_str, 0, "%s: True\r\n", key);
+			break;
+		case AST_JSON_FALSE:
+			ast_str_append(&output_str, 0, "%s: False\r\n", key);
+			break;
+		default:
+			ast_str_append(&output_str, 0, "%s: \r\n", key);
+			break;
+		}
+
 		if (!output_str) {
 			return NULL;
 		}




More information about the asterisk-commits mailing list