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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 13 11:11:29 CDT 2009


Author: eliel
Date: Mon Jul 13 11:11:24 2009
New Revision: 206184

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=206184
Log:
Compare a structure in a "atomic" way.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/include/asterisk/data.h
    team/group/data_api_gsoc2009/main/data.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=206184&r1=206183&r2=206184
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Mon Jul 13 11:11:24 2009
@@ -7493,6 +7493,15 @@
 	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;
+		}
+
+
 		data_queue = ast_data_add_node(data_root, "queue");
 		if (!data_queue) {
 			ao2_unlock(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=206184&r1=206183&r2=206184
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Mon Jul 13 11:11:24 2009
@@ -112,9 +112,6 @@
 	ast_data_get_cb get;
 	/*! \brief Data put callback implementation. */
 	ast_data_put_cb put;
-	/*! \brief The tokenizer is used to retrieve from the node generator
-	 *         the list of possible attributes in the search string. */
-	ast_data_tokenizer tokenizer;
 };
 
 /*! \brief This entries are for multiple registers. */
@@ -161,10 +158,10 @@
 };
 
 /* Generate the structure and the functions to access the members of a structure. */
-#define AST_DATA_STRUCTURE(__struct, __name)							\
-	__name(__AST_DATA_MAPPING_FUNCTION);							\
-	struct ast_data_mapping_structure __data_mapping_structure_##__struct[] = {		\
-		__name(__AST_DATA_MAPPING_STRUCTURE)						\
+#define AST_DATA_STRUCTURE(__struct, __name)								\
+	__name(__AST_DATA_MAPPING_FUNCTION);								\
+	static const struct ast_data_mapping_structure __data_mapping_structure_##__struct[] = {	\
+		__name(__AST_DATA_MAPPING_STRUCTURE)							\
 	}
 
 /* Generate the structure to access the members and setup the pointer of the getter. */
@@ -280,10 +277,16 @@
  * \param[in] mapping The structure mapping.
  * \param[in] mapping_len The lenght of the structure mapping.
  * \param[in] structure The structure pointer.
- */
-int ast_data_search_cmp_structure(struct ast_data_search *search,
-	struct ast_data_mapping_structure *mapping, size_t mapping_len,
-	void *structure);
+ * \param[in] structure_name The name of the structure to compare.
+ * \retval 0 If the structure matches.
+ * \retval 1 If the structure doesn't match.
+ */
+int __ast_data_search_cmp_structure(const struct ast_data_search *search,
+	const struct ast_data_mapping_structure *mapping, size_t mapping_len,
+	void *structure, const char *structure_name);
+#define ast_data_search_cmp_structure(search, structure_name, structure, structure_name_cmp)		\
+	__ast_data_search_cmp_structure(search, __data_mapping_structure_##structure_name,		\
+	ARRAY_LEN(__data_mapping_structure_##structure_name), structure, structure_name_cmp)
 
 /*!
  * \brief Retrieve a subtree from the asterisk data API.

Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=206184&r1=206183&r2=206184
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Mon Jul 13 11:11:24 2009
@@ -1023,21 +1023,83 @@
 	return data_search_comparison_result(node_value - value, cmp_type);
 }
 
-int ast_data_search_cmp_structure(struct ast_data_search *search,
-	struct ast_data_mapping_structure *mapping, size_t mapping_len,
-	void *structure)
+/*!
+ * \internal
+ * \brief Get the member pointer, from a mapping structure, based on its name.
+ * \XXX We will need to improve performance here!!.
+ * \retval <0 if the member was not found.
+ * \retval >=0 The member position in the mapping structure.
+ */
+static inline int data_search_mapping_find(const struct ast_data_mapping_structure *mapping,
+	size_t mapping_len,
+	const char *member_name)
+{
+	int i;
+
+	for (i = 0; i < mapping_len; i++) {
+		if (!strcmp(mapping[i].name, member_name)) {
+			return i;
+		}
+	}
+
+	return -1;
+}
+
+int __ast_data_search_cmp_structure(const struct ast_data_search *search,
+	const struct ast_data_mapping_structure *mapping, size_t mapping_len,
+	void *structure, const char *structure_name)
 {
 	struct ao2_iterator i;
-	struct ast_data_search *node;
-
-	i = ao2_iterator_init(search->children, 0);
+	struct ast_data_search *node, *struct_children;
+	int member, notmatch = 0;
+
+	if (!search) {
+		return 0;
+	}
+
+	struct_children = data_search_get_node(search, structure_name);
+	if (!struct_children) {
+		return 0;
+	}
+
+	i = ao2_iterator_init(struct_children->children, 0);
 	while ((node = ao2_iterator_next(&i))) {
-		/* XXX compare every member of the structure */
+		member = data_search_mapping_find(mapping, mapping_len, node->name);
+		if (member < 0) {
+			/* the structure member name doesn't match! */
+			ao2_ref(node, -1);
+			return 1;
+		}
+
+		if (mapping[member].type == AST_DATA_CONTAINER) {
+			/* XXX: Compare the internal structure. */
+			ao2_ref(node, -1);
+			continue;
+		}
+
+		notmatch = 0;
+		switch (mapping[member].type) {
+			case AST_DATA_STRING:
+				notmatch = ast_data_search_cmp_string(struct_children, node->name,
+					mapping[member].get.AST_DATA_STRING(structure));
+				break;
+			case AST_DATA_INTEGER:
+				notmatch = ast_data_search_cmp_int(struct_children, node->name,
+					mapping[member].get.AST_DATA_INTEGER(structure));
+				break;
+			case AST_DATA_BOOLEAN:
+			case AST_DATA_UNSIGNED_INTEGER:
+			case AST_DATA_DOUBLE:
+			case AST_DATA_IPADDR:
+			case AST_DATA_POINTER:
+			case AST_DATA_CONTAINER:
+				break;
+		}
 
 		ao2_ref(node, -1);
 	}
 
-	return 0;
+	return notmatch;
 }
 
 /*!

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=206184&r1=206183&r2=206184
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Mon Jul 13 11:11:24 2009
@@ -215,6 +215,7 @@
 	struct ast_data_query query = {
 		.version = AST_DATA_QUERY_VERSION,
 		.path = "asterisk/application/app_queue",
+		.search = "app_queue/queues/queue/name=cola2"
 	};
 
 	switch (cmd) {




More information about the asterisk-commits mailing list