[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r384683 - in /team/kmoore/stasis-b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 3 13:51:26 CDT 2013


Author: kmoore
Date: Wed Apr  3 13:51:23 2013
New Revision: 384683

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384683
Log:
Put down the groundwork for throwing around bridging messages

Added:
    team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h   (with props)
    team/kmoore/stasis-bridge_events/main/stasis_bridging.c   (with props)

Added: team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h?view=auto&rev=384683
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h (added)
+++ team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h Wed Apr  3 13:51:23 2013
@@ -1,0 +1,127 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013 Digium, Inc.
+ *
+ * Kinsey Moore <kmoore 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.
+ */
+
+#ifndef _STASIS_BRIDGING_H
+#define _STASIS_BRIDGING_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+struct ast_bridge;
+
+/*!
+ * \brief Structure that contains a snapshot of information about a bridge
+ */
+struct ast_bridge_snapshot {
+	AST_DECLARE_STRING_FIELDS(
+		/*! Immutable bridge UUID. */
+		AST_STRING_FIELD(uniqueid);
+		/*! Bridge technology that is handling the bridge */
+		AST_STRING_FIELD(technology);
+	);
+	/*! Linked list of channels participating in the bridge */
+	struct ao2_container *channels;
+	/*! Bridge flags to tweak behavior */
+	struct ast_flags feature_flags;
+	/*! Number of channels participating in the bridge */
+	unsigned int num_channels;
+	/*! Number of active channels in the bridge. */
+	unsigned int num_active;
+	/*!
+	 * \brief Count of the active temporary requests to inhibit bridge merges.
+	 * Zero if merges are allowed.
+	 *
+	 * \note Temporary as in try again in a moment.
+	 */
+	unsigned int inhibit_merge;
+	/*! The internal sample rate this bridge is mixed at when multiple channels are being mixed.
+	 *  If this value is 0, the bridge technology may auto adjust the internal mixing rate. */
+	unsigned int internal_sample_rate;
+	/*! The mixing interval indicates how quickly the bridges internal mixing should occur
+	 * for bridge technologies that mix audio. When set to 0, the bridge tech must choose a
+	 * default interval for itself. */
+	unsigned int internal_mixing_interval;
+	/*! TRUE if the bridge has been dissolved.  Any channel joining is immediately ejected. */
+	unsigned int dissolved:1;
+};
+
+/*!
+ * \since 12
+ * \brief Generate a snapshot of the bridge state. This is an ao2 object, so
+ * ao2_cleanup() to deallocate.
+ *
+ * \param chan The bridge from which to generate a snapshot
+ *
+ * \retval pointer on success (must be ast_freed)
+ * \retval NULL on error
+ */
+struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge);
+
+/*!
+ * \since 12
+ * \brief Message type for \ref ast_bridge_snapshot.
+ *
+ * \retval Message type for \ref ast_bridge_snapshot.
+ */
+struct stasis_message_type *ast_bridge_snapshot_type(void);
+
+/*!
+ * \since 12
+ * \brief A topic which publishes the events for a particular bridge.
+ *
+ * If the given \a bridge uniqueid is \c NULL, ast_bridge_topic_all() is returned.
+ *
+ * \param bridge_uniqueid Bridge's uniqueid or \c NULL.
+ *
+ * \retval Topic for bridge's events.
+ * \retval ast_bridge_topic_all() if \a bridge_uniqueid is \c NULL.
+ */
+struct stasis_topic *ast_bridge_topic(const char *bridge_uniqueid);
+
+/*!
+ * \since 12
+ * \brief A topic which publishes the events for all bridges.
+ * \retval Topic for all bridge events.
+ */
+struct stasis_topic *ast_bridge_topic_all(void);
+
+/*!
+ * \since 12
+ * \brief A caching topic which caches \ref ast_bridge_snapshot messages from
+ * ast_bridge_events_all(void).
+ *
+ * \retval Topic for all bridge events.
+ */
+struct stasis_caching_topic *ast_bridge_topic_all_cached(void);
+
+/*!
+ * \brief Dispose of the stasis bridging topics and message types
+ */
+void ast_stasis_bridging_shutdown(void);
+
+/*!
+ * \brief Initialize the stasis bridging topic and message types
+ */
+void ast_stasis_bridging_init(void);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif	/* _STASIS_BRIDGING_H */

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/stasis_bridging.c?view=auto&rev=384683
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_bridging.c (added)
+++ team/kmoore/stasis-bridge_events/main/stasis_bridging.c Wed Apr  3 13:51:23 2013
@@ -1,0 +1,164 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kinsey Moore <kmoore 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 Stasis Messages and Data Types for Bridge Objects
+ *
+ * \author Kinsey Moore <kmoore at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/astobj2.h"
+#include "asterisk/stasis.h"
+#include "asterisk/channel.h"
+#include "asterisk/stasis_bridging.h"
+#include "asterisk/bridging.h"
+#include "asterisk/bridging_technology.h"
+
+#define SNAPSHOT_CHANNELS_BUCKETS 13
+
+static struct stasis_message_type *bridge_snapshot_type;
+
+static struct stasis_topic *bridge_topic_all;
+
+static struct stasis_caching_topic *bridge_topic_all_cached;
+
+static struct stasis_topic_pool *bridge_topic_pool;
+
+static void bridge_snapshot_dtor(void *obj)
+{
+	struct ast_bridge_snapshot *snapshot = obj;
+	ast_string_field_free_memory(snapshot);
+	ao2_cleanup(snapshot->channels);
+	snapshot->channels = NULL;
+}
+
+static int chan_hash(const void *obj, const int flags)
+{
+	return ast_str_hash(obj);
+}
+
+static int chan_cmp(void *lhs, void *rhs, int flags)
+{
+	return strcmp(lhs, rhs) ? 0 : CMP_MATCH;
+}
+
+struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge)
+{
+	RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
+	struct ast_bridge_channel *bridge_channel;
+
+	snapshot = ao2_alloc(sizeof(*snapshot), bridge_snapshot_dtor);
+	if (!snapshot || ast_string_field_init(snapshot, 128)) {
+		return NULL;
+	}
+
+	snapshot->channels = ao2_container_alloc(SNAPSHOT_CHANNELS_BUCKETS, chan_hash, chan_cmp);
+	if (!snapshot->channels) {
+		return NULL;
+	}
+
+	AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
+		RAII_VAR(char *, ao2_uniqueid, NULL, ao2_cleanup);
+		const char *chan_uniqueid = ast_channel_uniqueid(bridge_channel->chan);
+
+		ao2_uniqueid = ao2_alloc(strlen(chan_uniqueid) + 1, NULL);
+		if (!ao2_uniqueid) {
+			return NULL;
+		}
+
+		/* safe strcpy */
+		strcpy(ao2_uniqueid, chan_uniqueid);
+		ao2_link(snapshot->channels, ao2_uniqueid);
+	}
+
+	ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);
+	ast_string_field_set(snapshot, technology, bridge->technology->name);
+
+	snapshot->feature_flags = bridge->feature_flags;
+	snapshot->num_channels = bridge->num_channels;
+	snapshot->num_active = bridge->num_active;
+	snapshot->inhibit_merge = bridge->inhibit_merge;
+	snapshot->internal_sample_rate = bridge->internal_sample_rate;
+	snapshot->internal_mixing_interval = bridge->internal_mixing_interval;
+	snapshot->dissolved = bridge->dissolved;
+
+	ao2_ref(snapshot, +1);
+	return snapshot;
+}
+
+struct stasis_message_type *ast_bridge_snapshot_type(void)
+{
+	return bridge_snapshot_type;
+}
+
+struct stasis_topic *ast_bridge_topic(const char *bridge_uniqueid)
+{
+	struct stasis_topic *bridge_topic = stasis_topic_pool_get_topic(bridge_topic_pool, bridge_uniqueid);
+	if (!bridge_topic) {
+		return ast_bridge_topic_all();
+	}
+	return bridge_topic;
+}
+
+struct stasis_topic *ast_bridge_topic_all(void)
+{
+	return bridge_topic_all;
+}
+
+struct stasis_caching_topic *ast_bridge_topic_all_cached(void)
+{
+	return bridge_topic_all_cached;
+}
+
+void ast_stasis_bridging_shutdown(void)
+{
+	ao2_cleanup(bridge_snapshot_type);
+	bridge_snapshot_type = NULL;
+	ao2_cleanup(bridge_topic_all);
+	bridge_topic_all = NULL;
+	bridge_topic_all_cached = stasis_caching_unsubscribe(bridge_topic_all_cached);
+	ao2_cleanup(bridge_topic_pool);
+	bridge_topic_pool = NULL;
+}
+
+static const char *bridge_snapshot_get_id(struct stasis_message *msg)
+{
+	struct ast_bridge_snapshot *snapshot;
+	if (stasis_message_type(msg) != ast_bridge_snapshot_type()) {
+		return NULL;
+	}
+	snapshot = stasis_message_data(msg);
+	return snapshot->uniqueid;
+}
+
+void ast_stasis_bridging_init(void)
+{
+	bridge_snapshot_type = stasis_message_type_create("ast_bridge_snapshot");
+	bridge_topic_all = stasis_topic_create("ast_bridge_topic_all");
+	bridge_topic_all_cached = stasis_caching_topic_create(bridge_topic_all, bridge_snapshot_get_id);
+	bridge_topic_pool = stasis_topic_pool_create(bridge_topic_all);
+}

Propchange: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list