Debian Codegraph @

res/ari/resource_device_states.c

raw symbols SCIP
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"
33 #include "asterisk/stasis_app_device_state.h"
34
35 void ast_ari_device_states_list(
36 struct ast_variable *headers,
37 struct ast_ari_device_states_list_args *args,
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
51 void ast_ari_device_states_get(struct ast_variable *headers,
52 struct ast_ari_device_states_get_args *args,
53 struct ast_ari_response *response)
54 {
55 struct ast_json *json;
56
57 if (!(json = stasis_app_device_state_to_json(
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
67 void ast_ari_device_states_update(struct ast_variable *headers,
68 struct ast_ari_device_states_update_args *args,
69 struct ast_ari_response *response)
70 {
71 switch (stasis_app_device_state_update(
72 args->device_name, args->device_state)) {
73 case STASIS_DEVICE_STATE_NOT_CONTROLLED:
74 ast_ari_response_error(response, 409,
75 "Conflict", "Uncontrolled device specified");
76 return;
77 case STASIS_DEVICE_STATE_MISSING:
78 ast_ari_response_error(response, 404,
79 "Not Found", "Device name is missing");
80 return;
81 case STASIS_DEVICE_STATE_UNKNOWN:
82 ast_ari_response_error(response, 500, "Internal Server Error",
83 "Unknown device");
84 return;
85 case STASIS_DEVICE_STATE_OK:
86 case STASIS_DEVICE_STATE_SUBSCRIBERS: /* shouldn't be returned for update */
87 ast_ari_response_no_content(response);
88 }
89 }
90
91 void ast_ari_device_states_delete(struct ast_variable *headers,
92 struct ast_ari_device_states_delete_args *args,
93 struct ast_ari_response *response)
94 {
95 switch (stasis_app_device_state_delete(args->device_name)) {
96 case STASIS_DEVICE_STATE_NOT_CONTROLLED:
97 ast_ari_response_error(response, 409,
98 "Conflict", "Uncontrolled device specified");
99 return;
100 case STASIS_DEVICE_STATE_MISSING:
101 ast_ari_response_error(response, 404,
102 "Not Found", "Device name is missing");
103 return;
104 case STASIS_DEVICE_STATE_SUBSCRIBERS:
105 ast_ari_response_error(response, 500,
106 "Internal Server Error",
107 "Cannot delete device with subscribers");
108 return;
109 case STASIS_DEVICE_STATE_OK:
110 case STASIS_DEVICE_STATE_UNKNOWN:
111 ast_ari_response_no_content(response);
112 }
113 }