return;
}
- ret = iotcon_state_create(&state);
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
iotcon_representation_destroy(resp_repr);
iotcon_response_destroy(response);
return;
}
- ret = iotcon_state_add_bool(resp_repr, "opened", true);
+ ret = iotcon_attributes_add_bool(resp_repr, "opened", true);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(resp_repr);
iotcon_response_destroy(response);
return;
ret = iotcon_response_set_representation(response, resp_repr);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(resp_repr);
iotcon_response_destroy(response);
return;
ret = iotcon_response_send(response);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(resp_repr);
iotcon_response_destroy(response);
return;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(resp_repr);
iotcon_response_destroy(response);
}
--- /dev/null
+/* Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+
+#include "iotcon-types.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-list.h"
+#include "icl-value.h"
+#include "icl-representation.h"
+#include "icl-attributes.h"
+
+iotcon_attributes_h icl_attributes_ref(iotcon_attributes_h attributes)
+{
+ RETV_IF(NULL == attributes, NULL);
+ RETV_IF(attributes->ref_count <= 0, NULL);
+
+ attributes->ref_count++;
+
+ return attributes;
+}
+
+
+API int iotcon_attributes_create(iotcon_attributes_h *ret_attributes)
+{
+ iotcon_attributes_h attributes;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == ret_attributes, IOTCON_ERROR_INVALID_PARAMETER);
+
+ attributes = calloc(1, sizeof(struct icl_attributes_s));
+ if (NULL == attributes) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ attributes->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
+ icl_value_destroy);
+ attributes->ref_count = 1;
+
+ *ret_attributes = attributes;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_attributes_destroy(iotcon_attributes_h attributes)
+{
+ RET_IF(NULL == attributes);
+
+ attributes->ref_count--;
+
+ if (0 != attributes->ref_count)
+ return;
+
+ g_hash_table_destroy(attributes->hash_table);
+ free(attributes);
+}
+
+
+API int iotcon_attributes_remove(iotcon_attributes_h attributes, const char *key)
+{
+ gboolean ret = FALSE;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup(%s) Fail", key);
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = g_hash_table_remove(attributes->hash_table, key);
+ if (FALSE == ret) {
+ ERR("g_hash_table_remove(%s) Fail", key);
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_attributes_get_int(iotcon_attributes_h attributes, const char *key,
+ int *val)
+{
+ iotcon_value_h value;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ icl_basic_s *real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_INT != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.i;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_int(iotcon_attributes_h attributes, const char *key,
+ int val)
+{
+ iotcon_value_h value;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_int(val);
+ if (NULL == value) {
+ ERR("icl_value_create_int(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_bool(iotcon_attributes_h attributes, const char *key,
+ bool *val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_BOOL != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.b;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_bool(iotcon_attributes_h attributes, const char *key,
+ bool val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_bool(val);
+ if (NULL == value) {
+ ERR("icl_value_create_bool(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_double(iotcon_attributes_h attributes,
+ const char *key, double *val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_DOUBLE != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.d;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_double(iotcon_attributes_h attributes,
+ const char *key, double val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_double(val);
+ if (NULL == value) {
+ ERR("icl_value_create_double(%f) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_str(iotcon_attributes_h attributes, const char *key,
+ char **val)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ if (IOTCON_TYPE_STR != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->val.s;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_str(iotcon_attributes_h attributes, const char *key,
+ char *val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_str(val);
+ if (NULL == value) {
+ ERR("icl_value_create_str(%s) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_byte_str(iotcon_attributes_h attributes, const char *key,
+ unsigned char **val, int *len)
+{
+ iotcon_value_h value = NULL;
+ icl_val_byte_str_s *real = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_val_byte_str_s*)value;
+ if (IOTCON_TYPE_BYTE_STR != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *val = real->s;
+ *len = real->len;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_byte_str(iotcon_attributes_h attributes,
+ const char *key, unsigned char *val, int len)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(len <= 0, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_byte_str(val, len);
+ if (NULL == value) {
+ ERR("icl_value_create_byte_str() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_is_null(iotcon_attributes_h attributes, const char *key,
+ bool *is_null)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == is_null, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = (iotcon_value_h) g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_basic_s*)value;
+ *is_null = (IOTCON_TYPE_NULL == real->type) ? true : false;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_null(iotcon_attributes_h attributes, const char *key)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_null();
+ if (NULL == value) {
+ ERR("icl_value_create_null() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_list(iotcon_attributes_h attributes, const char *key,
+ iotcon_list_h *list)
+{
+ iotcon_value_h value = NULL;
+ icl_val_list_s *real = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_val_list_s*)value;
+ if (IOTCON_TYPE_LIST != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *list = real->list;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_list(iotcon_attributes_h attributes, const char *key,
+ iotcon_list_h list)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+
+ value = icl_value_create_list(list);
+ if (NULL == value) {
+ ERR("icl_value_create_list() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_attributes(iotcon_attributes_h src, const char *key,
+ iotcon_attributes_h *dest)
+{
+ icl_val_attributes_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(src->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ real = (icl_val_attributes_s*)value;
+ if (IOTCON_TYPE_ATTRIBUTES != real->type) {
+ ERR("Invalid Type(%d)", real->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ *dest = real->attributes;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_add_attributes(iotcon_attributes_h attributes,
+ const char *key, iotcon_attributes_h val)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = icl_value_create_attributes(val);
+ if (NULL == value) {
+ ERR("icl_value_create_attributes(%p) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_attributes_get_type(iotcon_attributes_h attributes, const char *key,
+ iotcon_type_e *type)
+{
+ iotcon_value_h value = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_hash_table_lookup(attributes->hash_table, key);
+ if (NULL == value) {
+ ERR("g_hash_table_lookup() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+ *type = value->type;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_attributes_set_value(iotcon_attributes_h attributes, const char *key,
+ iotcon_value_h value)
+{
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+
+ g_hash_table_replace(attributes->hash_table, ic_utils_strdup(key), value);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_attributes_get_keys_count(iotcon_attributes_h attributes,
+ unsigned int *count)
+{
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == count, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *count = g_hash_table_size(attributes->hash_table);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_attributes_clone(iotcon_attributes_h attributes,
+ iotcon_attributes_h *attributes_clone)
+{
+ int ret;
+
+ iotcon_attributes_h temp = NULL;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes_clone, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (attributes->hash_table) {
+ ret = iotcon_attributes_create(&temp);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
+ return ret;
+ }
+
+ g_hash_table_foreach(attributes->hash_table, (GHFunc)icl_attributes_clone_foreach,
+ temp);
+ }
+
+ *attributes_clone = temp;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+void icl_attributes_clone_foreach(char *key, iotcon_value_h src_val,
+ iotcon_attributes_h dest_attributes)
+{
+ FN_CALL;
+ iotcon_value_h copied_val;
+
+ copied_val = icl_value_clone(src_val);
+ if (NULL == copied_val) {
+ ERR("icl_value_clone() Fail");
+ return;
+ }
+
+ icl_attributes_set_value(dest_attributes, key, copied_val);
+}
+
+
+API int iotcon_attributes_foreach(iotcon_attributes_h attributes,
+ iotcon_attributes_cb cb, void *user_data)
+{
+ GHashTableIter iter;
+ gpointer key;
+
+ RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ g_hash_table_iter_init(&iter, attributes->hash_table);
+ while (g_hash_table_iter_next(&iter, &key, NULL)) {
+ if (IOTCON_FUNC_STOP == cb(attributes, key, user_data))
+ break;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_LIBRARY_ATTRIBUTES_H__
+#define __IOT_CONNECTIVITY_LIBRARY_ATTRIBUTES_H__
+
+#include "icl-value.h"
+#include "icl-representation.h"
+
+int icl_attributes_set_value(iotcon_attributes_h attributes, const char *key,
+ iotcon_value_h value);
+
+void icl_attributes_clone_foreach(char *key, iotcon_value_h src_val,
+ iotcon_attributes_h dest_attributes);
+
+iotcon_attributes_h icl_attributes_ref(iotcon_attributes_h attributes);
+
+#endif /* __IOT_CONNECTIVITY_LIBRARY_ATTRIBUTES_H__ */
#include "icl-options.h"
#include "icl-representation.h"
#include "icl-types.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-lite-resource.h"
#include "icl-ioty.h"
#include "icl-ioty-types.h"
return ret;
}
- ret = iotcon_representation_set_state(repr, resource->state);
+ ret = iotcon_representation_set_attributes(repr, resource->attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return ret;
}
break;
case IOTCON_REQUEST_POST:
if (resource->cb) {
- if (false == resource->cb(resource, repr->state, resource->cb_data)) {
+ if (false == resource->cb(resource, repr->attributes, resource->cb_data)) {
res->result = IOTCON_RESPONSE_ERROR;
g_idle_add(_icl_ioty_ocprocess_lite_resource_response_idle_cb, res);
break;
}
}
- iotcon_state_destroy(resource->state);
- resource->state = repr->state;
- repr->state = NULL;
+ iotcon_attributes_destroy(resource->attributes);
+ resource->attributes = repr->attributes;
+ repr->attributes = NULL;
_icl_ioty_ocprocess_lite_resource_get_repr(resource, &(res->repr));
res->result = IOTCON_RESPONSE_OK;
g_idle_add(_icl_ioty_ocprocess_lite_resource_response_idle_cb, res);
#include "icl-types.h"
#include "icl-ioty-types.h"
-struct icl_state_list_s {
+struct icl_attributes_list_s {
OCRepPayloadPropType type;
size_t dimensions[MAX_REP_ARRAY_DEPTH];
GList *list;
};
static int _icl_ioty_parse_oic_rep_payload_value(OCRepPayloadValue *val,
- iotcon_state_h *state);
+ iotcon_attributes_h *attributes);
static int _icl_ioty_fill_oic_rep_payload_value(OCRepPayload *payload,
- iotcon_state_h state);
+ iotcon_attributes_h attributes);
static void _icl_ioty_free_resource_list(iotcon_remote_resource_h *resource_list,
int resource_count)
}
break;
case OCREP_PROP_OBJECT:
- ret = iotcon_list_create(IOTCON_TYPE_STATE, &l);
+ ret = iotcon_list_create(IOTCON_TYPE_ATTRIBUTES, &l);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create(IOTCON_TYPE_STATE) Fail(%d)", ret);
+ ERR("iotcon_list_create(IOTCON_TYPE_ATTRIBUTES) Fail(%d)", ret);
return ret;
}
for (i = 0; i < len; i++) {
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
ret = _icl_ioty_parse_oic_rep_payload_value(arr->objArray[index + i]->values,
- &state);
+ &attributes);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_parse_oic_rep_payload_value(%d)", ret);
iotcon_list_destroy(l);
return ret;
}
- ret = iotcon_list_add_state(l, state, -1);
+ ret = iotcon_list_add_attributes(l, attributes, -1);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_list_add_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_list_destroy(l);
return ret;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
}
break;
case OCREP_PROP_ARRAY:
}
static int _icl_ioty_parse_oic_rep_payload_value(OCRepPayloadValue *val,
- iotcon_state_h *state)
+ iotcon_attributes_h *attributes)
{
int ret, total_len;
- iotcon_state_h s;
+ iotcon_attributes_h s;
iotcon_list_h list;
- iotcon_state_h s_obj;
+ iotcon_attributes_h s_obj;
RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
- ret = iotcon_state_create(&s);
+ ret = iotcon_attributes_create(&s);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
return ret;
}
while (val) {
switch (val->type) {
case OCREP_PROP_INT:
- ret = iotcon_state_add_int(s, val->name, val->i);
+ ret = iotcon_attributes_add_int(s, val->name, val->i);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_int() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_int() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
case OCREP_PROP_BOOL:
- ret = iotcon_state_add_bool(s, val->name, val->b);
+ ret = iotcon_attributes_add_bool(s, val->name, val->b);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
case OCREP_PROP_DOUBLE:
- ret = iotcon_state_add_double(s, val->name, val->d);
+ ret = iotcon_attributes_add_double(s, val->name, val->d);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_double() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_double() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
case OCREP_PROP_STRING:
- ret = iotcon_state_add_str(s, val->name, val->str);
+ ret = iotcon_attributes_add_str(s, val->name, val->str);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_str() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_str() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
case OCREP_PROP_BYTE_STRING:
- ret = iotcon_state_add_byte_str(s, val->name, val->ocByteStr.bytes,
+ ret = iotcon_attributes_add_byte_str(s, val->name, val->ocByteStr.bytes,
val->ocByteStr.len);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_byte_str() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_byte_str() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
case OCREP_PROP_NULL:
- ret = iotcon_state_add_null(s, val->name);
+ ret = iotcon_attributes_add_null(s, val->name);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_null() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_null() Fail(%d)", ret);
+ iotcon_attributes_destroy(s);
return ret;
}
break;
&list);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_parse_oic_rep_payload_value_array() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ iotcon_attributes_destroy(s);
return ret;
}
- ret = iotcon_state_add_list(s, val->name, list);
+ ret = iotcon_attributes_add_list(s, val->name, list);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_list() Fail(%d)", ret);
+ ERR("iotcon_attributes_add_list() Fail(%d)", ret);
iotcon_list_destroy(list);
- iotcon_state_destroy(s);
+ iotcon_attributes_destroy(s);
return ret;
}
iotcon_list_destroy(list);
ret = _icl_ioty_parse_oic_rep_payload_value(val->obj->values, &s_obj);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_parse_oic_rep_payload_value() Fail(%d)", ret);
- iotcon_state_destroy(s);
+ iotcon_attributes_destroy(s);
return ret;
}
- ret = iotcon_state_add_state(s, val->name, s_obj);
+ ret = iotcon_attributes_add_attributes(s, val->name, s_obj);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_state() Fail(%d)", ret);
- iotcon_state_destroy(s_obj);
- iotcon_state_destroy(s);
+ ERR("iotcon_attributes_add_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(s_obj);
+ iotcon_attributes_destroy(s);
return ret;
}
- iotcon_state_destroy(s_obj);
+ iotcon_attributes_destroy(s_obj);
break;
default:
ERR("Invalid Type(%d)", val->type);
val = val->next;
}
- *state = s;
+ *attributes = s;
return IOTCON_ERROR_NONE;
}
OCRepPayload *child_node;
iotcon_resource_interfaces_h ifaces;
iotcon_representation_h repr;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
iotcon_resource_types_h types = NULL;
RETV_IF(NULL == payload, IOTCON_ERROR_INVALID_PARAMETER);
}
iotcon_resource_interfaces_destroy(ifaces);
- /* state */
+ /* attributes */
if (payload->values) {
- ret = _icl_ioty_parse_oic_rep_payload_value(payload->values, &state);
+ ret = _icl_ioty_parse_oic_rep_payload_value(payload->values, &attributes);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_representation_set_resource_types() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return ret;
}
- ret = iotcon_representation_set_state(repr, state);
+ ret = iotcon_representation_set_attributes(repr, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return ret;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
}
/* children */
}
static int _icl_ioty_fill_oic_rep_payload_value_array(OCRepPayload *payload,
- const char *key, struct icl_state_list_s *list)
+ const char *key, struct icl_attributes_list_s *list)
{
int i, j, len, ret;
bool *b_arr;
char **str_arr;
int64_t *i_arr;
OCByteString *byte_arr;
- struct OCRepPayload **state_arr;
+ struct OCRepPayload **attributes_arr;
GList *node;
RETV_IF(NULL == payload, IOTCON_ERROR_INVALID_PARAMETER);
free(byte_arr);
break;
case OCREP_PROP_OBJECT:
- state_arr = calloc(len, sizeof(struct OCRepPayload *));
- if (NULL == state_arr) {
+ attributes_arr = calloc(len, sizeof(struct OCRepPayload *));
+ if (NULL == attributes_arr) {
ERR("calloc() Fail(%d)", errno);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
for (node = list->list, i = 0; node; node = node->next, i++) {
- state_arr[i] = OCRepPayloadCreate();
- if (NULL == state_arr[i]) {
+ attributes_arr[i] = OCRepPayloadCreate();
+ if (NULL == attributes_arr[i]) {
ERR("OCRepPayloadCreate() Fail");
- free(state_arr);
+ free(attributes_arr);
return ret;
}
- ret = _icl_ioty_fill_oic_rep_payload_value(state_arr[i],
- ((icl_val_state_s*)node->data)->state);
+ ret = _icl_ioty_fill_oic_rep_payload_value(attributes_arr[i],
+ ((icl_val_attributes_s*)node->data)->attributes);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_fill_oic_rep_payload_value() Fail(%d)", ret);
for (j = 0; j <= i; j++)
- OCRepPayloadDestroy(state_arr[j]);
- free(state_arr);
+ OCRepPayloadDestroy(attributes_arr[j]);
+ free(attributes_arr);
return ret;
}
}
- OCRepPayloadSetPropObjectArrayAsOwner(payload, key, state_arr, list->dimensions);
+ OCRepPayloadSetPropObjectArrayAsOwner(payload, key, attributes_arr, list->dimensions);
break;
case OCREP_PROP_ARRAY:
case OCREP_PROP_NULL:
}
-static int _icl_ioty_state_list_to_value_list(iotcon_list_h list,
- struct icl_state_list_s *value_list, int depth)
+static int _icl_ioty_attributes_list_to_value_list(iotcon_list_h list,
+ struct icl_attributes_list_s *value_list, int depth)
{
int ret;
GList *c;
for (c = list->list; c; c = c->next)
value_list->list = g_list_append(value_list->list, c->data);
break;
- case IOTCON_TYPE_STATE:
+ case IOTCON_TYPE_ATTRIBUTES:
value_list->type = OCREP_PROP_OBJECT;
for (c = list->list; c; c = c->next)
value_list->list = g_list_append(value_list->list, c->data);
break;
case IOTCON_TYPE_LIST:
for (c = list->list; c; c = c->next) {
- ret = _icl_ioty_state_list_to_value_list(((icl_val_list_s *)c->data)->list, value_list, depth + 1);
+ ret = _icl_ioty_attributes_list_to_value_list(((icl_val_list_s *)c->data)->list,
+ value_list, depth + 1);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_ioty_state_list_to_value_list() Fail(%d)", ret);
+ ERR("_icl_ioty_attributes_list_to_value_list() Fail(%d)", ret);
return ret;
}
}
}
static int _icl_ioty_fill_oic_rep_payload_value(OCRepPayload *payload,
- iotcon_state_h state)
+ iotcon_attributes_h attributes)
{
FN_CALL;
int ret;
gpointer key, value;
OCRepPayload *repr_payload;
OCByteString byte_string;
- struct icl_value_s *state_value;
- struct icl_state_list_s value_list = {0};
+ struct icl_value_s *attributes_value;
+ struct icl_attributes_list_s value_list = {0};
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == payload, IOTCON_ERROR_INVALID_PARAMETER);
- g_hash_table_iter_init(&iter, state->hash_table);
+ g_hash_table_iter_init(&iter, attributes->hash_table);
while (g_hash_table_iter_next(&iter, &key, &value)) {
- state_value = (struct icl_value_s *)value;
- if (NULL == state_value) {
- ERR("state_value(%s) is NULL", key);
+ attributes_value = (struct icl_value_s *)value;
+ if (NULL == attributes_value) {
+ ERR("attributes_value(%s) is NULL", key);
continue;
}
- switch (state_value->type) {
+ switch (attributes_value->type) {
case IOTCON_TYPE_BOOL:
- OCRepPayloadSetPropBool(payload, key, ((icl_basic_s*)state_value)->val.b);
+ OCRepPayloadSetPropBool(payload, key, ((icl_basic_s*)attributes_value)->val.b);
break;
case IOTCON_TYPE_INT:
- OCRepPayloadSetPropInt(payload, key, ((icl_basic_s*)state_value)->val.i);
+ OCRepPayloadSetPropInt(payload, key, ((icl_basic_s*)attributes_value)->val.i);
break;
case IOTCON_TYPE_DOUBLE:
- OCRepPayloadSetPropDouble(payload, key, ((icl_basic_s*)state_value)->val.d);
+ OCRepPayloadSetPropDouble(payload, key, ((icl_basic_s*)attributes_value)->val.d);
break;
case IOTCON_TYPE_STR:
- OCRepPayloadSetPropString(payload, key, ((icl_basic_s*)state_value)->val.s);
+ OCRepPayloadSetPropString(payload, key, ((icl_basic_s*)attributes_value)->val.s);
break;
case IOTCON_TYPE_NULL:
OCRepPayloadSetNull(payload, key);
break;
case IOTCON_TYPE_BYTE_STR:
- byte_string.bytes = ((icl_val_byte_str_s*)state_value)->s;
- byte_string.len = ((icl_val_byte_str_s*)state_value)->len;
+ byte_string.bytes = ((icl_val_byte_str_s*)attributes_value)->s;
+ byte_string.len = ((icl_val_byte_str_s*)attributes_value)->len;
OCRepPayloadSetPropByteString(payload, key, byte_string);
break;
case IOTCON_TYPE_LIST:
- ret = _icl_ioty_state_list_to_value_list(((icl_val_list_s*)state_value)->list,
+ ret = _icl_ioty_attributes_list_to_value_list(((icl_val_list_s*)attributes_value)->list,
&value_list, 0);
if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_ioty_state_list_to_value_list() Fail(%d)", ret);
+ ERR("_icl_ioty_attributes_list_to_value_list() Fail(%d)", ret);
return ret;
}
ret = _icl_ioty_fill_oic_rep_payload_value_array(payload, key, &value_list);
g_list_free(value_list.list);
value_list.list = NULL;
break;
- case IOTCON_TYPE_STATE:
+ case IOTCON_TYPE_ATTRIBUTES:
repr_payload = OCRepPayloadCreate();
ret = _icl_ioty_fill_oic_rep_payload_value(repr_payload,
- ((icl_val_state_s*)state_value)->state);
+ ((icl_val_attributes_s*)attributes_value)->attributes);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_fill_oic_rep_payload_value() Fail(%d)", ret);
OCRepPayloadDestroy(repr_payload);
break;
case IOTCON_TYPE_NONE:
default:
- ERR("Invalid Type(%d)", state_value->type);
+ ERR("Invalid Type(%d)", attributes_value->type);
return IOTCON_ERROR_INVALID_PARAMETER;
}
}
OCRepPayloadAddResourceType(repr_payload, c->data);
}
- /* state */
- if (repr->state) {
- ret = _icl_ioty_fill_oic_rep_payload_value(repr_payload, repr->state);
+ /* attributes */
+ if (repr->attributes) {
+ ret = _icl_ioty_fill_oic_rep_payload_value(repr_payload, repr->attributes);
if (IOTCON_ERROR_NONE != ret) {
ERR("_icl_ioty_fill_oic_rep_payload_value() Fail(%d)", ret);
OCRepPayloadDestroy(repr_payload);
#include "icl-resource-types.h"
#include "icl-response.h"
#include "icl-observation.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-lite-resource.h"
#include "icl-ioty-ocprocess.h"
#include "icl-ioty-types.h"
int icl_ioty_lite_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
uint8_t policies,
- iotcon_state_h state,
+ iotcon_attributes_h attributes,
iotcon_lite_resource_post_request_cb cb,
void *user_data,
iotcon_lite_resource_h *resource_handle)
}
resource->uri_path = strdup(uri_path);
resource->policies = policies;
- resource->state = state;
- icl_state_ref(resource->state);
+ resource->policies = policies;
+ resource->attributes = attributes;
+ icl_attributes_ref(resource->attributes);
resource->cb = cb;
resource->cb_data = user_data;
return IOTCON_ERROR_NONE;
}
-int icl_ioty_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state)
+int icl_ioty_lite_resource_update_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h attributes)
{
int ret;
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- if (state)
- state = icl_state_ref(state);
+ if (attributes)
+ attributes = icl_attributes_ref(attributes);
- if (resource->state)
- iotcon_state_destroy(resource->state);
+ if (resource->attributes)
+ iotcon_attributes_destroy(resource->attributes);
- resource->state = state;
+ resource->attributes = attributes;
ret = icl_ioty_lite_resource_notify(resource);
if (IOTCON_ERROR_NONE != ret)
int icl_ioty_lite_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
uint8_t policies,
- iotcon_state_h state,
+ iotcon_attributes_h attributes,
iotcon_lite_resource_post_request_cb cb,
void *user_data,
iotcon_lite_resource_h *resource_handle);
int icl_ioty_lite_resource_destroy(iotcon_lite_resource_h resource);
-int icl_ioty_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state);
+int icl_ioty_lite_resource_update_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h attributes);
int icl_ioty_lite_resource_notify(iotcon_lite_resource_h resource);
int icl_ioty_response_send(iotcon_response_h response);
#include "iotcon-types.h"
#include "ic-utils.h"
#include "icl.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-representation.h"
#include "icl-value.h"
#include "icl-list.h"
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
- if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
+ if (type < IOTCON_TYPE_INT || IOTCON_TYPE_ATTRIBUTES < type) {
ERR("Invalid Type(%d)", type);
return IOTCON_ERROR_INVALID_TYPE;
}
}
-API int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos)
+API int iotcon_list_add_attributes(iotcon_list_h list, iotcon_attributes_h val, int pos)
{
iotcon_value_h value;
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
+ RETVM_IF(IOTCON_TYPE_ATTRIBUTES != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
- value = icl_value_create_state(val);
+ value = icl_value_create_attributes(val);
if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", val);
+ ERR("icl_value_create_attributes(%p) Fail", val);
return IOTCON_ERROR_OUT_OF_MEMORY;
}
}
-API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state)
+API int iotcon_list_get_nth_attributes(iotcon_list_h list, int pos,
+ iotcon_attributes_h *attributes)
{
int ret;
iotcon_value_h value;
- iotcon_state_h state_val;
+ iotcon_attributes_h attributes_val;
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
value = g_list_nth_data(list->list, pos);
if (NULL == value) {
return IOTCON_ERROR_NO_DATA;
}
- ret = icl_value_get_state(value, &state_val);
+ ret = icl_value_get_attributes(value, &attributes_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
+ ERR("icl_value_get_attributes() Fail(%d)", ret);
return IOTCON_ERROR_REPRESENTATION;
}
- *state = state_val;
+ *attributes = attributes_val;
return IOTCON_ERROR_NONE;
}
return IOTCON_ERROR_NONE;
}
-API int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb,
- void *user_data)
+API int iotcon_list_foreach_attributes(iotcon_list_h list,
+ iotcon_list_attributes_cb cb, void *user_data)
{
int index = 0;
GList *cur = NULL;
- icl_val_state_s *real = NULL;
+ icl_val_attributes_s *real = NULL;
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
+ RETVM_IF(IOTCON_TYPE_ATTRIBUTES != list->type, IOTCON_ERROR_INVALID_TYPE,
"Invalid Type(%d)", list->type);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
while (cur) {
GList *next = cur->next;
real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->state, user_data))
+ if (IOTCON_FUNC_STOP == cb(index, real->attributes, user_data))
break;
index++;
cur = next;
#include "ic-utils.h"
#include "icl.h"
#include "icl-representation.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-value.h"
#include "icl-list.h"
#include "icl-resource.h"
API int iotcon_lite_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
uint8_t policies,
- iotcon_state_h state,
+ iotcon_attributes_h attributes,
iotcon_lite_resource_post_request_cb cb,
void *user_data,
iotcon_lite_resource_h *resource_handle)
RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
- ret = icl_ioty_lite_resource_create(uri_path, res_types, policies, state, cb,
+ ret = icl_ioty_lite_resource_create(uri_path, res_types, policies, attributes, cb,
user_data, resource_handle);
if (IOTCON_ERROR_NONE != ret) {
ERR("icl_ioty_lite_resource_create() Fail(%d)", ret);
}
-API int iotcon_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state)
+API int iotcon_lite_resource_update_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h attributes)
{
int ret;
IOTCON_ERROR_PERMISSION_DENIED);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- ret = icl_ioty_lite_resource_update_state(resource, state);
+ ret = icl_ioty_lite_resource_update_attributes(resource, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_ioty_lite_resource_update_state() Fail(%d)", ret);
+ ERR("icl_ioty_lite_resource_update_attributes() Fail(%d)", ret);
return ret;
}
}
-API int iotcon_lite_resource_get_state(iotcon_lite_resource_h resource,
- iotcon_state_h *state)
+API int iotcon_lite_resource_get_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h *attributes)
{
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
- *state = resource->state;
+ *attributes = resource->attributes;
return IOTCON_ERROR_NONE;
}
struct icl_lite_resource {
char *uri_path;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
int64_t handle;
uint8_t policies;
iotcon_lite_resource_post_request_cb cb;
#include "icl-response.h"
#include "icl-list.h"
#include "icl-value.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-representation.h"
-static int _icl_repr_compare_state_value(struct icl_value_s *val1,
+static int _icl_repr_compare_attributes_value(struct icl_value_s *val1,
struct icl_value_s *val2);
-static int _icl_repr_compare_state(iotcon_state_h state1, iotcon_state_h state2);
+static int _icl_repr_compare_attributes(iotcon_attributes_h attributes1,
+ iotcon_attributes_h attributes2);
iotcon_representation_h icl_representation_ref(iotcon_representation_h repr)
{
iotcon_resource_types_destroy(repr->res_types);
/* null COULD be allowed */
- if (repr->state)
- iotcon_state_destroy(repr->state);
+ if (repr->attributes)
+ iotcon_attributes_destroy(repr->attributes);
free(repr);
}
return IOTCON_ERROR_NONE;
}
-API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- iotcon_resource_interfaces_h *ifaces)
+API int iotcon_representation_get_resource_interfaces(
+ iotcon_representation_h repr, iotcon_resource_interfaces_h *ifaces)
{
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_NONE;
}
-API int iotcon_representation_set_state(iotcon_representation_h repr,
- iotcon_state_h state)
+API int iotcon_representation_set_attributes(iotcon_representation_h repr,
+ iotcon_attributes_h attributes)
{
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- if (state)
- state = icl_state_ref(state);
+ if (attributes)
+ attributes = icl_attributes_ref(attributes);
- if (repr->state)
- iotcon_state_destroy(repr->state);
+ if (repr->attributes)
+ iotcon_attributes_destroy(repr->attributes);
- repr->state = state;
+ repr->attributes = attributes;
return IOTCON_ERROR_NONE;
}
-API int iotcon_representation_get_state(iotcon_representation_h repr,
- iotcon_state_h *state)
+API int iotcon_representation_get_attributes(iotcon_representation_h repr,
+ iotcon_attributes_h *attributes)
{
RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == attributes, IOTCON_ERROR_INVALID_PARAMETER);
- *state = repr->state;
+ *attributes = repr->attributes;
return IOTCON_ERROR_NONE;
}
}
}
- if (src->state) {
- ret = iotcon_state_clone(src->state, &cloned_repr->state);
+ if (src->attributes) {
+ ret = iotcon_attributes_clone(src->attributes, &cloned_repr->attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_clone() Fail(%d)", ret);
+ ERR("iotcon_attributes_clone() Fail(%d)", ret);
iotcon_representation_destroy(cloned_repr);
return ret;
}
return ret ;
}
-static int _icl_repr_compare_state_value_custom(gconstpointer p1,
+static int _icl_repr_compare_attributes_value_custom(gconstpointer p1,
gconstpointer p2)
{
struct icl_value_s *val1 = (struct icl_value_s *)p1;
struct icl_value_s *val2 = (struct icl_value_s *)p2;
- return _icl_repr_compare_state_value(val1, val2);
+ return _icl_repr_compare_attributes_value(val1, val2);
}
-static int _icl_repr_compare_state_list_value(struct icl_list_s *list1,
+static int _icl_repr_compare_attributes_list_value(struct icl_list_s *list1,
struct icl_list_s *list2)
{
GList *c;
return !!(list1->list - list2->list);
for (c = list1->list; c; c = c->next)
- g_list_find_custom(list2->list, c->data, _icl_repr_compare_state_value_custom);
+ g_list_find_custom(list2->list, c->data, _icl_repr_compare_attributes_value_custom);
return IC_EQUAL;
}
-static int _icl_repr_compare_state_value(struct icl_value_s *val1,
+static int _icl_repr_compare_attributes_value(struct icl_value_s *val1,
struct icl_value_s *val2)
{
int i;
return 1;
}
break;
- case IOTCON_TYPE_STATE:
- return _icl_repr_compare_state(((icl_val_state_s *)val1)->state,
- ((icl_val_state_s *)val2)->state);
+ case IOTCON_TYPE_ATTRIBUTES:
+ return _icl_repr_compare_attributes(((icl_val_attributes_s *)val1)->attributes,
+ ((icl_val_attributes_s *)val2)->attributes);
case IOTCON_TYPE_LIST:
- return _icl_repr_compare_state_list_value(((icl_val_list_s*)val1)->list,
+ return _icl_repr_compare_attributes_list_value(((icl_val_list_s*)val1)->list,
((icl_val_list_s*)val2)->list);
case IOTCON_TYPE_NULL:
return IC_EQUAL;
return IC_EQUAL;
}
-static int _icl_repr_compare_state(iotcon_state_h state1, iotcon_state_h state2)
+static int _icl_repr_compare_attributes(iotcon_attributes_h attributes1,
+ iotcon_attributes_h attributes2)
{
int ret;
gpointer key, value1, value2;
GHashTableIter iter;
- struct icl_value_s *state_val1, *state_val2;
+ struct icl_value_s *attributes_val1, *attributes_val2;
- if (NULL == state1 || NULL == state2)
- return !!(state1 - state2);
+ if (NULL == attributes1 || NULL == attributes2)
+ return !!(attributes1 - attributes2);
- if (NULL == state1->hash_table || NULL == state2->hash_table)
- return !!(IC_POINTER_TO_INT64(state1->hash_table) -
- IC_POINTER_TO_INT64(state2->hash_table));
+ if (NULL == attributes1->hash_table || NULL == attributes2->hash_table)
+ return !!(IC_POINTER_TO_INT64(attributes1->hash_table) -
+ IC_POINTER_TO_INT64(attributes2->hash_table));
- if (g_hash_table_size(state1->hash_table) != g_hash_table_size(state2->hash_table))
+ if (g_hash_table_size(attributes1->hash_table) !=
+ g_hash_table_size(attributes1->hash_table))
return 1;
- g_hash_table_iter_init(&iter, state1->hash_table);
+ g_hash_table_iter_init(&iter, attributes1->hash_table);
while (g_hash_table_iter_next(&iter, &key, &value1)) {
- value2 = g_hash_table_lookup(state2->hash_table, key);
- state_val1 = (struct icl_value_s *)value1;
- state_val2 = (struct icl_value_s *)value2;
- ret = _icl_repr_compare_state_value(state_val1, state_val2);
+ value2 = g_hash_table_lookup(attributes2->hash_table, key);
+ attributes_val1 = (struct icl_value_s *)value1;
+ attributes_val2 = (struct icl_value_s *)value2;
+ ret = _icl_repr_compare_attributes_value(attributes_val1, attributes_val2);
if (IC_EQUAL != ret)
return ret;
}
if (IC_EQUAL != ret)
return ret;
- /* state */
- ret = _icl_repr_compare_state(repr1->state, repr2->state);
+ /* attributes */
+ ret = _icl_repr_compare_attributes(repr1->attributes, repr2->attributes);
if (IC_EQUAL != ret)
return ret;
#include "iotcon-types.h"
#include "icl-value.h"
-struct icl_state_s {
+struct icl_attributes_s {
int ref_count;
GHashTable *hash_table;
};
GList *children;
iotcon_resource_types_h res_types;
iotcon_resource_interfaces_h interfaces;
- struct icl_state_s *state;
+ struct icl_attributes_s *attributes;
};
iotcon_representation_h icl_representation_ref(iotcon_representation_h repr);
+++ /dev/null
-/* Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-list.h"
-#include "icl-value.h"
-#include "icl-representation.h"
-#include "icl-state.h"
-
-iotcon_state_h icl_state_ref(iotcon_state_h state)
-{
- RETV_IF(NULL == state, NULL);
- RETV_IF(state->ref_count <= 0, NULL);
-
- state->ref_count++;
-
- return state;
-}
-
-
-API int iotcon_state_create(iotcon_state_h *ret_state)
-{
- iotcon_state_h state;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_state, IOTCON_ERROR_INVALID_PARAMETER);
-
- state = calloc(1, sizeof(struct icl_state_s));
- if (NULL == state) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- state->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
- icl_value_destroy);
- state->ref_count = 1;
-
- *ret_state = state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_state_destroy(iotcon_state_h state)
-{
- RET_IF(NULL == state);
-
- state->ref_count--;
-
- if (0 != state->ref_count)
- return;
-
- g_hash_table_destroy(state->hash_table);
- free(state);
-}
-
-
-API int iotcon_state_remove(iotcon_state_h state, const char *key)
-{
- gboolean ret = FALSE;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = g_hash_table_remove(state->hash_table, key);
- if (FALSE == ret) {
- ERR("g_hash_table_remove(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- icl_basic_s *real = (icl_basic_s*)value;
- if (IOTCON_TYPE_INT != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.i;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_int(iotcon_state_h state, const char *key, int val)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_int(val);
- if (NULL == value) {
- ERR("icl_value_create_int(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_BOOL != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.b;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_bool(val);
- if (NULL == value) {
- ERR("icl_value_create_bool(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_DOUBLE != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.d;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_double(iotcon_state_h state, const char *key, double val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_double(val);
- if (NULL == value) {
- ERR("icl_value_create_double(%f) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_STR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.s;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_str(val);
- if (NULL == value) {
- ERR("icl_value_create_str(%s) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_byte_str(iotcon_state_h state, const char *key,
- unsigned char **val, int *len)
-{
- iotcon_value_h value = NULL;
- icl_val_byte_str_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_byte_str_s*)value;
- if (IOTCON_TYPE_BYTE_STR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->s;
- *len = real->len;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_byte_str(iotcon_state_h state, const char *key,
- unsigned char *val, int len)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(len <= 0, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_byte_str(val, len);
- if (NULL == value) {
- ERR("icl_value_create_byte_str() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == is_null, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = (iotcon_value_h) g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- *is_null = (IOTCON_TYPE_NULL == real->type) ? true : false;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_null(iotcon_state_h state, const char *key)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_null();
- if (NULL == value) {
- ERR("icl_value_create_null() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_list(iotcon_state_h state, const char *key,
- iotcon_list_h *list)
-{
- iotcon_value_h value = NULL;
- icl_val_list_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_list_s*)value;
- if (IOTCON_TYPE_LIST != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *list = real->list;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_list(iotcon_state_h state, const char *key,
- iotcon_list_h list)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
-
- value = icl_value_create_list(list);
- if (NULL == value) {
- ERR("icl_value_create_list() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_state(iotcon_state_h src, const char *key,
- iotcon_state_h *dest)
-{
- icl_val_state_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(src->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_state_s*)value;
- if (IOTCON_TYPE_STATE != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *dest = real->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_state(iotcon_state_h state, const char *key,
- iotcon_state_h val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_state(val);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_type(iotcon_state_h state, const char *key,
- iotcon_type_e *type)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
- *type = value->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value)
-{
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count)
-{
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == count, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
-
- *count = g_hash_table_size(state->hash_table);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone)
-{
- int ret;
-
- iotcon_state_h temp = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state_clone, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (state->hash_table) {
- ret = iotcon_state_create(&temp);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- return ret;
- }
-
- g_hash_table_foreach(state->hash_table, (GHFunc)icl_state_clone_foreach, temp);
- }
-
- *state_clone = temp;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val,
- iotcon_state_h dest_state)
-{
- FN_CALL;
- iotcon_value_h copied_val;
-
- copied_val = icl_value_clone(src_val);
- if (NULL == copied_val) {
- ERR("icl_value_clone() Fail");
- return;
- }
-
- icl_state_set_value(dest_state, key, copied_val);
-}
-
-
-API int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb,
- void *user_data)
-{
- GHashTableIter iter;
- gpointer key;
-
- RETV_IF(false == ic_utils_check_oic_feature(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_iter_init(&iter, state->hash_table);
- while (g_hash_table_iter_next(&iter, &key, NULL)) {
- if (IOTCON_FUNC_STOP == cb(state, key, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __IOT_CONNECTIVITY_LIBRARY_STATE_H__
-#define __IOT_CONNECTIVITY_LIBRARY_STATE_H__
-
-#include "icl-value.h"
-#include "icl-representation.h"
-
-int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val,
- iotcon_state_h dest_state);
-
-iotcon_state_h icl_state_ref(iotcon_state_h state);
-
-#endif /* __IOT_CONNECTIVITY_LIBRARY_STATE_H__ */
#include "icl.h"
#include "icl-representation.h"
#include "icl-list.h"
-#include "icl-state.h"
+#include "icl-attributes.h"
#include "icl-value.h"
static iotcon_value_h _icl_value_create(int type)
case IOTCON_TYPE_LIST:
ret_val = calloc(1, sizeof(icl_val_list_s));
break;
- case IOTCON_TYPE_STATE:
- ret_val = calloc(1, sizeof(icl_val_state_s));
+ case IOTCON_TYPE_ATTRIBUTES:
+ ret_val = calloc(1, sizeof(icl_val_attributes_s));
break;
default:
ERR("Invalid Type(%d)", type);
return (iotcon_value_h)value;
}
-iotcon_value_h icl_value_create_state(iotcon_state_h val)
+iotcon_value_h icl_value_create_attributes(iotcon_attributes_h val)
{
- icl_val_state_s *value;
+ icl_val_attributes_s *value;
- value = (icl_val_state_s*)_icl_value_create(IOTCON_TYPE_STATE);
+ value = (icl_val_attributes_s*)_icl_value_create(IOTCON_TYPE_ATTRIBUTES);
if (NULL == value) {
- ERR("_icl_value_create(state) Fail");
+ ERR("_icl_value_create(attributes) Fail");
return NULL;
}
- value->state = icl_state_ref(val);
+ value->attributes = icl_attributes_ref(val);
return (iotcon_value_h)value;
}
return IOTCON_ERROR_NONE;
}
-int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state)
+int icl_value_get_attributes(iotcon_value_h value, iotcon_attributes_h *attributes)
{
- icl_val_state_s *real = (icl_val_state_s*)value;
+ icl_val_attributes_s *real = (icl_val_attributes_s*)value;
RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ RETVM_IF(IOTCON_TYPE_ATTRIBUTES != real->type, IOTCON_ERROR_INVALID_PARAMETER,
"Invalid Type(%d)", real->type);
- *state = real->state;
+ *attributes = real->attributes;
return IOTCON_ERROR_NONE;
}
int ret;
iotcon_value_h value;
iotcon_list_h list;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
RET_IF(NULL == data);
}
iotcon_list_destroy(list);
break;
- case IOTCON_TYPE_STATE:
- ret = icl_value_get_state(value, &state);
+ case IOTCON_TYPE_ATTRIBUTES:
+ ret = icl_value_get_attributes(value, &attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
+ ERR("icl_value_get_attributes() Fail(%d)", ret);
break;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
break;
default:
ERR("Invalid type(%d)", type);
case IOTCON_TYPE_LIST:
dest = icl_value_create_list(((icl_val_list_s*)real)->list);
break;
- case IOTCON_TYPE_STATE:
- dest = icl_value_create_state(((icl_val_state_s*)real)->state);
+ case IOTCON_TYPE_ATTRIBUTES:
+ dest = icl_value_create_attributes(((icl_val_attributes_s*)real)->attributes);
break;
default:
ERR("Invalid type(%d)", src->type);
typedef struct {
int type;
- struct icl_state_s *state;
-} icl_val_state_s;
+ struct icl_attributes_s *attributes;
+} icl_val_attributes_s;
/**
* @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
* #IOTCON_TYPE_NULL\n
* #IOTCON_TYPE_BYTE_STR\n
* #IOTCON_TYPE_LIST\n
- * #IOTCON_TYPE_STATE
+ * #IOTCON_TYPE_ATTRIBUTES
*
* @since_tizen 3.0
*/
iotcon_value_h icl_value_create_str(const char *val);
iotcon_value_h icl_value_create_byte_str(const unsigned char *val, int len);
iotcon_value_h icl_value_create_list(iotcon_list_h val);
-iotcon_value_h icl_value_create_state(iotcon_state_h val);
+iotcon_value_h icl_value_create_attributes(iotcon_attributes_h val);
int icl_value_get_int(iotcon_value_h value, int *val);
int icl_value_get_str(iotcon_value_h value, char **val);
int icl_value_get_byte_str(iotcon_value_h value, unsigned char **val, int *len);
int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
-int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state);
+int icl_value_get_attributes(iotcon_value_h value, iotcon_attributes_h *attributes);
void icl_value_destroy(gpointer data);
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __IOT_CONNECTIVITY_STRUCT_ATTRIBUTES_H__
+#define __IOT_CONNECTIVITY_STRUCT_ATTRIBUTES_H__
+
+#include <iotcon-types.h>
+
+/**
+ * @file iotcon-attributes.h
+ */
+
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE
+ * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE State
+ *
+ * @brief IoTCon State provides API to manage attributes.
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE_HEADER Required Header
+ * \#include <iotcon.h>
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE_OVERVIEW Overview
+ * The iotcon attributes API provides string key based hash table.
+ *
+ * Example :
+ * @code
+#include <iotcon.h>
+...
+static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
+ void *user_data)
+{
+ int ret;
+ int types;
+
+ ret = iotcon_request_get_types(request, &types);
+ if (IOTCON_ERROR_NONE != ret)
+ return;
+
+ if (IOTCON_REQUEST_GET & types) {
+ iotcon_response_h response = NULL;
+ iotcon_representation_h representation = NULL;
+ iotcon_attributes_h attributes = NULL;
+
+ ret = iotcon_response_create(request, &response);
+ if (IOTCON_ERROR_NONE != ret)
+ return;
+
+ ret = iotcon_representation_create(&representation);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ...
+
+ ret = iotcon_attributes_create(&attributes);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ret = iotcon_attributes_add_bool(attributes, "power", true);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ret = itocon_attributes_add_int(attributes, "brightness", 75);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ret = iotcon_representation_set_attributes(representation, attributes);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ...
+
+ ret = iotcon_response_set_representation(response, representation);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ ret = iotcon_response_send(response);
+ if (IOTCON_ERROR_NONE != ret) {
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ return;
+ }
+
+ iotcon_attributes_destroy(attributes);
+ iotcon_representation_destroy(representation);
+ iotcon_response_destroy(resopnse);
+ }
+ ...
+}
+ * @endcode
+ *
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE_FEATURE Related Features
+ * This API is related with the following features:\n
+ * - http://tizen.org/feature/iot.ocf\n
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
+ *
+ * @{
+ */
+
+/**
+ * @brief Creates a new attributes handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must destroy @a attributes by calling iotcon_attributes_destroy()
+ * if @a attributes is no longer needed.
+ *
+ * @param[out] attributes A newly allocated attributes handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_attributes_destroy()
+ */
+int iotcon_attributes_create(iotcon_attributes_h *attributes);
+
+/**
+ * @brief Destroys a attributes.
+ * @details Releases a @a attributes and its internal data.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle to free
+ *
+ * @return void
+ *
+ * @see iotcon_attributes_create()
+ */
+void iotcon_attributes_destroy(iotcon_attributes_h attributes);
+
+/**
+ * @brief Clones a attributes handle.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks You must destroy @a attributes_clone by calling iotcon_attributes_destroy()
+ * if @a attributes_clone is no longer needed.
+ *
+ * @param[in] attributes The attributes handle
+ * @param[out] attributes_clone The cloned attributes handle
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see iotcon_attributes_create()
+ * @see iotcon_attributes_destroy()
+ */
+int iotcon_attributes_clone(iotcon_attributes_h attributes, iotcon_attributes_h *attributes_clone);
+
+/**
+ * @brief Adds a new key and integer value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] val The value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_int(iotcon_attributes_h attributes, const char *key, int val);
+
+/**
+ * @brief Adds a new key and boolean value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] val The value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_bool(iotcon_attributes_h attributes, const char *key, bool val);
+
+/**
+ * @brief Adds a new key and double value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] val The value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_double(iotcon_attributes_h attributes, const char *key, double val);
+
+/**
+ * @brief Adds a new key and string value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] val The value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_str(iotcon_attributes_h attributes, const char *key, char *val);
+
+/**
+ * @brief Adds a new key and byte string value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with new @a val.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] val The value
+ * @param[in] len The length of @a val
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_byte_str(iotcon_attributes_h attributes, const char *key, unsigned char *val,
+ int len);
+
+/**
+ * @brief Adds a new key and list value into the attributes.
+ * @details If @a key is already exists, current list will be replaced with new @a list.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] list The value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_list(iotcon_attributes_h attributes, const char *key, iotcon_list_h list);
+
+/**
+ * @brief Adds a new key and attributes value into the attributes.
+ * @details If @a key is already exists, current attributes will be replaced with new @a src.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] dest The attributes handle
+ * @param[in] key The key
+ * @param[in] src The attributes handle to set newly
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_attributes(iotcon_attributes_h dest, const char *key, iotcon_attributes_h src);
+
+/**
+ * @brief Adds a new key with NULL value into the attributes.
+ * @details If @a key is already exists, current value will be replaced with NULL.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key to be set NULL
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_add_null(iotcon_attributes_h attributes, const char *key);
+
+/**
+ * @brief Gets the integer value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] val The integer value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_int(iotcon_attributes_h attributes, const char *key, int *val);
+
+/**
+ * @brief Gets the boolean value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] val The boolean value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_bool(iotcon_attributes_h attributes, const char *key, bool *val);
+
+/**
+ * @brief Gets the double value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] val The double value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_double(iotcon_attributes_h attributes, const char *key, double *val);
+
+/**
+ * @brief Gets the string value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a val must not be released using free().
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] val The string value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_str(iotcon_attributes_h attributes, const char *key, char **val);
+
+/**
+ * @brief Gets the byte string value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a val must not be released using free().
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] val The byte string value
+ * @param[out] len The length of @a val
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_byte_str(iotcon_attributes_h attributes, const char *key, unsigned char **val,
+ int *len);
+
+/**
+ * @brief Gets the list value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a list must not be released using iotcon_list_destroy().
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] list The list value
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_list(iotcon_attributes_h attributes, const char *key, iotcon_list_h *list);
+
+/**
+ * @brief Gets the attributes value from the given key.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks @a attributes must not be released using iotcon_attributes_destroy().
+ *
+ * @param[in] src The attributes handle
+ * @param[in] key The key
+ * @param[out] dest The attributes value at the key
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
+ */
+int iotcon_attributes_get_attributes(iotcon_attributes_h src, const char *key, iotcon_attributes_h *dest);
+
+/**
+ * @brief Checks whether the value of given key is NULL or not.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] is_null true if the type of the given key is null, otherwise false
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_is_null(iotcon_attributes_h attributes, const char *key, bool *is_null);
+
+/**
+ * @brief Removes the key and its associated value from the attributes.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ */
+int iotcon_attributes_remove(iotcon_attributes_h attributes, const char *key);
+
+/**
+ * @brief Gets the type of a value at the given key.
+ * @details It gets the data type of value related the @a key in @a attributes.
+ * The data type could be one of #iotcon_type_e.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[out] type The data type of value related the key in attributes handle.
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #IOTCON_ERROR_NO_DATA No data available
+ */
+int iotcon_attributes_get_type(iotcon_attributes_h attributes, const char *key,
+ iotcon_type_e *type);
+
+/**
+ * @brief Specifies the type of function passed to iotcon_attributes_foreach().
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] key The key
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return true to continue with the next iteration of the loop,
+ * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
+ * are more friendly values for the return.
+ *
+ * @pre iotcon_attributes_foreach() will invoke this callback function.
+ *
+ * @see iotcon_attributes_foreach()
+ */
+typedef bool (*iotcon_attributes_cb)(iotcon_attributes_h attributes, const char *key, void *user_data);
+
+/**
+ * @brief Calls a function for each element of attributes.
+ * @details iotcon_attributes_cb() will be called for each child.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[in] cb The callback function to invoke
+ * @param[in] user_data The user data to pass to the function
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @post iotcon_attributes_cb() will be called for each child.
+ *
+ * @see iotcon_attributes_cb()
+ */
+int iotcon_attributes_foreach(iotcon_attributes_h attributes, iotcon_attributes_cb cb, void *user_data);
+
+/**
+ * @brief Gets the number of keys in the attributes.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] attributes The attributes handle
+ * @param[out] count The number of keys
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #IOTCON_ERROR_NONE Successful
+ * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
+ * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int iotcon_attributes_get_keys_count(iotcon_attributes_h attributes, unsigned int *count);
+
+/**
+ * @}
+ */
+
+#endif /* __IOT_CONNECTIVITY_STRUCT_ATTRIBUTES_H__ */
IOTCON_TYPE_BYTE_STR, /**< Indicates for representation that have byte string type */
IOTCON_TYPE_NULL, /**< Indicates for representation that have null type */
IOTCON_TYPE_LIST, /**< Indicates for representation that have list type */
- IOTCON_TYPE_STATE, /**< Indicates for representation that have another representation type */
+ IOTCON_TYPE_ATTRIBUTES, /**< Indicates for representation that have another representation type */
} iotcon_type_e;
/**
*/
/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE List
+ * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE
+ * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_LIST_MODULE List
*
* @brief IoTCon List provides API to get data from list and set data to list.
*
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_HEADER Required Header
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_LIST_MODULE_HEADER Required Header
* \#include <iotcon.h>
*
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_OVERVIEW Overview
- * The iotcon list API provides list of bool, integer, double, string, byte string, list and state handle.
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_LIST_MODULE_OVERVIEW Overview
+ * The iotcon list API provides list of bool, integer, double, string, byte string, list and attributes handle.
*
* Example :
* @code
if (IOTCON_REQUEST_GET & types) {
iotcon_response_h response = NULL;
iotcon_representation_h representation = NULL;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
iotcon_list_h list = NULL;
ret = iotcon_response_create(request, &response);
...
- ret = iotcon_state_create(&state);
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
ret = iotcon_list_create(IOTCON_TYPE_INT, &list);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
ret = iotcon_list_add_int(list, 1);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
ret = iotcon_list_add_int(list, 2);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
ret = iotcon_list_add_int(list, 10);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
}
- ret = iotcon_state_add_list(state, "ids", list);
+ ret = itocon_attributes_add_list(attributes, "ids", list);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
}
- ret = iotcon_representation_set_state(representation, state);
+ ret = iotcon_representation_set_attributes(representation, attributes);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
ret = iotcon_response_set_representation(response, representation);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
ret = iotcon_response_send(response);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
return;
}
iotcon_list_destroy(list);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(representation);
iotcon_response_destroy(resopnse);
}
}
* @endcode
*
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_FEATURE Related Features
+ * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_LIST_MODULE_FEATURE Related Features
* This API is related with the following features:\n
* - http://tizen.org/feature/iot.ocf\n
*
int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos);
/**
- * @brief Adds a new element state value into the list at the given position.
+ * @brief Adds a new element attributes value into the list at the given position.
* @details If @a pos is negative, or is larger than the number of elements in the list,
* the new value is added on to the end of the list.
*
* @since_tizen 3.0
*
* @param[in] list The list handle
- * @param[in] val The new state value
+ * @param[in] val The new attributes value
* @param[in] pos The position to insert value
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
*/
-int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos);
+int iotcon_list_add_attributes(iotcon_list_h list, iotcon_attributes_h val, int pos);
/**
* @brief Gets the integer value at the given position.
int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest);
/**
- * @brief Gets the state value at the given position.
+ * @brief Gets the attributes value at the given position.
* @details Iterates over the list until it reaches the @a pos-1 position.
*
* @since_tizen 3.0
*
- * @remarks @a state must not be released using iotcon_state_destroy().
+ * @remarks @a attributes must not be released using iotcon_attributes_destroy().
*
* @param[in] list The list handle
* @param[in] pos The position
- * @param[out] state The state value to get
+ * @param[out] attributes The attributes value to get
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_NO_DATA No data available
* @retval #IOTCON_ERROR_REPRESENTATION Representation errors
*/
-int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state);
+int iotcon_list_get_nth_attributes(iotcon_list_h list, int pos, iotcon_attributes_h *attributes);
/**
* @brief Removes the value at the given position.
/**
* @brief Gets the type of the list.
- * @details It gets the data type of value related the @a key in @a state.
+ * @details It gets the data type of value related the @a key in @a attributes.
* The data type could be one of #iotcon_type_e.
*
* @since_tizen 3.0
int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb, void *user_data);
/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_state().
+ * @brief Specifies the type of function passed to iotcon_list_foreach_attributes().
*
* @since_tizen 3.0
*
- * @param[in] pos The number of the state value (0 being the first)
- * @param[in] value The state value
+ * @param[in] pos The number of the attributes value (0 being the first)
+ * @param[in] value The attributes value
* @param[in] user_data The user data to pass to the function
*
* @return true to continue with the next iteration of the loop,
* otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
* are more friendly values for the return.
*
- * @pre iotcon_list_foreach_state() will invoke this callback function.
+ * @pre iotcon_list_foreach_attributes() will invoke this callback function.
*
- * @see iotcon_list_foreach_state()
+ * @see iotcon_list_foreach_attributes()
*/
-typedef bool (*iotcon_list_state_cb)(int pos, iotcon_state_h value, void *user_data);
+typedef bool (*iotcon_list_attributes_cb)(int pos, iotcon_attributes_h value, void *user_data);
/**
- * @brief Gets all state of the given list by invoking the callback function.
- * @details iotcon_list_state_cb() will be called for each child.
+ * @brief Gets all attributes of the given list by invoking the callback function.
+ * @details iotcon_list_attributes_cb() will be called for each child.
*
* @since_tizen 3.0
*
* @param[in] list The handle to the list
- * @param[in] cb The callback function to get each state
+ * @param[in] cb The callback function to get each attributes
* @param[in] user_data The user data to be passed to the callback function
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @post iotcon_list_state_cb() will be called for each item.
+ * @post iotcon_list_attributes_cb() will be called for each item.
*
- * @see iotcon_list_state_cb()
+ * @see iotcon_list_attributes_cb()
*/
-int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb, void *user_data);
+int iotcon_list_foreach_attributes(iotcon_list_h list, iotcon_list_attributes_cb cb, void *user_data);
/**
* @}
* This API provides that the users manages resources without request handler.
* When client request by CRUD functions, internal default request handler will be invoked.
* The default request handler will create response and send to client automatically.
- * When updated state by iotcon_lite_resource_update_state(), changes will notify to observers.
+ * When updated attributes by iotcon_lite_resource_update_attributes(), changes will notify to observers.
*
* Example :
* @code
...
static iotcon_lite_resource_h _resource;
-static bool _state_changed_cb(iotcon_lite_resource_h resource, iotcon_state_h state, void *user_data)
+static bool _attributes_changed_cb(iotcon_lite_resource_h resource, iotcon_attributes_h attributes, void *user_data)
{
return true;
}
int ret;
iotcon_lite_resource_h resource = NULL;
iotcon_resource_types_h resource_types = NULL;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
ret = iotcon_resource_types_create(&resource_types);
if (IOTCON_ERROR_NONE != ret)
return;
}
- ret = iotcon_state_create(&state);
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(resource_types);
return;
}
- ret = iotcon_state_add_bool(state, "power", true);
+ ret = iotcon_attributes_add_bool(attributes, "power", true);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return;
}
- ret = iotcon_state_add_int(state, "brightness", 75);
+ ret = iotcon_attributes_add_int(attributes, "brightness", 75);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return;
}
ret = iotcon_lite_resource_create("/light/1", resource_types,
- IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, state,
- _state_changed_cb, NULL, &resource);
+ IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, attributes,
+ _attributes_changed_cb, NULL, &resource);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
_resource = resource;
static void _update_brightness(int brightness)
{
int ret;
- iotcon_state_h state = NULL;
- iotcon_state_h state_clone = NULL;
+ iotcon_attributes_h attributes = NULL;
+ iotcon_attributes_h attributes_clone = NULL;
- ret = iotcon_lite_resource_get_state(_resource, &state);
+ ret = iotcon_lite_resource_get_attributes(_resource, &attributes);
if (IOTCON_ERROR_NONE != ret)
return;
- ret = iotcon_state_clone(state, &state_clone);
+ ret = iotcon_attributes_clone(attributes, &attributes_clone);
if (IOTCON_ERROR_NONE != ret)
return;
- ret = iotcon_state_add_int(state_clone, "brightness", brightness);
+ ret = iotcon_attributes_add_int(attributes_clone, "brightness", brightness);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state_clone);
+ iotcon_attributes_destroy(attributes_clone);
return;
}
- ret = iotcon_lite_resource_update_state(_resource, state_clone);
+ ret = iotcon_lite_resource_update_attributes(_resource, attributes_clone);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state_clone);
+ iotcon_attributes_destroy(attributes_clone);
return;
}
- iotcon_state_destroy(state_clone);
+ iotcon_attributes_destroy(attributes_clone);
}
* @endcode
* @since_tizen 3.0
*
* @param[in] resource The handle of the lite resource
- * @param[in] state The state of the lite resource
+ * @param[in] attributes The attributes of the lite resource
* @param[in] user_data The user data to pass to the function
*
* @pre The callback must be registered using iotcon_lite_resource_create()
* @see iotcon_lite_resource_create()
*/
typedef bool (*iotcon_lite_resource_post_request_cb)(iotcon_lite_resource_h resource,
- iotcon_state_h state, void *user_data);
+ iotcon_attributes_h attributes, void *user_data);
/**
* @brief Creates a lite resource handle and registers the resource in server.
- * @details Registers a resource specified by @a uri_path, @a res_types, @a state which have
+ * @details Registers a resource specified by @a uri_path, @a res_types, @a attributes which have
* @a properties in IoTCon server.\n
* When client requests some operations, it send a response to client, automatically.\n
* The @a policies can contain multiple policies like
* @param[in] uri_path The URI path of the resource
* @param[in] res_types The list of type of the resource
* @param[in] policies The policies of the resource\n Set of #iotcon_resource_policy_e
- * @param[in] state The state handle to set
+ * @param[in] attributes The attributes handle to set
* @param[in] cb The callback function to add into callback list
* @param[in] user_data The user data to pass to the callback function
* @param[out] resource_handle The handle of the resource
int iotcon_lite_resource_create(const char *uri_path,
iotcon_resource_types_h res_types,
uint8_t policies,
- iotcon_state_h state,
+ iotcon_attributes_h attributes,
iotcon_lite_resource_post_request_cb cb,
void *user_data,
iotcon_lite_resource_h *resource_handle);
int iotcon_lite_resource_destroy(iotcon_lite_resource_h resource);
/**
- * @brief Updates state into the lite resource handle.
+ * @brief Updates attributes into the lite resource handle.
*
* @since_tizen 3.0
* @privlevel public
* @privilege %http://tizen.org/privilege/internet
*
* @param[in] resource The handle of the lite resource
- * @param[in] state The state handle to update
+ * @param[in] attributes The attributes handle to update
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
*
* @pre iotcon_initialize() should be called to initialize.
*
- * @see iotcon_lite_resource_get_state()
+ * @see iotcon_lite_resource_get_attributes()
*/
-int iotcon_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state);
+int iotcon_lite_resource_update_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h attributes);
/**
- * @brief Gets state from the lite resource handle.
+ * @brief Gets attributes from the lite resource handle.
*
* @since_tizen 3.0
*
- * @remarks @a state must not be released using iotcon_state_destroy().
+ * @remarks @a attributes must not be released using iotcon_attributes_destroy().
*
* @param[in] resource The handle of the lite resource
- * @param[out] state The state handle of the lite resource
+ * @param[out] attributes The attributes handle of the lite resource
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*
- * @see iotcon_lite_resource_update_state()
+ * @see iotcon_lite_resource_update_attributes()
*/
-int iotcon_lite_resource_get_state(iotcon_lite_resource_h resource,
- iotcon_state_h *state);
+int iotcon_lite_resource_get_attributes(iotcon_lite_resource_h resource,
+ iotcon_attributes_h *attributes);
/**
* @}
...
if (IOTCON_REQUEST_PUT & types) {
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
iotcon_representation_h repr = NULL;
...
if (IOTCON_ERROR_NONE != ret)
return;
- ret = iotcon_state_create(&state);
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
iotcon_representation_destroy(repr);
return;
...
ret = iotcon_resource_notify(resource, repr, _observers, IOTCON_QOS_HIGH);
if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
}
return;
}
- ret = iotcon_state_add_str(resp_repr, "type", "lamp");
+ ret = iotcon_attributes_add_str(resp_repr, "type", "lamp");
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_state_add_str(resp_repr, "where", "desk");
+ ret = iotcon_attributes_add_str(resp_repr, "where", "desk");
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_state_add_double(resp_repr, "default_bright", 200.0);
+ ret = iotcon_attributes_add_double(resp_repr, "default_bright", 200.0);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_state_add_str(resp_repr, "unit", "lux");
+ ret = iotcon_attributes_add_str(resp_repr, "unit", "lux");
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_state_add_bool(resp_repr, "bright_step", true);
+ ret = iotcon_attributes_add_bool(resp_repr, "bright_step", true);
if (IOTCON_ERROR_NONE != ret) {
iotcon_resource_types_destroy(types);
iotcon_representation_destroy(resp_repr);
return;
}
- ret = iotcon_state_add_list(resp_repr, "bright_step_list", bright_step_list);
+ ret = iotcon_attributes_add_list(resp_repr, "bright_step_list", bright_step_list);
if (IOTCON_ERROR_NONE != ret) {
iotcon_list_destroy(bright_step_list);
iotcon_resource_types_destroy(types);
iotcon_resource_interfaces_h *ifaces);
/**
- * @brief Sets a new state handle into the representation.
+ * @brief Sets a new attributes handle into the representation.
*
* @since_tizen 3.0
*
* @param[in] repr The representation handle
- * @param[in] state The state handle to set newly
+ * @param[in] attributes The attributes handle to set newly
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_set_state(iotcon_representation_h repr, iotcon_state_h state);
+int iotcon_representation_set_attributes(iotcon_representation_h repr, iotcon_attributes_h attributes);
/**
- * @brief Gets a state handle in the representation.
+ * @brief Gets a attributes handle in the representation.
*
* @since_tizen 3.0
*
- * @remarks @a state must not be released using iotcon_state_destroy().
+ * @remarks @a attributes must not be released using iotcon_attributes_destroy().
*
* @param[in] repr The representation handle
- * @param[in] state The state handle to get
+ * @param[in] attributes The attributes handle to get
*
* @return 0 on success, otherwise a negative error value.
* @retval #IOTCON_ERROR_NONE Successful
* @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
* @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
*/
-int iotcon_representation_get_state(iotcon_representation_h repr, iotcon_state_h *state);
+int iotcon_representation_get_attributes(iotcon_representation_h repr, iotcon_attributes_h *attributes);
/**
* @brief Adds a new child representation on to the end of the parent representation.
* @code
#include <iotcon.h>
-static void _state_foreach(iotcon_state_h state, const char *key, void *user_data)
+static void _attributes_foreach(iotcon_attributes_h attributes, const char *key, void *user_data)
{
- // handle state
+ // handle attributes
...
}
int ret;
iotcon_response_result_e response_result;
iotcon_representation_h repr = NULL;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
if (IOTCON_ERROR_NONE != err)
return;
if (IOTCON_ERROR_NONE != ret)
return;
- ret = iotcon_representation_get_state(repr, &state);
+ ret = iotcon_representation_get_attributes(repr, &attributes);
if (IOTCON_ERROR_NONE != ret)
return;
- ret = iotcon_state_foreach(state, _state_foreach, NULL);
+ ret = iotcon_attributes_foreach(attributes, _attributes_foreach, NULL);
if (IOTCON_ERROR_NONE != ret)
return;
* @code
#include <iotcon.h>
-static iotcon_state_h _create_state()
+static iotcon_attributes_h _create_attributes()
{
int ret;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
- // create & set state
+ // create & set attributes
...
- return state;
+ return attributes;
}
static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
if (IOTCON_REQUEST_GET & types) {
iotcon_response_h response = NULL;
iotcon_representation_h repr = NULL;
- iotcon_state_h state = NULL;
+ iotcon_attributes_h attributes = NULL;
ret = iotcon_response_create(request, &response);
if (IOTCON_ERROR_NONE != ret)
return;
}
- ret = iotcon_representation_set_state(response, _create_state());
+ ret = iotcon_representation_set_attributes(response, _create_attributes());
if (IOTCON_ERROR_NONE != ret) {
iotcon_representation_destroy(repr);
iotcon_response_destroy(response);
+++ /dev/null
-/*
- * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __IOT_CONNECTIVITY_STRUCT_STATE_H__
-#define __IOT_CONNECTIVITY_STRUCT_STATE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-state.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE State
- *
- * @brief IoTCon State provides API to manage state.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_OVERVIEW Overview
- * The iotcon state API provides string key based hash table.
- *
- * Example :
- * @code
-#include <iotcon.h>
-...
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- int types;
-
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_REQUEST_GET & types) {
- iotcon_response_h response = NULL;
- iotcon_representation_h representation = NULL;
- iotcon_state_h state = NULL;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_representation_create(&representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_state_add_bool(state, "power", true);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_state_add_int(state, "brightness", 75);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_representation_set_state(representation, state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_response_set_representation(response, representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.ocf\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new state handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a state by calling iotcon_state_destroy()
- * if @a state is no longer needed.
- *
- * @param[out] state A newly allocated state handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_state_destroy()
- */
-int iotcon_state_create(iotcon_state_h *state);
-
-/**
- * @brief Destroys a state.
- * @details Releases a @a state and its internal data.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle to free
- *
- * @return void
- *
- * @see iotcon_state_create()
- */
-void iotcon_state_destroy(iotcon_state_h state);
-
-/**
- * @brief Clones a state handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a state_clone by calling iotcon_state_destroy()
- * if @a state_clone is no longer needed.
- *
- * @param[in] state The state handle
- * @param[out] state_clone The cloned state handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_state_create()
- * @see iotcon_state_destroy()
- */
-int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone);
-
-/**
- * @brief Adds a new key and integer value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_int(iotcon_state_h state, const char *key, int val);
-
-/**
- * @brief Adds a new key and boolean value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val);
-
-/**
- * @brief Adds a new key and double value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_double(iotcon_state_h state, const char *key, double val);
-
-/**
- * @brief Adds a new key and string value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val);
-
-/**
- * @brief Adds a new key and byte string value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- * @param[in] len The length of @a val
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_byte_str(iotcon_state_h state, const char *key, unsigned char *val,
- int len);
-
-/**
- * @brief Adds a new key and list value into the state.
- * @details If @a key is already exists, current list will be replaced with new @a list.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] list The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_list(iotcon_state_h state, const char *key, iotcon_list_h list);
-
-/**
- * @brief Adds a new key and state value into the state.
- * @details If @a key is already exists, current state will be replaced with new @a src.
- *
- * @since_tizen 3.0
- *
- * @param[in] dest The state handle
- * @param[in] key The key
- * @param[in] src The state handle to set newly
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_state(iotcon_state_h dest, const char *key, iotcon_state_h src);
-
-/**
- * @brief Adds a new key with NULL value into the state.
- * @details If @a key is already exists, current value will be replaced with NULL.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key to be set NULL
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_null(iotcon_state_h state, const char *key);
-
-/**
- * @brief Gets the integer value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The integer value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val);
-
-/**
- * @brief Gets the boolean value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The boolean value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val);
-
-/**
- * @brief Gets the double value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The double value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val);
-
-/**
- * @brief Gets the string value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The string value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val);
-
-/**
- * @brief Gets the byte string value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The byte string value
- * @param[out] len The length of @a val
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_byte_str(iotcon_state_h state, const char *key, unsigned char **val,
- int *len);
-
-/**
- * @brief Gets the list value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a list must not be released using iotcon_list_destroy().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] list The list value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_list(iotcon_state_h state, const char *key, iotcon_list_h *list);
-
-/**
- * @brief Gets the state value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a state must not be released using iotcon_state_destroy().
- *
- * @param[in] src The state handle
- * @param[in] key The key
- * @param[out] dest The state value at the key
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_state(iotcon_state_h src, const char *key, iotcon_state_h *dest);
-
-/**
- * @brief Checks whether the value of given key is NULL or not.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] is_null true if the type of the given key is null, otherwise false
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null);
-
-/**
- * @brief Removes the key and its associated value from the state.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_state_remove(iotcon_state_h state, const char *key);
-
-/**
- * @brief Gets the type of a value at the given key.
- * @details It gets the data type of value related the @a key in @a state.
- * The data type could be one of #iotcon_type_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] type The data type of value related the key in state handle.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_state_get_type(iotcon_state_h state, const char *key,
- iotcon_type_e *type);
-
-/**
- * @brief Specifies the type of function passed to iotcon_state_foreach().
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_state_foreach() will invoke this callback function.
- *
- * @see iotcon_state_foreach()
- */
-typedef bool (*iotcon_state_cb)(iotcon_state_h state, const char *key, void *user_data);
-
-/**
- * @brief Calls a function for each element of state.
- * @details iotcon_state_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_state_cb() will be called for each child.
- *
- * @see iotcon_state_cb()
- */
-int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data);
-
-/**
- * @brief Gets the number of keys in the state.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[out] count The number of keys
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_STRUCT_STATE_H__ */
* @ref CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE,
* @ref CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE,
* @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE,
+ * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_MODULE,
+ * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_ATTRIBUTES_LIST_MODULE,
* @ref CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE.
*
* @{
typedef struct icl_list_s* iotcon_list_h;
/**
- * @brief The handle of state.
- * @details @a iotcon_state_h is an opaque data structure to have attribute value map.
+ * @brief The handle of attributes.
+ * @details @a iotcon_attributes_h is an opaque data structure to have attribute value map.
* Attribute value map consists of a key and a value.
* Datatype of the key is string and the value should be one of them #IOTCON_TYPE_INT,
* #IOTCON_TYPE_BOOL, #IOTCON_TYPE_DOUBLE, #IOTCON_TYPE_STR, #IOTCON_TYPE_NULL,
- * #IOTCON_TYPE_LIST and #IOTCON_TYPE_STATE
+ * #IOTCON_TYPE_LIST and #IOTCON_TYPE_ATTRIBUTES
*
* @since_tizen 3.0
*/
-typedef struct icl_state_s* iotcon_state_h;
+typedef struct icl_attributes_s* iotcon_attributes_h;
/**
* @}
#include <iotcon-list.h>
#include <iotcon-query.h>
-#include <iotcon-state.h>
+#include <iotcon-attributes.h>
#include <iotcon-options.h>
#include <iotcon-representation.h>
#include <iotcon-resource-types.h>
int ret;
bool opened;
static int i = 0;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_representation_h repr;
iotcon_response_result_e response_result;
return;
}
- ret = iotcon_representation_get_state(repr, &state);
+ ret = iotcon_representation_get_attributes(repr, &attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return;
}
- ret = iotcon_state_get_bool(state, "opened", &opened);
+ ret = iotcon_attributes_get_bool(attributes, "opened", &opened);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return;
}
iotcon_response_h response, void *user_data)
{
int ret;
- iotcon_state_h recv_state;
+ iotcon_attributes_h recv_attributes;
char *host, *created_uri_path;
iotcon_connectivity_type_e connectivity_type;
iotcon_response_result_e response_result;
return;
}
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ ret = iotcon_representation_get_attributes(recv_repr, &recv_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return;
}
- ret = iotcon_state_get_str(recv_state, "createduripath", &created_uri_path);
+ ret = iotcon_attributes_get_str(recv_attributes, "createduripath", &created_uri_path);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_str() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_str() Fail(%d)", ret);
return;
}
DBG("New resource created : %s", created_uri_path);
iotcon_response_result_e response_result;
iotcon_representation_h send_repr;
iotcon_representation_h recv_repr;
- iotcon_state_h send_state;
- iotcon_state_h recv_state = NULL;
+ iotcon_attributes_h send_attributes;
+ iotcon_attributes_h recv_attributes = NULL;
ret = iotcon_response_get_result(response, &response_result);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ ret = iotcon_representation_get_attributes(recv_repr, &recv_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return;
}
- ret = iotcon_state_get_bool(recv_state, "opened", &opened);
+ ret = iotcon_attributes_get_bool(recv_attributes, "opened", &opened);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return;
}
return;
}
- ret = iotcon_state_create(&send_state);
+ ret = iotcon_attributes_create(&send_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(send_repr);
return;
}
- ret = iotcon_state_add_bool(send_state, "opened", !opened);
+ ret = iotcon_attributes_add_bool(send_attributes, "opened", !opened);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(send_attributes);
iotcon_representation_destroy(send_repr);
return;
}
- ret = iotcon_representation_set_state(send_repr, send_state);
+ ret = iotcon_representation_set_attributes(send_repr, send_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(send_attributes);
iotcon_representation_destroy(send_repr);
return;
}
- iotcon_state_destroy(send_state);
+ iotcon_attributes_destroy(send_attributes);
/* send PUT request */
ret = iotcon_remote_resource_put(resource, send_repr, NULL, _on_response, NULL);
/* Door Resource */
typedef struct _door_resource_s {
- bool state;
+ bool attributes;
char *uri_path;
char *type;
iotcon_resource_interfaces_h ifaces;
{
int ret;
- door->state = false;
+ door->attributes = false;
door->uri_path = strdup(DOOR_RESOURCE_URI);
if (NULL == door->uri_path) {
free(door->uri_path);
}
-static void _check_door_state(door_resource_s door)
+static void _check_door_attributes(door_resource_s door)
{
- if (false == door.state)
+ if (false == door.attributes)
INFO("[Door] closed.");
else
INFO("[Door] opened.");
static iotcon_representation_h _get_door_representation(door_resource_s *door)
{
int ret;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_representation_h repr;
/* create a door Representation */
return NULL;
}
- /* create a door state */
- ret = iotcon_state_create(&state);
+ /* create a door attributes */
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return NULL;
}
ret = iotcon_representation_set_uri_path(repr, door->uri_path);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_state_add_bool(state, "opened", door->state);
+ ret = iotcon_attributes_add_bool(attributes, "opened", door->attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_representation_set_state(repr, state);
+ ret = iotcon_representation_set_attributes(repr, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
return repr;
}
{
int ret;
bool bval;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
- ret = iotcon_representation_get_state(repr, &state);
+ ret = iotcon_representation_get_attributes(repr, &attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return -1;
}
- ret = iotcon_state_get_bool(state, "opened", &bval);
+ ret = iotcon_attributes_get_bool(attributes, "opened", &bval);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return -1;
}
- door->state = bval;
+ door->attributes = bval;
return 0;
}
return -1;
}
- _check_door_state(*door);
+ _check_door_attributes(*door);
resp_repr = _get_door_representation(door);
if (NULL == resp_repr) {
return 0;
}
-static gboolean _door_state_changer(gpointer user_data)
+static gboolean _door_attributes_changer(gpointer user_data)
{
int ret;
static int i = 0;
if ((5 == i++) || NULL == door->observers)
return G_SOURCE_REMOVE;
- if (false == door->state) {
- door->state = true;
+ if (false == door->attributes) {
+ door->attributes = true;
INFO("[Door] closed -> opened");
} else {
- door->state = false;
+ door->attributes = false;
INFO("[Door] opened -> closed");
}
static int _request_handler_post(door_resource_s *door, iotcon_request_h request)
{
int ret;
- iotcon_state_h resp_state;
+ iotcon_attributes_h resp_attributes;
iotcon_representation_h resp_repr = NULL;
iotcon_resource_h new_door_handle;
INFO("POST request");
return -1;
}
- ret = iotcon_state_create(&resp_state);
+ ret = iotcon_attributes_create(&resp_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(resp_repr);
return -1;
}
- ret = iotcon_state_add_str(resp_state, "createduripath", DOOR_RESOURCE_URI2);
+ ret = iotcon_attributes_add_str(resp_attributes, "createduripath", DOOR_RESOURCE_URI2);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_str() Fail(%d)", ret);
- iotcon_state_destroy(resp_state);
+ ERR("iotcon_attributes_add_str() Fail(%d)", ret);
+ iotcon_attributes_destroy(resp_attributes);
iotcon_representation_destroy(resp_repr);
return -1;
}
- ret = iotcon_representation_set_state(resp_repr, resp_state);
+ ret = iotcon_representation_set_attributes(resp_repr, resp_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(resp_state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(resp_attributes);
iotcon_representation_destroy(resp_repr);
return -1;
}
- iotcon_state_destroy(resp_state);
+ iotcon_attributes_destroy(resp_attributes);
ret = _send_response(request, resp_repr, IOTCON_RESPONSE_RESOURCE_CREATED);
if (0 != ret) {
return -1;
}
- _check_door_state(my_door);
+ _check_door_attributes(my_door);
/* add observe */
- g_timeout_add_seconds(5, _door_state_changer, &my_door);
+ g_timeout_add_seconds(5, _door_attributes_changer, &my_door);
g_main_loop_run(loop);
g_main_loop_unref(loop);
{
int ret;
bool opened;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
INFO("Resource is cached");
- ret = iotcon_representation_get_state(representation, &state);
+ ret = iotcon_representation_get_attributes(representation, &attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return;
}
- ret = iotcon_state_get_bool(state, "opened", &opened);
+ ret = iotcon_attributes_get_bool(attributes, "opened", &opened);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return;
}
free(door->uri_path);
}
-static void _check_door_state(door_resource_s door)
+static void _check_door_attributes(door_resource_s door)
{
if (false == door.state)
INFO("[Door] closed.");
INFO("[Door] opened.");
}
-static gboolean _door_state_changer(gpointer user_data)
+static gboolean _door_attributes_changer(gpointer user_data)
{
int ret;
door_resource_s *door = user_data;
- iotcon_state_h recv_state, send_state;
+ iotcon_attributes_h recv_attributes, send_attributes;
- ret = iotcon_lite_resource_get_state(door->handle, &recv_state);
+ ret = iotcon_lite_resource_get_attributes(door->handle, &recv_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_lite_resource_get_state() Fail(%d)", ret);
+ ERR("iotcon_lite_resource_get_attributes() Fail(%d)", ret);
return G_SOURCE_CONTINUE;
}
- ret = iotcon_state_get_bool(recv_state, "opened", &(door->state));
+ ret = iotcon_attributes_get_bool(recv_attributes, "opened", &(door->state));
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return G_SOURCE_CONTINUE;
}
else
door->state = true;
- ret = iotcon_state_create(&send_state);
+ ret = iotcon_attributes_create(&send_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
return G_SOURCE_CONTINUE;
}
- ret = iotcon_state_add_bool(send_state, "opened", door->state);
+ ret = iotcon_attributes_add_bool(send_attributes, "opened", door->state);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(send_attributes);
return G_SOURCE_CONTINUE;
}
- ret = iotcon_lite_resource_update_state(door->handle, send_state);
+ ret = iotcon_lite_resource_update_attributes(door->handle, send_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_lite_resource_update_state() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
+ ERR("iotcon_lite_resource_update_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(send_attributes);
return G_SOURCE_CONTINUE;
}
- iotcon_state_destroy(send_state);
+ iotcon_attributes_destroy(send_attributes);
- _check_door_state(*door);
+ _check_door_attributes(*door);
return G_SOURCE_CONTINUE;
}
-static bool _door_state_changed(iotcon_lite_resource_h resource,
- iotcon_state_h state, void *user_data)
+static bool _door_attributes_changed(iotcon_lite_resource_h resource,
+ iotcon_attributes_h attributes, void *user_data)
{
FN_CALL;
bool opened;
int ret;
- ret = iotcon_state_get_bool(state, "opened", &opened);
+ ret = iotcon_attributes_get_bool(attributes, "opened", &opened);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
return false;
}
DBG("opened: %d", opened);
uint8_t policies, void *user_data)
{
int ret;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_lite_resource_h handle;
iotcon_resource_types_h resource_types;
return NULL;
}
- ret = iotcon_state_create(&state);
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_resource_types_destroy(resource_types);
return NULL;
}
- ret = iotcon_state_add_bool(state, "opened", false);
+ ret = iotcon_attributes_add_bool(attributes, "opened", false);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return NULL;
}
/* register door resource */
- ret = iotcon_lite_resource_create(uri_path, resource_types, policies, state,
- _door_state_changed, NULL, &handle);
+ ret = iotcon_lite_resource_create(uri_path, resource_types, policies, attributes,
+ _door_attributes_changed, NULL, &handle);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_lite_resource_create() Fail");
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return NULL;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_resource_types_destroy(resource_types);
return handle;
return -1;
}
- _check_door_state(my_door);
+ _check_door_attributes(my_door);
- g_timeout_add_seconds(7, _door_state_changer, &my_door);
+ g_timeout_add_seconds(7, _door_attributes_changer, &my_door);
g_main_loop_run(loop);
g_main_loop_unref(loop);
char *uri_path, *str_val;
iotcon_list_h list_val;
iotcon_representation_h child_repr;
- iotcon_state_h recv_state, child_state;
+ iotcon_attributes_h recv_attributes, child_attributes;
unsigned int key_count, children_count;
INFO("GET request was successful");
}
DBG("uri_path : %s", uri_path);
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
+ ret = iotcon_representation_get_attributes(recv_repr, &recv_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
return;
}
- ret = iotcon_state_get_keys_count(recv_state, &key_count);
+ ret = iotcon_attributes_get_keys_count(recv_attributes, &key_count);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_keys_count() Fail(%d)", ret);
return;
}
if (key_count) {
- ret = iotcon_state_get_str(recv_state, "name", &str_val);
+ ret = iotcon_attributes_get_str(recv_attributes, "name", &str_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_str() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_str() Fail(%d)", ret);
return;
}
DBG("name : %s", str_val);
- ret = iotcon_state_get_list(recv_state, "today_temp", &list_val);
+ ret = iotcon_attributes_get_list(recv_attributes, "today_temp", &list_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_list() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_list() Fail(%d)", ret);
return;
}
return;
}
- ret = iotcon_state_is_null(recv_state, "null value", &is_null);
+ ret = iotcon_attributes_is_null(recv_attributes, "null value", &is_null);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_is_null() Fail(%d)", ret);
+ ERR("iotcon_attributes_is_null() Fail(%d)", ret);
return;
}
}
DBG("uri_path : %s", uri_path);
- ret = iotcon_representation_get_state(child_repr, &child_state);
+ ret = iotcon_representation_get_attributes(child_repr, &child_attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
+ ERR("iotcon_representation_get_attributes() Fail(%d)", ret);
continue;
}
if (TEST_STR_EQUAL == strncmp(LIGHT_RESOURCE_URI_PREFIX, uri_path,
strlen(LIGHT_RESOURCE_URI_PREFIX))) {
- ret = iotcon_state_get_keys_count(child_state, &key_count);
+ ret = iotcon_attributes_get_keys_count(child_attributes, &key_count);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_keys_count() Fail(%d)", ret);
continue;
}
if (key_count) {
- ret = iotcon_state_get_int(child_state, "brightness", &int_val);
+ ret = iotcon_attributes_get_int(child_attributes, "brightness", &int_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_int() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_int() Fail(%d)", ret);
continue;
}
DBG("brightness : %d", int_val);
}
} else if (TEST_STR_EQUAL == strncmp(FAN_RESOURCE_URI_PREFIX, uri_path,
strlen(FAN_RESOURCE_URI_PREFIX))) {
- ret = iotcon_state_get_keys_count(child_state, &key_count);
+ ret = iotcon_attributes_get_keys_count(child_attributes, &key_count);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_keys_count() Fail(%d)", ret);
continue;
}
if (key_count) {
- ret = iotcon_state_get_bool(child_state, "state", &bool_val);
+ ret = iotcon_attributes_get_bool(child_attributes, "state", &bool_val);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
+ ERR("iotcon_attributes_get_bool() Fail(%d)", ret);
continue;
}
DBG("state : %d", bool_val);
static iotcon_representation_h _get_light_representation(light_resource_s *light)
{
int ret;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_representation_h repr;
/* create a light Representation */
return NULL;
}
- /* create a light state */
- ret = iotcon_state_create(&state);
+ /* create a light attributes */
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_state_add_int(state, "brightness", light->brightness);
+ ret = iotcon_attributes_add_int(attributes, "brightness", light->brightness);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_int() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_int() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- /* Set a light state into light Representation */
- ret = iotcon_representation_set_state(repr, state);
+ /* Set a light attributes into light Representation */
+ ret = iotcon_representation_set_attributes(repr, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
return repr;
}
static iotcon_representation_h _get_fan_representation(fan_resource_s *fan)
{
int ret;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_representation_h repr;
/* create a fan Representation */
return NULL;
}
- /* create a fan state */
- ret = iotcon_state_create(&state);
+ /* create a fan attributes */
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_state_add_bool(state, "state", fan->state);
+ ret = iotcon_attributes_add_bool(attributes, "attributes", fan->state);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_bool() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- /* Set a light state into light Representation */
- ret = iotcon_representation_set_state(repr, state);
+ /* Set a light attributes into light Representation */
+ ret = iotcon_representation_set_attributes(repr, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
return repr;
}
static iotcon_representation_h _get_room_representation(room_resource_s *room)
{
int ret;
- iotcon_state_h state;
+ iotcon_attributes_h attributes;
iotcon_list_h today_temp;
iotcon_representation_h repr, light_repr, fan_repr;
return NULL;
}
- /* create a room state */
- ret = iotcon_state_create(&state);
+ /* create a room attributes */
+ ret = iotcon_attributes_create(&attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
+ ERR("iotcon_attributes_create() Fail(%d)", ret);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_state_add_str(state, "name", room->name);
+ ret = iotcon_attributes_add_str(attributes, "name", room->name);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_str() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_str() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
/* set null */
- ret = iotcon_state_add_null(state, "null value");
+ ret = iotcon_attributes_add_null(attributes, "null value");
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_null() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_attributes_add_null() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
ret = iotcon_list_create(IOTCON_TYPE_INT, &today_temp);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_create() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_add_int() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_add_int() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_add_int() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_add_int() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_list_add_int() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- ret = iotcon_state_add_list(state, "today_temp", today_temp);
+ ret = iotcon_attributes_add_list(attributes, "today_temp", today_temp);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_list() Fail(%d)", ret);
+ ERR("iotcon_attributes_add_list() Fail(%d)", ret);
iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
iotcon_list_destroy(today_temp);
- /* Set a room state into room Representation */
- ret = iotcon_representation_set_state(repr, state);
+ /* Set a room attributes into room Representation */
+ ret = iotcon_representation_set_attributes(repr, attributes);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
+ ERR("iotcon_representation_set_attributes() Fail(%d)", ret);
+ iotcon_attributes_destroy(attributes);
iotcon_representation_destroy(repr);
return NULL;
}
- iotcon_state_destroy(state);
+ iotcon_attributes_destroy(attributes);
light_repr = _get_light_representation(room->child_light);
if (NULL == light_repr) {