Asterisk - The Open Source Telephony Project  18.5.0
resource_device_states.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  * Kevin Harwell <[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/deviceStates.{format} implementation- Device state resources
22  *
23  * \author Kevin Harwell <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include "resource_device_states.h"
34 
36  struct ast_variable *headers,
38  struct ast_ari_response *response)
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 }
50 
53  struct ast_ari_response *response)
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 }
66 
69  struct ast_ari_response *response)
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 }
90 
93  struct ast_ari_response *response)
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 }
Stasis Application Device State API. See StasisApplication API" for detailed documentation.
ast_device_state
Device States.
Definition: devicestate.h:52
Asterisk main include file. File version handling, generic pbx functions.
enum stasis_device_state_result stasis_app_device_state_delete(const char *name)
Delete a device controlled by ARI.
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)...
Structure for variables, used for configurations and for channel variables.
const char * args
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
Generated file - declares stubs to be implemented in res/ari/resource_deviceStates.c.
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_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.
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
struct ast_json * stasis_app_device_states_to_json(void)
Convert device states to json array.
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.
Abstract JSON element (object, array, string, int, ...).
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.
struct ast_json * stasis_app_device_state_to_json(const char *name, enum ast_device_state state)
Convert device state to json.