Asterisk - The Open Source Telephony Project  18.5.0
Functions
resource_device_states.c File Reference

/api-docs/deviceStates.{format} implementation- Device state resources More...

#include "asterisk.h"
#include "resource_device_states.h"
#include "asterisk/stasis_app_device_state.h"
Include dependency graph for resource_device_states.c:

Go to the source code of this file.

Functions

void ast_ari_device_states_delete (struct ast_variable *headers, struct ast_ari_device_states_delete_args *args, struct ast_ari_response *response)
 Destroy a device-state controlled by ARI. More...
 
void ast_ari_device_states_get (struct ast_variable *headers, struct ast_ari_device_states_get_args *args, struct ast_ari_response *response)
 Retrieve the current state of a device. More...
 
void ast_ari_device_states_list (struct ast_variable *headers, struct ast_ari_device_states_list_args *args, struct ast_ari_response *response)
 List all ARI controlled device states. More...
 
void ast_ari_device_states_update (struct ast_variable *headers, struct ast_ari_device_states_update_args *args, struct ast_ari_response *response)
 Change the state of a device controlled by ARI. (Note - implicitly creates the device state). More...
 

Detailed Description

/api-docs/deviceStates.{format} implementation- Device state resources

Author
Kevin Harwell kharw.nosp@m.ell@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file resource_device_states.c.

Function Documentation

◆ ast_ari_device_states_delete()

void ast_ari_device_states_delete ( struct ast_variable headers,
struct ast_ari_device_states_delete_args args,
struct ast_ari_response response 
)

Destroy a device-state controlled by ARI.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 91 of file resource_device_states.c.

References ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_device_states_delete_args::device_name, stasis_app_device_state_delete(), STASIS_DEVICE_STATE_MISSING, STASIS_DEVICE_STATE_NOT_CONTROLLED, STASIS_DEVICE_STATE_OK, STASIS_DEVICE_STATE_SUBSCRIBERS, and STASIS_DEVICE_STATE_UNKNOWN.

Referenced by ast_ari_device_states_delete_cb().

94 {
97  ast_ari_response_error(response, 409,
98  "Conflict", "Uncontrolled device specified");
99  return;
101  ast_ari_response_error(response, 404,
102  "Not Found", "Device name is missing");
103  return;
105  ast_ari_response_error(response, 500,
106  "Internal Server Error",
107  "Cannot delete device with subscribers");
108  return;
111  ast_ari_response_no_content(response);
112  }
113 }
enum stasis_device_state_result stasis_app_device_state_delete(const char *name)
Delete a device controlled by ARI.
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

◆ ast_ari_device_states_get()

void ast_ari_device_states_get ( struct ast_variable headers,
struct ast_ari_device_states_get_args args,
struct ast_ari_response response 
)

Retrieve the current state of a device.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 51 of file resource_device_states.c.

References ast_ari_response_error(), ast_ari_response_ok(), ast_ari_device_states_get_args::device_name, and stasis_app_device_state_to_json().

Referenced by ast_ari_device_states_get_cb().

54 {
55  struct ast_json *json;
56 
58  args->device_name, ast_device_state(args->device_name)))) {
59  ast_ari_response_error(response, 500,
60  "Internal Server Error", "Error building response");
61  return;
62  }
63 
64  ast_ari_response_ok(response, json);
65 }
ast_device_state
Device States.
Definition: devicestate.h:52
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
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
Abstract JSON element (object, array, string, int, ...).
struct ast_json * stasis_app_device_state_to_json(const char *name, enum ast_device_state state)
Convert device state to json.

◆ ast_ari_device_states_list()

void ast_ari_device_states_list ( struct ast_variable headers,
struct ast_ari_device_states_list_args args,
struct ast_ari_response response 
)

List all ARI controlled device states.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 35 of file resource_device_states.c.

References ast_ari_response_error(), ast_ari_response_ok(), and stasis_app_device_states_to_json().

Referenced by ast_ari_device_states_list_cb().

39 {
40  struct ast_json *json;
41 
42  if (!(json = stasis_app_device_states_to_json())) {
43  ast_ari_response_error(response, 500,
44  "Internal Server Error", "Error building response");
45  return;
46  }
47 
48  ast_ari_response_ok(response, json);
49 }
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
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
struct ast_json * stasis_app_device_states_to_json(void)
Convert device states to json array.
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_device_states_update()

void ast_ari_device_states_update ( struct ast_variable headers,
struct ast_ari_device_states_update_args args,
struct ast_ari_response response 
)

Change the state of a device controlled by ARI. (Note - implicitly creates the device state).

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 67 of file resource_device_states.c.

References ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_device_states_update_args::device_name, ast_ari_device_states_update_args::device_state, stasis_app_device_state_update(), STASIS_DEVICE_STATE_MISSING, STASIS_DEVICE_STATE_NOT_CONTROLLED, STASIS_DEVICE_STATE_OK, STASIS_DEVICE_STATE_SUBSCRIBERS, and STASIS_DEVICE_STATE_UNKNOWN.

Referenced by ast_ari_device_states_update_cb().

70 {
72  args->device_name, args->device_state)) {
74  ast_ari_response_error(response, 409,
75  "Conflict", "Uncontrolled device specified");
76  return;
78  ast_ari_response_error(response, 404,
79  "Not Found", "Device name is missing");
80  return;
82  ast_ari_response_error(response, 500, "Internal Server Error",
83  "Unknown device");
84  return;
86  case STASIS_DEVICE_STATE_SUBSCRIBERS: /* shouldn't be returned for update */
88  }
89 }
enum stasis_device_state_result stasis_app_device_state_update(const char *name, const char *value)
Changes the state of a device controlled by ARI.
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