[svn-commits] eliel: branch group/data_api_gsoc2009 r210633 - /team/group/data_api_gsoc2009...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 5 14:36:38 CDT 2009


Author: eliel
Date: Wed Aug  5 14:36:32 2009
New Revision: 210633

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=210633
Log:
Add a new CLI command "data show providers" to list all the
registered providers.


Modified:
    team/group/data_api_gsoc2009/main/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=210633&r1=210632&r2=210633
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Wed Aug  5 14:36:32 2009
@@ -2476,7 +2476,7 @@
 		e->command = "data get";
 		e->usage = ""
 			"Usage: data get <path> [<search> [<filter>]]\n"
-			"   get the tree based on a path.\n";
+			"       Get the tree based on a path.\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
@@ -2510,10 +2510,81 @@
 
 /*!
  * \internal
+ * \brief Print the list of data providers.
+ * \param[in] fd The CLI file descriptor.
+ * \param[in] name The last node visited name.
+ * \param[in] container The childrens of the last node.
+ * \param[in] path The path to the current node.
+ */
+static void data_provider_print_cli(int fd, const char *name, struct ao2_container *container, struct ast_str *path)
+{
+	struct ao2_iterator i;
+	struct ast_str *current_path;
+	struct data_provider *provider;
+
+	current_path = ast_str_create(60);
+	if (!current_path) {
+		return;
+	}
+
+	ast_str_reset(current_path);
+	if (path) {
+		ast_str_set(&current_path, 0, "%s/%s", ast_str_buffer(path), name);
+	} else {
+		ast_str_set(&current_path, 0, "%s", name);
+	}
+
+	i = ao2_iterator_init(container, 0);
+	while ((provider = ao2_iterator_next(&i))) {
+		if (provider->handler) {
+			/* terminal node, print it. */
+			ast_cli(fd, "%s/%s (", ast_str_buffer(current_path),
+				provider->name);
+			if (provider->handler->get) {
+				ast_cli(fd, "get");
+			}
+			if (provider->handler->put) {
+				ast_cli(fd, "%sput", (provider->handler->get ? "," : ""));
+			}
+			ast_cli(fd, ") [%s]\n", provider->registrar);
+		}
+		data_provider_print_cli(fd, provider->name, provider->children, current_path);
+		ao2_ref(provider, -1);
+	}
+
+	ast_free(current_path);
+}
+
+/*!
+ * \brief Handle CLI command "data show providers"
+ */
+static char *handle_cli_data_show_providers(struct ast_cli_entry *e, int cmd,
+		struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "data show providers";
+		e->usage = ""
+			"Usage: data show providers\n"
+			"       Show the list of registered providers\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	data_read_lock();
+	data_provider_print_cli(a->fd, "", root_data.container, NULL);
+	data_unlock();
+
+	return CLI_SUCCESS;
+}
+/*!
+ * \internal
  * \brief Data API CLI commands.
  */
 static struct ast_cli_entry cli_data[] = {
 	AST_CLI_DEFINE(handle_cli_data_get, "Data API get"),
+	AST_CLI_DEFINE(handle_cli_data_show_providers, "Show providers")
 };
 
 int ast_data_init(void)




More information about the svn-commits mailing list