[asterisk-commits] dlee: trunk r396568 - in /trunk: include/asterisk/ res/ res/ari/ res/stasis/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 13 10:27:36 CDT 2013
Author: dlee
Date: Tue Aug 13 10:27:32 2013
New Revision: 396568
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396568
Log:
ARI: allow other operations to happen while bridged
This patch changes ARI bridging to allow other channel operations to
happen while the channel is bridged.
ARI channel operations are designed to queue up and execute
sequentially. This meant, though, that while a channel was bridged,
any other channel operations would queue up and execute only after the
channel left the bridge.
This patch changes ARI bridging so that channel commands can execute
while the channel is bridged. For most operations, things simply work
as expected. The one thing that ended up being a bit odd is recording.
The current recording implementation will fail when one attempts to
record a channel that's in a bridge. Note that the bridge itself may
be recording; it's recording a specific channel in the bridge that
fails. While this is an annoying limitation, channel recording is
still very useful for use cases such as voice mail, and bridge
recording makes up much of the difference for other use cases.
(closes issue ASTERISK-22084)
Review: https://reviewboard.asterisk.org/r/2726/
Removed:
trunk/res/res_stasis_bridge_add.c
trunk/res/res_stasis_bridge_add.exports.in
Modified:
trunk/include/asterisk/bridge_features.h
trunk/include/asterisk/bridge_internal.h
trunk/include/asterisk/stasis_app.h
trunk/include/asterisk/stasis_app_impl.h
trunk/res/ari/resource_bridges.c
trunk/res/res_stasis.c
trunk/res/res_stasis_playback.c
trunk/res/res_stasis_recording.c
trunk/res/stasis/control.c
trunk/res/stasis/control.h
Modified: trunk/include/asterisk/bridge_features.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridge_features.h?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/include/asterisk/bridge_features.h (original)
+++ trunk/include/asterisk/bridge_features.h Tue Aug 13 10:27:32 2013
@@ -24,6 +24,8 @@
#ifndef _ASTERISK_BRIDGING_FEATURES_H
#define _ASTERISK_BRIDGING_FEATURES_H
+
+#include "asterisk/channel.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
Modified: trunk/include/asterisk/bridge_internal.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bridge_internal.h?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/include/asterisk/bridge_internal.h (original)
+++ trunk/include/asterisk/bridge_internal.h Tue Aug 13 10:27:32 2013
@@ -36,6 +36,7 @@
struct ast_bridge;
struct ast_bridge_channel;
+struct ast_bridge_methods;
/*!
* \brief Register the new bridge with the system.
Modified: trunk/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_app.h?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/include/asterisk/stasis_app.h (original)
+++ trunk/include/asterisk/stasis_app.h Tue Aug 13 10:27:32 2013
@@ -348,21 +348,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: trunk/include/asterisk/stasis_app_impl.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_app_impl.h?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/include/asterisk/stasis_app_impl.h (original)
+++ trunk/include/asterisk/stasis_app_impl.h Tue Aug 13 10:27:32 2013
@@ -85,4 +85,14 @@
int stasis_app_send_command_async(struct stasis_app_control *control,
stasis_app_command_cb command, void *data);
+/*!
+ * \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: trunk/res/ari/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_bridges.c?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/ari/resource_bridges.c (original)
+++ trunk/res/ari/resource_bridges.c Tue Aug 13 10:27:32 2013
@@ -214,10 +214,8 @@
* is added to the channel snapshot. A 409 response should be issued if the bridge
* uniqueids don't match */
for (i = 0; i < list->count; ++i) {
- if (stasis_app_control_remove_channel_from_bridge(list->controls[i], bridge)) {
- ast_ari_response_error(response, 500, "Internal Error",
- "Could not remove channel from bridge");
- }
+ stasis_app_control_remove_channel_from_bridge(list->controls[i],
+ bridge);
}
if (response->response_code) {
Modified: trunk/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis.c?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/res_stasis.c (original)
+++ trunk/res/res_stasis.c Tue Aug 13 10:27:32 2013
@@ -593,6 +593,13 @@
RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
int r;
int command_count;
+
+ if (stasis_app_get_bridge(control)) {
+ /* Bridge is handling channel frames */
+ control_wait(control);
+ control_dispatch_all(control, chan);
+ continue;
+ }
r = ast_waitfor(chan, MAX_WAIT_MS);
Modified: trunk/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_playback.c?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/res_stasis_playback.c (original)
+++ trunk/res/res_stasis_playback.c Tue Aug 13 10:27:32 2013
@@ -34,6 +34,8 @@
#include "asterisk/app.h"
#include "asterisk/astobj2.h"
+#include "asterisk/bridge.h"
+#include "asterisk/bridge_internal.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
@@ -73,11 +75,55 @@
/*! Number of milliseconds to skip for forward/reverse operations */
int skipms;
+ /*! Set when playback has been completed */
+ int done;
+ /*! Condition for waiting on done to be set */
+ ast_cond_t done_cond;
/*! Number of milliseconds of media that has been played */
long playedms;
/*! Current playback state */
enum stasis_app_playback_state state;
};
+
+static void playback_dtor(void *obj)
+{
+ struct stasis_app_playback *playback = obj;
+
+ ast_string_field_free_memory(playback);
+ ast_cond_destroy(&playback->done_cond);
+}
+
+static struct stasis_app_playback *playback_create(
+ struct stasis_app_control *control)
+{
+ RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
+ char id[AST_UUID_STR_LEN];
+ int res;
+
+ if (!control) {
+ return NULL;
+ }
+
+ playback = ao2_alloc(sizeof(*playback), playback_dtor);
+ if (!playback || ast_string_field_init(playback, 128)) {
+ return NULL;
+ }
+
+ res = ast_cond_init(&playback->done_cond, NULL);
+ if (res != 0) {
+ ast_log(LOG_ERROR, "Error creating done condition: %s\n",
+ strerror(errno));
+ return NULL;
+ }
+
+ ast_uuid_generate_str(id, sizeof(id));
+ ast_string_field_set(playback, id, id);
+
+ playback->control = control;
+
+ ao2_ref(playback, +1);
+ return playback;
+}
static int playback_hash(const void *obj, int flags)
{
@@ -144,12 +190,6 @@
stasis_app_control_publish(playback->control, message);
}
-static void playback_cleanup(struct stasis_app_playback *playback)
-{
- ao2_unlink_flags(playbacks, playback,
- OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
-}
-
static int playback_first_update(struct stasis_app_playback *playback,
const char *uniqueid)
{
@@ -191,11 +231,21 @@
playback_publish(playback);
}
-static void *play_uri(struct stasis_app_control *control,
- struct ast_channel *chan, void *data)
-{
- RAII_VAR(struct stasis_app_playback *, playback, NULL,
- playback_cleanup);
+/*!
+ * \brief RAII_VAR function to mark a playback as done when leaving scope.
+ */
+static void mark_as_done(struct stasis_app_playback *playback)
+{
+ SCOPED_AO2LOCK(lock, playback);
+ playback->done = 1;
+ ast_cond_broadcast(&playback->done_cond);
+}
+
+static void play_on_channel(struct stasis_app_playback *playback,
+ struct ast_channel *chan)
+{
+ RAII_VAR(struct stasis_app_playback *, mark_when_done, playback,
+ mark_as_done);
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
RAII_VAR(char *, file, NULL, ast_free);
int res;
@@ -210,7 +260,6 @@
const char *pause = NULL;
const char *restart = NULL;
- playback = data;
ast_assert(playback != NULL);
offsetms = playback->offsetms;
@@ -218,7 +267,7 @@
res = playback_first_update(playback, ast_channel_uniqueid(chan));
if (res != 0) {
- return NULL;
+ return;
}
if (ast_channel_state(chan) != AST_STATE_UP) {
@@ -241,11 +290,11 @@
} else {
/* Play URL */
ast_log(LOG_ERROR, "Unimplemented\n");
- return NULL;
+ return;
}
if (!file) {
- return NULL;
+ return;
}
res = ast_control_streamfile_lang(chan, file, fwd, rev, stop, pause,
@@ -254,14 +303,87 @@
playback_final_update(playback, offsetms, res,
ast_channel_uniqueid(chan));
+ return;
+}
+
+/*!
+ * \brief Special case code to play while a channel is in a bridge.
+ *
+ * \param bridge_channel The channel's bridge_channel.
+ * \param playback_id Id of the playback to start.
+ */
+static void play_on_channel_in_bridge(struct ast_bridge_channel *bridge_channel,
+ const char *playback_id)
+{
+ RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
+
+ playback = stasis_app_playback_find_by_id(playback_id);
+ if (!playback) {
+ ast_log(LOG_ERROR, "Couldn't find playback %s\n",
+ playback_id);
+ return;
+ }
+
+ play_on_channel(playback, bridge_channel->chan);
+}
+
+/*!
+ * \brief \ref RAII_VAR function to remove a playback from the global list when
+ * leaving scope.
+ */
+static void remove_from_playbacks(struct stasis_app_playback *playback)
+{
+ ao2_unlink_flags(playbacks, playback,
+ OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+}
+
+static void *play_uri(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ RAII_VAR(struct stasis_app_playback *, playback, NULL,
+ remove_from_playbacks);
+ struct ast_bridge *bridge;
+ int res;
+
+ playback = data;
+
+ if (!control) {
+ return NULL;
+ }
+
+ bridge = stasis_app_get_bridge(control);
+ if (bridge) {
+ struct ast_bridge_channel *bridge_chan;
+
+ /* Queue up playback on the bridge */
+ ast_bridge_lock(bridge);
+ bridge_chan = bridge_find_channel(bridge, chan);
+ if (bridge_chan) {
+ ast_bridge_channel_queue_playfile(
+ bridge_chan,
+ play_on_channel_in_bridge,
+ playback->id,
+ NULL); /* moh_class */
+ }
+ ast_bridge_unlock(bridge);
+
+ /* Wait for playback to complete */
+ ao2_lock(playback);
+ while (!playback->done) {
+ res = ast_cond_wait(&playback->done_cond,
+ ao2_object_get_lockaddr(playback));
+ if (res != 0) {
+ ast_log(LOG_ERROR,
+ "Error waiting for playback to complete: %s\n",
+ strerror(errno));
+ }
+ }
+ ao2_unlock(playback);
+ } else {
+ play_on_channel(playback, chan);
+ }
+
return NULL;
-}
-
-static void playback_dtor(void *obj)
-{
- struct stasis_app_playback *playback = obj;
-
- ast_string_field_free_memory(playback);
}
static void set_target_uri(
@@ -291,7 +413,6 @@
int skipms, long offsetms)
{
RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
- char id[AST_UUID_STR_LEN];
if (skipms < 0 || offsetms < 0) {
return NULL;
@@ -300,21 +421,15 @@
ast_debug(3, "%s: Sending play(%s) command\n",
stasis_app_control_get_channel_id(control), uri);
- playback = ao2_alloc(sizeof(*playback), playback_dtor);
- if (!playback || ast_string_field_init(playback, 128)) {
- return NULL;
- }
+ playback = playback_create(control);
if (skipms == 0) {
skipms = PLAYBACK_DEFAULT_SKIPMS;
}
- ast_uuid_generate_str(id, sizeof(id));
- ast_string_field_set(playback, id, id);
ast_string_field_set(playback, media, uri);
ast_string_field_set(playback, language, language);
set_target_uri(playback, target_type, target_id);
- playback->control = control;
playback->skipms = skipms;
playback->offsetms = offsetms;
ao2_link(playbacks, playback);
@@ -346,15 +461,7 @@
struct stasis_app_playback *stasis_app_playback_find_by_id(const char *id)
{
- RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
-
- playback = ao2_find(playbacks, id, OBJ_KEY);
- if (playback == NULL) {
- return NULL;
- }
-
- ao2_ref(playback, +1);
- return playback;
+ return ao2_find(playbacks, id, OBJ_KEY);
}
struct ast_json *stasis_app_playback_to_json(
Modified: trunk/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_recording.c?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/res_stasis_recording.c (original)
+++ trunk/res/res_stasis_recording.c Tue Aug 13 10:27:32 2013
@@ -231,10 +231,11 @@
recording = data;
ast_assert(recording != NULL);
- ao2_lock(recording);
- recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
- recording_publish(recording);
- ao2_unlock(recording);
+ if (stasis_app_get_bridge(control)) {
+ ast_log(LOG_ERROR, "Cannot record channel while in bridge\n");
+ recording_fail(recording);
+ return NULL;
+ }
switch (recording->options->terminate_on) {
case STASIS_APP_RECORDING_TERMINATE_NONE:
@@ -257,6 +258,11 @@
recording_fail(recording);
return NULL;
}
+
+ ao2_lock(recording);
+ recording->state = STASIS_APP_RECORDING_STATE_RECORDING;
+ recording_publish(recording);
+ ao2_unlock(recording);
ast_play_and_record_full(chan,
NULL, /* playfile */
Modified: trunk/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis/control.c?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/stasis/control.c (original)
+++ trunk/res/stasis/control.c Tue Aug 13 10:27:32 2013
@@ -33,32 +33,58 @@
#include "control.h"
#include "asterisk/dial.h"
#include "asterisk/bridge.h"
+#include "asterisk/bridge_after.h"
#include "asterisk/bridge_basic.h"
#include "asterisk/frame.h"
#include "asterisk/pbx.h"
#include "asterisk/musiconhold.h"
struct stasis_app_control {
+ ast_cond_t wait_cond;
/*! 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;
+ /*!
+ * Holding place for channel's PBX while imparted to a bridge.
+ */
+ struct ast_pbx *pbx;
+ /*!
+ * When set, /c app_stasis should exit and continue in the dialplan.
+ */
+ int is_done:1;
};
+static void control_dtor(void *obj)
+{
+ struct stasis_app_control *control = obj;
+
+ ao2_cleanup(control->command_queue);
+ ast_cond_destroy(&control->wait_cond);
+}
+
struct stasis_app_control *control_create(struct ast_channel *channel)
{
- struct stasis_app_control *control;
-
- control = ao2_alloc(sizeof(*control), NULL);
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ int res;
+
+ control = ao2_alloc(sizeof(*control), control_dtor);
if (!control) {
+ return NULL;
+ }
+
+ res = ast_cond_init(&control->wait_cond, NULL);
+ if (res != 0) {
+ ast_log(LOG_ERROR, "Error initializing ast_cond_t: %s\n",
+ strerror(errno));
return NULL;
}
@@ -66,14 +92,21 @@
AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
if (!control->command_queue) {
- ao2_cleanup(control);
return NULL;
}
control->channel = channel;
+ ao2_ref(control, +1);
return control;
}
+
+static void *noop_cb(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ return NULL;
+}
+
static struct stasis_app_command *exec_command(
struct stasis_app_control *control, stasis_app_command_cb command_fn,
@@ -81,14 +114,18 @@
{
RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
+ command_fn = command_fn ? : noop_cb;
+
command = command_create(command_fn, data);
if (!command) {
return NULL;
}
- /* command_queue is a thread safe list; no lock needed */
- ao2_link(control->command_queue, command);
+ ao2_lock(control->command_queue);
+ ao2_link_flags(control->command_queue, command, OBJ_NOLOCK);
+ ast_cond_signal(&control->wait_cond);
+ ao2_unlock(control->command_queue);
ao2_ref(command, +1);
return command;
@@ -194,6 +231,14 @@
struct ast_channel *chan, void *data)
{
RAII_VAR(struct stasis_app_control_continue_data *, continue_data, data, ast_free);
+
+ ast_assert(control->channel != NULL);
+
+ /* If we're in a Stasis bridge, depart it before going back to the
+ * dialplan */
+ if (stasis_app_get_bridge(control)) {
+ ast_bridge_depart(control->channel);
+ }
/* Called from stasis_app_exec thread; no lock needed */
ast_explicit_goto(control->channel, continue_data->context, continue_data->extension, continue_data->priority);
@@ -422,6 +467,161 @@
return 0;
}
+struct ast_bridge *stasis_app_get_bridge(struct stasis_app_control *control)
+{
+ if (!control) {
+ return NULL;
+ } else {
+ SCOPED_AO2LOCK(lock, control);
+ return control->bridge;
+ }
+}
+
+
+static void bridge_after_cb(struct ast_channel *chan, void *data)
+{
+ struct stasis_app_control *control = data;
+ SCOPED_AO2LOCK(lock, control);
+
+ ast_debug(3, "%s, %s: Channel leaving bridge\n",
+ ast_channel_uniqueid(chan), control->bridge->uniqueid);
+
+ ast_assert(chan == control->channel);
+
+ /* Restore the channel's PBX */
+ ast_channel_pbx_set(control->channel, control->pbx);
+ control->pbx = NULL;
+
+ /* No longer in the bridge */
+ control->bridge = NULL;
+
+ /* Wakeup the command_queue loop */
+ exec_command(control, NULL, NULL);
+}
+
+static void bridge_after_cb_failed(enum ast_bridge_after_cb_reason reason,
+ void *data)
+{
+ struct stasis_app_control *control = data;
+
+ bridge_after_cb(control->channel, data);
+
+ ast_debug(3, " reason: %s\n",
+ ast_bridge_after_cb_reason_string(reason));
+}
+
+static void *app_control_add_channel_to_bridge(
+ struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ struct ast_bridge *bridge = data;
+ int res;
+
+ if (!control || !bridge) {
+ return NULL;
+ }
+
+ ast_debug(3, "%s: Adding to bridge %s\n",
+ stasis_app_control_get_channel_id(control),
+ bridge->uniqueid);
+
+ ast_assert(chan != NULL);
+
+ /* Depart whatever Stasis bridge we're currently in. */
+ if (stasis_app_get_bridge(control)) {
+ /* Note that it looks like there's a race condition here, since
+ * we don't have control locked. But this happens from the
+ * control callback thread, so there won't be any other
+ * concurrent attempts to bridge.
+ */
+ ast_bridge_depart(chan);
+ }
+
+
+ res = ast_bridge_set_after_callback(chan, bridge_after_cb,
+ bridge_after_cb_failed, control);
+ if (res != 0) {
+ ast_log(LOG_ERROR, "Error setting after-bridge callback\n");
+ return NULL;
+ }
+
+ {
+ /* pbx and bridge are modified by the bridging impart thread.
+ * It shouldn't happen concurrently, but we still need to lock
+ * for the memory fence.
+ */
+ SCOPED_AO2LOCK(lock, control);
+
+ /* Save off the channel's PBX */
+ ast_assert(control->pbx == NULL);
+ if (!control->pbx) {
+ control->pbx = ast_channel_pbx(chan);
+ ast_channel_pbx_set(chan, NULL);
+ }
+
+ res = ast_bridge_impart(bridge,
+ chan,
+ NULL, /* swap channel */
+ NULL, /* features */
+ 0); /* independent - false allows us to ast_bridge_depart() */
+
+ if (res != 0) {
+ ast_log(LOG_ERROR, "Error adding channel to bridge\n");
+ ast_channel_pbx_set(chan, control->pbx);
+ control->pbx = NULL;
+ return NULL;
+ }
+
+ ast_assert(stasis_app_get_bridge(control) == NULL);
+ control->bridge = bridge;
+ }
+ return NULL;
+}
+
+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);
+}
+
+static void *app_control_remove_channel_from_bridge(
+ struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ struct ast_bridge *bridge = data;
+
+ if (!control) {
+ return NULL;
+ }
+
+ /* We should only depart from our own bridge */
+ ast_debug(3, "%s: Departing bridge %s\n",
+ stasis_app_control_get_channel_id(control),
+ bridge->uniqueid);
+
+ 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);
+}
+
const char *stasis_app_control_get_channel_id(
const struct stasis_app_control *control)
{
@@ -464,9 +664,22 @@
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);
-}
+void control_wait(struct stasis_app_control *control)
+{
+ if (!control) {
+ return;
+ }
+
+ ast_assert(control->command_queue != NULL);
+
+ ao2_lock(control->command_queue);
+ while (ao2_container_count(control->command_queue) == 0) {
+ int res = ast_cond_wait(&control->wait_cond,
+ ao2_object_get_lockaddr(control->command_queue));
+ if (res < 0) {
+ ast_log(LOG_ERROR, "Error waiting on command queue\n");
+ break;
+ }
+ }
+ ao2_unlock(control->command_queue);
+}
Modified: trunk/res/stasis/control.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis/control.h?view=diff&rev=396568&r1=396567&r2=396568
==============================================================================
--- trunk/res/stasis/control.h (original)
+++ trunk/res/stasis/control.h Tue Aug 13 10:27:32 2013
@@ -48,8 +48,29 @@
int control_dispatch_all(struct stasis_app_control *control,
struct ast_channel *chan);
+/*!
+ * \brief Blocks until \a control's command queue has a command available.
+ *
+ * \param control Control to block on.
+ */
+void control_wait(struct stasis_app_control *control);
+
+/*!
+ * \brief Signals that a control object should finish and exit back to the
+ * dialplan.
+ *
+ * \param control Control object to continue.
+ */
+void control_continue(struct stasis_app_control *control);
+
+/*!
+ * \brief Returns true if control_continue() has been called on this \a control.
+ *
+ * \param control Control to query.
+ * \return True (non-zero) if control_continue() has been called.
+ * \return False (zero) otherwise.
+ */
int control_is_done(struct stasis_app_control *control);
-void control_continue(struct stasis_app_control *control);
#endif /* _ASTERISK_RES_STASIS_CONTROL_H */
More information about the asterisk-commits
mailing list