Asterisk - The Open Source Telephony Project  18.5.0
resource_playbacks.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012 - 2013, Digium, Inc.
5  *
6  * David M. Lee, II <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief /api-docs/playbacks.{format} implementation- Playback control resources
22  *
23  * \author David M. Lee, II <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
33 #include "resource_playbacks.h"
34 
35 void ast_ari_playbacks_get(struct ast_variable *headers,
37  struct ast_ari_response *response)
38 {
39  RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
40  struct ast_json *json;
41 
43  if (playback == NULL) {
44  ast_ari_response_error(response, 404, "Not Found",
45  "Playback not found");
46  return;
47  }
48 
49  json = stasis_app_playback_to_json(playback);
50  if (json == NULL) {
51  ast_ari_response_error(response, 500,
52  "Internal Server Error", "Error building response");
53  return;
54  }
55 
56  ast_ari_response_ok(response, json);
57 }
58 void ast_ari_playbacks_stop(struct ast_variable *headers,
60  struct ast_ari_response *response)
61 {
62  RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
64 
66  if (playback == NULL) {
67  ast_ari_response_error(response, 404, "Not Found",
68  "Playback not found");
69  return;
70  }
71 
73  switch (res) {
76  return;
78  ast_ari_response_error(response, 500,
79  "Internal Server Error", "Could not stop playback");
80  return;
82  /* Stop operation should be valid even when not playing */
83  ast_assert(0);
84  ast_ari_response_error(response, 500,
85  "Internal Server Error", "Could not stop playback");
86  return;
87  }
88 }
91  struct ast_ari_response *response)
92 {
93  RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
96 
97  if (!args->operation) {
98  ast_ari_response_error(response, 400,
99  "Bad Request", "Missing operation");
100  return;
101  }
102  if (strcmp(args->operation, "unpause") == 0) {
104  } else if (strcmp(args->operation, "pause") == 0) {
105  oper = STASIS_PLAYBACK_PAUSE;
106  } else if (strcmp(args->operation, "restart") == 0) {
108  } else if (strcmp(args->operation, "reverse") == 0) {
110  } else if (strcmp(args->operation, "forward") == 0) {
112  } else {
113  ast_ari_response_error(response, 400,
114  "Bad Request", "Invalid operation %s",
115  args->operation);
116  return;
117  }
118 
120  if (playback == NULL) {
121  ast_ari_response_error(response, 404, "Not Found",
122  "Playback not found");
123  return;
124  }
125 
126  res = stasis_app_playback_operation(playback, oper);
127  switch (res) {
129  ast_ari_response_no_content(response);
130  return;
132  ast_ari_response_error(response, 500,
133  "Internal Server Error", "Could not %s playback",
134  args->operation);
135  return;
137  ast_ari_response_error(response, 409, "Conflict",
138  "Can only %s while media is playing", args->operation);
139  return;
140  }
141 }
void ast_ari_playbacks_control(struct ast_variable *headers, struct ast_ari_playbacks_control_args *args, struct ast_ari_response *response)
Control a playback.
enum stasis_playback_oper_results stasis_app_playback_operation(struct stasis_app_playback *playback, enum stasis_app_playback_media_operation operation)
Controls the media for a given playback operation.
Asterisk main include file. File version handling, generic pbx functions.
Generated file - declares stubs to be implemented in res/ari/resource_playbacks.c.
stasis_app_playback_media_operation
Structure for variables, used for configurations and for channel variables.
struct ast_json * stasis_app_playback_to_json(const struct stasis_app_playback *playback)
Convert a playback to its JSON representation.
#define ast_assert(a)
Definition: utils.h:695
const char * args
#define NULL
Definition: resample.c:96
void ast_ari_playbacks_get(struct ast_variable *headers, struct ast_ari_playbacks_get_args *args, struct ast_ari_response *response)
Get a playback&#39;s details.
struct stasis_app_playback * stasis_app_playback_find_by_id(const char *id)
Finds the playback object with the given id.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
stasis_playback_oper_results
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition: res_ari.c:259
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
void ast_ari_playbacks_stop(struct ast_variable *headers, struct ast_ari_playbacks_stop_args *args, struct ast_ari_response *response)
Stop a playback.
Stasis Application Playback API. See StasisApplication API" for detailed documentation.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).