[asterisk-commits] eliel: branch group/data_api_gsoc2009 r207359 - /team/group/data_api_gsoc2009...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 20 10:10:31 CDT 2009


Author: eliel
Date: Mon Jul 20 10:10:29 2009
New Revision: 207359

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=207359
Log:
Simplify the app_queue/queues node generator.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c

Modified: team/group/data_api_gsoc2009/apps/app_queue.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/apps/app_queue.c?view=diff&rev=207359&r1=207358&r2=207359
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Mon Jul 20 10:10:29 2009
@@ -7539,12 +7539,11 @@
 static void queues_data_provider_get_helper(const struct ast_data_search *search,
 	struct ast_data *data_root, struct call_queue *queue)
 {
-	int member_added = 0, caller_added = 0;
-	int member_notmatch = 1, caller_notmatch = 1, caller_channel_notmatch = 1;
+	int member_notmatch, caller_notmatch, caller_channel_notmatch;
 	struct ao2_iterator im;
 	struct member *member;
 	struct queue_ent *qe;
-	struct ast_data *data_queue = NULL, *data_members = NULL;
+	struct ast_data *data_queue, *data_members = NULL;
 	struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
 
 	/* compare the search pattern. */
@@ -7554,6 +7553,14 @@
 		return;
 	}
 
+	data_queue = ast_data_add_node(data_root, "queue");
+	if (!data_queue) {
+		return;
+	}
+
+	ast_data_add_structure(call_queue, data_queue, queue);
+
+	member_notmatch = ast_data_search_has_condition(search, "queue/members/member");
 	/* add queue members */
 	im = ao2_iterator_init(queue->members, 0);
 	while ((member = ao2_iterator_next(&im))) {
@@ -7563,14 +7570,6 @@
 			member_notmatch = 0;
 		}
 
-		if (!data_queue) {
-			data_queue = ast_data_add_node(data_root, "queue");
-			if (!data_queue) {
-				ao2_ref(member, -1);
-				continue;
-			}
-		}
-
 		if (!data_members) {
 			data_members = ast_data_add_node(data_queue, "members");
 			if (!data_members) {
@@ -7587,18 +7586,17 @@
 
 		ast_data_add_structure(member, data_member, member);
 
-		member_added++;
-
 		ao2_ref(member, -1);
 	}
 
-	if (!member_added) {
-		/* if there is a condition to match, but this queue has nothing to compare,
-		 * do not return it. */
-		member_notmatch = ast_data_search_has_condition(search,
-			"queue/members/member");
-	}
-
+	if (member_notmatch) {
+		ast_data_remove_node(data_root, data_queue);
+		return;
+	}
+
+	caller_notmatch = ast_data_search_has_condition(search, "queue/callers/caller");
+	caller_channel_notmatch = ast_data_search_has_condition(search,
+		"queue/callers/caller/channel");
 	/* include the callers inside the result. */
 	if (queue->head) {
 		for (qe = queue->head; qe; qe = qe->next) {
@@ -7613,13 +7611,6 @@
 				caller_channel_notmatch = 0;
 			}
 
-			if (!data_queue) {
-				data_queue = ast_data_add_node(data_root, "queue");
-				if (!data_queue) {
-					continue;
-				}
-			}
-
 			if (!data_callers) {
 				data_callers = ast_data_add_node(data_queue, "callers");
 				if (!data_callers) {
@@ -7634,8 +7625,6 @@
 
 			ast_data_add_structure(queue_ent, data_caller, qe);
 
-			caller_added++;
-
 			/* add the caller channel. */
 			data_caller_channel = ast_data_add_node(data_caller, "channel");
 			if (!data_caller_channel) {
@@ -7646,24 +7635,8 @@
 		}
 	}
 
-	if (!caller_added) {
-		/* if there is a condition to match, but this queue has nothing to compare,
-		 * do not return it. */
-		caller_notmatch = ast_data_search_has_condition(search, "queue/callers/caller");
-		caller_channel_notmatch = ast_data_search_has_condition(search, "queue/callers/caller/channel");
-	}
-
-	/* if there was a member added to the tree, then added the following
-	 * queue to the tree. */
-	if (!member_notmatch && !caller_notmatch && !caller_channel_notmatch) {
-		if (!data_queue) {
-			data_queue = ast_data_add_node(data_root, "queue");
-			if (!data_queue) {
-				return;
-			}
-		}
-		ast_data_add_structure(call_queue, data_queue, queue);
-	} else {
+	/* if this queue doesn't match remove the added queue. */
+	if (caller_notmatch || caller_channel_notmatch) {
 		ast_data_remove_node(data_root, data_queue);
 	}
 }




More information about the asterisk-commits mailing list