[asterisk-commits] dlee: branch dlee/ari-async-bridge r395836 - in /team/dlee/ari-async-bridge: ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 30 20:53:17 CDT 2013
Author: dlee
Date: Tue Jul 30 20:53:15 2013
New Revision: 395836
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395836
Log:
Initial idea
Added:
team/dlee/ari-async-bridge/res/res_stasis_bridge.c
- copied, changed from r395795, team/dlee/ari-async-bridge/res/res_stasis_bridge_add.c
Removed:
team/dlee/ari-async-bridge/res/res_stasis_bridge_add.c
Modified:
team/dlee/ari-async-bridge/include/asterisk/stasis_app.h
team/dlee/ari-async-bridge/include/asterisk/stasis_app_impl.h
team/dlee/ari-async-bridge/res/ari/resource_bridges.c
team/dlee/ari-async-bridge/res/stasis/control.c
Modified: team/dlee/ari-async-bridge/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/include/asterisk/stasis_app.h?view=diff&rev=395836&r1=395835&r2=395836
==============================================================================
--- team/dlee/ari-async-bridge/include/asterisk/stasis_app.h (original)
+++ team/dlee/ari-async-bridge/include/asterisk/stasis_app.h Tue Jul 30 20:53:15 2013
@@ -330,21 +330,18 @@
*
* \param control Control whose channel should be removed from the bridge
* \param bridge Pointer to the bridge
+ */
+void stasis_app_control_remove_channel_from_bridge(
+ struct stasis_app_control *control, struct ast_bridge *bridge);
+
+/*!
+ * \brief Destroy the bridge.
+ *
+ * \param bridge_id Uniqueid of bridge to be destroyed
*
* \retval non-zero on failure
* \retval zero on success
*/
-int stasis_app_control_remove_channel_from_bridge(
- struct stasis_app_control *control, struct ast_bridge *bridge);
-
-/*!
- * \brief Destroy the bridge.
- *
- * \param bridge_id Uniqueid of bridge to be destroyed
- *
- * \retval non-zero on failure
- * \retval zero on success
- */
void stasis_app_bridge_destroy(const char *bridge_id);
/*!
Modified: team/dlee/ari-async-bridge/include/asterisk/stasis_app_impl.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/include/asterisk/stasis_app_impl.h?view=diff&rev=395836&r1=395835&r2=395836
==============================================================================
--- team/dlee/ari-async-bridge/include/asterisk/stasis_app_impl.h (original)
+++ team/dlee/ari-async-bridge/include/asterisk/stasis_app_impl.h Tue Jul 30 20:53:15 2013
@@ -85,4 +85,25 @@
int stasis_app_send_command_async(struct stasis_app_control *control,
stasis_app_command_cb command, void *data);
+/*!
+ * \since 12
+ * \brief Changes the bridge currently associated with a control object.
+ *
+ * \param control Control object for the channel to query.
+ * \param bridge New bridge to set on the control object. Or \c NULL to clear
+ * the association.
+ */
+void stasis_app_set_bridge(struct stasis_app_control *control,
+ struct ast_bridge *bridge);
+
+/*!
+ * \since 12
+ * \brief Gets the bridge currently associated with a control object.
+ *
+ * \param control Control object for the channel to query.
+ * \return Associated \ref ast_bridge.
+ * \return \c NULL if not associated with a bridge.
+ */
+struct ast_bridge *stasis_app_get_bridge(struct stasis_app_control *control);
+
#endif /* _ASTERISK_RES_STASIS_H */
Modified: team/dlee/ari-async-bridge/res/ari/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/res/ari/resource_bridges.c?view=diff&rev=395836&r1=395835&r2=395836
==============================================================================
--- team/dlee/ari-async-bridge/res/ari/resource_bridges.c (original)
+++ team/dlee/ari-async-bridge/res/ari/resource_bridges.c Tue Jul 30 20:53:15 2013
@@ -137,15 +137,7 @@
return;
}
- /* BUGBUG this should make sure the bridge requested for removal is actually
- * the bridge the channel is in. This will be possible once the bridge uniqueid
- * is added to the channel snapshot. A 409 response should be issued if the bridge
- * uniqueids don't match */
- if (stasis_app_control_remove_channel_from_bridge(control, bridge)) {
- ast_ari_response_error(response, 500, "Internal Error",
- "Could not remove channel from bridge");
- return;
- }
+ stasis_app_control_remove_channel_from_bridge(control, bridge);
ast_ari_response_no_content(response);
}
Copied: team/dlee/ari-async-bridge/res/res_stasis_bridge.c (from r395795, team/dlee/ari-async-bridge/res/res_stasis_bridge_add.c)
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/res/res_stasis_bridge.c?view=diff&rev=395836&p1=team/dlee/ari-async-bridge/res/res_stasis_bridge_add.c&r1=395795&p2=team/dlee/ari-async-bridge/res/res_stasis_bridge.c&r2=395836
==============================================================================
--- team/dlee/ari-async-bridge/res/res_stasis_bridge_add.c (original)
+++ team/dlee/ari-async-bridge/res/res_stasis_bridge.c Tue Jul 30 20:53:15 2013
@@ -36,24 +36,66 @@
#include "asterisk/stasis_app_impl.h"
#include "asterisk/bridge.h"
-static void *app_control_join_bridge(struct stasis_app_control *control,
+static void *app_control_add_channel_to_bridge(
+ struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
- struct ast_bridge_features features;
+ struct ast_bridge_features *features;
struct ast_bridge *bridge = data;
- ast_bridge_features_init(&features);
- ast_bridge_join(bridge, chan, NULL, &features, NULL, 0);
- ast_bridge_features_cleanup(&features);
+
+ ast_debug(3, "%s: Adding to bridge\n",
+ stasis_app_control_get_channel_id(control));
+
+ features = ast_bridge_features_new();
+ if (!features) {
+ ast_log(LOG_ERROR,
+ "Failed to allocate bridge features; proceeding without.\n");
+ }
+
+ ast_bridge_impart(bridge,
+ chan,
+ NULL, /* swap channel */
+ features,
+ 0); /* independent - false allows us to ast_bridge_depart() */
return NULL;
}
-void stasis_app_control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
+void stasis_app_control_add_channel_to_bridge(
+ struct stasis_app_control *control, struct ast_bridge *bridge)
{
ast_debug(3, "%s: Sending channel add_to_bridge command\n",
stasis_app_control_get_channel_id(control));
+ stasis_app_send_command_async(control,
+ app_control_add_channel_to_bridge, bridge);
+}
- stasis_app_send_command_async(control, app_control_join_bridge, bridge);
+static void *app_control_remove_channel_from_bridge(
+ struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ struct ast_bridge *bridge = data;
+
+ ast_debug(3, "%s: Departing bridge\n",
+ stasis_app_control_get_channel_id(control));
+ if (bridge != stasis_app_get_bridge(control)) {
+ ast_log(LOG_WARNING, "%s: Not in bridge %s; not removing\n",
+ stasis_app_control_get_channel_id(control),
+ bridge->uniqueid);
+ return NULL;
+ }
+
+ ast_bridge_depart(chan);
+ return NULL;
+}
+
+void stasis_app_control_remove_channel_from_bridge(
+ struct stasis_app_control *control, struct ast_bridge *bridge)
+{
+ ast_debug(3, "%s: Sending channel remove_from_bridge command\n",
+ stasis_app_control_get_channel_id(control));
+ stasis_app_send_command_async(control,
+ app_control_remove_channel_from_bridge, bridge);
}
static int load_module(void)
@@ -66,7 +108,7 @@
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application bridge add channel support",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application bridge support",
.load = load_module,
.unload = unload_module,
.nonoptreq = "res_stasis");
Modified: team/dlee/ari-async-bridge/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-async-bridge/res/stasis/control.c?view=diff&rev=395836&r1=395835&r2=395836
==============================================================================
--- team/dlee/ari-async-bridge/res/stasis/control.c (original)
+++ team/dlee/ari-async-bridge/res/stasis/control.c Tue Jul 30 20:53:15 2013
@@ -43,15 +43,19 @@
/*! Queue of commands to dispatch on the channel */
struct ao2_container *command_queue;
/*!
- * When set, /c app_stasis should exit and continue in the dialplan.
- */
- int is_done:1;
- /*!
* The associated channel.
* Be very careful with the threading associated w/ manipulating
* the channel.
*/
struct ast_channel *channel;
+ /*!
+ * When a channel is in a bridge, the bridge that it is in.
+ */
+ struct ast_bridge *bridge;
+ /*!
+ * When set, /c app_stasis should exit and continue in the dialplan.
+ */
+ int is_done:1;
};
struct stasis_app_control *control_create(struct ast_channel *channel)
@@ -417,6 +421,23 @@
return 0;
}
+void stasis_app_set_bridge(struct stasis_app_control *control,
+ struct ast_bridge *bridge)
+{
+ if (!control) {
+ return;
+ }
+ control->bridge = bridge;
+}
+
+struct ast_bridge *stasis_app_get_bridge(struct stasis_app_control *control)
+{
+ if (!control) {
+ return NULL;
+ }
+ return control->bridge;
+}
+
const char *stasis_app_control_get_channel_id(
const struct stasis_app_control *control)
{
@@ -458,10 +479,3 @@
ao2_iterator_destroy(&i);
return count;
}
-
-/* Must be defined here since it must operate on the channel outside of the queue */
-int stasis_app_control_remove_channel_from_bridge(
- struct stasis_app_control *control, struct ast_bridge *bridge)
-{
- return ast_bridge_remove(bridge, control->channel);
-}
More information about the asterisk-commits
mailing list