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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 14 14:14:19 CDT 2009


Author: eliel
Date: Tue Jul 14 14:14:16 2009
New Revision: 206561

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=206561
Log:
Support realtime queues.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/tests/test_data.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=206561&r1=206560&r2=206561
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Tue Jul 14 14:14:16 2009
@@ -7473,6 +7473,75 @@
 
 /*!
  * \internal
+ * \brief Add a queue to the data_root node.
+ * \param[in] search The search tree.
+ * \param[in] data_root The main result node.
+ * \param[in] queue The queue to add.
+ */
+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;
+	struct ao2_iterator im;
+	struct member *member;
+	struct ast_data *data_queue = NULL, *data_members = NULL, *data_member;
+
+	/* compare the search pattern. */
+	if (ast_data_search_cmp_structure(search, call_queue, queue, "queues/queue")) {
+		/* this doesn't match! continue! */
+		return;
+	}
+
+	if (queue->members) {
+		member_added = 0;
+		im = ao2_iterator_init(queue->members, 0);
+		while ((member = ao2_iterator_next(&im))) {
+			/* compare the member structure. */
+			if (ast_data_search_cmp_structure(search, member, member,
+						"queues/queue/members/member")) {
+				ao2_ref(member, -1);
+				continue;
+			}
+
+			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) {
+					ao2_ref(member, -1);
+					continue;
+				}
+			}
+
+			data_member = ast_data_add_node(data_members, "member");
+			if (!data_member) {
+				ao2_ref(member, -1);
+				continue;
+			}
+
+			ast_data_add_structure(member, data_member, member);
+			member_added = 1;
+			ao2_ref(member, -1);
+		}
+	}
+
+	/* if there was a member added to the tree, then added the following
+	 * queue to the tree. */
+	if (member_added) {
+		ast_data_add_structure(call_queue, data_queue, queue);
+	}
+}
+
+/*!
+ * \internal
  * \brief Callback used to generate the queues tree.
  * \param[in] search The search pattern tree.
  * \retval NULL on error.
@@ -7480,81 +7549,38 @@
  */
 static struct ast_data *queues_data_provider_get(const struct ast_data_search *search)
 {
-	struct ao2_iterator i, im;
+	struct ao2_iterator i;
 	struct call_queue *queue;
-	struct member *member;
-	struct ast_data *data_root, *data_queue = NULL, *data_member;
-	struct ast_data *data_members = NULL;
-	int member_added;
+	struct ast_data *data_root;
+	struct ast_config *cfg;
+	char *queuename;
 
 	data_root = ast_data_create("queues");
 	if (!data_root) {
 		return NULL;
 	}
 
+	/* realtime queues. */
+	cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
+	if (cfg) {
+		for (queuename = ast_category_browse(cfg, NULL);
+				!ast_strlen_zero(queuename);
+				queuename = ast_category_browse(cfg, queuename)) {
+			if ((queue = load_realtime_queue(queuename))) {
+				ao2_lock(queue);
+				queues_data_provider_get_helper(search, data_root, queue);
+				ao2_unlock(queue);
+				queue_unref(queue);
+			}
+		}
+		ast_config_destroy(cfg);
+	}
+
+	/* static queues. */
 	i = ao2_iterator_init(queues, 0);
 	while ((queue = ao2_iterator_next(&i))) {
 		ao2_lock(queue);
-
-		/* compare the search pattern. */
-		if (ast_data_search_cmp_structure(search, call_queue, queue,
-			"queues/queue")) {
-			/* this doesn't match! continue! */
-			ao2_unlock(queue);
-			queue_unref(queue);
-			continue;
-		}
-
-		member_added = 1;
-		if (queue->members) {
-			member_added = 0;
-			im = ao2_iterator_init(queue->members, 0);
-			while ((member = ao2_iterator_next(&im))) {
-				/* compare the member structure. */
-				if (ast_data_search_cmp_structure(search, member, member,
-					"queues/queue/members/member")) {
-					ao2_ref(member, -1);
-					continue;
-				}
-
-				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) {
-						ao2_ref(member, -1);
-						continue;
-					}
-				}
-
-				data_member = ast_data_add_node(data_members, "member");
-				if (!data_member) {
-					ao2_ref(member, -1);
-					continue;
-				}
-
-				ast_data_add_structure(member, data_member, member);
-				member_added = 1;
-				ao2_ref(member, -1);
-			}
-		}
-		/* if there was a member added to the tree, then added the following
-		 * queue to the tree. */
-		if (member_added) {
-			ast_data_add_structure(call_queue, data_queue, queue);
-		}
-
-		data_queue = NULL;
-		data_members = NULL;
-
+		queues_data_provider_get_helper(search, data_root, queue);
 		ao2_unlock(queue);
 		queue_unref(queue);
 	}

Modified: team/group/data_api_gsoc2009/tests/test_data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/tests/test_data.c?view=diff&rev=206561&r1=206560&r2=206561
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Jul 14 14:14:16 2009
@@ -215,7 +215,7 @@
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
 		.path = "asterisk/application/app_queue",
-		.search = "app_queue/queues/queue/members/member/interface=Agent/1000,app_queue/queues/queue/name=cola1",
+		.search = "app_queue/queues/queue/members/member/interface=Agent/1000",
 	};
 
 	switch (cmd) {




More information about the asterisk-commits mailing list