[svn-commits] qwell: branch qwell/ari_channel_dial r392861 - in /team/qwell/ari_channel_dia...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 25 13:54:54 CDT 2013


Author: qwell
Date: Tue Jun 25 13:54:52 2013
New Revision: 392861

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392861
Log:
Re-work structure a bit.  Move allocation closer to the actual work.

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=392861&r1=392860&r2=392861
==============================================================================
--- team/qwell/ari_channel_dial/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_dial/include/asterisk/stasis_app.h Tue Jun 25 13:54:52 2013
@@ -136,11 +136,6 @@
 const char *stasis_app_control_get_channel_id(
 	const struct stasis_app_control *control);
 
-struct stasis_app_dial {
-	char endpoint[AST_CHANNEL_NAME];
-	int timeout;
-};
-
 /*!
  * \brief Dial an endpoint and bridge it to a channel in \c res_stasis
  *
@@ -148,8 +143,12 @@
  *
  * \param control Control for \c res_stasis
  * \param endpoint The endpoint to dial.
- */
-void stasis_app_control_dial(struct stasis_app_control *control, struct stasis_app_dial *dial_data);
+ * \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.

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=392861&r1=392860&r2=392861
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis/control.c (original)
+++ team/qwell/ari_channel_dial/res/stasis/control.c Tue Jun 25 13:54:52 2013
@@ -87,11 +87,16 @@
 	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_dial *, dial_data, data, ast_free);
+	RAII_VAR(struct stasis_app_control_dial_data *, dial_data, data, ast_free);
 	enum ast_dial_result res;
 	char *tech, *resource;
 
@@ -133,9 +138,27 @@
 	return NULL;
 }
 
-void stasis_app_control_dial(struct stasis_app_control *control, struct stasis_app_dial *dial_data)
-{
+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)

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=392861&r1=392860&r2=392861
==============================================================================
--- team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_dial/res/stasis_http/resource_channels.c Tue Jun 25 13:54:52 2013
@@ -83,26 +83,16 @@
 void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
 {
 	struct stasis_app_control *control;
-	struct stasis_app_dial *dial_data;
-	int timeout = 30000;
 
 	control = find_control(response, args->channel_id);
 	if (control == NULL) {
 		return;
 	}
 
-	dial_data = ast_calloc(1, sizeof(*dial_data));
-
-	ast_copy_string(dial_data->endpoint, args->endpoint, sizeof(dial_data->endpoint));
-
-	if (args->timeout > 0) {
-		timeout = args->timeout * 1000;
-	} else if (args->timeout == -1) {
-		timeout = -1;
-	}
-	dial_data->timeout = timeout;
-
-	stasis_app_control_dial(control, dial_data);
+	if (stasis_app_control_dial(control, args->endpoint, args->timeout)) {
+		stasis_http_response_alloc_failed(response);
+		return;
+	}
 
 	stasis_http_response_no_content(response);
 }




More information about the svn-commits mailing list