[svn-commits] eliel: branch eliel/data_retrieval r191780 - in /team/eliel/data_retrieval: i...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat May 2 13:54:33 CDT 2009


Author: eliel
Date: Sat May  2 13:54:30 2009
New Revision: 191780

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=191780
Log:
Allow to register multiple nodes/callbacks at the same time.

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=191780&r1=191779&r2=191780
==============================================================================
--- team/eliel/data_retrieval/include/asterisk/data.h (original)
+++ team/eliel/data_retrieval/include/asterisk/data.h Sat May  2 13:54:30 2009
@@ -38,40 +38,37 @@
  *      ast_data_register("/node/path", callback_fn);
  * \endcode
  *
+ * If you instead want to register multiple nodes at once use:
+ * \code
+ *      static const struct ast_data_handler handler_struct1 = {
+ *		.read = handler_callback_read1
+ *	};
+ *	... other handlers ...
+ *
+ *	static const struct ast_data_entry list_providers[] = {
+ *		AST_DATA_ENTRY("/path1/node1", &handler_struct1),
+ *		AST_DATA_ENTRY("/path2/node2", &handler_struct2),
+ *		AST_DATA_ENTRY("/path3/node3", &handler_struct3),
+ *	};
+ *
+ *      ...
+ *      
+ *      ast_data_register_multiple(list_providers, ARRAY_LEN(list_providers));
+ * \endcode
+ *
  * To unregister a callback function already registered you can just call:
  * 
  * \code
- *      ast_data_unregister(NULL);
+ *	ast_data_unregister(NULL);
  * \endcode
  * And every node registered by the current module (file) will be unregistered.
  * If you want to unregister an specific node use:
  *
  * \code
- *      ast_data_unregister("/node/path");
- * \endcode
- *
- * The asterisk data is organized in a hierarchical structure. The data
- * is retrieved passing a path of the node we want to get:
- * \code
- * 	struct ast_data *handler;
- *
- * 	handler = ast_data_get("/asterisk/channels/sip/channels");
- * \endcode
- *
- * The returned handler is used to get specific nodes values and
- * iterate throw the returned nodes.
- *
- * To access each specific node you must use the specific getter made
- * for the node type you are trying to retrieve.
- *
- * \code
- * 	long uniqueid;
- *
- * 	uniqueid = ast_date_get_long(handler, "uniqueid");
+ *	ast_data_unregister("/node/path");
  * \endcode
  *
  */
-
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
@@ -89,6 +86,16 @@
 	ast_data_read_cb read;
 };
 
+/*! \brief This entries are for multiple registers. */
+struct ast_data_entry {
+	/*! \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) { .path = __path, .handler = __handler }
+
 /*!
  * \brief Register a data provider.
  * \param[in] path The path of the node to register.
@@ -100,6 +107,17 @@
  */
 int __ast_data_register(const char *path, const struct ast_data_handler *handler, const char *registrar);
 #define ast_data_register(path, handler) __ast_data_register(path, handler, __FILE__)
+
+/*!
+ * \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.
+ * \retval < 0 on error (none of the nodes are being registered on error).
+ * \retval 0 on success.
+ */
+int __ast_data_register_multiple(const struct ast_data_entry *data_entries, size_t entries, const char *registrar);
+#define ast_data_register_multiple(data_entries, entries) __ast_data_register_multiple(data_entries, entries, __FILE__);
 
 /*!
  * \brief Unregister 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=191780&r1=191779&r2=191780
==============================================================================
--- team/eliel/data_retrieval/main/data.c (original)
+++ team/eliel/data_retrieval/main/data.c Sat May  2 13:54:30 2009
@@ -382,6 +382,24 @@
 	return 0;
 }
 
+int __ast_data_register_multiple(const struct ast_data_entry *data_entries, size_t entries, const char *registrar)
+{
+	int i, res;
+
+	for (i = 0; i < entries; i++) {
+		res = __ast_data_register(data_entries[i].path, data_entries[i].handler, registrar);
+		if (res) {
+			/* unregister all the already registered nodes, and make this action atomic. */
+			while ((--i) >= 0) {
+				__ast_data_unregister(data_entries[i].path, registrar);
+			}
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 int __ast_data_unregister(const char *path, const char *registrar)
 {
 	int ret = 0;
@@ -412,6 +430,12 @@
 	.read = test_data_provider
 };
 
+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),
+};
+
 int ast_data_init(void)
 {
 	ast_rwlock_init(&root_data_lock);
@@ -422,7 +446,7 @@
 	}
 
 	/* some tests */
-	ast_data_register("asterisk/node1/node11/node111", &test_provider);
+	ast_data_register_multiple(test_providers, ARRAY_LEN(test_providers));
 	ast_data_unregister(NULL);
 
 	return 0;




More information about the svn-commits mailing list