[asterisk-commits] file: branch file/bridging r79047 - /team/file/bridging/apps/app_confbridge.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 10 13:13:56 CDT 2007


Author: file
Date: Fri Aug 10 13:13:56 2007
New Revision: 79047

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79047
Log:
Add ConfBridge application. This totals around 150 lines and implements a very basic conferencing application utilizing the bridging core.

Added:
    team/file/bridging/apps/app_confbridge.c   (with props)

Added: team/file/bridging/apps/app_confbridge.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_confbridge.c?view=auto&rev=79047
==============================================================================
--- team/file/bridging/apps/app_confbridge.c (added)
+++ team/file/bridging/apps/app_confbridge.c Fri Aug 10 13:13:56 2007
@@ -1,0 +1,165 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Joshua Colp <jcolp 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 Conference Bridge application
+ *
+ * \author\verbatim Joshua Colp <jcolp at digium.com> \endverbatim
+ * 
+ * This is a conference bridge application utilizing the bridging core.
+ * \ingroup applications
+ */
+
+#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"
+#include "asterisk/bridging.h"
+
+static char *app = "ConfBridge";
+static char *synopsis = 
+"Conference Bridge application.";
+static char *descrip = "This application is a template to build other applications from.\n"
+ " It shows you the basic structure to create your own Asterisk applications.\n";
+
+enum {
+	OPTION_DYNAMIC = (1 << 0),
+} option_flags;
+
+AST_APP_OPTIONS(app_opts,{
+	AST_APP_OPTION('d', OPTION_DYNAMIC),
+});
+
+struct conference_bridge {
+	const char *name;                       /*!< Name of the conference bridge */
+	struct ast_bridge *bridge;              /*!< Bridge structure doing the mixing */
+	int users;                              /*!< Number of users present */
+	int dynamic:1;                          /*!< Is this conference bridge dynamically generated? */
+	AST_LIST_ENTRY(conference_bridge) list; /*!< Linked list information */
+};
+
+static AST_LIST_HEAD_STATIC(conference_bridges, conference_bridge);
+
+static struct conference_bridge *find_conference_bridge(const char *name, int dynamic)
+{
+	struct conference_bridge *conference_bridge = NULL;
+
+	AST_LIST_LOCK(&conference_bridges);
+
+	/* Look for an already existing conference bridge */
+	AST_LIST_TRAVERSE(&conference_bridges, conference_bridge, list) {
+		if (!strcasecmp(conference_bridge->name, name))
+			break;
+	}
+
+	/* If one was not found and we can dynamically create it, do so */
+	if (!conference_bridge && dynamic && (conference_bridge = ast_calloc(1, sizeof(*conference_bridge)))) {
+		conference_bridge->dynamic = 1;
+		conference_bridge->name = name;
+		if (!(conference_bridge->bridge = ast_bridge_new(AST_BRIDGE_CAPABILITY_MULTIMIX, 0))) {
+			free(conference_bridge);
+			conference_bridge = NULL;
+		} else
+			AST_LIST_INSERT_TAIL(&conference_bridges, conference_bridge, list);
+	}
+
+	/* Increment user count if we found a conference bridge */
+	if (conference_bridge)
+		ast_atomic_fetchadd_int(&conference_bridge->users, +1);
+
+	AST_LIST_UNLOCK(&conference_bridges);
+
+	return conference_bridge;
+}
+
+static int app_exec(struct ast_channel *chan, void *data)
+{
+	int res = 0;
+	struct ast_flags flags;
+	char *parse;
+	struct conference_bridge *conference_bridge = NULL;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(conf_name);
+		AST_APP_ARG(options);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "%s requires an argument (conference name[,options])\n", app);
+		return -1;
+	}
+
+	/* We need to make a copy of the input string if we are going to modify it! */
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (args.argc == 2)
+		ast_app_parse_options(app_opts, &flags, NULL, args.options);
+
+	/* Look for a conference bridge matching the provided name */
+	if (!(conference_bridge = find_conference_bridge(args.conf_name, ast_test_flag(&flags, OPTION_DYNAMIC)))) {
+		ast_log(LOG_WARNING, "Conference bridge with name %s does not exist.\n", args.conf_name);
+		return -1;
+	}
+
+	/* Actually join the bridge */
+	ast_bridge_join(conference_bridge->bridge, chan);
+
+	/* Drop ourselves from the conference bridge and remove it if needed */
+	AST_LIST_LOCK(&conference_bridges);
+	/* Decrement users count, and if this is dynamic remove it if we are the last one */
+	if (ast_atomic_fetchadd_int(&conference_bridge->users, -1) == 1 && conference_bridge->dynamic) {
+		/* Remove from list */
+		AST_LIST_REMOVE(&conference_bridges, conference_bridge, list);
+		/* Drop bridge */
+		ast_bridge_destroy(conference_bridge->bridge);
+		/* Finally deallocate ourselves */
+		ast_free(conference_bridge);
+	}
+	AST_LIST_UNLOCK(&conference_bridges);
+
+	return res;
+}
+
+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, "Conference Bridge Application");

Propchange: team/file/bridging/apps/app_confbridge.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/file/bridging/apps/app_confbridge.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/file/bridging/apps/app_confbridge.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list