[asterisk-commits] eliel: branch group/data_api_gsoc2009 r209450 - in /team/group/data_api_gsoc2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 29 07:47:47 CDT 2009


Author: eliel
Date: Wed Jul 29 07:47:42 2009
New Revision: 209450

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=209450
Log:
Fix russellb review board comments.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/apps/app_queue.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/apps/app_queue.c?view=diff&rev=209450&r1=209449&r2=209450
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Wed Jul 29 07:47:42 2009
@@ -6301,11 +6301,21 @@
 /*! \brief direct ouput to manager or cli with proper terminator */
 static void do_print(struct mansession *s, int fd, const char *str)
 {
-	if (s) {
+	if (s)
 		astman_append(s, "%s\r\n", str);
+	else
+		ast_cli(fd, "%s\n", str);
+}
+
+/*! \brief Print that no queues where found. */
+static void do_print_noqueues(struct ast_str *out, struct mansession *s, int fd, const char *queue)
+{
+	if (queue) {
+		ast_str_set(&out, 0, "No such queue: %s.", queue);
 	} else {
-		ast_cli(fd, "%s\n", str);
-	}
+		ast_str_set(&out, 0, "No queues.");
+	}
+	do_print(s, fd, ast_str_buffer(out));
 }
 
 /*! 
@@ -6341,23 +6351,19 @@
 	}
 
 	queues = ast_data_get(&query);
+
+	if (search) {
+		ast_free(search);
+	}
+
 	if (!queues) {
 		return CLI_FAILURE;
-	}
-
-	if (search) {
-		ast_free(search);
 	}
 
 	iq = ast_data_iterator_init(queues, "queue");
 	if (!iq) {
 		ast_data_free(queues);
-		if (argc == 3) {
-			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
-		} else {
-			ast_str_set(&out, 0, "No queues.");
-		}
-		do_print(s, fd, ast_str_buffer(out));
+		do_print_noqueues(out, s, fd, (argc == 3 ? argv[2] : NULL));
 	}
 
 	while ((queue = ast_data_iterator_next(iq))) {
@@ -6461,12 +6467,7 @@
 	ast_data_iterator_end(iq);
 
 	if (!found) {
-		if (argc == 3) {
-			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
-		} else {
-			ast_str_set(&out, 0, "No queues.");
-		}
-		do_print(s, fd, ast_str_buffer(out));
+		do_print_noqueues(out, s, fd, (argc == 3 ? argv[2] : NULL));
 	}
 
 	ast_data_free(queues);

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=209450&r1=209449&r2=209450
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Wed Jul 29 07:47:42 2009
@@ -26,6 +26,8 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
+#include <regex.h>
+
 #include "asterisk/_private.h"
 #include "asterisk/module.h"
 #include "asterisk/utils.h"
@@ -34,11 +36,10 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/xml.h"
 #include "asterisk/linkedlists.h"
-#include <regex.h>
-
-#define NUM_DATA_NODE_BUCKETS	60
-#define NUM_DATA_RESULT_BUCKETS 60
-#define NUM_DATA_SEARCH_BUCKETS 60
+
+#define NUM_DATA_NODE_BUCKETS	59
+#define NUM_DATA_RESULT_BUCKETS 59
+#define NUM_DATA_SEARCH_BUCKETS 59
 
 /*! \brief The last compatible version. */
 static const uint32_t latest_handler_compatible_version = 0;
@@ -140,15 +141,12 @@
 	unsigned int is_pattern:1;
 };
 
-/*! \brief The asterisk data main content structure. */
-static struct ao2_container *root_data;
-
-/*!
- * \internal
- * \brief asterisk data locking mechanism.
- * \see root_data
- */
-static ast_rwlock_t root_data_lock;
+struct {
+	/*! \brief The asterisk data main content structure. */
+	struct ao2_container *container;
+	/*! \brief asterisk data locking mechanism. */
+	ast_rwlock_t lock;
+} root_data;
 
 /*!
  * \internal
@@ -197,20 +195,20 @@
  * \brief Lock the data registered handlers structure for writing.
  * \see data_unlock
  */
-#define data_write_lock() ast_rwlock_wrlock(&root_data_lock)
+#define data_write_lock() ast_rwlock_wrlock(&root_data.lock)
 
 /*!
  * \internal
  * \brief Lock the data registered handlers structure for reading.
  * \see data_unlock
  */
-#define data_read_lock() ast_rwlock_rdlock(&root_data_lock)
+#define data_read_lock() ast_rwlock_rdlock(&root_data.lock)
 
 /*!
  * \internal
  * \brief Unlock the data registered handlers structure.
  */
-#define data_unlock() ast_rwlock_unlock(&root_data_lock)
+#define data_unlock() ast_rwlock_unlock(&root_data.lock)
 
 /*!
  * \internal
@@ -228,7 +226,7 @@
 		return 1;
 	}
 
-	ast_log(LOG_ERROR, "The module is not compatible with the current data api version\n");
+	ast_log(LOG_ERROR, "A module is not compatible with the current data api version\n");
 
 	return 0;
 }
@@ -490,7 +488,7 @@
 	/* create the node structure for the registered handler. */
 	data_write_lock();
 
-	node = data_provider_create(root_data, path, registrar);
+	node = data_provider_create(root_data.container, path, registrar);
 	if (!node) {
 		ast_log(LOG_ERROR, "Unable to create the specified path (%s) "
 			"for '%s'.\n", path, registrar);
@@ -528,7 +526,7 @@
 				registrar, mod);
 		if (res) {
 			/* unregister all the already registered nodes, and make
-			 * this an atomic atomic. */
+			 * this an atomic action. */
 			while ((--i) >= 0) {
 				__ast_data_unregister(data_entries[i].path, registrar);
 			}
@@ -545,9 +543,9 @@
 
 	data_write_lock();
 	if (path) {
-		ret = data_provider_release(root_data, path, registrar);
+		ret = data_provider_release(root_data.container, path, registrar);
 	} else {
-		data_provider_release_all(root_data, registrar);
+		data_provider_release_all(root_data.container, registrar);
 	}
 	data_unlock();
 
@@ -1645,7 +1643,7 @@
 
 	/* start searching the root node name */
 	node_name = next_node_name(&tmp_path);
-	provider_child = data_provider_find(root_data, node_name, NULL);
+	provider_child = data_provider_find(root_data.container, node_name, NULL);
 
 	/* continue with the rest of the path. */
 	while (provider_child) {
@@ -2128,9 +2126,9 @@
 
 int ast_data_init(void)
 {
-	ast_rwlock_init(&root_data_lock);
-
-	if (!(root_data = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
+	ast_rwlock_init(&root_data.lock);
+
+	if (!(root_data.container = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
 		data_provider_hash, data_provider_cmp))) {
 		return -1;
 	}




More information about the asterisk-commits mailing list