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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 5 09:53:06 CDT 2010


Author: eliel
Date: Wed May  5 09:53:03 2010
New Revision: 261230

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=261230
Log:
Implements a data provider for the meetme application and the unit testing
of it.
The unit testing is not working as expected, i am having some truble with the
"test" channel being destroyed twice.


Modified:
    team/eliel/data_api_providers_gsoc2010/apps/app_meetme.c

Modified: team/eliel/data_api_providers_gsoc2010/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/apps/app_meetme.c?view=diff&rev=261230&r1=261229&r2=261230
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/apps/app_meetme.c (original)
+++ team/eliel/data_api_providers_gsoc2010/apps/app_meetme.c Wed May  5 09:53:03 2010
@@ -59,6 +59,8 @@
 #include "asterisk/dial.h"
 #include "asterisk/causes.h"
 #include "asterisk/paths.h"
+#include "asterisk/data.h"
+#include "asterisk/test.h"
 
 #include "enter.h"
 #include "leave.h"
@@ -1774,6 +1776,7 @@
 		}
 		ast_mutex_destroy(&conf->announcelistlock);
 	}
+
 	if (conf->origframe)
 		ast_frfree(conf->origframe);
 	if (conf->lchan)
@@ -1785,6 +1788,7 @@
 	if (conf->recordingfilename) {
 		ast_free(conf->recordingfilename);
 	}
+
 	if (conf->recordingformat) {
 		ast_free(conf->recordingformat);
 	}
@@ -6694,6 +6698,169 @@
 	return sla_load_config(0);
 }
 
+#define MEETME_DATA_EXPORT(MEMBER)					\
+	MEMBER(ast_conference, confno, AST_DATA_STRING)			\
+	MEMBER(ast_conference, dahdiconf, AST_DATA_INTEGER)		\
+	MEMBER(ast_conference, users, AST_DATA_INTEGER)			\
+	MEMBER(ast_conference, markedusers, AST_DATA_INTEGER)		\
+	MEMBER(ast_conference, maxusers, AST_DATA_INTEGER)		\
+	MEMBER(ast_conference, isdynamic, AST_DATA_BOOLEAN)		\
+	MEMBER(ast_conference, locked, AST_DATA_BOOLEAN)		\
+	MEMBER(ast_conference, recordingfilename, AST_DATA_STRING)	\
+	MEMBER(ast_conference, recordingformat, AST_DATA_STRING)	\
+	MEMBER(ast_conference, pin, AST_DATA_STRING)			\
+	MEMBER(ast_conference, pinadmin, AST_DATA_STRING)		\
+	MEMBER(ast_conference, start, AST_DATA_INTEGER)			\
+	MEMBER(ast_conference, endtime, AST_DATA_INTEGER)
+
+AST_DATA_STRUCTURE(ast_conference, MEETME_DATA_EXPORT);
+
+#define MEETME_USER_DATA_EXPORT(MEMBER)				\
+	MEMBER(ast_conf_user, user_no, AST_DATA_INTEGER)	\
+	MEMBER(ast_conf_user, talking, AST_DATA_BOOLEAN)	\
+	MEMBER(ast_conf_user, dahdichannel, AST_DATA_BOOLEAN)	\
+	MEMBER(ast_conf_user, jointime, AST_DATA_INTEGER)	\
+	MEMBER(ast_conf_user, kicktime, AST_DATA_INTEGER)	\
+	MEMBER(ast_conf_user, timelimit, AST_DATA_INTEGER)	\
+	MEMBER(ast_conf_user, play_warning, AST_DATA_INTEGER)
+
+AST_DATA_STRUCTURE(ast_conf_user, MEETME_USER_DATA_EXPORT);
+
+/*!
+ * \internal
+ * \brief Implements the meetme data provider.
+ */
+static int meetme_data_provider_get(const struct ast_data_search *search,
+	struct ast_data *data_root)
+{
+	struct ast_conference *cnf;
+	struct ast_conf_user *user;
+	struct ast_data *data_meetme, *data_meetme_users, *data_meetme_user;
+	struct ast_data *data_meetme_user_channel, *data_meetme_user_volume;
+
+	AST_LIST_LOCK(&confs);
+	AST_LIST_TRAVERSE(&confs, cnf, list) {
+		data_meetme = ast_data_add_node(data_root, "meetme");
+		if (!data_meetme) {
+			continue;
+		}
+
+		ast_data_add_structure(ast_conference, data_meetme, cnf);
+
+		if (!AST_LIST_EMPTY(&cnf->userlist)) {
+			data_meetme_users = ast_data_add_node(data_meetme, "users");
+			if (!data_meetme_user) {
+				ast_data_remove_node(data_root, data_meetme);
+				continue;
+			}
+
+			AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
+				data_meetme_user = ast_data_add_node(data_meetme_users, "user");
+				if (!data_meetme_user) {
+					continue;
+				}
+				/* user structure. */
+				ast_data_add_structure(ast_conf_user, data_meetme_user, user);
+
+				/* user's channel */
+				data_meetme_user_channel = ast_data_add_node(data_meetme_user, "channel");
+				if (!data_meetme_user_channel) {
+					continue;
+				}
+
+				ast_channel_data_add_structure(data_meetme_user_channel, user->chan);
+
+				/* volume structure */
+				data_meetme_user_volume = ast_data_add_node(data_meetme_user, "listen-volume");
+				if (!data_meetme_user_volume) {
+					continue;
+				}
+				ast_data_add_int(data_meetme_user_volume, "desired", user->listen.desired);
+				ast_data_add_int(data_meetme_user_volume, "actual", user->listen.actual);
+
+				data_meetme_user_volume = ast_data_add_node(data_meetme_user, "talk-volume");
+				if (!data_meetme_user_volume) {
+					continue;
+				}
+				ast_data_add_int(data_meetme_user_volume, "desired", user->talk.desired);
+				ast_data_add_int(data_meetme_user_volume, "actual", user->talk.actual);
+			}
+		}
+
+		if (!ast_data_search_match(search, data_meetme)) {
+			ast_data_remove_node(data_root, data_meetme);
+		}
+	}
+	AST_LIST_UNLOCK(&confs);
+
+	return 0;
+}
+
+static const struct ast_data_handler meetme_data_provider = {
+	.version = AST_DATA_HANDLER_VERSION,
+	.get = meetme_data_provider_get
+};
+
+static const struct ast_data_entry meetme_data_providers[] = {
+	AST_DATA_ENTRY("asterisk/application/app_meetme/list", &meetme_data_provider),
+};
+
+#ifdef TEST_FRAMEWORK
+AST_TEST_DEFINE(test_meetme_data_provider)
+{
+	struct ast_channel *chan;
+	struct ast_conference *cnf;
+	struct ast_data *node;
+	struct ast_data_query query = {
+		.path = "/asterisk/application/app_meetme/list",
+		.search = "list/meetme/confno=9898"
+	};
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "meetme_get_data_test";
+		info->category = "main/data/app_meetme/list";
+		info->summary = "Meetme data provider unit test";
+		info->description =
+			"Tests whether the Meetme data provider implementation works as expected.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, 0, 0, "MeetMeTest");
+	if (!chan) {
+		return AST_TEST_FAIL;
+	}
+
+	cnf = build_conf("9898", "", "1234", 1, 1, 1, chan);
+	if (!cnf) {
+		ast_hangup(chan);
+		return AST_TEST_FAIL;
+	}
+
+	node = ast_data_get(&query);
+	if (!node) {
+		dispose_conf(cnf);
+		ast_hangup(chan);
+		return AST_TEST_FAIL;
+	}
+
+	if (strcmp(ast_data_retrieve_string(node, "meetme/confno"), "9898")) {
+		dispose_conf(cnf);
+		ast_hangup(chan);
+		ast_data_free(node);
+		return AST_TEST_FAIL;
+	}
+
+	ast_data_free(node);
+	dispose_conf(cnf);
+	ast_hangup(chan);
+
+	return AST_TEST_PASS;
+}
+#endif
+
 static int unload_module(void)
 {
 	int res = 0;
@@ -6709,6 +6876,11 @@
 	res |= ast_unregister_application(slastation_app);
 	res |= ast_unregister_application(slatrunk_app);
 
+#ifdef TEST_FRAMEWORK
+	AST_TEST_UNREGISTER(test_meetme_data_provider);
+#endif
+	ast_data_unregister(NULL);
+
 	ast_devstate_prov_del("Meetme");
 	ast_devstate_prov_del("SLA");
 	
@@ -6719,6 +6891,8 @@
 
 	return res;
 }
+
+
 
 static int load_module(void)
 {
@@ -6737,6 +6911,11 @@
 	res |= ast_register_application_xml(slastation_app, sla_station_exec);
 	res |= ast_register_application_xml(slatrunk_app, sla_trunk_exec);
 
+#ifdef TEST_FRAMEWORK
+	AST_TEST_REGISTER(test_meetme_data_provider);
+#endif
+	ast_data_register_multiple(meetme_data_providers, ARRAY_LEN(meetme_data_providers));
+
 	res |= ast_devstate_prov_add("Meetme", meetmestate);
 	res |= ast_devstate_prov_add("SLA", sla_state);
 




More information about the asterisk-commits mailing list