[asterisk-commits] file: branch group/bridging_api r54037 - in /team/group/bridging_api: ./ brid...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Feb 12 10:12:17 MST 2007


Author: file
Date: Mon Feb 12 11:12:16 2007
New Revision: 54037

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54037
Log:
Might as well commit the beginnings of the bridging API... note this is nowhere near complete or functional.

Added:
    team/group/bridging_api/bridges/
    team/group/bridging_api/bridges/Makefile   (with props)
    team/group/bridging_api/bridges/bridge_simple.c   (with props)
    team/group/bridging_api/include/asterisk/bridging.h   (with props)
    team/group/bridging_api/main/bridging.c   (with props)
Modified:
    team/group/bridging_api/Makefile
    team/group/bridging_api/main/Makefile

Modified: team/group/bridging_api/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/Makefile?view=diff&rev=54037&r1=54036&r2=54037
==============================================================================
--- team/group/bridging_api/Makefile (original)
+++ team/group/bridging_api/Makefile Mon Feb 12 11:12:16 2007
@@ -239,7 +239,7 @@
 
 ASTCFLAGS+=$(MALLOC_DEBUG)$(BUSYDETECT)$(OPTIONS)
 
-MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs main
+MOD_SUBDIRS:=res channels pbx apps codecs formats cdr funcs bridges main
 OTHER_SUBDIRS:=utils agi
 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)

Added: team/group/bridging_api/bridges/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/bridges/Makefile?view=auto&rev=54037
==============================================================================
--- team/group/bridging_api/bridges/Makefile (added)
+++ team/group/bridging_api/bridges/Makefile Mon Feb 12 11:12:16 2007
@@ -1,0 +1,25 @@
+#
+# Asterisk -- A telephony toolkit for Linux.
+# 
+# Makefile for bridging modules
+#
+# Copyright (C) 2007, Digium, Inc.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License
+#
+
+-include ../menuselect.makeopts ../menuselect.makedeps
+
+C_MODS:=$(filter-out $(MENUSELECT_FUNCS),$(patsubst %.c,%,$(wildcard bridge_*.c)))
+
+LOADABLE_MODS:=$(C_MODS)
+
+ifneq ($(findstring bridges,$(MENUSELECT_EMBED)),)
+  EMBEDDED_MODS:=$(LOADABLE_MODS)
+  LOADABLE_MODS:=
+endif
+
+all: _all
+
+include $(ASTTOPDIR)/Makefile.moddir_rules

Propchange: team/group/bridging_api/bridges/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridging_api/bridges/Makefile
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridging_api/bridges/Makefile
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/bridging_api/bridges/bridge_simple.c
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/bridges/bridge_simple.c?view=auto&rev=54037
==============================================================================
--- team/group/bridging_api/bridges/bridge_simple.c (added)
+++ team/group/bridging_api/bridges/bridge_simple.c Mon Feb 12 11:12:16 2007
@@ -1,0 +1,70 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * 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 Simple Two Channel Bridge
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ * 
+ * \ingroup bridges
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+#include "asterisk/bridging.h"
+
+static int simple_bridge_create(struct ast_bridge *br)
+{
+	return -1;
+}
+
+static int simple_bridge_destroy(struct ast_bridge *br)
+{
+	return -1;
+}
+
+static struct ast_bridge_type simple_bridge_type = {
+	.name = "simple",
+	.capabilities = AST_BRIDGE_CAPABILITY_1TO1,
+	.create = simple_bridge_create,
+	.destroy = simple_bridge_destroy,
+};
+
+static int unload_module(void)
+{
+	return ast_bridge_type_unregister(&simple_bridge_type);
+}
+
+static int load_module(void)
+{
+	return ast_bridge_type_register(&simple_bridge_type, ast_module_info->self);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Two Channel Bridge");

Propchange: team/group/bridging_api/bridges/bridge_simple.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridging_api/bridges/bridge_simple.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridging_api/bridges/bridge_simple.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/bridging_api/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/include/asterisk/bridging.h?view=auto&rev=54037
==============================================================================
--- team/group/bridging_api/include/asterisk/bridging.h (added)
+++ team/group/bridging_api/include/asterisk/bridging.h Mon Feb 12 11:12:16 2007
@@ -1,0 +1,75 @@
+/*
+ * 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 Bridging API
+ */
+
+#ifndef _ASTERISK_BRIDGING_H
+#define _ASTERISK_BRIDGING_H
+
+struct ast_bridge_channel {
+	struct ast_channel *chan;
+	AST_LIST_ENTRY(ast_bridge_channel) list;
+};
+
+struct ast_bridge {
+	struct ast_bridge_type *bt;
+	AST_LIST_HEAD_NOLOCK(, ast_bridge_channel) bridge_channels;
+};
+
+enum ast_bridge_capabilities {
+	AST_BRIDGE_CAPABILITY_1TO1 = (1 << 0),
+	AST_BRIDGE_CAPABILITY_MULTIMIX = (1 << 1),
+};
+
+struct ast_bridge_type {
+        const char *name;               /*!< Name */
+	int capabilities;               /*!< Bridge capabilities */
+	struct ast_module *module;      /*!< Module that the bridge type belongs to */
+	int (*create)(struct ast_bridge *br);
+	int (*destroy)(struct ast_bridge *br);
+        AST_RWLIST_ENTRY(ast_bridge_type) list;
+};
+
+/*! \brief Registers a bridge type
+ * \param bt Bridge type to register
+ * \param mod Module that bridge type belongs to
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_type_register(struct ast_bridge_type *bt, struct ast_module *mod);
+
+/*! \brief Unregisters a bridge type
+ * \param bt Bridge type to unregister
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_type_unregister(struct ast_bridge_type *bt);
+
+/*! \brief Create a bridge with given capabilities
+ * \param capabilities Capabilities to request that the bridge be created with
+ * \return Returns bridge structure on success, NULL on failure
+ */
+struct ast_bridge *ast_bridge_create(int capabilities);
+
+/*! \brief Destroy a bridge
+ * \param br Bridge to destroy
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_destroy(struct ast_bridge *br);
+
+#endif /* _ASTERISK_BRIDGING_H */

Propchange: team/group/bridging_api/include/asterisk/bridging.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridging_api/include/asterisk/bridging.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridging_api/include/asterisk/bridging.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/group/bridging_api/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/main/Makefile?view=diff&rev=54037&r1=54036&r2=54037
==============================================================================
--- team/group/bridging_api/main/Makefile (original)
+++ team/group/bridging_api/main/Makefile Mon Feb 12 11:12:16 2007
@@ -26,7 +26,7 @@
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
 	cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
-	strcompat.o threadstorage.o dial.o
+	strcompat.o threadstorage.o dial.o bridging.o
 
 # we need to link in the objects statically, not as a library, because
 # otherwise modules will not have them available if none of the static

Added: team/group/bridging_api/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/group/bridging_api/main/bridging.c?view=auto&rev=54037
==============================================================================
--- team/group/bridging_api/main/bridging.c (added)
+++ team/group/bridging_api/main/bridging.c Mon Feb 12 11:12:16 2007
@@ -1,0 +1,171 @@
+/*
+ * 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 Bridging API
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/options.h"
+#include "asterisk/utils.h"
+#include "asterisk/lock.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/module.h"
+#include "asterisk/bridging.h"
+
+static AST_RWLIST_HEAD_STATIC(bridge_types, ast_bridge_type);
+
+/*! \brief Registers a bridge type
+ * \param bt Bridge type to register
+ * \param mod Module that bridge type belongs to
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_type_register(struct ast_bridge_type *bt, struct ast_module *mod)
+{
+	struct ast_bridge_type *bridge_type;
+
+	/* Since our module information couldn't be statically declared when compiled... we have to set the value here */
+	bt->module = mod;
+
+	/* Ensure that a bridge type of this name is not already registered */
+	AST_RWLIST_WRLOCK(&bridge_types);
+	AST_RWLIST_TRAVERSE(&bridge_types, bridge_type, list) {
+		if (!strcasecmp(bridge_type->name, bt->name))
+			break;
+	}
+
+	/* Uh oh... bridge type already registered */
+	if (bridge_type) {
+		AST_RWLIST_UNLOCK(&bridge_types);
+		return -1;
+	}
+
+	/* Insert new one and give the user some notification */
+	AST_RWLIST_INSERT_TAIL(&bridge_types, bt, list);
+	AST_RWLIST_UNLOCK(&bridge_types);
+
+	if (option_verbose > 1)
+		ast_verbose(VERBOSE_PREFIX_2 "Registered bridge type %s\n", bt->name);
+
+	return 0;
+}
+
+/*! \brief Unregisters a bridge type
+ * \param bt Bridge type to unregister
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_type_unregister(struct ast_bridge_type *bt)
+{
+	struct ast_bridge_type *bridge_type;
+
+	/* Ensure this bridge type was already registered */
+	AST_RWLIST_WRLOCK(&bridge_types);
+	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&bridge_types, bridge_type, list) {
+		if (bridge_type == bt) {
+			AST_RWLIST_REMOVE_CURRENT(&bridge_types, list);
+			if (option_verbose > 1)
+				ast_verbose(VERBOSE_PREFIX_2 "Unregistered bridge type %s\n", bt->name);
+			break;
+		}
+	}
+	AST_RWLIST_TRAVERSE_SAFE_END
+	AST_RWLIST_UNLOCK(&bridge_types);
+
+	return (bridge_type) ? 0 : -1;
+}
+
+static struct ast_bridge_type *find_bridge_type(int capabilities)
+{
+	struct ast_bridge_type *bt, *best = NULL;
+	int combined = 0, combined_best = 0;
+
+	AST_RWLIST_RDLOCK(&bridge_types);
+	AST_RWLIST_TRAVERSE(&bridge_types, bt, list) {
+		combined = bt->capabilities & capabilities;
+		/* If the combined capabilities match what we want, bail out now */
+		if (combined == capabilities) {
+			best = bt;
+			break;
+		}
+		/* If we've got nothing in common or this is not as good as the current best, continue on */
+		if (!combined || combined_best >= combined)
+			continue;
+		combined_best = combined;
+		best = bt;
+	}
+	/* If we have a match increment it's module reference count */
+	if (best)
+		ast_module_ref(best->module);
+	AST_RWLIST_UNLOCK(&bridge_types);
+
+	return best;
+}
+
+/*! \brief Create a bridge with given capabilities
+ * \param capabilities Capabilities to request that the bridge be created with
+ * \return Returns bridge structure on success, NULL on failure
+ */
+struct ast_bridge *ast_bridge_create(int capabilities)
+{
+	struct ast_bridge_type *bt = NULL;
+	struct ast_bridge *br = NULL;
+
+	/* If no capabilities are specified, just assume 1TO1 for safeness */
+	if (!capabilities)
+		capabilities = AST_BRIDGE_CAPABILITY_1TO1;
+
+	/* If we fail to find a bridge type with the given capabilities just give up */
+	if (!(bt = find_bridge_type(capabilities)))
+		return NULL;
+
+	/* Allocate a new bridge */
+	if (!(br = ast_calloc(1, sizeof(*br)))) {
+		ast_module_unref(bt->module);
+		return NULL;
+	}
+
+	/* Make the bridge type part of this bridge */
+	br->bt = bt;
+
+	return br;
+}
+
+/*! \brief Destroy a bridge
+ * \param br Bridge to destroy
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_destroy(struct ast_bridge *br)
+{
+	return -1;
+}

Propchange: team/group/bridging_api/main/bridging.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridging_api/main/bridging.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridging_api/main/bridging.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the asterisk-commits mailing list