[asterisk-commits] eliel: branch group/data_api_gsoc2009 r199231 - in /team/group/data_api_gsoc2...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jun 5 09:15:24 CDT 2009
Author: eliel
Date: Fri Jun 5 09:15:21 2009
New Revision: 199231
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=199231
Log:
Start defining the API functions.
Modified:
team/group/data_api_gsoc2009/include/asterisk/data.h
team/group/data_api_gsoc2009/main/data.c
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=199231&r1=199230&r2=199231
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Fri Jun 5 09:15:21 2009
@@ -98,6 +98,19 @@
#define AST_DATA_ENTRY(__path, __handler) { .path = __path, .handler = __handler }
+/*! \brief A query to the data API is specified in this structure. */
+struct ast_data_query {
+ /*! \brief Path to the node to retrieve. */
+ const char *path;
+ /*! \brief Search string, return the nodes that match this conditions.
+ * Setting it to NULL will match every node in the specified path. */
+ const char *search;
+ /*! \brief Filter string, return the internal nodes specified here.
+ * Setting it to NULL will return every internal node. */
+ const char *filter;
+ /* XXX: Complete with security related stuff. */
+};
+
/*!
* \brief Register a data provider.
* \param[in] path The path of the node to register.
@@ -134,6 +147,23 @@
int __ast_data_unregister(const char *path, const char *registrar);
#define ast_data_unregister(path) __ast_data_unregister(path, __FILE__)
+/*!
+ * \brief Retrieve a subtree from the asterisk data API.
+ * \param[in] query
+ * \retval NULL on error.
+ * \retval The dynamically allocated requested sub-tree (it needs to be released using
+ * ast_data_free.
+ * \see ast_data_free
+ */
+struct ast_data *ast_data_get(const struct ast_data_query *query);
+
+/*!
+ * \brief Release the allocated memory of a returned subtree.
+ * \param[in] res The sub-tree pointer returned by a call to ast_data_get.
+ * \see ast_data_get
+ */
+void ast_data_free(struct ast_data *res);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
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=199231&r1=199230&r2=199231
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Fri Jun 5 09:15:21 2009
@@ -421,6 +421,18 @@
return ret;
}
+void ast_data_free(struct ast_data *res)
+{
+ /* TODO: implement this. */
+}
+
+struct ast_data *ast_data_get(const struct ast_data_query *query)
+{
+ /* TODO: implement this. */
+ return NULL;
+}
+
+/* XXX: test callback */
static struct ast_data_node *test_data_provider(void)
{
struct ast_data_node *res = NULL;
@@ -428,16 +440,34 @@
return res;
}
+/* XXX: test */
static const struct ast_data_handler test_provider = {
.get = test_data_provider
};
+/* XXX: test */
static const struct ast_data_entry test_providers[] = {
AST_DATA_ENTRY("asterisk/node1/node11/node111", &test_provider),
AST_DATA_ENTRY("asterisk/node1/node11/node112", &test_provider),
AST_DATA_ENTRY("asterisk/node1/node11/node113", &test_provider),
};
+/* XXX: test */
+static void runtest(void)
+{
+ struct ast_data *res;
+ struct ast_data_query q = {
+ .path = "/asterisk/node1",
+ .search = NULL,
+ .filter = NULL
+ };
+
+ /* some tests */
+ ast_data_register_multiple(test_providers, ARRAY_LEN(test_providers));
+ res = ast_data_get(&q);
+ ast_data_unregister(NULL);
+}
+
int ast_data_init(void)
{
ast_rwlock_init(&root_data_lock);
@@ -447,9 +477,8 @@
return -1;
}
- /* some tests */
- ast_data_register_multiple(test_providers, ARRAY_LEN(test_providers));
- ast_data_unregister(NULL);
+ /* XXX: test */
+ runtest();
return 0;
}
More information about the asterisk-commits
mailing list