2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012 - 2013, Digium, Inc.
6 * Kevin Harwell <kharwell@digium.com>
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.
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.
21 * \brief /api-docs/deviceStates.{format} implementation- Device state resources
23 * \author Kevin Harwell <kharwell@digium.com>
27 <depend type="module">res_stasis_device_states</depend>
28 <support_level>core</support_level>
33 ASTERISK_REGISTER_FILE()
35 #include "resource_device_states.h"
36 #include "asterisk/stasis_app_device_state.h"
38 void ast_ari_device_states_list(
39 struct ast_variable *headers,
40 struct ast_ari_device_states_list_args *args,
41 struct ast_ari_response *response)
43 struct ast_json *json;
45 if (!(json = stasis_app_device_states_to_json())) {
46 ast_ari_response_error(response, 500,
47 "Internal Server Error", "Error building response");
51 ast_ari_response_ok(response, json);
54 void ast_ari_device_states_get(struct ast_variable *headers,
55 struct ast_ari_device_states_get_args *args,
56 struct ast_ari_response *response)
58 struct ast_json *json;
60 if (!(json = stasis_app_device_state_to_json(
61 args->device_name, ast_device_state(args->device_name)))) {
62 ast_ari_response_error(response, 500,
63 "Internal Server Error", "Error building response");
67 ast_ari_response_ok(response, json);
70 void ast_ari_device_states_update(struct ast_variable *headers,
71 struct ast_ari_device_states_update_args *args,
72 struct ast_ari_response *response)
74 switch (stasis_app_device_state_update(
75 args->device_name, args->device_state)) {
76 case STASIS_DEVICE_STATE_NOT_CONTROLLED:
77 ast_ari_response_error(response, 409,
78 "Conflict", "Uncontrolled device specified");
80 case STASIS_DEVICE_STATE_MISSING:
81 ast_ari_response_error(response, 404,
82 "Not Found", "Device name is missing");
84 case STASIS_DEVICE_STATE_UNKNOWN:
85 ast_ari_response_error(response, 500, "Internal Server Error",
88 case STASIS_DEVICE_STATE_OK:
89 case STASIS_DEVICE_STATE_SUBSCRIBERS: /* shouldn't be returned for update */
90 ast_ari_response_no_content(response);
94 void ast_ari_device_states_delete(struct ast_variable *headers,
95 struct ast_ari_device_states_delete_args *args,
96 struct ast_ari_response *response)
98 switch (stasis_app_device_state_delete(args->device_name)) {
99 case STASIS_DEVICE_STATE_NOT_CONTROLLED:
100 ast_ari_response_error(response, 409,
101 "Conflict", "Uncontrolled device specified");
103 case STASIS_DEVICE_STATE_MISSING:
104 ast_ari_response_error(response, 404,
105 "Not Found", "Device name is missing");
107 case STASIS_DEVICE_STATE_SUBSCRIBERS:
108 ast_ari_response_error(response, 500,
109 "Internal Server Error",
110 "Cannot delete device with subscribers");
112 case STASIS_DEVICE_STATE_OK:
113 case STASIS_DEVICE_STATE_UNKNOWN:
114 ast_ari_response_no_content(response);