[asterisk-commits] eliel: branch group/data_api_gsoc2009 r207349 - in /team/group/data_api_gsoc2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 18 16:23:47 CDT 2009


Author: eliel
Date: Sat Jul 18 16:23:41 2009
New Revision: 207349

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=207349
Log:
Use the data api search mechanism when running the 'queue show' command if an
argument is specified instead of getting every queue and parsing only the needed
nodes.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/include/asterisk/data.h

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=207349&r1=207348&r2=207349
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Sat Jul 18 16:23:41 2009
@@ -6301,10 +6301,11 @@
 /*! \brief direct ouput to manager or cli with proper terminator */
 static void do_print(struct mansession *s, int fd, const char *str)
 {
-	if (s)
+	if (s) {
 		astman_append(s, "%s\r\n", str);
-	else
+	} else {
 		ast_cli(fd, "%s\n", str);
+	}
 }
 
 /*! 
@@ -6315,7 +6316,7 @@
 */
 static char *__queues_show(struct mansession *s, int fd, int argc, const char * const *argv)
 {
-	struct ast_str *out = ast_str_alloca(240);
+	struct ast_str *out = ast_str_alloca(240), *search = NULL;
 	time_t now = time(NULL);
 	struct ast_data *queues, *queue, *member, *caller;
 	struct ast_data_iterator *iq, *im, *ic;
@@ -6325,17 +6326,27 @@
 	float sl;
 	int callscompleted, has_members, has_callers, penalty, calls;
 	const char *name, *membername, *interface;
+	int found = 0;
 
 	if (argc != 2 && argc != 3) {
 		return CLI_SHOWUSAGE;
 	}
 
 	if (argc == 3)	{ /* specific queue */
+		search = ast_str_create(64);
+		if (search) {
+			ast_str_set(&search, 0, "queues/queue/name=%s", argv[2]);
+			query.search = ast_str_buffer(search);
+		}
 	}
 
 	queues = ast_data_get(&query);
 	if (!queues) {
 		return CLI_FAILURE;
+	}
+
+	if (search) {
+		ast_free(search);
 	}
 
 	iq = ast_data_iterator_init(queues, "queue");
@@ -6350,11 +6361,10 @@
 	}
 
 	while ((queue = ast_data_iterator_next(iq))) {
+		found++;
+
 		/* print queue statistics. */
 		name = ast_data_retrieve_string(queue, "name");
-		if (argc == 3 && strcasecmp(name, argv[2])) {
-			continue;
-		}
 
 		ast_str_set(&out, 0, "%-12.12s has %d calls (max ", name,
 			ast_data_retrieve_int(queue, "count"));
@@ -6448,31 +6458,15 @@
 	}
 	ast_data_iterator_end(iq);
 
-#if 0
-			struct queue_ent *qe;
-			int pos = 1;
-
-			do_print(s, fd, "   Callers: ");
-			for (qe = q->head; qe; qe = qe->next) {
-				ast_str_set(&out, 0, "      %d. %s (wait: %ld:%2.2ld, prio: %d)",
-					pos++, qe->chan->name, (long) (now - qe->start) / 60,
-					(long) (now - qe->start) % 60, qe->prio);
-				do_print(s, fd, ast_str_buffer(out));
-			}
-		}
-		do_print(s, fd, "");	/* blank line between entries */
-		ao2_unlock(q);
-		queue_unref(q); /* Unref the iterator's reference */
-	}
-	ao2_unlock(queues);
 	if (!found) {
-		if (argc == 3)
+		if (argc == 3) {
 			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
-		else
+		} else {
 			ast_str_set(&out, 0, "No queues.");
+		}
 		do_print(s, fd, ast_str_buffer(out));
 	}
-#endif
+
 	return CLI_SUCCESS;
 }
 
@@ -7543,7 +7537,7 @@
 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 = 1;
+	int member_added = 1, member_notmatch = 0, caller_notmatch = 0;
 	struct ao2_iterator im;
 	struct member *member;
 	struct queue_ent *qe;
@@ -7551,7 +7545,7 @@
 	struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
 
 	/* compare the search pattern. */
-	if (ast_data_search_cmp_structure(search, call_queue, queue, "queues/queue")) {
+	if (ast_data_search_cmp_structure(search, call_queue, queue, "queue")) {
 		/* this doesn't match! continue! */
 		return;
 	}
@@ -7563,8 +7557,9 @@
 		while ((member = ao2_iterator_next(&im))) {
 			/* compare the member structure. */
 			if (ast_data_search_cmp_structure(search, member, member,
-						"queues/queue/members/member")) {
+						"queue/members/member")) {
 				ao2_ref(member, -1);
+				member_notmatch = 1;
 				continue;
 			}
 
@@ -7601,6 +7596,13 @@
 	/* include the callers inside the result. */
 	if (queue->head) {
 		for (qe = queue->head; qe; qe = qe->next) {
+			/* compare the member structure. */
+			if (ast_data_search_cmp_structure(search, queue_ent, qe,
+						"queue/callers/caller")) {
+				caller_notmatch = 1;
+				continue;
+			}
+
 			if (!data_queue) {
 				data_queue = ast_data_add_node(data_root, "queue");
 				if (!data_queue) {
@@ -7633,7 +7635,13 @@
 
 	/* if there was a member added to the tree, then added the following
 	 * queue to the tree. */
-	if (member_added) {
+	if (member_added || (!member_notmatch && !caller_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);
 	}
 }

Modified: team/group/data_api_gsoc2009/include/asterisk/data.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/data.h?view=diff&rev=207349&r1=207348&r2=207349
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Sat Jul 18 16:23:41 2009
@@ -146,15 +146,13 @@
 struct ast_data_query {
 	/*! \brief Data query version. */
 	uint32_t version;
-	AST_DECLARE_STRING_FIELDS(
-		/*! \brief Path to the node to retrieve. */
-		AST_STRING_FIELD(path);
-		/*! \brief Filter string, return the internal nodes specified here.
-		 *         Setting it to NULL will return every internal node. */
-		AST_STRING_FIELD(filter);
-		/*! \brief Search condition. */
-		AST_STRING_FIELD(search);
-	);
+	/*! \brief Path to the node to retrieve. */
+	char *path;
+	/*! \brief Filter string, return the internal nodes specified here.
+	 *         Setting it to NULL will return every internal node. */
+	char *filter;
+	/*! \brief Search condition. */
+	char *search;
 };
 
 /*! \brief Map the members of a structure. */




More information about the asterisk-commits mailing list