[asterisk-commits] qwell: branch qwell/ari_channel_mute r393348 - in /team/qwell/ari_channel_mut...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 1 14:28:54 CDT 2013
Author: qwell
Date: Mon Jul 1 14:28:45 2013
New Revision: 393348
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393348
Log:
Multiple revisions 393326,393332
........
r393326 | qwell | 2013-07-01 13:19:15 -0500 (Mon, 01 Jul 2013) | 9 lines
ARI: Implement channel dial.
This creates a new outbound channel, and bridges it to a channel already in
the Stasis application.
(closes issue ASTERISK-21620)
Review: https://reviewboard.asterisk.org/r/2634/
........
r393332 | qwell | 2013-07-01 13:56:21 -0500 (Mon, 01 Jul 2013) | 8 lines
ARI: Implement channel hold/unhold.
This puts the channel on hold (rather than queueing a frame from the channel).
(closes issue ASTERISK-21619)
Review: https://reviewboard.asterisk.org/r/2647/
........
Merged revisions 393326,393332 from http://svn.asterisk.org/svn/asterisk/trunk
Modified:
team/qwell/ari_channel_mute/ (props changed)
team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
team/qwell/ari_channel_mute/res/res_stasis_http_channels.c
team/qwell/ari_channel_mute/res/stasis/control.c
team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c
team/qwell/ari_channel_mute/res/stasis_http/resource_channels.h
team/qwell/ari_channel_mute/rest-api/api-docs/channels.json
Propchange: team/qwell/ari_channel_mute/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jul 1 14:28:45 2013
@@ -1,1 +1,1 @@
-/trunk:1-393317
+/trunk:1-393347
Modified: team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/include/asterisk/stasis_app.h?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_mute/include/asterisk/stasis_app.h Mon Jul 1 14:28:45 2013
@@ -137,6 +137,20 @@
const struct stasis_app_control *control);
/*!
+ * \brief Dial an endpoint and bridge it to a channel in \c res_stasis
+ *
+ * If the channel is no longer in \c res_stasis, this function does nothing.
+ *
+ * \param control Control for \c res_stasis
+ * \param endpoint The endpoint to dial.
+ * \param timeout The amount of time to wait for answer, before giving up.
+ *
+ * \return 0 for success
+ * \return -1 for error.
+ */
+int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout);
+
+/*!
* \brief Exit \c res_stasis and continue execution in the dialplan.
*
* If the channel is no longer in \c res_stasis, this function does nothing.
@@ -178,6 +192,18 @@
int stasis_app_control_answer(struct stasis_app_control *control);
/*!
+ * \brief Place the channel associated with the control on hold.
+ * \param control Control for \c res_stasis.
+ */
+void stasis_app_control_hold(struct stasis_app_control *control);
+
+/*!
+ * \brief Remove the channel associated with the control from hold.
+ * \param control Control for \c res_stasis.
+ */
+void stasis_app_control_unhold(struct stasis_app_control *control);
+
+/*!
* \brief Returns the most recent snapshot for the associated channel.
*
* The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
Modified: team/qwell/ari_channel_mute/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/res_stasis_http_channels.c?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/res/res_stasis_http_channels.c (original)
+++ team/qwell/ari_channel_mute/res/res_stasis_http_channels.c Mon Jul 1 14:28:45 2013
@@ -170,6 +170,9 @@
if (strcmp(i->name, "context") == 0) {
args.context = (i->value);
} else
+ if (strcmp(i->name, "timeout") == 0) {
+ args.timeout = atoi(i->value);
+ } else
{}
}
for (i = path_vars; i; i = i->next) {
Modified: team/qwell/ari_channel_mute/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis/control.c?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis/control.c (original)
+++ team/qwell/ari_channel_mute/res/stasis/control.c Mon Jul 1 14:28:45 2013
@@ -31,7 +31,9 @@
#include "command.h"
#include "control.h"
+#include "asterisk/dial.h"
#include "asterisk/bridging.h"
+#include "asterisk/bridging_basic.h"
#include "asterisk/bridging_features.h"
#include "asterisk/pbx.h"
@@ -86,6 +88,80 @@
return command;
}
+struct stasis_app_control_dial_data {
+ char endpoint[AST_CHANNEL_NAME];
+ int timeout;
+};
+
+static void *app_control_dial(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy);
+ RAII_VAR(struct stasis_app_control_dial_data *, dial_data, data, ast_free);
+ enum ast_dial_result res;
+ char *tech, *resource;
+
+ struct ast_channel *new_chan;
+ struct ast_bridge *bridge;
+
+ tech = dial_data->endpoint;
+ if (!(resource = strchr(tech, '/'))) {
+ return NULL;
+ }
+ *resource++ = '\0';
+
+ if (!dial) {
+ ast_log(LOG_ERROR, "Failed to create dialing structure.\n");
+ return NULL;
+ }
+
+ if (ast_dial_append(dial, tech, resource) < 0) {
+ ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource);
+ return NULL;
+ }
+
+ ast_dial_set_global_timeout(dial, dial_data->timeout);
+
+ res = ast_dial_run(dial, NULL, 0);
+
+ if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
+ return NULL;
+ }
+
+ if (!(bridge = ast_bridge_basic_new())) {
+ ast_log(LOG_ERROR, "Failed to create basic bridge.\n");
+ return NULL;
+ }
+
+ ast_bridge_impart(bridge, new_chan, NULL, NULL, 1);
+ stasis_app_control_add_channel_to_bridge(control, bridge);
+
+ return NULL;
+}
+
+int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout)
+{
+ struct stasis_app_control_dial_data *dial_data;
+
+ if (!(dial_data = ast_calloc(1, sizeof(*dial_data)))) {
+ return -1;
+ }
+
+ ast_copy_string(dial_data->endpoint, endpoint, sizeof(dial_data->endpoint));
+
+ if (timeout > 0) {
+ dial_data->timeout = timeout * 1000;
+ } else if (timeout == -1) {
+ dial_data->timeout = -1;
+ } else {
+ dial_data->timeout = 30000;
+ }
+
+ stasis_app_send_command_async(control, app_control_dial, dial_data);
+
+ return 0;
+}
+
int control_is_done(struct stasis_app_control *control)
{
/* Called from stasis_app_exec thread; no lock needed */
@@ -216,6 +292,32 @@
return 0;
}
+static void *app_control_hold(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ ast_indicate(control->channel, AST_CONTROL_HOLD);
+
+ return NULL;
+}
+
+void stasis_app_control_hold(struct stasis_app_control *control)
+{
+ stasis_app_send_command_async(control, app_control_hold, NULL);
+}
+
+static void *app_control_unhold(struct stasis_app_control *control,
+ struct ast_channel *chan, void *data)
+{
+ ast_indicate(control->channel, AST_CONTROL_UNHOLD);
+
+ return NULL;
+}
+
+void stasis_app_control_unhold(struct stasis_app_control *control)
+{
+ stasis_app_send_command_async(control, app_control_unhold, NULL);
+}
+
struct ast_channel_snapshot *stasis_app_control_get_snapshot(
const struct stasis_app_control *control)
{
Modified: team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c Mon Jul 1 14:28:45 2013
@@ -34,6 +34,8 @@
#include "asterisk/file.h"
#include "asterisk/pbx.h"
+#include "asterisk/dial.h"
+#include "asterisk/bridging.h"
#include "asterisk/callerid.h"
#include "asterisk/stasis_app.h"
#include "asterisk/stasis_app_playback.h"
@@ -80,7 +82,19 @@
void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
{
- ast_log(LOG_ERROR, "TODO: stasis_http_dial\n");
+ struct stasis_app_control *control;
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ if (stasis_app_control_dial(control, args->endpoint, args->timeout)) {
+ stasis_http_response_alloc_failed(response);
+ return;
+ }
+
+ stasis_http_response_no_content(response);
}
void stasis_http_continue_in_dialplan(
@@ -160,11 +174,32 @@
}
void stasis_http_hold_channel(struct ast_variable *headers, struct ast_hold_channel_args *args, struct stasis_http_response *response)
{
- ast_log(LOG_ERROR, "TODO: stasis_http_hold_channel\n");
-}
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ /* Response filled in by find_control */
+ return;
+ }
+
+ stasis_app_control_hold(control);
+
+ stasis_http_response_no_content(response);
+}
+
void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_channel_args *args, struct stasis_http_response *response)
{
- ast_log(LOG_ERROR, "TODO: stasis_http_unhold_channel\n");
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ /* Response filled in by find_control */
+ return;
+ }
+
+ stasis_app_control_unhold(control);
+
+ stasis_http_response_no_content(response);
}
void stasis_http_play_on_channel(struct ast_variable *headers,
Modified: team/qwell/ari_channel_mute/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis_http/resource_channels.h?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis_http/resource_channels.h (original)
+++ team/qwell/ari_channel_mute/res/stasis_http/resource_channels.h Mon Jul 1 14:28:45 2013
@@ -113,6 +113,8 @@
const char *extension;
/*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */
const char *context;
+ /*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
+ int timeout;
};
/*!
* \brief Create a new channel (originate) and bridge to this channel.
Modified: team/qwell/ari_channel_mute/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/rest-api/api-docs/channels.json?view=diff&rev=393348&r1=393347&r2=393348
==============================================================================
--- team/qwell/ari_channel_mute/rest-api/api-docs/channels.json (original)
+++ team/qwell/ari_channel_mute/rest-api/api-docs/channels.json Mon Jul 1 14:28:45 2013
@@ -183,6 +183,15 @@
"required": false,
"allowMultiple": false,
"dataType": "string"
+ },
+ {
+ "name": "timeout",
+ "description": "Timeout (in seconds) before giving up dialing, or -1 for no timeout.",
+ "paramType": "query",
+ "required": false,
+ "allowMultiple": false,
+ "dataType": "int",
+ "defaultValue": 30
}
],
"errorResponses": [
More information about the asterisk-commits
mailing list