[asterisk-commits] eliel: branch eliel/data_api_providers_gsoc2010 r281360 - in /team/eliel/data...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 9 10:06:51 CDT 2010


Author: eliel
Date: Mon Aug  9 10:06:48 2010
New Revision: 281360

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281360
Log:
Implements de /asterisk/core/translation AstData API node.


Modified:
    team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
    team/eliel/data_api_providers_gsoc2010/main/data.c
    team/eliel/data_api_providers_gsoc2010/main/translate.c

Modified: team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h?view=diff&rev=281360&r1=281359&r2=281360
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h (original)
+++ team/eliel/data_api_providers_gsoc2010/include/asterisk/data.h Mon Aug  9 10:06:48 2010
@@ -197,6 +197,7 @@
 	AST_DATA_TIMESTAMP,
 	AST_DATA_SECONDS,
 	AST_DATA_MILLISECONDS,
+	AST_DATA_MICROSECONDS,
 	AST_DATA_POINTER
 };
 
@@ -226,6 +227,7 @@
 		unsigned int AST_DATA_TIMESTAMP;
 		unsigned int AST_DATA_SECONDS;
 		unsigned int AST_DATA_MILLISECONDS;
+		unsigned int AST_DATA_MICROSECONDS;
 		double AST_DATA_DOUBLE;
 		unsigned int AST_DATA_UNSIGNED_INTEGER;
 		unsigned int AST_DATA_BOOLEAN;
@@ -287,6 +289,7 @@
 		int (*AST_DATA_TIMESTAMP)(void *ptr);
 		int (*AST_DATA_SECONDS)(void *ptr);
 		int (*AST_DATA_MILLISECONDS)(void *ptr);
+		int (*AST_DATA_MICROSECONDS)(void *ptr);
 		double (*AST_DATA_DOUBLE)(void *ptr);
 		unsigned int (*AST_DATA_UNSIGNED_INTEGER)(void *ptr);
 		unsigned int (*AST_DATA_BOOLEAN)(void *ptr);
@@ -584,6 +587,17 @@
 	unsigned int milliseconds);
 
 /*!
+ * \brief Add a microseconds node type.
+ * \param[in] root The root of the ast_data to insert into.
+ * \param[in] childname The name of the child element to be added.
+ * \param[in] microseconds The value for the new node.
+ * \retval NULL on error (memory exhaustion only).
+ * \retval non-NULL a newly allocated node.
+ */
+struct ast_data *ast_data_add_microseconds(struct ast_data *root, const char *childname,
+	unsigned int microseconds);
+
+/*!
  * \brief Add a string node type.
  * \param[in] root The root of the ast_data to insert into.
  * \param[in] childname The name of the child element to be added.

Modified: team/eliel/data_api_providers_gsoc2010/main/data.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/data.c?view=diff&rev=281360&r1=281359&r2=281360
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/data.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/data.c Mon Aug  9 10:06:48 2010
@@ -122,6 +122,7 @@
 	{ AST_DATA_TIMESTAMP,		"timestamp" },
 	{ AST_DATA_SECONDS,		"seconds" },
 	{ AST_DATA_MILLISECONDS,	"milliseconds" },
+	{ AST_DATA_MICROSECONDS,	"microseconds" },
 	{ AST_DATA_POINTER,		"pointer" }
 };
 
@@ -1353,6 +1354,11 @@
 				node->name,
 				mapping[member].get.AST_DATA_MILLISECONDS(structure));
 			break;
+		case AST_DATA_MICROSECONDS:
+			notmatch = data_search_cmp_uint(struct_children,
+				node->name,
+				mapping[member].get.AST_DATA_MICROSECONDS(structure));
+			break;
 		case AST_DATA_STRING:
 			notmatch = data_search_cmp_string(struct_children,
 				node->name,
@@ -1427,6 +1433,7 @@
 	case AST_DATA_TIMESTAMP:
 	case AST_DATA_SECONDS:
 	case AST_DATA_MILLISECONDS:
+	case AST_DATA_MICROSECONDS:
 	case AST_DATA_UNSIGNED_INTEGER:
 	case AST_DATA_DOUBLE:
 	case AST_DATA_BOOLEAN:
@@ -1543,6 +1550,7 @@
 			case AST_DATA_TIMESTAMP:
 			case AST_DATA_SECONDS:
 			case AST_DATA_MILLISECONDS:
+			case AST_DATA_MICROSECONDS:
 			case AST_DATA_DOUBLE:
 				notmatch = data_search_cmp_uint(s_child, d_child->name,
 					d_child->payload.dbl);
@@ -2163,6 +2171,11 @@
 				node->payload.uint);
 			ast_xml_set_text(child_xml, node_content);
 			break;
+		case AST_DATA_MICROSECONDS:
+			snprintf(node_content, sizeof(node_content), "%d",
+				node->payload.uint);
+			ast_xml_set_text(child_xml, node_content);
+			break;
 		case AST_DATA_STRING:
 			ast_xml_set_text(child_xml, node->payload.str);
 			break;
@@ -2308,6 +2321,7 @@
 	case AST_DATA_TIMESTAMP:
 	case AST_DATA_SECONDS:
 	case AST_DATA_MILLISECONDS:
+	case AST_DATA_MICROSECONDS:
 	case AST_DATA_UNSIGNED_INTEGER:
 		node->payload.uint = *(unsigned int *) ptr;
 		break;
@@ -2411,6 +2425,12 @@
 	return __ast_data_add(root, childname, AST_DATA_MILLISECONDS, &milliseconds);
 }
 
+struct ast_data *ast_data_add_microseconds(struct ast_data *root, const char *childname,
+	unsigned int microseconds)
+{
+	return __ast_data_add(root, childname, AST_DATA_MICROSECONDS, &microseconds);
+}
+
 struct ast_data *ast_data_add_password(struct ast_data *root, const char *childname,
 	const char *value)
 {
@@ -2492,6 +2512,10 @@
 		case AST_DATA_MILLISECONDS:
 			ast_data_add_milliseconds(root, mapping[i].name,
 				mapping[i].get.AST_DATA_MILLISECONDS(structure));
+			break;
+		case AST_DATA_MICROSECONDS:
+			ast_data_add_microseconds(root, mapping[i].name,
+				mapping[i].get.AST_DATA_MICROSECONDS(structure));
 			break;
 		case AST_DATA_STRING:
 			ast_data_add_str(root, mapping[i].name,
@@ -2658,6 +2682,9 @@
 		break;
 	case AST_DATA_MILLISECONDS:
 		content->value.AST_DATA_MILLISECONDS = node->payload.uint;
+		break;
+	case AST_DATA_MICROSECONDS:
+		content->value.AST_DATA_MICROSECONDS = node->payload.uint;
 		break;
 	case AST_DATA_CHARACTER:
 		content->value.AST_DATA_CHARACTER = node->payload.character;
@@ -2700,6 +2727,7 @@
 	{ AST_DATA_TIMESTAMP, COLOR_CYAN },
 	{ AST_DATA_SECONDS, COLOR_MAGENTA },
 	{ AST_DATA_MILLISECONDS, COLOR_BRMAGENTA },
+	{ AST_DATA_MICROSECONDS, COLOR_BRCYAN },
 	{ AST_DATA_CHARACTER, COLOR_GRAY },
 	{ AST_DATA_INTEGER, COLOR_RED },
 	{ AST_DATA_UNSIGNED_INTEGER, COLOR_RED },
@@ -2796,6 +2824,11 @@
 				node->payload.uint);
 		break;
 	case AST_DATA_MILLISECONDS:
+		ast_str_append(&output, 0, "%s%s: %d\n", ast_str_buffer(tabs),
+				node->name,
+				node->payload.uint);
+		break;
+	case AST_DATA_MICROSECONDS:
 		ast_str_append(&output, 0, "%s%s: %d\n", ast_str_buffer(tabs),
 				node->name,
 				node->payload.uint);
@@ -3066,6 +3099,7 @@
 		case AST_DATA_TIMESTAMP:
 		case AST_DATA_SECONDS:
 		case AST_DATA_MILLISECONDS:
+		case AST_DATA_MICROSECONDS:
 		case AST_DATA_UNSIGNED_INTEGER:
 			astman_append(s, ": %u\r\n", node->payload.uint);
 			break;

Modified: team/eliel/data_api_providers_gsoc2010/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/main/translate.c?view=diff&rev=281360&r1=281359&r2=281360
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/main/translate.c (original)
+++ team/eliel/data_api_providers_gsoc2010/main/translate.c Mon Aug  9 10:06:48 2010
@@ -39,6 +39,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
+#include "asterisk/data.h"
 
 #define MAX_RECALC 1000 /* max sample recalc */
 
@@ -576,14 +577,70 @@
 	return CLI_SUCCESS;
 }
 
+/*!
+ * \internal
+ * \brief Callback used to generate the translation tree.
+ * \param[in] search The search pattern tree.
+ * \retval <0 on error.
+ * \retval 0 The generated tree.
+ */
+static int translation_data_provider_get(const struct ast_data_search *search,
+        struct ast_data *data_root)
+{
+#define SHOW_TRANS 16
+	int x, y;
+	struct ast_data *data_from, *data_to;
+
+	AST_RWLIST_RDLOCK(&translators);
+	for (x = 0; x < SHOW_TRANS; x++) {
+		/* Go ahead and move to next iteration if dealing with an unknown codec */
+		if (!strcmp(ast_getformatname(1LL << (x)), "unknown")) {
+			continue;
+		}
+
+		/* Actual codec output */
+		data_from = ast_data_add_node(data_root, ast_getformatname(1LL << (x)));
+		if (!data_from) {
+			continue;
+		}
+		for (y = 0; y < SHOW_TRANS; y++) {
+			if (tr_matrix[x][y].step) {
+				/* Go ahead and move to next iteration if dealing with an unknown codec */
+				if (!strcmp(ast_getformatname(1LL << (y)), "unknown")) {
+					continue;
+				}
+
+				data_to = ast_data_add_node(data_from, ast_getformatname(1LL << (y)));
+				if (!data_to) {
+					continue;
+				}
+				ast_data_add_microseconds(data_to, "cost", tr_matrix[x][y].cost);
+				ast_data_add_int(data_to, "step", tr_matrix[x][y].multistep);
+			}
+		}
+	}
+	AST_RWLIST_UNLOCK(&translators);
+
+	return 0;
+}
+
 static struct ast_cli_entry cli_translate[] = {
 	AST_CLI_DEFINE(handle_cli_core_show_translation, "Display translation matrix")
 };
 
+static const struct ast_data_handler translation_data_provider = {
+	.version = AST_DATA_HANDLER_VERSION,
+	.get = translation_data_provider_get
+};
+
+static const struct ast_data_entry translate_data_providers[] = {
+	AST_DATA_ENTRY("asterisk/core/translation", &translation_data_provider),
+};
+
 /*! \brief register codec translator */
 int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
 {
-	static int added_cli = 0;
+	static int added_cli = 0, added_data_provider = 0;
 	struct ast_translator *u;
 	char tmp[80];
 
@@ -640,6 +697,11 @@
 	if (!added_cli) {
 		ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
 		added_cli++;
+	}
+
+	if (!added_data_provider) {
+		ast_data_register_multiple_core(translate_data_providers, ARRAY_LEN(translate_data_providers));
+		added_data_provider++;
 	}
 
 	AST_RWLIST_WRLOCK(&translators);




More information about the asterisk-commits mailing list