[asterisk-commits] qwell: branch qwell/ari_channel_dial r392267 - in /team/qwell/ari_channel_dia...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 19 13:21:58 CDT 2013


Author: qwell
Date: Wed Jun 19 13:21:56 2013
New Revision: 392267

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392267
Log:
Change how dialing is handled.  Queue it up.

Modified:
    team/qwell/ari_channel_dial/include/asterisk/stasis_app.h
    team/qwell/ari_channel_dial/res/stasis/control.c
    team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c

Modified: team/qwell/ari_channel_dial/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/include/asterisk/stasis_app.h?view=diff&rev=392267&r1=392266&r2=392267
==============================================================================
--- team/qwell/ari_channel_dial/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_dial/include/asterisk/stasis_app.h Wed Jun 19 13:21:56 2013
@@ -137,6 +137,16 @@
 	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.
+ */
+void stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint);
+
+/*!
  * \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.

Modified: team/qwell/ari_channel_dial/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/stasis/control.c?view=diff&rev=392267&r1=392266&r2=392267
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis/control.c (original)
+++ team/qwell/ari_channel_dial/res/stasis/control.c Wed Jun 19 13:21:56 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"
 
 struct stasis_app_control {
@@ -85,6 +87,44 @@
 	return command;
 }
 
+static void *app_control_dial(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	const char *endpoint = data;
+	enum ast_dial_result res;
+	struct ast_dial *dial;
+	char *tech, *resource;
+
+	struct ast_channel *new_chan;
+	struct ast_bridge *bridge;
+
+	tech = ast_strdupa(endpoint);
+	resource = strchr(tech, '/');
+	*resource++ = '\0';
+
+	dial = ast_dial_create();
+	ast_dial_append(dial, tech, resource);
+	res = ast_dial_run(dial, NULL, 0);
+
+	if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
+		return NULL;
+	}
+
+	bridge = ast_bridge_basic_new();
+
+	ast_bridge_impart(bridge, new_chan, NULL, NULL, 1);
+	stasis_app_control_add_channel_to_bridge(control, bridge);
+
+	ast_dial_destroy(dial);
+
+	return NULL;
+}
+
+void stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint)
+{
+	stasis_app_send_command_async(control, app_control_dial, (void *)endpoint);
+}
+
 int control_is_done(struct stasis_app_control *control)
 {
 	/* Called from stasis_app_exec thread; no lock needed */

Modified: team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c?view=diff&rev=392267&r1=392266&r2=392267
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c Wed Jun 19 13:21:56 2013
@@ -80,47 +80,16 @@
 	return control;
 }
 
-static void dial_cb(struct ast_dial *dial)
-{
-	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
-
-	struct ast_channel *new_chan;
-	struct ast_bridge *bridge;
-
-	if (ast_dial_state(dial) != AST_DIAL_RESULT_ANSWERED || !(control = ast_dial_get_user_data(dial)) || !(new_chan = ast_dial_answered_steal(dial))) {
-		return;
-	}
-
-	ast_dial_join(dial);
-	ast_dial_destroy(dial);
-
-	bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_1TO1MIX, AST_BRIDGE_FLAG_DISSOLVE_HANGUP);
-
-	ast_bridge_impart(bridge, new_chan, NULL, NULL, 1);
-	stasis_app_control_add_channel_to_bridge(control, bridge);
-}
-
 void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
 {
-	RAII_VAR(struct ast_channel *, existing_chan, NULL, ao2_cleanup);
 	struct stasis_app_control *control;
-	struct ast_dial *dial;
-	char *tech, *resource;
 
 	control = find_control(response, args->channel_id);
 	if (control == NULL) {
 		return;
 	}
 
-	tech = ast_strdupa(args->endpoint);
-	resource = strchr(tech, '/');
-	*resource++ = '\0';
-
-	dial = ast_dial_create();
-	ast_dial_append(dial, tech, resource);
-	ast_dial_set_user_data(dial, control);
-	ast_dial_set_state_callback(dial, &dial_cb);
-	ast_dial_run(dial, NULL, 1);
+	stasis_app_control_dial(control, args->endpoint);
 
 	stasis_http_response_no_content(response);
 }




More information about the asterisk-commits mailing list