[asterisk-commits] russell: branch russell/res_monkeys r71267 - /team/russell/res_monkeys/apps/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jun 24 03:22:16 CDT 2007


Author: russell
Date: Sun Jun 24 03:22:15 2007
New Revision: 71267

URL: http://svn.digium.com/view/asterisk?view=rev&rev=71267
Log:
Add a Monkeys application to demonstrate channel attached threads ... as well
as for a fun new method of teletorture.

Added:
    team/russell/res_monkeys/apps/app_monkeys.c   (with props)

Added: team/russell/res_monkeys/apps/app_monkeys.c
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/apps/app_monkeys.c?view=auto&rev=71267
==============================================================================
--- team/russell/res_monkeys/apps/app_monkeys.c (added)
+++ team/russell/res_monkeys/apps/app_monkeys.c Sun Jun 24 03:22:15 2007
@@ -1,0 +1,141 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Russell Bryant, <russell at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Monkeys!
+ *
+ * \author Russell Bryant <russell at digium.com>
+ * 
+ * This is a silly application that demonstrates channel attached threads.
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+	<defaultenabled>no</defaultenabled>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/lock.h"
+#include "asterisk/app.h"
+
+static char *app = "Monkeys";
+
+static char *synopsis = "Stick Monkeys on a Channel.";
+
+static char *descrip = 
+"   This application takes a group of monkeys and sticks them on a channel\n"
+"to torment the channel for the rest of its lifetime in the system.\n"
+"";
+
+/*! In seconds */
+#define MONKEYNESS 60
+
+static void monkey_business(struct ast_channel *victim)
+{
+	struct ast_channel *bridged;
+
+	ast_channel_lock(victim);
+
+	if ((bridged = ast_bridged_channel(victim)))
+		ast_autoservice_start(bridged);
+
+	ast_stopstream(victim);
+	if (!ast_streamfile(victim, "tt-monkeys", victim->language)) {
+		ast_waitstream(victim, "");
+		ast_stopstream(victim);
+	}
+
+	ast_channel_unlock(victim);
+
+	if (bridged)
+		ast_autoservice_stop(bridged);
+}
+
+static void *monkey_thread(void *data)
+{
+	struct ast_chan_thread_args *thread_args = data;
+
+	while (!thread_args->stop_thread) {
+		struct timeval tv;
+		struct timespec ts = { 0, };
+
+		tv = ast_tvadd(ast_tvnow(), ast_samp2tv(MONKEYNESS, 1));
+		ts.tv_sec = tv.tv_sec;
+		ts.tv_nsec = tv.tv_usec * 1000;
+
+		ast_mutex_lock(&thread_args->lock);
+		if (thread_args->stop_thread) {
+			ast_mutex_unlock(&thread_args->lock);
+			break;
+		}
+		ast_cond_timedwait(&thread_args->cond, &thread_args->lock, &ts);
+		ast_mutex_unlock(&thread_args->lock);
+
+		if (thread_args->stop_thread)
+			break;
+
+		monkey_business(thread_args->chan);
+	}
+
+	return NULL;
+}
+
+static int app_exec(struct ast_channel *chan, void *data)
+{
+	struct ast_module_user *u;
+	int res = 0;
+
+	u = ast_module_user_add(chan);
+
+	if (ast_chan_thread_create(chan, monkey_thread))
+		res = -1;
+
+	ast_module_user_remove(u);
+
+	return 0;
+}
+
+static int unload_module(void)
+{
+	return ast_unregister_application(app);
+}
+
+static int load_module(void)
+{
+	if (ast_register_application(app, app_exec, synopsis, descrip))
+		return AST_MODULE_LOAD_DECLINE;
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Monkeys Application");

Propchange: team/russell/res_monkeys/apps/app_monkeys.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/russell/res_monkeys/apps/app_monkeys.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/russell/res_monkeys/apps/app_monkeys.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list