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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 4 08:12:57 CDT 2009


Author: eliel
Date: Tue Aug  4 08:12:53 2009
New Revision: 210233

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=210233
Log:
Add a test command "data test get <path>" to retrieve every path
from the CLI for testing.

Modified:
    team/group/data_api_gsoc2009/main/data.c
    team/group/data_api_gsoc2009/tests/test_data.c

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=210233&r1=210232&r2=210233
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Tue Aug  4 08:12:53 2009
@@ -578,51 +578,66 @@
 	int i;
 	struct ao2_iterator iter;
 	struct ast_data *node;
-
-	ast_debug(1, "%s (container)\n", root->name);
-	depth = depth + 1;
+	struct ast_str *tabs;
+
+	tabs = ast_str_create(depth * 10 + 1);
+	if (!tabs) {
+		return;
+	}
+	ast_str_reset(tabs);
+	for (i = 0; i < depth; i++) {
+		ast_str_append(&tabs, 0, "\t");
+	}
+
+	ast_debug(1, "%s%s (container)\n", ast_str_buffer(tabs), root->name);
 
 	iter = ao2_iterator_init(root->children, 0);
 	while ((node = ao2_iterator_next(&iter))) {
-		/* XXX compare every member of the structure */
-		for (i = 0; i < depth; i++)
-			ast_debug(1, "\t>> ");
-
-		ast_debug(1, "%s ", node->name);
-
 		switch (root->type) {
 		case AST_DATA_POINTER:
-			ast_debug(1, " (pointer): %p\n", node->payload.ptr);
+			ast_debug(1, "%s%s (pointer): %p\n", ast_str_buffer(tabs),
+				node->name, node->payload.ptr);
 			break;
 		case AST_DATA_STRING:
-			ast_debug(1, " (string)[%u]: \"%s\"",
+			ast_debug(1, "%s%s (string)[%u]: \"%s\"", ast_str_buffer(tabs),
+				node->name,
 				(unsigned int) strlen(node->payload.str),
 				node->payload.str);
 			break;
 		case AST_DATA_CONTAINER:
-			__ast_data_print_debug(node, depth);
+			__ast_data_print_debug(node, depth + 1);
 			break;
 		case AST_DATA_INTEGER:
-			ast_debug(1, " (integer): %d\n", node->payload.sint);
+			ast_debug(1, "%s%s (integer): %d\n", ast_str_buffer(tabs),
+				node->name,
+				node->payload.sint);
 			break;
 		case AST_DATA_UNSIGNED_INTEGER:
-			ast_debug(1, " (unsigned integer): %u\n", node->payload.uint);
+			ast_debug(1, "%s%s (unsigned integer): %u\n", ast_str_buffer(tabs),
+				node->name,
+				node->payload.uint);
 			break;
 		case AST_DATA_DOUBLE:
-			ast_debug(1, " (double): %lf\n", node->payload.dbl);
+			ast_debug(1, "%s%s (double): %lf\n", ast_str_buffer(tabs),
+				node->name,
+				node->payload.dbl);
 			break;
 		case AST_DATA_BOOLEAN:
-			ast_debug(1, " (boolean): %s\n",
+			ast_debug(1, "%s%s (boolean): %s\n", ast_str_buffer(tabs),
+				node->name,
 				((node->payload.boolean) ? "True" : "False"));
 			break;
 		case AST_DATA_IPADDR:
-			ast_debug(1, " (ipaddr): %s\n",
+			ast_debug(1, "%s%s (ipaddr): %s\n", ast_str_buffer(tabs),
+				node->name,
 				ast_inet_ntoa(node->payload.ipaddr));
 			break;
 		}
 
 		ao2_ref(node, -1);
 	}
+
+	ast_free(tabs);
 }
 
 /*!
@@ -631,6 +646,7 @@
  */
 void ast_data_print_debug(const struct ast_data *root)
 {
+	ast_debug(1, "\n");
 	__ast_data_print_debug(root, 0);
 }
 

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=210233&r1=210232&r2=210233
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Tue Aug  4 08:12:53 2009
@@ -195,6 +195,8 @@
 	/* finish the iterator. */
 	ast_cli(a->fd, "Finish iterating...\n");
 	ast_data_iterator_end(i);
+
+	ast_data_print_debug(res);
 
 	ast_data_free(res);
 
@@ -242,10 +244,44 @@
 	return res;
 }
 
+static char *handle_cli_data_get(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_data_query query = { .version = AST_DATA_QUERY_VERSION };
+	struct ast_data *tree;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "data test get";
+		e->usage = "Usage: data test get <path>\n"
+			   "   Dump data to the console\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc != e->args + 1) {
+		return CLI_SHOWUSAGE;
+	}
+
+	query.path = (char *) a->argv[e->args];
+
+	tree = ast_data_get(&query);
+	if (!tree) {
+		return CLI_FAILURE;
+	}
+
+	ast_data_print_debug(tree);
+
+	ast_data_free(tree);
+
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cli_data[] = {
 	AST_CLI_DEFINE(handle_cli_data_get_bench, "Benchmark ast_data get performance"),
 	AST_CLI_DEFINE(handle_cli_data_get_automatic, "Test data get"),
-	AST_CLI_DEFINE(handle_cli_data_get_dump, "Dump test data to xml")
+	AST_CLI_DEFINE(handle_cli_data_get_dump, "Dump test data to xml"),
+	AST_CLI_DEFINE(handle_cli_data_get, "Get data from the tree")
 };
 
 static int unload_module(void)




More information about the asterisk-commits mailing list