summaryrefslogtreecommitdiff
path: root/res/ari/resource_device_states.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-11-23 17:48:28 +0000
committerKevin Harwell <kharwell@digium.com>2013-11-23 17:48:28 +0000
commited483779946553e2ec42472c6b665b86dcb07066 (patch)
tree954ae85065f670f111954e36e5bd77d4f271778a /res/ari/resource_device_states.c
parent05cbf8df9b2ea0b41e049698b9f51ee4365ceab0 (diff)
ARI: Implement device state API
Created a data model and implemented functionality for an ARI device state resource. The following operations have been added that allow a user to manipulate an ARI controlled device: Create/Change the state of an ARI controlled device PUT /deviceStates/{deviceName}&{deviceState} Retrieve all ARI controlled devices GET /deviceStates Retrieve the current state of a device GET /deviceStates/{deviceName} Destroy a device-state controlled by ARI DELETE /deviceStates/{deviceName} The ARI controlled device must begin with 'Stasis:'. An example controlled device name would be Stasis:Example. A 'DeviceStateChanged' event has also been added so that an application can subscribe and receive device change events. Any device state, ARI controlled or not, can be subscribed to. While adding the event, the underlying subscription control mechanism was refactored so that all current and future resource subscriptions would be the same. Each event resource must now register itself in order to be able to properly handle [un]subscribes. (issue ASTERISK-22838) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/3025/ ........ Merged revisions 403134 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403135 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/resource_device_states.c')
-rw-r--r--res/ari/resource_device_states.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/res/ari/resource_device_states.c b/res/ari/resource_device_states.c
new file mode 100644
index 000000000..50b876740
--- /dev/null
+++ b/res/ari/resource_device_states.c
@@ -0,0 +1,111 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012 - 2013, Digium, Inc.
+ *
+ * Kevin Harwell <kharwell@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief /api-docs/deviceStates.{format} implementation- Device state resources
+ *
+ * \author Kevin Harwell <kharwell@digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "resource_device_states.h"
+#include "asterisk/stasis_app_device_state.h"
+
+void ast_ari_device_states_list(
+ struct ast_variable *headers,
+ struct ast_ari_device_states_list_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+ if (!(json = stasis_app_device_states_to_json())) {
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Error building response");
+ return;
+ }
+
+ ast_ari_response_ok(response, json);
+}
+
+void ast_ari_device_states_get(struct ast_variable *headers,
+ struct ast_ari_device_states_get_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+ if (!(json = stasis_app_device_state_to_json(
+ args->device_name, ast_device_state(args->device_name)))) {
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Error building response");
+ return;
+ }
+
+ ast_ari_response_ok(response, json);
+}
+
+void ast_ari_device_states_update(struct ast_variable *headers,
+ struct ast_ari_device_states_update_args *args,
+ struct ast_ari_response *response)
+{
+ switch (stasis_app_device_state_update(
+ args->device_name, args->device_state)) {
+ case STASIS_DEVICE_STATE_NOT_CONTROLLED:
+ ast_ari_response_error(response, 409,
+ "Conflict", "Uncontrolled device specified");
+ return;
+ case STASIS_DEVICE_STATE_MISSING:
+ ast_ari_response_error(response, 404,
+ "Not Found", "Device name is missing");
+ return;
+ case STASIS_DEVICE_STATE_UNKNOWN:
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Unknown device");
+ return;
+ case STASIS_DEVICE_STATE_OK:
+ case STASIS_DEVICE_STATE_SUBSCRIBERS: /* shouldn't be returned for update */
+ ast_ari_response_no_content(response);
+ }
+}
+
+void ast_ari_device_states_delete(struct ast_variable *headers,
+ struct ast_ari_device_states_delete_args *args,
+ struct ast_ari_response *response)
+{
+ switch (stasis_app_device_state_delete(args->device_name)) {
+ case STASIS_DEVICE_STATE_NOT_CONTROLLED:
+ ast_ari_response_error(response, 409,
+ "Conflict", "Uncontrolled device specified");
+ return;
+ case STASIS_DEVICE_STATE_MISSING:
+ ast_ari_response_error(response, 404,
+ "Not Found", "Device name is missing");
+ return;
+ case STASIS_DEVICE_STATE_SUBSCRIBERS:
+ ast_ari_response_error(response, 500,
+ "Internal Server Error",
+ "Cannot delete device with subscribers");
+ return;
+ case STASIS_DEVICE_STATE_OK:
+ case STASIS_DEVICE_STATE_UNKNOWN:
+ ast_ari_response_no_content(response);
+ }
+}