[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r384758 - in /team/kmoore/stasis-b...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 4 12:57:27 CDT 2013
Author: kmoore
Date: Thu Apr 4 12:57:24 2013
New Revision: 384758
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384758
Log:
Add bridge merge event and make sure to actually call the init and shutdown hooks
Modified:
team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h
team/kmoore/stasis-bridge_events/main/bridging.c
team/kmoore/stasis-bridge_events/main/stasis_bridging.c
Modified: 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=diff&rev=384758&r1=384757&r2=384758
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/stasis_bridging.h Thu Apr 4 12:57:24 2013
@@ -122,6 +122,28 @@
*/
void ast_bridge_publish_state(struct ast_bridge *bridge);
+struct ast_bridge_merge_message {
+ struct ast_bridge_snapshot *from; /*!< Bridge from which channels will be removed during the merge */
+ struct ast_bridge_snapshot *to; /*!< Bridge to which channels will be added during the merge */
+};
+
+/*!
+ * \since 12
+ * \brief Message type for \ref ast_bridge_merge_message.
+ *
+ * \retval Message type for \ref ast_bridge_merge_message.
+ */
+struct stasis_message_type *ast_bridge_merge_message_type(void);
+
+/*!
+ * \since 12
+ * \brief Publish a bridge merger
+ *
+ * \param bridge1 The bridge to which channels are being added
+ * \param bridge2 The bridge from which channels are being removed
+ */
+void ast_bridge_publish_merge(struct ast_bridge *bridge1, struct ast_bridge *bridge2);
+
/*!
* \brief Dispose of the stasis bridging topics and message types
*/
Modified: team/kmoore/stasis-bridge_events/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/bridging.c?view=diff&rev=384758&r1=384757&r2=384758
==============================================================================
--- team/kmoore/stasis-bridge_events/main/bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/bridging.c Thu Apr 4 12:57:24 2013
@@ -2709,6 +2709,8 @@
ast_debug(1, "Merging bridge %s into bridge %s\n",
bridge2->uniqueid, bridge1->uniqueid);
+ ast_bridge_publish_merge(bridge1, bridge2);
+
/* Move channels from bridge2 over to bridge1 */
while ((bridge_channel = AST_LIST_FIRST(&bridge2->channels))) {
bridge_channel_pull(bridge_channel);
@@ -3662,6 +3664,7 @@
{
ao2_cleanup(bridge_manager);
bridge_manager = NULL;
+ ast_stasis_bridging_shutdown();
}
int ast_bridging_init(void)
@@ -3671,6 +3674,8 @@
return -1;
}
+ ast_stasis_bridging_init();
+
ast_register_atexit(bridge_shutdown);
return 0;
}
Modified: 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=diff&rev=384758&r1=384757&r2=384758
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/stasis_bridging.c Thu Apr 4 12:57:24 2013
@@ -47,6 +47,8 @@
static struct stasis_caching_topic *bridge_topic_all_cached;
static struct stasis_topic_pool *bridge_topic_pool;
+
+static struct stasis_message_type *bridge_merge_message_type;
static void bridge_snapshot_dtor(void *obj)
{
@@ -160,8 +162,66 @@
return;
}
- ast_assert(ast_bridge_topic(bridge) != NULL);
stasis_publish(ast_bridge_topic(bridge), msg);
+}
+
+struct stasis_message_type *ast_bridge_merge_message_type(void)
+{
+ return bridge_merge_message_type;
+}
+
+static void bridge_merge_message_dtor(void *obj)
+{
+ struct ast_bridge_merge_message *msg = obj;
+
+ ao2_cleanup(msg->to);
+ msg->to = NULL;
+ ao2_cleanup(msg->from);
+ msg->from = NULL;
+}
+
+static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_bridge *bridge1, struct ast_bridge *bridge2)
+{
+ RAII_VAR(struct ast_bridge_merge_message *, msg, NULL, ao2_cleanup);
+
+ msg = ao2_alloc(sizeof(*msg), bridge_merge_message_dtor);
+ if (!msg) {
+ return NULL;
+ }
+
+ msg->to = ast_bridge_snapshot_create(bridge1);
+ if (!msg->to) {
+ return NULL;
+ }
+
+ msg->from = ast_bridge_snapshot_create(bridge2);
+ if (!msg->from) {
+ return NULL;
+ }
+
+ ao2_ref(msg, +1);
+ return msg;
+}
+
+void ast_bridge_publish_merge(struct ast_bridge *bridge1, struct ast_bridge *bridge2)
+{
+ RAII_VAR(struct ast_bridge_merge_message *, merge_msg, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+ ast_assert(bridge1 != NULL);
+ ast_assert(bridge2 != NULL);
+
+ merge_msg = bridge_merge_message_create(bridge1, bridge2);
+ if (!merge_msg) {
+ return;
+ }
+
+ msg = stasis_message_create(ast_bridge_snapshot_type(), merge_msg);
+ if (!msg) {
+ return;
+ }
+
+ stasis_publish(ast_bridge_topic_all(), msg);
}
void ast_stasis_bridging_shutdown(void)
@@ -173,6 +233,8 @@
bridge_topic_all_cached = stasis_caching_unsubscribe(bridge_topic_all_cached);
ao2_cleanup(bridge_topic_pool);
bridge_topic_pool = NULL;
+ ao2_cleanup(bridge_merge_message_type);
+ bridge_merge_message_type = NULL;
}
static const char *bridge_snapshot_get_id(struct stasis_message *msg)
@@ -191,4 +253,5 @@
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);
-}
+ bridge_snapshot_type = stasis_message_type_create("ast_bridge_merge_message");
+}
More information about the asterisk-commits
mailing list