2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "st_things.h"
20 static const char *PROP_POWER = "power";
22 #define VALUE_STR_LEN_MAX 32
23 static const char *VALUE_SWITCH_ON = "on";
24 static const char *VALUE_SWITCH_OFF = "off";
25 static char g_switch[VALUE_STR_LEN_MAX] = "off";
27 extern void set_switch_status(bool status);
29 bool handle_get_request_on_resource_capability_switch(st_things_get_request_message_s* req_msg, st_things_representation_s* resp_rep)
31 DBG("Received a GET request on %s\n", req_msg->resource_uri);
33 if (req_msg->has_property_key(req_msg, PROP_POWER)) {
34 resp_rep->set_str_value(resp_rep, PROP_POWER, g_switch);
40 bool handle_set_request_on_resource_capability_switch(st_things_set_request_message_s* req_msg, st_things_representation_s* resp_rep)
42 DBG("Received a SET request on %s\n", req_msg->resource_uri);
44 char *str_value = NULL;
45 req_msg->rep->get_str_value(req_msg->rep, PROP_POWER, &str_value);
47 /* check validation */
48 if ((0 != strncmp(str_value, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON)))
49 && (0 != strncmp(str_value, VALUE_SWITCH_OFF, strlen(VALUE_SWITCH_OFF)))) {
50 ERR("Not supported value!!");
55 if (0 != strncmp(str_value, g_switch, strlen(g_switch))) {
56 strncpy(g_switch, str_value, VALUE_STR_LEN_MAX);
57 if (0 == strncmp(g_switch, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON))) {
58 set_switch_status(true);
61 set_switch_status(false);
64 resp_rep->set_str_value(resp_rep, PROP_POWER, g_switch);
66 st_things_notify_observers(req_msg->resource_uri);