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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 10 14:11:17 CDT 2009


Author: eliel
Date: Fri Jul 10 14:11:14 2009
New Revision: 205943

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205943
Log:
Introduce the structure manipulation functions for adding nodes in a massive 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

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=205943&r1=205942&r2=205943
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Fri Jul 10 14:11:14 2009
@@ -7389,15 +7389,40 @@
 	AST_CLI_DEFINE(handle_queue_reset, "Reset statistics for a queue"),
 };
 
+static const struct ast_data_structure_mapping data_structure_call_queue[] =
+{
+	AST_DATA_STRUCTURE_MEMBER(name,	AST_DATA_STRING, struct call_queue),
+	AST_DATA_STRUCTURE_MEMBER(moh, AST_DATA_STRING, struct call_queue),
+	AST_DATA_STRUCTURE_MEMBER(announce, AST_DATA_STRING, struct call_queue),
+	AST_DATA_STRUCTURE_MEMBER(context, AST_DATA_STRING, struct call_queue),
+	AST_DATA_STRUCTURE_MEMBER(membermacro, AST_DATA_STRING, struct call_queue),
+	AST_DATA_STRUCTURE_MEMBER(wrapuptime, AST_DATA_INTEGER, struct call_queue),
+};
+
+static const struct ast_data_structure_mapping data_structure_member[] =
+{
+	AST_DATA_STRUCTURE_MEMBER_ADDITIONAL(interface, AST_DATA_CHAR, struct member, 80),
+	AST_DATA_STRUCTURE_MEMBER_ADDITIONAL(state_interface, AST_DATA_CHAR, struct member, 80),
+	AST_DATA_STRUCTURE_MEMBER_ADDITIONAL(membername, AST_DATA_CHAR, struct member, 80),
+	AST_DATA_STRUCTURE_MEMBER(penalty, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(calls, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(dynamic, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(realtime, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(status, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(paused, AST_DATA_INTEGER, struct member),
+	AST_DATA_STRUCTURE_MEMBER(rt_uniqueid, AST_DATA_STRING, struct member),
+};
+
 /*!
  * \internal
  * \brief XXX-document this.
  */
 static struct ast_data *queues_data_provider_get(const struct ast_data_search *search)
 {
-	struct ao2_iterator i;
+	struct ao2_iterator i, im;
 	struct call_queue *queue;
-	struct ast_data *res, *q;
+	struct member *member;
+	struct ast_data *res, *q, *m;
 
 	res = ast_data_create("queues");
 	if (!res) {
@@ -7415,7 +7440,24 @@
 			continue;
 		}
 
-		ast_data_add_str(q, "name", queue->name);
+		ast_data_add_structure(q, data_structure_call_queue,
+			ARRAY_LEN(data_structure_call_queue), queue);
+
+		if (queue->members) {
+			m = ast_data_add_node(res, "members");
+			if (!m) {
+				ao2_unlock(queue);
+				queue_unref(queue);
+				continue;
+			}
+
+			im = ao2_iterator_init(queue->members, 0);
+			while ((member = ao2_iterator_next(&im))) {
+				ast_data_add_structure(m, data_structure_member,
+					ARRAY_LEN(data_structure_member), member);
+				ao2_ref(member, -1);
+			}
+		}
 
 		ao2_unlock(queue);
 		queue_unref(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=205943&r1=205942&r2=205943
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Fri Jul 10 14:11:14 2009
@@ -84,6 +84,7 @@
 	AST_DATA_DOUBLE,
 	AST_DATA_BOOLEAN,
 	AST_DATA_STRING,
+	AST_DATA_CHAR,
 	AST_DATA_IPADDR,
 	AST_DATA_POINTER
 };
@@ -143,6 +144,23 @@
 	);
 };
 
+#define AST_DATA_STRUCTURE_MEMBER(__name, __type, __structure) { .name = #__name, 	\
+	.offset = offsetof(__structure, __name), .type = __type }
+#define AST_DATA_STRUCTURE_MEMBER_ADDITIONAL(__name, __type, __structure, __additional) \
+	{ .name = #__name, .offset = offsetof(__structure, __name), 			\
+	.type = __type, .additional = (void *)__additional }
+
+struct ast_data_structure_mapping {
+	/*! \brief The name of the structure member. */
+	const char *name;
+	/*! \brief The offset of the member inside the structure. */
+	int offset;
+	/*! \brief The type of the member. */
+	enum ast_data_type type;
+	/*! \brief Additional type specification. (depends of the type) */
+	void *additional;
+};
+
 /*!
  * \brief Register a data provider.
  * \param[in] path The path of the node to register.
@@ -190,7 +208,7 @@
 #define ast_data_search_cmp(_root, _name, _value) ({					\
 	int __ret = 0;									\
 	if (__builtin_types_compatible_p(typeof(_value), int))				\
-		__ret  = ast_data_search_cmp_sint(_root, _name, (void *) _value);	\
+		__ret  = ast_data_search_cmp_int(_root, _name, (void *) _value);	\
 	else if (__builtin_types_compatible_p(typeof(_value), char[]))			\
 		__ret = ast_data_search_cmp_string(_root, _name, (void *) _value);	\
 	else										\
@@ -222,7 +240,18 @@
  * \param[in] value The value to compare.
  * \returns The strcmp return value.
  */
-int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, void *value);
+int ast_data_search_cmp_int(const struct ast_data_search *root, const char *name, void *value);
+
+/*!
+ * \brief Based on a search tree, evaluate every member of a structure against it.
+ * \param[in] search The search tree.
+ * \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_structure_mapping *mapping, size_t mapping_len,
+	void *structure);
 
 /*!
  * \brief Retrieve a subtree from the asterisk data API.
@@ -340,6 +369,14 @@
 	unsigned int boolean);
 
 /*!
+ * \brief
+ * XXX-document this
+ */
+int ast_data_add_structure(struct ast_data *root,
+	const struct ast_data_structure_mapping *mapping, size_t mapping_len,
+	void *structure);
+
+/*!
  * \brief Initialize an iterator.
  * \param[in] tree The returned tree by a call to ast_data_get.
  * \param[in] elements Which elements to iterate through.

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=205943&r1=205942&r2=205943
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Fri Jul 10 14:11:14 2009
@@ -764,7 +764,7 @@
 	int i;
 	struct ast_data_search *root, *child;
 	enum data_search_comparison cmp_type;
-	ssize_t search_string_len;
+	size_t search_string_len;
 
 	if (!search_string) {
 		ast_log(LOG_ERROR, "You must pass a valid search string.\n");
@@ -941,7 +941,7 @@
 	return data_search_comparison_result(ret, cmp_type);
 }
 
-int ast_data_search_cmp_sint(const struct ast_data_search *root, const char *name, void *value)
+int ast_data_search_cmp_int(const struct ast_data_search *root, const char *name, void *value)
 {
 	struct ast_data_search *child;
 	int node_value;
@@ -958,6 +958,23 @@
 	ao2_ref(child, -1);
 
 	return data_search_comparison_result(node_value - (int)value, cmp_type);
+}
+
+int ast_data_search_cmp_structure(struct ast_data_search *search,
+	struct ast_data_structure_mapping *mapping, size_t mapping_len,
+	void *structure)
+{
+	struct ao2_iterator i;
+	struct ast_data_search *node;
+
+	i = ao2_iterator_init(search->children, 0);
+	while ((node = ao2_iterator_next(&i))) {
+		/* XXX compare every member of the structure */
+
+		ao2_ref(node, -1);
+	}
+
+	return 0;
 }
 
 /*!
@@ -981,6 +998,7 @@
 	case AST_DATA_DOUBLE:
 	case AST_DATA_BOOLEAN:
 	case AST_DATA_IPADDR:
+	case AST_DATA_CHAR:
 		break;
 	}
 }
@@ -1454,6 +1472,9 @@
 			} else {
 				ast_xml_set_text(child_xml, "false");
 			}
+			break;
+		case AST_DATA_CHAR:
+			ast_xml_set_text(child_xml, node->payload.str);
 			break;
 		case AST_DATA_POINTER:
 			break;
@@ -1615,6 +1636,60 @@
 	return __ast_data_add(root, childname, AST_DATA_STRING, name);
 }
 
+int ast_data_add_structure(struct ast_data *root,
+	const struct ast_data_structure_mapping *mapping, size_t mapping_len,
+	void *structure)
+{
+	int i, a;
+	struct ast_str *tmp;
+
+	for (i = 0; i < mapping_len; i++) {
+		switch (mapping[i].type) {
+		case AST_DATA_INTEGER:
+			ast_data_add_int(root, mapping[i].name,
+				*((int *)(structure + mapping[i].offset)));
+			break;
+		case AST_DATA_UNSIGNED_INTEGER:
+			ast_data_add_uint(root, mapping[i].name,
+				*((unsigned int *)(structure + mapping[i].offset)));
+			break;
+		case AST_DATA_DOUBLE:
+			ast_data_add_dbl(root, mapping[i].name,
+				*((double *)(structure + mapping[i].offset)));
+			break;
+		case AST_DATA_BOOLEAN:
+			ast_data_add_bool(root, mapping[i].name,
+				*((unsigned int *)(structure + mapping[i].offset)));
+			break;
+		case AST_DATA_STRING:
+			ast_data_add_str(root, mapping[i].name,
+				*((const char **)(structure + mapping[i].offset)));
+			break;
+		case AST_DATA_CHAR:
+			tmp = ast_str_create((int) mapping[i].additional + 1);
+			if (!tmp) {
+				break;
+			}
+			for (a = 0; a < (int) mapping[i].additional; a++) {
+				ast_str_append(&tmp, 0, "%c",
+					*((const char *)(structure + mapping[i].offset + a)));
+			}
+			ast_data_add_str(root, mapping[i].name, ast_str_buffer(tmp));
+			ast_free(tmp);
+			break;
+		case AST_DATA_CONTAINER:
+			break;
+		case AST_DATA_IPADDR:
+			ast_data_add_str(root, mapping[i].name,
+				ast_inet_ntoa(*((struct in_addr *)(structure + mapping[i].offset))));
+			break;
+		case AST_DATA_POINTER:
+			break;
+		}
+	}
+	return 0;
+}
+
 struct ast_data *ast_data_create(const char *name)
 {
 	if (ast_strlen_zero(name)) {




More information about the asterisk-commits mailing list