[asterisk-commits] eliel: branch group/data_api_gsoc2009 r204946 - in /team/group/data_api_gsoc2...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jul 3 16:56:33 CDT 2009
Author: eliel
Date: Fri Jul 3 16:56:29 2009
New Revision: 204946
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=204946
Log:
Pass the version for each structure.
Pass the module registering the provider to increment the ref count when using it.
Modified:
team/group/data_api_gsoc2009/include/asterisk/data.h
team/group/data_api_gsoc2009/main/data.c
team/group/data_api_gsoc2009/tests/test_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=204946&r1=204945&r2=204946
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Fri Jul 3 16:56:29 2009
@@ -87,8 +87,9 @@
AST_DATA_POINTER
};
-/*! \brief The Data API version. */
-#define AST_DATA_VERSION 0x1
+/*! \brief The Data API structures version. */
+#define AST_DATA_HANDLER_VERSION 1
+#define AST_DATA_QUERY_VERSION 1
/*! \brief opaque definition of an ast_data handler, a tree node. */
struct ast_data;
@@ -102,6 +103,8 @@
/*! \brief The structure of the node handler. */
struct ast_data_handler {
+ /*! \brief Structure version. */
+ uint32_t version;
/*! \brief Data get callback implementation. */
ast_data_get_cb get;
/*! \brief Data put callback implementation. */
@@ -113,15 +116,13 @@
/*! \brief This entries are for multiple registers. */
struct ast_data_entry {
- /*! \brief Data handler entry version. */
- uint32_t version;
/*! \brief Path of the node to register. */
const char *path;
/*! \brief Data handler structure. */
const struct ast_data_handler *handler;
};
-#define AST_DATA_ENTRY(__path, __handler) { .version = AST_DATA_VERSION, .path = __path, .handler = __handler }
+#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 {
@@ -142,33 +143,33 @@
/*!
* \brief Register a data provider.
- * \param[in] version Data provider version.
* \param[in] path The path of the node to register.
* \param[in] handler The structure defining this node handler.
* \param[in] registrar Who is registering this node.
+ * \param[in] mod The module registering this handler.
* \see ast_data_unregister
* \retval <0 on error.
* \retval 0 on success.
* \see __ast_data_unregister, __ast_data_register_multiple
*/
-int __ast_data_register(uint32_t version, const char *path,
- const struct ast_data_handler *handler,
- const char *registrar);
-#define ast_data_register(path, handler) __ast_data_register(AST_DATA_VERSION, path, handler, __FILE__)
+int __ast_data_register(const char *path, const struct ast_data_handler *handler,
+ const char *registrar, struct ast_module *mod);
+#define ast_data_register(path, handler) __ast_data_register(path, handler, __FILE__, ast_module_info->self)
/*!
* \brief Register multiple data providers at once.
* \param[in] data_entries An array of data_entries structures.
* \param[in] entries The number of entries in the data_entries array.
* \param[in] registrar Who is registering this nodes.
+ * \param[in] mod The module registering this handlers.
* \retval <0 on error (none of the nodes are being registered on error).
* \retval 0 on success.
* \see __ast_data_register, __ast_data_unregister
*/
int __ast_data_register_multiple(const struct ast_data_entry *data_entries,
- size_t entries, const char *registrar);
+ size_t entries, const char *registrar, struct ast_module *mod);
#define ast_data_register_multiple(data_entries, entries) \
- __ast_data_register_multiple(data_entries, entries, __FILE__)
+ __ast_data_register_multiple(data_entries, entries, __FILE__, ast_module_info->self)
/*!
* \brief Unregister a data provider.
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=204946&r1=204945&r2=204946
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Fri Jul 3 16:56:29 2009
@@ -27,6 +27,7 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/_private.h"
+#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/data.h"
@@ -37,7 +38,16 @@
#define NUM_DATA_RESULT_BUCKETS 60
/*! \brief The last compatible version. */
-static const uint32_t latest_compatible_version = 0;
+static const uint32_t latest_handler_compatible_version = 0;
+
+/*! \brief The last compatible version. */
+static const uint32_t latest_query_compatible_version = 0;
+
+/*! \brief Current handler structure version. */
+static const uint32_t current_handler_version = AST_DATA_HANDLER_VERSION;
+
+/*! \brief Current query structure version. */
+static const uint32_t current_query_version = AST_DATA_QUERY_VERSION;
/*! \brief The data tree to be returned by the callbacks and
managed by functions local to this file. */
@@ -71,6 +81,8 @@
struct data_provider {
/*! \brief node content handler. */
const struct ast_data_handler *handler;
+ /*! \brief Module providing this handler. */
+ struct ast_module *module;
/*! \brief children nodes. */
struct ao2_container *children;
/*! \brief Who registered this node. */
@@ -165,13 +177,16 @@
/*!
* \internal
* \brief Check if a version is compatible with the current core.
+ * \param[in] structure_version The current structure version.
+ * \param[in] latest_compatible The latest compatible version.
+ * \param[in] current The current Data API version.
* \retval 1 If the module is compatible.
* \retval 0 If the module is NOT compatible.
*/
-static int data_structure_compatible(int structure_version)
-{
- if (structure_version >= latest_compatible_version
- && structure_version <= AST_DATA_VERSION) {
+static int data_structure_compatible(int structure_version, uint32_t latest_compatible,
+ uint32_t current)
+{
+ if (structure_version >= latest_compatible && structure_version <= current) {
return 1;
}
@@ -418,8 +433,8 @@
return ret ? ret : child;
}
-int __ast_data_register(uint32_t version, const char *path, const struct ast_data_handler *handler,
- const char *registrar)
+int __ast_data_register(const char *path, const struct ast_data_handler *handler,
+ const char *registrar, struct ast_module *mod)
{
struct data_provider *node;
@@ -427,7 +442,10 @@
return -1;
}
- if (!data_structure_compatible(version)) {
+ /* check if the handler structure is compatible. */
+ if (!data_structure_compatible(handler->version,
+ latest_handler_compatible_version,
+ current_handler_version)) {
return -1;
}
@@ -453,6 +471,7 @@
/* add handler to that node. */
node->handler = handler;
+ node->module = mod;
ao2_ref(node, -1);
@@ -462,14 +481,13 @@
}
int __ast_data_register_multiple(const struct ast_data_entry *data_entries,
- size_t entries, const char *registrar)
+ size_t entries, const char *registrar, struct ast_module *mod)
{
int i, res;
for (i = 0; i < entries; i++) {
- res = __ast_data_register(data_entries[i].version, data_entries[i].path,
- data_entries[i].handler,
- registrar);
+ res = __ast_data_register(data_entries[i].path, data_entries[i].handler,
+ registrar, mod);
if (res) {
/* unregister all the already registered nodes, and make
* this an atomic atomic. */
@@ -646,6 +664,10 @@
return NULL;
}
+ if (root_provider->module) {
+ ast_module_ref(root_provider->module);
+ }
+
/* if this is a terminal node, just run the callback function. */
if (root_provider->handler && root_provider->handler->get) {
generated = root_provider->handler->get();
@@ -654,7 +676,12 @@
ao2_ref(generated, -1);
}
+ ast_module_unref(root_provider->module);
return node;
+ }
+
+ if (root_provider->module) {
+ ast_module_unref(root_provider->module);
}
/* if this is not a terminal node, generate every child node. */
@@ -747,7 +774,8 @@
struct ast_data *res;
/* check compatibility */
- if (!data_structure_compatible(query->version)) {
+ if (!data_structure_compatible(query->version, latest_query_compatible_version,
+ current_query_version)) {
return NULL;
}
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=204946&r1=204945&r2=204946
==============================================================================
--- team/group/data_api_gsoc2009/tests/test_data.c (original)
+++ team/group/data_api_gsoc2009/tests/test_data.c Fri Jul 3 16:56:29 2009
@@ -68,10 +68,12 @@
}
static const struct ast_data_handler full_provider = {
+ .version = AST_DATA_HANDLER_VERSION,
.get = test_data_full_provider
};
static const struct ast_data_handler null_provider = {
+ .version = AST_DATA_HANDLER_VERSION,
.get = test_data_null_provider
};
@@ -89,9 +91,11 @@
static char *handle_cli_data_get_bench(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_data_query query_null = {
+ .version = AST_DATA_QUERY_VERSION,
.path = "test/null",
};
struct ast_data_query query_full = {
+ .version = AST_DATA_QUERY_VERSION,
.path = "test",
};
struct ast_data *res;
@@ -132,6 +136,7 @@
struct ast_data *res, *node;
struct ast_data_iterator *i;
struct ast_data_query query = {
+ .version = AST_DATA_QUERY_VERSION,
.path = "test",
};
@@ -185,6 +190,7 @@
struct ast_xml_doc *doc;
FILE *outfile;
struct ast_data_query query = {
+ .version = AST_DATA_QUERY_VERSION,
.path = "test",
};
More information about the asterisk-commits
mailing list