[asterisk-commits] eliel: branch eliel/data_retrieval r183689 - in /team/eliel/data_retrieval: i...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 23 08:01:29 CDT 2009


Author: eliel
Date: Mon Mar 23 08:01:25 2009
New Revision: 183689

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183689
Log:
Generate the xml

Modified:
    team/eliel/data_retrieval/include/asterisk/data.h
    team/eliel/data_retrieval/main/data.c

Modified: team/eliel/data_retrieval/include/asterisk/data.h
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/include/asterisk/data.h?view=diff&rev=183689&r1=183688&r2=183689
==============================================================================
--- team/eliel/data_retrieval/include/asterisk/data.h (original)
+++ team/eliel/data_retrieval/include/asterisk/data.h Mon Mar 23 08:01:25 2009
@@ -27,10 +27,12 @@
 extern "C" {
 #endif
 
-/*! \brief opaque definition. */
+/*! \brief opaque definition of an ast_data handler. */
 struct ast_data;
+/*! \brief opaque definition of an ast_data_node result. */
+struct ast_data_node;
 
-typedef struct ast_data *(*ast_data_cb)(void);
+typedef struct ast_data_node *(*ast_data_cb)(void);
 
 /*!
  * \brief Register a data provider.

Modified: team/eliel/data_retrieval/main/data.c
URL: http://svn.digium.com/svn-view/asterisk/team/eliel/data_retrieval/main/data.c?view=diff&rev=183689&r1=183688&r2=183689
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Mon Mar 23 08:01:25 2009
@@ -89,12 +89,10 @@
  * \internal
  * \brief Lock the data registered handlers structure for reading.
  */
-#if 0
 static void data_read_lock(void)
 {
 	ast_rwlock_rdlock(&root_data_lock);
 }
-#endif
 
 /*!
  * \internal
@@ -279,6 +277,64 @@
 	return ret ? ret : child;
 }
 
+static struct ast_xml_node *data_xml_node_retrieve(struct ao2_container *parent, const char *path)
+{
+	char *rpath, *node_name;
+	struct ast_xml_node *node, *generated;
+	struct data_node *child;
+
+	rpath = strdupa(path);
+	if (!rpath) {
+		return NULL;
+	}
+
+	node_name = next_node_name(&rpath);
+	if (!node_name) {
+		return NULL;
+	}
+
+	node = ast_xml_new_node(node_name);
+
+	child = data_find_child(parent, node_name);
+	if (!child) {
+		return node;
+	}
+
+	if (!child->read) {
+		generated = data_xml_node_retrieve(child->children, rpath);
+	} else {
+		generated = (struct ast_xml_node *) child->read();
+	}
+
+	if (generated) {
+		ast_xml_add_child(node, generated);
+	}
+
+	return node;
+}
+
+static struct ast_xml_doc *data_xml_retrieve(const char *path)
+{
+	struct ast_xml_doc *doc;
+	struct ast_xml_node *root_node;
+
+	doc = ast_xml_new();
+	if (!doc) {
+		ast_log(LOG_ERROR, "Unable to create internal data representation structure.\n");
+		return NULL;
+	}
+
+	root_node = data_xml_node_retrieve(root_data, path);
+	if (!root_node) {
+		ast_xml_close(doc);
+		return NULL;
+	}
+
+	ast_xml_set_root(doc, root_node);
+
+	return doc;
+}
+
 int ast_data_register(const char *path, ast_data_cb read_handler)
 {
 	struct data_node *node;
@@ -315,13 +371,38 @@
 	return 0;
 }
 
-static struct ast_data *test_data_provider(void)
+struct ast_data *ast_data_get(const char *path)
+{
+	struct ast_xml_doc *doc;
+
+	data_read_lock();
+	doc = data_xml_retrieve(path);
+	data_unlock();
+
+	if (!doc) {
+		ast_log(LOG_ERROR, "Unable to get data from %s\n", path);
+		return NULL;
+	}
+
+	return (struct ast_data *) doc;
+}
+
+void ast_data_free(struct ast_data *retrieved_data)
+{
+	struct ast_xml_doc *dom = (struct ast_xml_doc *) retrieved_data;
+
+	if (dom) {
+		ast_xml_close(dom);
+	}
+}
+
+static struct ast_data_node *test_data_provider(void)
 {
 	struct ast_xml_node *node;
 
 	node = ast_xml_new_node("jojo");
 
-	return (struct ast_data *) node;
+	return (struct ast_data_node *) node;
 }
 
 int ast_data_init(void)




More information about the asterisk-commits mailing list