[asterisk-commits] jrose: trunk r394810 - in /trunk: include/asterisk/ res/ res/stasis/ res/stas...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 19 14:40:30 CDT 2013


Author: jrose
Date: Fri Jul 19 14:40:27 2013
New Revision: 394810

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394810
Log:
ARI: MOH start and stop for a channel

(issue ASTERISK-21974)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2680/

Modified:
    trunk/include/asterisk/stasis_app.h
    trunk/res/res_stasis_http_channels.c
    trunk/res/stasis/control.c
    trunk/res/stasis_http/resource_channels.c
    trunk/res/stasis_http/resource_channels.h
    trunk/rest-api/api-docs/channels.json

Modified: trunk/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_app.h?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/include/asterisk/stasis_app.h (original)
+++ trunk/include/asterisk/stasis_app.h Fri Jul 19 14:40:27 2013
@@ -252,6 +252,19 @@
 void stasis_app_control_unhold(struct stasis_app_control *control);
 
 /*!
+ * \brief Play music on hold to a channel (does not affect hold status)
+ * \param control Control for \c res_stasis.
+ * \param moh_class class of music on hold to play (NULL allowed)
+ */
+void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class);
+
+/*!
+ * \brief Stop playing music on hold to a channel (does not affect hold status)
+ * \param control Control for \c res_stasis.
+ */
+void stasis_app_control_moh_stop(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: trunk/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_http_channels.c?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/res/res_stasis_http_channels.c (original)
+++ trunk/res/res_stasis_http_channels.c Fri Jul 19 14:40:27 2013
@@ -668,6 +668,116 @@
 #endif /* AST_DEVMODE */
 }
 /*!
+ * \brief Parameter parsing callback for /channels/{channelId}/mohstart.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void stasis_http_moh_start_channel_cb(
+	struct ast_variable *get_params, struct ast_variable *path_vars,
+	struct ast_variable *headers, struct stasis_http_response *response)
+{
+#if defined(AST_DEVMODE)
+	int is_valid;
+	int code;
+#endif /* AST_DEVMODE */
+
+	struct ast_moh_start_channel_args args = {};
+	struct ast_variable *i;
+
+	for (i = get_params; i; i = i->next) {
+		if (strcmp(i->name, "mohClass") == 0) {
+			args.moh_class = (i->value);
+		} else
+		{}
+	}
+	for (i = path_vars; i; i = i->next) {
+		if (strcmp(i->name, "channelId") == 0) {
+			args.channel_id = (i->value);
+		} else
+		{}
+	}
+	stasis_http_moh_start_channel(headers, &args, response);
+#if defined(AST_DEVMODE)
+	code = response->response_code;
+
+	switch (code) {
+	case 500: /* Internal server error */
+	case 404: /* Channel not found */
+	case 409: /* Channel not in a Stasis application */
+		is_valid = 1;
+		break;
+	default:
+		if (200 <= code && code <= 299) {
+			is_valid = ari_validate_void(
+				response->message);
+		} else {
+			ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstart\n", code);
+			is_valid = 0;
+		}
+	}
+
+	if (!is_valid) {
+		ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstart\n");
+		stasis_http_response_error(response, 500,
+			"Internal Server Error", "Response validation failed");
+	}
+#endif /* AST_DEVMODE */
+}
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/mohstop.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void stasis_http_moh_stop_channel_cb(
+	struct ast_variable *get_params, struct ast_variable *path_vars,
+	struct ast_variable *headers, struct stasis_http_response *response)
+{
+#if defined(AST_DEVMODE)
+	int is_valid;
+	int code;
+#endif /* AST_DEVMODE */
+
+	struct ast_moh_stop_channel_args args = {};
+	struct ast_variable *i;
+
+	for (i = path_vars; i; i = i->next) {
+		if (strcmp(i->name, "channelId") == 0) {
+			args.channel_id = (i->value);
+		} else
+		{}
+	}
+	stasis_http_moh_stop_channel(headers, &args, response);
+#if defined(AST_DEVMODE)
+	code = response->response_code;
+
+	switch (code) {
+	case 500: /* Internal server error */
+	case 404: /* Channel not found */
+	case 409: /* Channel not in a Stasis application */
+		is_valid = 1;
+		break;
+	default:
+		if (200 <= code && code <= 299) {
+			is_valid = ari_validate_void(
+				response->message);
+		} else {
+			ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstop\n", code);
+			is_valid = 0;
+		}
+	}
+
+	if (!is_valid) {
+		ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstop\n");
+		stasis_http_response_error(response, 500,
+			"Internal Server Error", "Response validation failed");
+	}
+#endif /* AST_DEVMODE */
+}
+/*!
  * \brief Parameter parsing callback for /channels/{channelId}/play.
  * \param get_params GET parameters in the HTTP request.
  * \param path_vars Path variables extracted from the request.
@@ -995,6 +1105,24 @@
 	.children = {  }
 };
 /*! \brief REST handler for /api-docs/channels.{format} */
+static struct stasis_rest_handlers channels_channelId_mohstart = {
+	.path_segment = "mohstart",
+	.callbacks = {
+		[AST_HTTP_POST] = stasis_http_moh_start_channel_cb,
+	},
+	.num_children = 0,
+	.children = {  }
+};
+/*! \brief REST handler for /api-docs/channels.{format} */
+static struct stasis_rest_handlers channels_channelId_mohstop = {
+	.path_segment = "mohstop",
+	.callbacks = {
+		[AST_HTTP_POST] = stasis_http_moh_stop_channel_cb,
+	},
+	.num_children = 0,
+	.children = {  }
+};
+/*! \brief REST handler for /api-docs/channels.{format} */
 static struct stasis_rest_handlers channels_channelId_play = {
 	.path_segment = "play",
 	.callbacks = {
@@ -1030,8 +1158,8 @@
 		[AST_HTTP_GET] = stasis_http_get_channel_cb,
 		[AST_HTTP_DELETE] = stasis_http_delete_channel_cb,
 	},
-	.num_children = 10,
-	.children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
+	.num_children = 12,
+	.children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_mohstart,&channels_channelId_mohstop,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
 };
 /*! \brief REST handler for /api-docs/channels.{format} */
 static struct stasis_rest_handlers channels = {

Modified: trunk/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis/control.c?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/res/stasis/control.c (original)
+++ trunk/res/stasis/control.c Fri Jul 19 14:40:27 2013
@@ -37,6 +37,7 @@
 #include "asterisk/bridging_features.h"
 #include "asterisk/frame.h"
 #include "asterisk/pbx.h"
+#include "asterisk/musiconhold.h"
 
 struct stasis_app_control {
 	/*! Queue of commands to dispatch on the channel */
@@ -325,6 +326,40 @@
 	stasis_app_send_command_async(control, app_control_unhold, NULL);
 }
 
+static void *app_control_moh_start(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	char *moh_class = data;
+
+	ast_moh_start(chan, moh_class, NULL);
+
+	ast_free(moh_class);
+	return NULL;
+}
+
+void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
+{
+	char *data = NULL;
+
+	if (!ast_strlen_zero(moh_class)) {
+		data = ast_strdup(moh_class);
+	}
+
+	stasis_app_send_command_async(control, app_control_moh_start, data);
+}
+
+static void *app_control_moh_stop(struct stasis_app_control *control,
+	struct ast_channel *chan, void *data)
+{
+	ast_moh_stop(chan);
+	return NULL;
+}
+
+void stasis_app_control_moh_stop(struct stasis_app_control *control)
+{
+	stasis_app_send_command_async(control, app_control_moh_stop, NULL);
+}
+
 struct ast_channel_snapshot *stasis_app_control_get_snapshot(
 	const struct stasis_app_control *control)
 {

Modified: trunk/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis_http/resource_channels.c?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/res/stasis_http/resource_channels.c (original)
+++ trunk/res/stasis_http/resource_channels.c Fri Jul 19 14:40:27 2013
@@ -226,6 +226,34 @@
 
 	stasis_app_control_unhold(control);
 
+	stasis_http_response_no_content(response);
+}
+
+void stasis_http_moh_start_channel(struct ast_variable *headers, struct ast_moh_start_channel_args *args, struct stasis_http_response *response)
+{
+	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_moh_start(control, args->moh_class);
+	stasis_http_response_no_content(response);
+}
+
+void stasis_http_moh_stop_channel(struct ast_variable *headers, struct ast_moh_stop_channel_args *args, struct stasis_http_response *response)
+{
+	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_moh_stop(control);
 	stasis_http_response_no_content(response);
 }
 

Modified: trunk/res/stasis_http/resource_channels.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/stasis_http/resource_channels.h?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/res/stasis_http/resource_channels.h (original)
+++ trunk/res/stasis_http/resource_channels.h Fri Jul 19 14:40:27 2013
@@ -212,6 +212,36 @@
  * \param[out] response HTTP response
  */
 void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_channel_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_moh_start_channel() */
+struct ast_moh_start_channel_args {
+	/*! \brief Channel's id */
+	const char *channel_id;
+	/*! \brief Music on hold class to use */
+	const char *moh_class;
+};
+/*!
+ * \brief Play music on hold to a channel.
+ *
+ * Using media operations such as playOnChannel on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_moh_start_channel(struct ast_variable *headers, struct ast_moh_start_channel_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_moh_stop_channel() */
+struct ast_moh_stop_channel_args {
+	/*! \brief Channel's id */
+	const char *channel_id;
+};
+/*!
+ * \brief Stop playing music on hold to a channel.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_moh_stop_channel(struct ast_variable *headers, struct ast_moh_stop_channel_args *args, struct stasis_http_response *response);
 /*! \brief Argument struct for stasis_http_play_on_channel() */
 struct ast_play_on_channel_args {
 	/*! \brief Channel's id */

Modified: trunk/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/trunk/rest-api/api-docs/channels.json?view=diff&rev=394810&r1=394809&r2=394810
==============================================================================
--- trunk/rest-api/api-docs/channels.json (original)
+++ trunk/rest-api/api-docs/channels.json Fri Jul 19 14:40:27 2013
@@ -439,6 +439,79 @@
 					"httpMethod": "POST",
 					"summary": "Remove a channel from hold.",
 					"nickname": "unholdChannel",
+					"responseClass": "void",
+					"parameters": [
+						{
+							"name": "channelId",
+							"description": "Channel's id",
+							"paramType": "path",
+							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Channel not found"
+						},
+						{
+							"code": 409,
+							"reason": "Channel not in a Stasis application"
+						}
+					]
+				}
+			]
+		},
+		{
+			"path": "/channels/{channelId}/mohstart",
+			"description": "Play music on hold to a channel",
+			"operations": [
+				{
+					"httpMethod": "POST",
+					"summary": "Play music on hold to a channel.",
+					"notes": "Using media operations such as playOnChannel on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.",
+					"nickname": "mohStartChannel",
+					"responseClass": "void",
+					"parameters": [
+						{
+							"name": "channelId",
+							"description": "Channel's id",
+							"paramType": "path",
+							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						},
+						{
+							"name": "mohClass",
+							"description": "Music on hold class to use",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Channel not found"
+						},
+						{
+							"code": 409,
+							"reason": "Channel not in a Stasis application"
+						}
+					]
+				}
+			]
+		},
+		{
+			"path": "/channels/{channelId}/mohstop",
+			"description": "Stop playing music on hold to a channel",
+			"operations": [
+				{
+					"httpMethod": "POST",
+					"summary": "Stop playing music on hold to a channel.",
+					"nickname": "mohStopChannel",
 					"responseClass": "void",
 					"parameters": [
 						{




More information about the asterisk-commits mailing list