[svn-commits] eliel: branch group/data_api_gsoc2009 r204651 - in /team/group/data_api_gsoc2...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 1 12:49:05 CDT 2009


Author: eliel
Date: Wed Jul  1 12:49:02 2009
New Revision: 204651

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=204651
Log:
Check for compatibility inside the data API (for future changes in the API).


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=204651&r1=204650&r2=204651
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Wed Jul  1 12:49:02 2009
@@ -87,6 +87,9 @@
 	AST_DATA_POINTER
 };
 
+/*! \brief The Data API version. */
+#define AST_DATA_VERSION 0x1
+
 /*! \brief opaque definition of an ast_data handler, a tree node. */
 struct ast_data;
 
@@ -106,21 +109,19 @@
 	/*! \brief The tokenizer is used to retrieve from the node generator
 	 *         the list of possible attributes in the search string. */
 	ast_data_tokenizer tokenizer;
-	/*! \brief ast_data_handler version */
-	#define AST_DATA_HANDLER_VERSION 1
 };
 
 /*! \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;
-	/*! \brief ast_data_entry version */
-	#define AST_DATA_ENTRY_VERSION 1
-};
-
-#define AST_DATA_ENTRY(__path, __handler) { .path = __path, .handler = __handler }
+};
+
+#define AST_DATA_ENTRY(__path, __handler) { .version = AST_DATA_VERSION, .path = __path, .handler = __handler }
 
 /*! \brief Specifies the user information to be passed to the
  *         data API.
@@ -143,6 +144,8 @@
 
 /*! \brief A query to the data API is specified in this structure. */
 struct ast_data_query {
+	/*! \brief Data query version. */
+	uint32_t version;
 	AST_DECLARE_STRING_FIELDS(
 		/*! \brief Path to the node to retrieve. */
 		AST_STRING_FIELD(path);
@@ -163,6 +166,7 @@
 
 /*!
  * \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.
@@ -171,9 +175,10 @@
  * \retval 0 on success.
  * \see __ast_data_unregister, __ast_data_register_multiple
  */
-int __ast_data_register(const char *path, const struct ast_data_handler *handler,
+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(path, handler, __FILE__)
+#define ast_data_register(path, handler) __ast_data_register(AST_DATA_VERSION, path, handler, __FILE__)
 
 /*!
  * \brief Register multiple data providers at once.

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=204651&r1=204650&r2=204651
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Wed Jul  1 12:49:02 2009
@@ -36,6 +36,9 @@
 #define NUM_DATA_NODE_BUCKETS	60
 #define NUM_DATA_RESULT_BUCKETS 60
 
+/*! \brief The last compatible version. */
+static const uint32_t latest_compatible_version = 0;
+
 /*! \brief The data tree to be returned by the callbacks and 
 		   managed by functions local to this file. */
 struct ast_data {
@@ -158,6 +161,24 @@
  * \brief Unlock the data registered handlers structure.
  */
 #define data_unlock() ast_rwlock_unlock(&root_data_lock)
+
+/*!
+ * \internal
+ * \brief Check if a version is compatible with the current core.
+ * \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) {
+		return 1;
+	}
+
+	ast_log(LOG_ERROR, "The module is not compatible with the current data api version\n");
+
+	return 0;
+}
 
 /*!
  * \internal
@@ -400,12 +421,16 @@
 	return ret ? ret : child;
 }
 
-int __ast_data_register(const char *path, const struct ast_data_handler *handler,
+int __ast_data_register(uint32_t version, const char *path, const struct ast_data_handler *handler,
 	const char *registrar)
 {
 	struct data_provider *node;
 
 	if (!path) {
+		return -1;
+	}
+
+	if (!data_structure_compatible(version)) {
 		return -1;
 	}
 
@@ -445,7 +470,8 @@
 	int i, res;
 
 	for (i = 0; i < entries; i++) {
-		res = __ast_data_register(data_entries[i].path, data_entries[i].handler,
+		res = __ast_data_register(data_entries[i].version, data_entries[i].path,
+				data_entries[i].handler,
 				registrar);
 		if (res) {
 			/* unregister all the already registered nodes, and make
@@ -724,6 +750,11 @@
 struct ast_data *ast_data_get(const struct ast_data_query *query)
 {
 	struct ast_data *res;
+
+	/* check compatibility */
+	if (!data_structure_compatible(query->version)) {
+		return NULL;
+	}
 
 	data_read_lock();
 	res = data_result_generate(query, query->path);




More information about the svn-commits mailing list