Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions
resource_playbacks.h File Reference

Generated file - declares stubs to be implemented in res/ari/resource_playbacks.c. More...

#include "asterisk/ari.h"
Include dependency graph for resource_playbacks.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_playbacks_control_args
 
struct  ast_ari_playbacks_get_args
 
struct  ast_ari_playbacks_stop_args
 

Functions

void ast_ari_playbacks_control (struct ast_variable *headers, struct ast_ari_playbacks_control_args *args, struct ast_ari_response *response)
 Control a playback. More...
 
int ast_ari_playbacks_control_parse_body (struct ast_json *body, struct ast_ari_playbacks_control_args *args)
 Body parsing function for /playbacks/{playbackId}/control. More...
 
void ast_ari_playbacks_get (struct ast_variable *headers, struct ast_ari_playbacks_get_args *args, struct ast_ari_response *response)
 Get a playback's details. More...
 
void ast_ari_playbacks_stop (struct ast_variable *headers, struct ast_ari_playbacks_stop_args *args, struct ast_ari_response *response)
 Stop a playback. More...
 

Detailed Description

Generated file - declares stubs to be implemented in res/ari/resource_playbacks.c.

Playback control resources

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file resource_playbacks.h.

Function Documentation

◆ ast_ari_playbacks_control()

void ast_ari_playbacks_control ( struct ast_variable headers,
struct ast_ari_playbacks_control_args args,
struct ast_ari_response response 
)

Control a playback.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 89 of file resource_playbacks.c.

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) {
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
119 playback = stasis_app_playback_find_by_id(args->playback_id);
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) {
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_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
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define NULL
Definition: resample.c:96
struct stasis_app_playback * stasis_app_playback_find_by_id(const char *id)
Finds the playback object with the given id.
stasis_playback_oper_results
@ STASIS_PLAYBACK_OPER_NOT_PLAYING
@ STASIS_PLAYBACK_OPER_FAILED
@ STASIS_PLAYBACK_OPER_OK
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.
stasis_app_playback_media_operation
@ STASIS_PLAYBACK_RESTART
@ STASIS_PLAYBACK_FORWARD
@ STASIS_PLAYBACK_REVERSE
@ STASIS_PLAYBACK_UNPAUSE
@ STASIS_PLAYBACK_PAUSE
const char * args
#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:941

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_no_content(), NULL, RAII_VAR, stasis_app_playback_find_by_id(), stasis_app_playback_operation(), STASIS_PLAYBACK_FORWARD, STASIS_PLAYBACK_OPER_FAILED, STASIS_PLAYBACK_OPER_NOT_PLAYING, STASIS_PLAYBACK_OPER_OK, STASIS_PLAYBACK_PAUSE, STASIS_PLAYBACK_RESTART, STASIS_PLAYBACK_REVERSE, and STASIS_PLAYBACK_UNPAUSE.

Referenced by ast_ari_playbacks_control_cb().

◆ ast_ari_playbacks_control_parse_body()

int ast_ari_playbacks_control_parse_body ( struct ast_json body,
struct ast_ari_playbacks_control_args args 
)

Body parsing function for /playbacks/{playbackId}/control.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 174 of file res_ari_playbacks.c.

177{
178 struct ast_json *field;
179 /* Parse query parameters out of it */
180 field = ast_json_object_get(body, "operation");
181 if (field) {
182 args->operation = ast_json_string_get(field);
183 }
184 return 0;
185}
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
Abstract JSON element (object, array, string, int, ...).

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_playbacks_control_cb().

◆ ast_ari_playbacks_get()

void ast_ari_playbacks_get ( struct ast_variable headers,
struct ast_ari_playbacks_get_args args,
struct ast_ari_response response 
)

Get a playback's details.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 35 of file resource_playbacks.c.

38{
39 RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
40 struct ast_json *json;
41
42 playback = stasis_app_playback_find_by_id(args->playback_id);
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}
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
struct ast_json * stasis_app_playback_to_json(const struct stasis_app_playback *playback)
Convert a playback to its JSON representation.

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_ok(), NULL, RAII_VAR, stasis_app_playback_find_by_id(), and stasis_app_playback_to_json().

Referenced by ast_ari_playbacks_get_cb().

◆ ast_ari_playbacks_stop()

void ast_ari_playbacks_stop ( struct ast_variable headers,
struct ast_ari_playbacks_stop_args args,
struct ast_ari_response response 
)

Stop a playback.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 58 of file resource_playbacks.c.

61{
62 RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
64
65 playback = stasis_app_playback_find_by_id(args->playback_id);
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}
@ STASIS_PLAYBACK_STOP
#define ast_assert(a)
Definition: utils.h:739

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_no_content(), ast_assert, NULL, RAII_VAR, stasis_app_playback_find_by_id(), stasis_app_playback_operation(), STASIS_PLAYBACK_OPER_FAILED, STASIS_PLAYBACK_OPER_NOT_PLAYING, STASIS_PLAYBACK_OPER_OK, and STASIS_PLAYBACK_STOP.

Referenced by ast_ari_playbacks_stop_cb().