[asterisk-commits] russell: branch russell/data_retrieval r111941 - in /team/russell/data_retrie...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 28 18:50:59 CDT 2008


Author: russell
Date: Fri Mar 28 18:50:58 2008
New Revision: 111941

URL: http://svn.digium.com/view/asterisk?view=rev&rev=111941
Log:
Tweak the API a bit, and add a "test_provider" to verify that my CLI logic for
printing out multiple tiered data was correct

Modified:
    team/russell/data_retrieval/channels/chan_sip.c
    team/russell/data_retrieval/include/asterisk/data.h
    team/russell/data_retrieval/main/data.c

Modified: team/russell/data_retrieval/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/channels/chan_sip.c?view=diff&rev=111941&r1=111940&r2=111941
==============================================================================
--- team/russell/data_retrieval/channels/chan_sip.c (original)
+++ team/russell/data_retrieval/channels/chan_sip.c Fri Mar 28 18:50:58 2008
@@ -21440,29 +21440,23 @@
 	AST_CLI_DEFINE(sip_show_tcp, "List TCP Connections")
 };
 
-static struct ast_data_node *sip_settings_data(struct ast_data_provider *data_prov,
+static struct ast_data_node *sip_settings_data(const struct ast_data_provider *data_prov,
 	const struct ast_data_node *query)
 {
 	struct ast_data_node *settings_node;
-	int res = 0;
 
 	if (!(settings_node = ast_data_node_new("sip_settings"))) {
 		return NULL;
 	}
 
-	res |= ast_data_node_add_child_str(settings_node, "bindaddr", ast_inet_ntoa(bindaddr.sin_addr));
-	res |= ast_data_node_add_child_uint(settings_node, "bindport", (uint32_t) ntohs(bindaddr.sin_port));
-	res |= ast_data_node_add_child_bool(settings_node, "videosupport",
+	ast_data_node_add_child_str(settings_node, "bindaddr", ast_inet_ntoa(bindaddr.sin_addr));
+	ast_data_node_add_child_uint(settings_node, "bindport", (uint32_t) ntohs(bindaddr.sin_port));
+	ast_data_node_add_child_bool(settings_node, "videosupport",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT));
-	res |= ast_data_node_add_child_bool(settings_node, "textsupport",
+	ast_data_node_add_child_bool(settings_node, "textsupport",
 		ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT));
-	res |= ast_data_node_add_child_bool(settings_node, "autocreatepeer", autocreatepeer);
-	res |= ast_data_node_add_child_bool(settings_node, "match_auth_username", global_match_auth_username);
-		
-	if (res) {
-		ast_data_node_destroy(settings_node);
-		settings_node = NULL;
-	}
+	ast_data_node_add_child_bool(settings_node, "autocreatepeer", autocreatepeer);
+	ast_data_node_add_child_bool(settings_node, "match_auth_username", global_match_auth_username);
 
 	return settings_node;
 }

Modified: team/russell/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/include/asterisk/data.h?view=diff&rev=111941&r1=111940&r2=111941
==============================================================================
--- team/russell/data_retrieval/include/asterisk/data.h (original)
+++ team/russell/data_retrieval/include/asterisk/data.h Fri Mar 28 18:50:58 2008
@@ -96,11 +96,17 @@
 
 int ast_data_node_add_child(struct ast_data_node *parent, struct ast_data_node *child);
 
-int ast_data_node_add_child_bool(struct ast_data_node *parent, const char *name, unsigned int val);
+struct ast_data_node *ast_data_node_add_child_grouping(struct ast_data_node *parent, 
+	const char *name);
 
-int ast_data_node_add_child_uint(struct ast_data_node *parent, const char *name, uint32_t uint);
+struct ast_data_node *ast_data_node_add_child_bool(struct ast_data_node *parent, 
+	const char *name, unsigned int val);
 
-int ast_data_node_add_child_str(struct ast_data_node *parent, const char *name, const char *str);
+struct ast_data_node *ast_data_node_add_child_uint(struct ast_data_node *parent, 
+	const char *name, uint32_t uint);
+
+struct ast_data_node *ast_data_node_add_child_str(struct ast_data_node *parent, 
+	const char *name, const char *str);
 
 /*! @} */
 
@@ -118,7 +124,7 @@
 
 struct ast_data_provider;
 
-typedef struct ast_data_node *(*ast_data_provider_cb)(struct ast_data_provider *data_prov,
+typedef struct ast_data_node *(*ast_data_provider_cb)(const struct ast_data_provider *data_prov,
 	const struct ast_data_node *query);
 
 struct ast_data_provider {

Modified: team/russell/data_retrieval/main/data.c
URL: http://svn.digium.com/view/asterisk/team/russell/data_retrieval/main/data.c?view=diff&rev=111941&r1=111940&r2=111941
==============================================================================
--- team/russell/data_retrieval/main/data.c (original)
+++ team/russell/data_retrieval/main/data.c Fri Mar 28 18:50:58 2008
@@ -164,43 +164,77 @@
 	return 0;
 }
 
-int ast_data_node_add_child_bool(struct ast_data_node *parent, const char *name, unsigned int val)
+struct ast_data_node *ast_data_node_add_child_grouping(struct ast_data_node *parent, 
+	const char *name)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return -1;
+		return NULL;
+	}
+
+	if (ast_data_node_add_child(parent, node)) {
+		node = ast_data_node_destroy(node);
+	}
+
+	return node;
+}
+
+struct ast_data_node *ast_data_node_add_child_bool(struct ast_data_node *parent, 
+	const char *name, unsigned int val)
+{
+	struct ast_data_node *node;
+
+	if (!(node = ast_data_node_new(name))) {
+		return NULL;
 	}
 
 	ast_data_node_set_payload_bool(node, val);
 
-	return ast_data_node_add_child(parent, node);
-}
-
-int ast_data_node_add_child_uint(struct ast_data_node *parent, const char *name, uint32_t uint)
+	if (ast_data_node_add_child(parent, node)) {
+		node = ast_data_node_destroy(node);
+	}
+
+	return node;
+}
+
+struct ast_data_node *ast_data_node_add_child_uint(struct ast_data_node *parent, 
+	const char *name, uint32_t uint)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return -1;
+		return NULL;
 	}
 
 	ast_data_node_set_payload_uint(node, uint);
 
-	return ast_data_node_add_child(parent, node);
-}
-
-int ast_data_node_add_child_str(struct ast_data_node *parent, const char *name, const char *str)
+	if (ast_data_node_add_child(parent, node)) {
+		node = ast_data_node_destroy(node);
+	}
+
+	return node;
+}
+
+struct ast_data_node *ast_data_node_add_child_str(struct ast_data_node *parent, 
+	const char *name, const char *str)
 {
 	struct ast_data_node *node;
 
 	if (!(node = ast_data_node_new(name))) {
-		return -1;
-	}
-
-	ast_data_node_set_payload_str(node, str);
-
-	return ast_data_node_add_child(parent, node);
+		return NULL;
+	}
+
+	if (ast_data_node_set_payload_str(node, str)) {
+		node = ast_data_node_destroy(node);
+		return NULL;
+	}
+
+	if (ast_data_node_add_child(parent, node)) {
+		node = ast_data_node_destroy(node);
+	}
+
+	return node;
 }
 
 struct ast_data_node *ast_data_query(const struct ast_data_node *query)
@@ -308,6 +342,31 @@
 	struct ast_data_prov_holder *holder2 = arg;
 
 	return strcasecmp(holder1->data_prov->name, holder2->data_prov->name) ? 0 : CMP_MATCH;
+}
+
+static struct ast_data_node *test_provider(const struct ast_data_provider *data_prov,
+	const struct ast_data_node *query)
+{
+	struct ast_data_node *results, *fruit, *orange, *veggies;
+
+	if (!(results = ast_data_node_new("test_provider"))) {
+		return NULL;
+	}
+
+	fruit = ast_data_node_add_child_grouping(results, "fruits");
+
+	ast_data_node_add_child_str(fruit, "fruit", "apple");
+	orange = ast_data_node_add_child_grouping(fruit, "oranges");
+	ast_data_node_add_child_str(orange, "orange", "mandarin");
+	ast_data_node_add_child_str(orange, "orange", "navel");
+	ast_data_node_add_child_str(fruit, "fruit", "banana");
+
+	veggies = ast_data_node_add_child_grouping(results, "veggies");
+	ast_data_node_add_child_str(veggies, "veggie", "broccoli");
+	ast_data_node_add_child_str(veggies, "veggie", "squash");
+	ast_data_node_add_child_str(veggies, "veggie", "spinach");
+
+	return results;
 }
 
 static void cli_print_node(struct ast_cli_args *a, struct ast_str **buf, 
@@ -405,6 +464,7 @@
 		"");
 
 	ast_data_node_destroy(query);
+	ast_data_node_destroy(results);
 	ast_free(buf);
 
 	return CLI_SUCCESS;
@@ -414,11 +474,17 @@
 	AST_CLI_DEFINE(cli_data_get, "Get data from the ADL (Asterisk Data Layer)"),
 };
 
+static struct ast_data_provider data_provs[] = {
+	AST_DATA_PROVIDER(test_provider, "test_provider"),
+};
+
 int ast_data_init(void)
 {
 	if (!(data_providers = ao2_container_alloc(NUM_DATA_PROV_BUCKETS, data_prov_hash, data_prov_cmp)))
 		return -1;
 
+	ast_data_provider_register_multiple(data_provs, ARRAY_LEN(data_provs));
+
 	ast_cli_register_multiple(data_cli, ARRAY_LEN(data_cli));
 
 	return 0;




More information about the asterisk-commits mailing list