[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r270256 - /team/eliel/data_ap...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 14 13:56:35 CDT 2010


Author: eliel
Date: Mon Jun 14 13:56:29 2010
New Revision: 270256

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=270256
Log:
res_odbc data provider.


Modified:
    team/eliel/data_api_providers_gsoc2010/res/res_odbc.c

Modified: team/eliel/data_api_providers_gsoc2010/res/res_odbc.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/res/res_odbc.c?view=diff&rev=270256&r1=270255&r2=270256
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/res/res_odbc.c (original)
+++ team/eliel/data_api_providers_gsoc2010/res/res_odbc.c Mon Jun 14 13:56:29 2010
@@ -52,6 +52,7 @@
 #include "asterisk/app.h"
 #include "asterisk/strings.h"
 #include "asterisk/threadstorage.h"
+#include "asterisk/data.h"
 
 /*** DOCUMENTATION
 	<function name="ODBC" language="en_US">
@@ -167,6 +168,17 @@
 	char name[0];                   /*!< Name of this transaction ID */
 };
 
+#define DATA_EXPORT_ODBC_CLASS(MEMBER)				\
+	MEMBER(odbc_class, name, AST_DATA_STRING)		\
+	MEMBER(odbc_class, dsn, AST_DATA_STRING)		\
+	MEMBER(odbc_class, username, AST_DATA_STRING)		\
+	MEMBER(odbc_class, password, AST_DATA_PASSWORD)		\
+	MEMBER(odbc_class, limit, AST_DATA_INTEGER)		\
+	MEMBER(odbc_class, count, AST_DATA_INTEGER)		\
+	MEMBER(odbc_class, forcecommit, AST_DATA_BOOLEAN)
+
+AST_DATA_STRUCTURE(odbc_class, DATA_EXPORT_ODBC_CLASS);
+
 static const char *isolation2text(int iso)
 {
 	if (iso == SQL_TXN_READ_COMMITTED) {
@@ -1589,6 +1601,84 @@
 static const char * const app_commit = "ODBC_Commit";
 static const char * const app_rollback = "ODBC_Rollback";
 
+/*!
+ * \internal
+ * \brief Implements the channels provider.
+ */
+static int data_odbc_provider_handler(const struct ast_data_search *search,
+		struct ast_data *root)
+{
+	struct ao2_iterator aoi, aoi2;
+	struct odbc_class *class;
+	struct odbc_obj *current; 
+	struct ast_data *data_odbc_class, *data_odbc_connections, *data_odbc_connection;
+	int count;
+
+	aoi = ao2_iterator_init(class_container, 0);
+	while ((class = ao2_iterator_next(&aoi))) {
+		data_odbc_class = ast_data_add_node(root, "class");
+		if (!data_odbc_class) {
+			ao2_ref(class, -1);
+			continue;
+		}
+
+		ast_data_add_structure(odbc_class, data_odbc_class, class);
+
+		if (!ao2_container_count(class->obj_container)) {
+			ao2_ref(class, -1);
+			continue;
+		}
+
+		data_odbc_connections = ast_data_add_node(data_odbc_class, "connections");
+		if (!data_odbc_connections) {
+			ao2_ref(class, -1);
+			continue;
+		}
+
+		ast_data_add_bool(data_odbc_class, "pooled", class->haspool);
+
+		count = 0;
+		aoi2 = ao2_iterator_init(class->obj_container, 0);
+		while ((current = ao2_iterator_next(&aoi2))) {
+			data_odbc_connection = ast_data_add_node(data_odbc_connections, "connection");
+			if (!data_odbc_connection) {
+				ao2_ref(current, -1);
+				continue;
+			}
+
+			ast_mutex_lock(&current->lock);
+			ast_data_add_str(data_odbc_connection, "status", current->used ? "in use" :
+					current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
+			ast_mutex_unlock(&current->lock);
+
+			if (class->haspool) {
+				ast_data_add_int(data_odbc_connection, "number", ++count);
+			}
+
+			ao2_ref(current, -1);
+		}
+		ao2_ref(class, -1);
+
+		if (!ast_data_search_match(search, data_odbc_class)) {
+			ast_data_remove_node(root, data_odbc_class);
+		}
+	}
+	return 0;
+}
+
+/*!
+ * \internal
+ * \brief /asterisk/res/odbc/listprovider.
+ */
+static const struct ast_data_handler odbc_provider = {
+	.version = AST_DATA_HANDLER_VERSION,
+	.get = data_odbc_provider_handler
+};
+
+static const struct ast_data_entry odbc_providers[] = {
+	AST_DATA_ENTRY("/asterisk/res/odbc/list", &odbc_provider),
+};
+
 static int reload(void)
 {
 	struct odbc_cache_tables *table;
@@ -1676,6 +1766,7 @@
 	if (load_odbc_config() == -1)
 		return AST_MODULE_LOAD_DECLINE;
 	ast_cli_register_multiple(cli_odbc, ARRAY_LEN(cli_odbc));
+	ast_data_register_multiple(odbc_providers, ARRAY_LEN(odbc_providers));
 	ast_register_application_xml(app_commit, commit_exec);
 	ast_register_application_xml(app_rollback, rollback_exec);
 	ast_custom_function_register(&odbc_function);




More information about the asterisk-commits mailing list