#include "icl-request.h"
#include "icl-response.h"
#include "icl-remote-resource.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-device.h"
#include "icl-payload.h"
#include "icl-observation.h"
#include "iotcon.h"
#include "ic-utils.h"
#include "icl.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
#include "icl-device.h"
--- /dev/null
+/*
+ * Copyright (c) 2015 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 "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "iotcon-representation.h"
+#include "icl.h"
+#include "icl-state.h"
+#include "icl-representation.h"
+#include "icl-value.h"
+#include "icl-list.h"
+
+void icl_list_inc_ref_count(iotcon_list_h val)
+{
+ RET_IF(NULL == val);
+ RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count++;
+}
+
+static bool _icl_list_dec_ref_count(iotcon_list_h val)
+{
+ bool ret;
+
+ RETV_IF(NULL == val, false);
+ RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count--;
+ if (0 == val->ref_count)
+ ret = true;
+ else
+ ret = false;
+
+ return ret;
+}
+
+static int _icl_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
+{
+ iotcon_list_h list;
+
+ list = calloc(1, sizeof(struct icl_list_s));
+ if (NULL == list) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ icl_list_inc_ref_count(list);
+ list->type = type;
+
+ *ret_list = list;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
+{
+ int ret;
+ iotcon_list_h list;
+
+ RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
+ ERR("Invalid Type(%d)", type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ ret = _icl_list_create(type, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_icl_list_create() Fail");
+ return ret;
+ }
+
+ *ret_list = list;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_add_int(iotcon_list_h list, int val, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
+ list->type);
+
+ value = icl_value_create_int(val);
+ if (NULL == value) {
+ ERR("icl_value_create_int(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_add_bool(iotcon_list_h list, bool val, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+
+ value = icl_value_create_bool(val);
+ if (NULL == value) {
+ ERR("icl_value_create_bool(%d) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_add_double(iotcon_list_h list, double val, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+
+ value = icl_value_create_double(val);
+ if (NULL == value) {
+ ERR("icl_value_create_double(%f) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_add_str(iotcon_list_h list, char *val, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+
+ value = icl_value_create_str(val);
+ if (NULL == value) {
+ ERR("icl_value_create_str(%s) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+
+ value = icl_value_create_list(val);
+ if (NULL == value) {
+ ERR("icl_value_create_list(%p) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ icl_list_inc_ref_count(val);
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos)
+{
+ iotcon_value_h value;
+
+ 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,
+ "Invalid Type(%d)", list->type);
+
+ value = icl_value_create_state(val);
+ if (NULL == value) {
+ ERR("icl_value_create_state(%p) Fail", val);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ icl_state_inc_ref_count(val);
+
+ return icl_list_insert(list, value, pos);
+}
+
+
+API int iotcon_list_get_nth_int(iotcon_list_h list, int pos, int *val)
+{
+ int ival, ret;
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_int(value, &ival);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_int() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *val = ival;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_nth_bool(iotcon_list_h list, int pos, bool *val)
+{
+ int ret;
+ bool bval;
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_bool(value, &bval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_bool() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *val = bval;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_nth_double(iotcon_list_h list, int pos, double *val)
+{
+ int ret;
+ double dbval;
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_double(value, &dbval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_double() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *val = dbval;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val)
+{
+ int ret;
+ char *strval;
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_str(value, &strval);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_str() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *val = strval;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest)
+{
+ int ret;
+ iotcon_value_h value;
+ iotcon_list_h list_val;
+
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == src->list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(src->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_list(value, &list_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_list() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *dest = list_val;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state)
+{
+ int ret;
+ iotcon_value_h value;
+ iotcon_state_h state_val;
+
+ 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);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ ret = icl_value_get_state(value, &state_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_state() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ *state = state_val;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static int _icl_list_remove_nth_value(iotcon_list_h list, int pos)
+{
+ iotcon_value_h value;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_list_nth_data(list->list, pos);
+ if (NULL == value) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ if (IOTCON_TYPE_STR == value->type) {
+ icl_basic_s *real = (icl_basic_s*)value;
+ free(real->val.s);
+ } else if (IOTCON_TYPE_LIST == value->type) {
+ icl_val_list_s *real = (icl_val_list_s*)value;
+ iotcon_list_destroy(real->list);
+ } else if (IOTCON_TYPE_STATE == value->type) {
+ icl_val_state_s *real = (icl_val_state_s*)value;
+ iotcon_state_destroy(real->state);
+ }
+
+ icl_list_remove(list, value);
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_remove_nth(iotcon_list_h list, int pos)
+{
+ int ret;
+
+ ret = _icl_list_remove_nth_value(list, pos);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("_icl_list_remove_nth_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+API int iotcon_list_get_type(iotcon_list_h list, int *type)
+{
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *type = list->type;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_list_get_length(iotcon_list_h list, unsigned int *length)
+{
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *length = g_list_length(list->list);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+int icl_list_remove(iotcon_list_h list, iotcon_value_h val)
+{
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ list->list = g_list_remove(list->list, val);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
+{
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+
+ list->list = g_list_insert(list->list, value, pos);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb,
+ void *user_data)
+{
+ GList *cur;
+ int index = 0;
+ icl_basic_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->val.i, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb,
+ void *user_data)
+{
+ GList *cur;
+ int index = 0;
+ icl_basic_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->val.b, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
+ void *user_data)
+{
+ GList *cur;
+ int index = 0;
+ icl_basic_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->val.d, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb,
+ void *user_data)
+{
+ GList *cur;
+ int index = 0;
+ icl_basic_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
+ list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->val.s, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb,
+ void *user_data)
+{
+ int index = 0;
+ GList *cur = NULL;
+ icl_val_list_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->list, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb,
+ void *user_data)
+{
+ int index = 0;
+ GList *cur = NULL;
+ icl_val_state_s *real = NULL;
+
+ RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
+ "Invalid Type(%d)", list->type);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);;
+
+ cur = list->list;
+ while (cur) {
+ GList *next = cur->next;
+ real = cur->data;
+ if (IOTCON_FUNC_STOP == cb(index, real->state, user_data))
+ break;
+ index++;
+ cur = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static iotcon_value_h _icl_list_get_nth_value(iotcon_list_h list, int pos)
+{
+ RETV_IF(NULL == list, NULL);
+ RETV_IF(NULL == list->list, NULL);
+
+ return g_list_nth_data(list->list, pos);
+}
+
+
+API void iotcon_list_destroy(iotcon_list_h list)
+{
+ FN_CALL;
+ GList *cur = NULL;
+
+ RET_IF(NULL == list);
+
+ if (false == _icl_list_dec_ref_count(list))
+ return;
+
+ cur = list->list;
+ while (cur) {
+ icl_value_destroy(cur->data);
+ cur = cur->next;
+ }
+ free(list);
+}
+
+static int _icl_list_clone_value(iotcon_list_h list, iotcon_list_h ret_list)
+{
+ int i, ret, count;
+ iotcon_value_h value, copied_value;
+
+ count = g_list_length(list->list);
+ for (i = 0; i < count; i++) {
+ value = _icl_list_get_nth_value(list, i);
+ if (NULL == value) {
+ ERR("_icl_list_get_nth_value() Fail");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+ if (list->type != value->type) {
+ ERR("Type Mismatching(list:%d, value:%d)", list->type, value->type);
+ return IOTCON_ERROR_INVALID_TYPE;
+ }
+
+ copied_value = icl_value_clone(value);
+ if (NULL == copied_value) {
+ ERR("icl_value_clone() Fail");
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ ret = icl_list_insert(ret_list, copied_value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_list_insert() Fail");
+ icl_value_destroy(copied_value);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static int _icl_list_clone_list(iotcon_list_h list, iotcon_list_h ret_list)
+{
+ int i, ret, count;
+
+ iotcon_value_h value;
+ iotcon_list_h list_val, copied_list;
+
+ count = g_list_length(list->list);
+ for (i = 0; i < count; i++) {
+ ret = iotcon_list_get_nth_list(list, i, &list_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_get_nth_list() Fail(%d)", ret);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ copied_list = icl_list_clone(list_val);
+ if (NULL == copied_list) {
+ ERR("icl_list_clone() Fail");
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ value = icl_value_create_list(copied_list);
+ if (NULL == value) {
+ ERR("icl_value_create_list(%p) Fail", copied_list);
+ iotcon_list_destroy(copied_list);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ ret = icl_list_insert(ret_list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_list_insert(%d) Fail", ret);
+ icl_value_destroy(value);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+static int _icl_list_clone_state(iotcon_list_h list, iotcon_list_h ret_list)
+{
+ int i, ret, count;
+ iotcon_value_h value;
+ iotcon_state_h state_val;
+ iotcon_state_h copied_state = NULL;
+
+ count = g_list_length(list->list);
+ for (i = 0; i < count; i++) {
+ ret = iotcon_list_get_nth_state(list, i, &state_val);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_get_nth_state() Fail");
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+
+ if (state_val->hash_table) {
+ g_hash_table_foreach(state_val->hash_table, (GHFunc)icl_state_clone_foreach,
+ copied_state);
+ }
+
+ value = icl_value_create_state(copied_state);
+ if (NULL == value) {
+ ERR("icl_value_create_state(%p) Fail", copied_state);
+ iotcon_state_destroy(copied_state);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+
+ ret = icl_list_insert(ret_list, value, -1);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_list_insert(%d) Fail", ret);
+ icl_value_destroy(value);
+ return IOTCON_ERROR_REPRESENTATION;
+ }
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+iotcon_list_h icl_list_clone(iotcon_list_h list)
+{
+ int ret;
+ iotcon_list_h ret_list = NULL;
+
+ RETV_IF(NULL == list, NULL);
+ RETV_IF(NULL == list->list, NULL);
+
+ ret = iotcon_list_create(list->type, &ret_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_list_create(%d) Fail(%d)", list->type, ret);
+ return NULL;
+ }
+
+ switch (list->type) {
+ case IOTCON_TYPE_INT:
+ case IOTCON_TYPE_BOOL:
+ case IOTCON_TYPE_DOUBLE:
+ case IOTCON_TYPE_STR:
+ case IOTCON_TYPE_NULL:
+ ret = _icl_list_clone_value(list, ret_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_icl_list_clone_value() Fail(%d)", ret);
+ iotcon_list_destroy(ret_list);
+ return NULL;
+ }
+ break;
+ case IOTCON_TYPE_LIST:
+ ret = _icl_list_clone_list(list, ret_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_icl_list_clone_list() Fail(%d)", ret);
+ iotcon_list_destroy(ret_list);
+ return NULL;
+ }
+ break;
+ case IOTCON_TYPE_STATE:
+ ret = _icl_list_clone_state(list, ret_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_icl_list_clone_state() Fail(%d)", ret);
+ iotcon_list_destroy(ret_list);
+ return NULL;
+ }
+ break;
+ default:
+ ERR("Invalid type(%d)", list->type);
+ iotcon_list_destroy(ret_list);
+ return NULL;
+ }
+
+ return ret_list;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_MANAGER_LIBRARY_LIST_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__
+
+#include <glib.h>
+
+#include "iotcon-struct.h"
+#include "icl-value.h"
+
+struct icl_list_s {
+ int type;
+ int ref_count;
+ GList *list;
+};
+
+int icl_list_remove(iotcon_list_h list, iotcon_value_h val);
+int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
+
+iotcon_list_h icl_list_clone(iotcon_list_h list);
+
+void icl_list_inc_ref_count(iotcon_list_h val);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__ */
#include "ic-utils.h"
#include "icl.h"
#include "icl-dbus.h"
-#include "icl-repr.h"
-#include "icl-repr-state.h"
-#include "icl-repr-value.h"
-#include "icl-repr-list.h"
+#include "icl-representation.h"
+#include "icl-state.h"
+#include "icl-value.h"
+#include "icl-list.h"
#include "icl-dbus-type.h"
#include "icl-payload.h"
#include "icl-resource.h"
#include "iotcon.h"
#include "ic-utils.h"
#include "icl.h"
-#include "icl-repr.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
+#include "icl-representation.h"
+#include "icl-list.h"
+#include "icl-value.h"
#include "icl-resource-types.h"
#include "icl-response.h"
#include "icl-payload.h"
#include "icl.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
-#include "icl-repr.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
+#include "icl-representation.h"
+#include "icl-list.h"
+#include "icl-value.h"
#include "icl-remote-resource.h"
static int _caching_compare_state(iotcon_state_h state1, iotcon_state_h state2);
#include "icl-options.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-response.h"
#include "icl-remote-resource.h"
#include "icl-payload.h"
#include "icl.h"
#include "icl-options.h"
#include "icl-dbus.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-remote-resource.h"
#include "icl-resource-types.h"
#include "icl-payload.h"
+++ /dev/null
-/*
- * Copyright (c) 2015 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 "iotcon-struct.h"
-#include "iotcon-constant.h"
-#include "iotcon-representation.h"
-#include "icl.h"
-#include "icl-repr-state.h"
-#include "icl-repr.h"
-#include "icl-repr-value.h"
-#include "icl-repr-list.h"
-
-void icl_list_inc_ref_count(iotcon_list_h val)
-{
- RET_IF(NULL == val);
- RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count++;
-}
-
-static bool _icl_list_dec_ref_count(iotcon_list_h val)
-{
- bool ret;
-
- RETV_IF(NULL == val, false);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count--;
- if (0 == val->ref_count)
- ret = true;
- else
- ret = false;
-
- return ret;
-}
-
-static int _icl_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
-{
- iotcon_list_h list;
-
- list = calloc(1, sizeof(struct icl_list_s));
- if (NULL == list) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- icl_list_inc_ref_count(list);
- list->type = type;
-
- *ret_list = list;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_create(iotcon_types_e type, iotcon_list_h *ret_list)
-{
- int ret;
- iotcon_list_h list;
-
- RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
- ERR("Invalid Type(%d)", type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- ret = _icl_list_create(type, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_create() Fail");
- return ret;
- }
-
- *ret_list = list;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_add_int(iotcon_list_h list, int val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
-
- value = icl_value_create_int(val);
- if (NULL == value) {
- ERR("icl_value_create_int(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_bool(iotcon_list_h list, bool val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_bool(val);
- if (NULL == value) {
- ERR("icl_value_create_bool(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_double(iotcon_list_h list, double val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_double(val);
- if (NULL == value) {
- ERR("icl_value_create_double(%f) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_str(iotcon_list_h list, char *val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_str(val);
- if (NULL == value) {
- ERR("icl_value_create_str(%s) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_list(val);
- if (NULL == value) {
- ERR("icl_value_create_list(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- icl_list_inc_ref_count(val);
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos)
-{
- iotcon_value_h value;
-
- 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,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_state(val);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- icl_state_inc_ref_count(val);
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_get_nth_int(iotcon_list_h list, int pos, int *val)
-{
- int ival, ret;
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_int(value, &ival);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_int() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = ival;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_bool(iotcon_list_h list, int pos, bool *val)
-{
- int ret;
- bool bval;
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_bool(value, &bval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_bool() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = bval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_double(iotcon_list_h list, int pos, double *val)
-{
- int ret;
- double dbval;
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_double(value, &dbval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_double() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = dbval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val)
-{
- int ret;
- char *strval;
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_str(value, &strval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_str() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = strval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest)
-{
- int ret;
- iotcon_value_h value;
- iotcon_list_h list_val;
-
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == src->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(src->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_list(value, &list_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *dest = list_val;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state)
-{
- int ret;
- iotcon_value_h value;
- iotcon_state_h state_val;
-
- 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);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_state(value, &state_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *state = state_val;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_list_remove_nth_value(iotcon_list_h list, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- if (IOTCON_TYPE_STR == value->type) {
- icl_basic_s *real = (icl_basic_s*)value;
- free(real->val.s);
- } else if (IOTCON_TYPE_LIST == value->type) {
- icl_val_list_s *real = (icl_val_list_s*)value;
- iotcon_list_destroy(real->list);
- } else if (IOTCON_TYPE_STATE == value->type) {
- icl_val_state_s *real = (icl_val_state_s*)value;
- iotcon_state_destroy(real->state);
- }
-
- icl_list_remove(list, value);
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_remove_nth(iotcon_list_h list, int pos)
-{
- int ret;
-
- ret = _icl_list_remove_nth_value(list, pos);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_icl_list_remove_nth_value() Fail(%d)", ret);
-
- return ret;
-}
-
-API int iotcon_list_get_type(iotcon_list_h list, int *type)
-{
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *type = list->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_length(iotcon_list_h list, unsigned int *length)
-{
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
-
- *length = g_list_length(list->list);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_list_remove(iotcon_list_h list, iotcon_value_h val)
-{
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- list->list = g_list_remove(list->list, val);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
-{
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- list->list = g_list_insert(list->list, value, pos);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.i, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.b, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.d, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.s, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb,
- void *user_data)
-{
- int index = 0;
- GList *cur = NULL;
- icl_val_list_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->list, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb,
- void *user_data)
-{
- int index = 0;
- GList *cur = NULL;
- icl_val_state_s *real = NULL;
-
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);;
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->state, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static iotcon_value_h _icl_list_get_nth_value(iotcon_list_h list, int pos)
-{
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
-
- return g_list_nth_data(list->list, pos);
-}
-
-
-API void iotcon_list_destroy(iotcon_list_h list)
-{
- FN_CALL;
- GList *cur = NULL;
-
- RET_IF(NULL == list);
-
- if (false == _icl_list_dec_ref_count(list))
- return;
-
- cur = list->list;
- while (cur) {
- icl_value_destroy(cur->data);
- cur = cur->next;
- }
- free(list);
-}
-
-static int _icl_list_clone_value(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
- iotcon_value_h value, copied_value;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- value = _icl_list_get_nth_value(list, i);
- if (NULL == value) {
- ERR("_icl_list_get_nth_value() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- if (list->type != value->type) {
- ERR("Type Mismatching(list:%d, value:%d)", list->type, value->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- copied_value = icl_value_clone(value);
- if (NULL == copied_value) {
- ERR("icl_value_clone() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, copied_value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert() Fail");
- icl_value_destroy(copied_value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_list_clone_list(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
-
- iotcon_value_h value;
- iotcon_list_h list_val, copied_list;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- ret = iotcon_list_get_nth_list(list, i, &list_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_get_nth_list() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- copied_list = icl_list_clone(list_val);
- if (NULL == copied_list) {
- ERR("icl_list_clone() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- value = icl_value_create_list(copied_list);
- if (NULL == value) {
- ERR("icl_value_create_list(%p) Fail", copied_list);
- iotcon_list_destroy(copied_list);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert(%d) Fail", ret);
- icl_value_destroy(value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_list_clone_state(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
- iotcon_value_h value;
- iotcon_state_h state_val;
- iotcon_state_h copied_state = NULL;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- ret = iotcon_list_get_nth_state(list, i, &state_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_get_nth_state() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
-
- if (state_val->hash_table) {
- g_hash_table_foreach(state_val->hash_table, (GHFunc)icl_state_clone_foreach,
- copied_state);
- }
-
- value = icl_value_create_state(copied_state);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", copied_state);
- iotcon_state_destroy(copied_state);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert(%d) Fail", ret);
- icl_value_destroy(value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-iotcon_list_h icl_list_clone(iotcon_list_h list)
-{
- int ret;
- iotcon_list_h ret_list = NULL;
-
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
-
- ret = iotcon_list_create(list->type, &ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create(%d) Fail(%d)", list->type, ret);
- return NULL;
- }
-
- switch (list->type) {
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_STR:
- case IOTCON_TYPE_NULL:
- ret = _icl_list_clone_value(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_value() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- case IOTCON_TYPE_LIST:
- ret = _icl_list_clone_list(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_list() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- case IOTCON_TYPE_STATE:
- ret = _icl_list_clone_state(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_state() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- default:
- ERR("Invalid type(%d)", list->type);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
-
- return ret_list;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_MANAGER_LIBRARY_REPRESENTATION_LIST_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_LIST_H__
-
-#include <glib.h>
-
-#include "iotcon-struct.h"
-#include "icl-repr-value.h"
-
-struct icl_list_s {
- int type;
- int ref_count;
- GList *list;
-};
-
-int icl_list_remove(iotcon_list_h list, iotcon_value_h val);
-int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
-
-iotcon_list_h icl_list_clone(iotcon_list_h list);
-
-void icl_list_inc_ref_count(iotcon_list_h val);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_LIST_H__ */
+++ /dev/null
-/* Copyright (c) 2015 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 <glib.h>
-
-#include "iotcon-struct.h"
-#include "iotcon-constant.h"
-#include "iotcon-representation.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
-#include "icl-repr.h"
-#include "icl-repr-state.h"
-
-void icl_state_inc_ref_count(iotcon_state_h val)
-{
- RET_IF(NULL == val);
- RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count++;
-}
-
-
-int icl_state_dec_ref_count(iotcon_state_h val)
-{
- RETV_IF(NULL == val, -1);
- RETVM_IF(val->ref_count <= 0, 0, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count--;
-
- return val->ref_count;
-}
-
-
-API int iotcon_state_create(iotcon_state_h *ret_state)
-{
- errno = 0;
- iotcon_state_h state;
-
- 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);
- icl_state_inc_ref_count(state);
-
- *ret_state = state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_state_destroy(iotcon_state_h state)
-{
- RET_IF(NULL == state);
-
- if (0 == icl_state_dec_ref_count(state)) {
- g_hash_table_destroy(state->hash_table);
- free(state);
- }
-}
-
-
-int icl_state_del_value(iotcon_state_h state, const char *key)
-{
- gboolean ret = FALSE;
- iotcon_value_h value = NULL;
-
- 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(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_set_int(iotcon_state_h state, const char *key, int val)
-{
- iotcon_value_h value;
-
- 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_unset(iotcon_state_h state, const char *key)
-{
- int ret;
-
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_state_del_value(state, key);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_state_del_value() Fail(%d)", ret);
-
- return ret;
-}
-
-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(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_set_bool(iotcon_state_h state, const char *key, bool val)
-{
- iotcon_value_h value = NULL;
-
- 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(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_set_double(iotcon_state_h state, const char *key, double val)
-{
- iotcon_value_h value = NULL;
-
- 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(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_set_str(iotcon_state_h state, const char *key, char *val)
-{
- iotcon_value_h value = NULL;
-
- 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_is_null(iotcon_state_h state, const char *key, bool *is_null)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, 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_set_null(iotcon_state_h state, const char *key)
-{
- iotcon_value_h value = NULL;
-
- 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(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_set_list(iotcon_state_h state, const char *key, iotcon_list_h list)
-{
- iotcon_value_h value = NULL;
-
- 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;
- }
- icl_list_inc_ref_count(list);
-
- 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(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_set_state(iotcon_state_h state, const char *key, iotcon_state_h val)
-{
- iotcon_value_h value = NULL;
-
- 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;
- }
- icl_state_inc_ref_count(val);
-
- 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, int *type)
-{
- iotcon_value_h value = NULL;
-
- 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;
-}
-
-
-int icl_state_clone(iotcon_state_h src, iotcon_state_h *dest)
-{
- int ret;
-
- iotcon_state_h cloned_state = NULL;
-
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (src->hash_table) {
- ret = iotcon_state_create(&cloned_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- return ret;
- }
-
- g_hash_table_foreach(src->hash_table, (GHFunc)icl_state_clone_foreach,
- cloned_state);
- }
-
- *dest = cloned_state;
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_MANAGER_LIBRARY_REPRESENTATION_STATE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_STATE_H__
-
-#include "iotcon-struct.h"
-#include "iotcon-constant.h"
-#include "icl-repr-value.h"
-
-void icl_state_inc_ref_count(iotcon_state_h val);
-int icl_state_dec_ref_count(iotcon_state_h val);
-
-int icl_state_del_value(iotcon_state_h state, const char *key);
-
-int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
-
-int icl_state_clone(iotcon_state_h src, iotcon_state_h *dest);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_STATE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 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 "iotcon-struct.h"
-#include "iotcon-representation.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-repr.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
-
-static iotcon_value_h _icl_value_create(int type)
-{
- iotcon_value_h ret_val;
-
- switch (type) {
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_STR:
- case IOTCON_TYPE_NULL:
- ret_val = calloc(1, sizeof(icl_basic_s));
- break;
- 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));
- break;
- default:
- ERR("Invalid Type(%d)", type);
- return NULL;
- }
-
- if (NULL == ret_val) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- ret_val->type = type;
-
- return ret_val;
-}
-
-
-iotcon_value_h icl_value_create_null()
-{
- iotcon_value_h value;
-
- value = _icl_value_create(IOTCON_TYPE_NULL);
- if (NULL == value) {
- ERR("_icl_value_create(NULL) Fail");
- return NULL;
- }
-
- return value;
-}
-
-iotcon_value_h icl_value_create_int(int val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_INT);
- if (NULL == value) {
- ERR("_icl_value_create(INT:%d) Fail", val);
- return NULL;
- }
-
- value->val.i = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_bool(bool val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_BOOL);
- if (NULL == value) {
- ERR("_icl_value_create(BOOL:%d) Fail", val);
- return NULL;
- }
-
- value->val.b = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_double(double val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_DOUBLE);
- if (NULL == value) {
- ERR("_icl_value_create(DOUBLE:%f) Fail", val);
- return NULL;
- }
-
- value->val.d = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_str(const char *val)
-{
- icl_basic_s *value;
-
- RETV_IF(NULL == val, NULL);
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_STR);
- if (NULL == value) {
- ERR("_icl_value_create(STR:%s) Fail", val);
- return NULL;
- }
-
- value->val.s = ic_utils_strdup(val);
-
- return (iotcon_value_h)value;
-}
-
-
-iotcon_value_h icl_value_create_list(iotcon_list_h val)
-{
- icl_val_list_s *value;
-
- value = (icl_val_list_s*)_icl_value_create(IOTCON_TYPE_LIST);
- if (NULL == value) {
- ERR("_icl_value_create(LIST) Fail");
- return NULL;
- }
-
- value->list = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_state(iotcon_state_h val)
-{
- icl_val_state_s *value;
-
- value = (icl_val_state_s*)_icl_value_create(IOTCON_TYPE_STATE);
- if (NULL == value) {
- ERR("_icl_value_create(state) Fail");
- return NULL;
- }
-
- value->state = val;
-
- return (iotcon_value_h)value;
-}
-
-int icl_value_get_int(iotcon_value_h value, int *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.i;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_bool(iotcon_value_h value, bool *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.b;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_double(iotcon_value_h value, double *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.d;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_str(iotcon_value_h value, char **val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.s;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list)
-{
- icl_val_list_s *real = (icl_val_list_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *list = real->list;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state)
-{
- icl_val_state_s *real = (icl_val_state_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *state = real->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-void icl_value_destroy(gpointer data)
-{
- int ret;
- iotcon_value_h value;
- iotcon_list_h list;
- iotcon_state_h state;
-
- RET_IF(NULL == data);
-
- value = data;
-
- int type = value->type;
- switch (type) {
- case IOTCON_TYPE_STR:
- free(((icl_basic_s*)value)->val.s);
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_NULL:
- break;
- case IOTCON_TYPE_LIST:
- DBG("value is list");
- ret = icl_value_get_list(value, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
- break;
- }
- iotcon_list_destroy(list);
- break;
- case IOTCON_TYPE_STATE:
- DBG("value is Repr");
- ret = icl_value_get_state(value, &state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
- break;
- }
- iotcon_state_destroy(state);
- break;
- default:
- ERR("Invalid type(%d)", type);
- break;
- }
- free(value);
-}
-
-
-iotcon_value_h icl_value_clone(iotcon_value_h src)
-{
- iotcon_value_h dest = NULL;
- icl_basic_s *real = (icl_basic_s*)src;
-
- RETV_IF(NULL == src, NULL);
-
- switch (src->type) {
- case IOTCON_TYPE_INT:
- dest = icl_value_create_int(real->val.i);
- break;
- case IOTCON_TYPE_BOOL:
- dest = icl_value_create_bool(real->val.b);
- break;
- case IOTCON_TYPE_DOUBLE:
- dest = icl_value_create_double(real->val.d);
- break;
- case IOTCON_TYPE_STR:
- dest = icl_value_create_str(ic_utils_strdup(real->val.s));
- break;
- case IOTCON_TYPE_NULL:
- dest = icl_value_create_null();
- break;
- default:
- ERR("Invalid type(%d)", src->type);
- break;
- }
-
- if (NULL == dest)
- ERR("ic_value_create_xxx(%d) Fail", src->type);
-
- return dest;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_MANAGER_LIBRARY_REPRESENTATION_VALUE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_VALUE_H__
-
-#include <glib.h>
-#include <tizen_type.h>
-
-#include "iotcon-struct.h"
-
-struct icl_value_s {
- int type;
-};
-
-typedef struct {
- int type;
- union {
- int i;
- bool b;
- double d;
- char *s;
- } val;
-} icl_basic_s;
-
-typedef struct {
- int type;
- struct icl_list_s *list;
-} icl_val_list_s;
-
-typedef struct {
- int type;
- struct icl_state_s *state;
-} icl_val_state_s;
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
- * @brief The handle of representation value.
- * @details iotcon_value_h is an opaque data structure to have variant datatype and
- * store values along with information about the type of that value.\n
- * The range of possible values is determined by the type.\n
- * The type of iotcon_value_h should be one of them\n
- * #IOTCON_TYPE_INT\n
- * #IOTCON_TYPE_BOOL\n
- * #IOTCON_TYPE_DOUBLE\n
- * #IOTCON_TYPE_STR\n
- * #IOTCON_TYPE_NULL\n
- * #IOTCON_TYPE_LIST\n
- * #IOTCON_TYPE_STATE
- *
- * @since_tizen 3.0
- */
-typedef struct icl_value_s* iotcon_value_h;
-
-iotcon_value_h icl_value_create_null();
-iotcon_value_h icl_value_create_int(int val);
-iotcon_value_h icl_value_create_bool(bool val);
-iotcon_value_h icl_value_create_double(double val);
-iotcon_value_h icl_value_create_str(const char *val);
-iotcon_value_h icl_value_create_list(iotcon_list_h val);
-iotcon_value_h icl_value_create_state(iotcon_state_h val);
-
-
-int icl_value_get_int(iotcon_value_h value, int *val);
-int icl_value_get_bool(iotcon_value_h value, bool *val);
-int icl_value_get_double(iotcon_value_h value, double *val);
-int icl_value_get_str(iotcon_value_h value, char **val);
-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);
-
-void icl_value_destroy(gpointer data);
-
-iotcon_value_h icl_value_clone(iotcon_value_h src);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_VALUE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <glib.h>
-#include <tizen_type.h>
-
-#include "iotcon-struct.h"
-#include "iotcon-representation.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource.h"
-#include "icl-resource-types.h"
-#include "icl-response.h"
-#include "icl-repr-list.h"
-#include "icl-repr-value.h"
-#include "icl-repr-state.h"
-#include "icl-repr.h"
-
-void icl_representation_inc_ref_count(iotcon_representation_h val)
-{
- RET_IF(NULL == val);
- RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count++;
-}
-
-
-static bool _icl_representation_dec_ref_count(iotcon_representation_h val)
-{
- bool ret;
-
- RETV_IF(NULL == val, -1);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
-
- val->ref_count--;
- if (0 == val->ref_count)
- ret = true;
- else
- ret = false;
-
- return ret;
-}
-
-
-API int iotcon_representation_create(iotcon_representation_h *ret_repr)
-{
- errno = 0;
- iotcon_representation_h repr;
-
- RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- repr = calloc(1, sizeof(struct icl_representation_s));
- if (NULL == repr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- repr->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
- icl_representation_inc_ref_count(repr);
-
- *ret_repr = repr;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_representation_destroy(iotcon_representation_h repr)
-{
- RET_IF(NULL == repr);
-
- if (false == _icl_representation_dec_ref_count(repr))
- return;
-
- free(repr->uri_path);
-
- /* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
- g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
-
- /* null COULD be allowed */
- if (repr->res_types)
- iotcon_resource_types_destroy(repr->res_types);
-
- /* null COULD be allowed */
- if (repr->state)
- iotcon_state_destroy(repr->state);
-
- free(repr);
-}
-
-
-API int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
- *uri_path = repr->uri_path;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_uri_path(iotcon_representation_h repr,
- const char *uri_path)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- free(repr->uri_path);
- repr->uri_path = NULL;
-
- if (NULL == uri_path)
- return IOTCON_ERROR_INVALID_PARAMETER;
-
- repr->uri_path = strdup(uri_path);
- if (NULL == repr->uri_path) {
- ERR("strdup() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h *types)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
- *types = repr->res_types;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h types)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_resource_types_destroy(repr->res_types);
- repr->res_types = NULL;
-
- if (types)
- repr->res_types = icl_resource_types_ref(types);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- int *ifaces)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- *ifaces = repr->interfaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
- int ifaces)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
- IOTCON_ERROR_INVALID_PARAMETER);
-
- repr->interfaces = ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_set_state(iotcon_representation_h repr,
- iotcon_state_h state)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (repr->state) {
- ERR("state already set. Remove first !");
- return IOTCON_ERROR_ALREADY;
- }
-
- icl_state_inc_ref_count(state);
- repr->state = state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_get_state(iotcon_representation_h repr,
- iotcon_state_h *state)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-
- *state = repr->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_del_state(iotcon_representation_h repr)
-{
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (repr->state)
- iotcon_state_destroy(repr->state);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_append_child(iotcon_representation_h parent,
- iotcon_representation_h child)
-{
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- icl_representation_inc_ref_count(child);
- parent->children = g_list_append(parent->children, child);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_remove_child(iotcon_representation_h parent,
- iotcon_representation_h child)
-{
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- parent->children = g_list_remove(parent->children, child);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_foreach_children(iotcon_representation_h parent,
- iotcon_children_cb cb, void *user_data)
-{
- GList *list, *next;
-
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- list = parent->children;
- while (list) {
- next = list->next;
- if (IOTCON_FUNC_STOP == cb(list->data, user_data))
- break;
- list = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_children_count(iotcon_representation_h parent,
- unsigned int *count)
-{
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
-
- *count = g_list_length(parent->children);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
- iotcon_representation_h *child)
-{
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- *child = g_list_nth_data(parent->children, pos);
- if (NULL == *child) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data)
-{
- GHashTableIter iter;
- gpointer key;
-
- 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;
-}
-
-
-API int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count)
-{
- RETV_IF(NULL == state, 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;
-}
-
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state)
-{
- FN_CALL;
- int type, ret;
- iotcon_value_h value, copied_val;
- iotcon_list_h child_list, copied_list;
- iotcon_state_h child_state;
- iotcon_state_h copied_state = NULL;
-
- type = src_val->type;
- switch (type) {
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_STR:
- case IOTCON_TYPE_NULL:
- 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);
- break;
- case IOTCON_TYPE_LIST:
- ret = icl_value_get_list(src_val, &child_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
- return;
- }
-
- copied_list = icl_list_clone(child_list);
- if (NULL == copied_list) {
- ERR("icl_list_clone() Fail");
- return;
- }
-
- value = icl_value_create_list(copied_list);
- if (NULL == value) {
- ERR("icl_value_create_list() Fail");
- iotcon_list_destroy(copied_list);
- return;
- }
-
- icl_state_set_value(dest_state, key, value);
- break;
- case IOTCON_TYPE_STATE:
- ret = icl_value_get_state(src_val, &child_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
- return;
- }
-
- g_hash_table_foreach(child_state->hash_table, (GHFunc)icl_state_clone_foreach,
- copied_state);
-
- value = icl_value_create_state(copied_state);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", copied_state);
- return;
- }
-
- icl_state_set_value(dest_state, key, value);
- break;
- default:
- ERR("Invalid type(%d)", type);
- return;
- }
-}
-
-API int iotcon_representation_clone(const iotcon_representation_h src,
- iotcon_representation_h *dest)
-{
- FN_CALL;
- int ret;
- GList *node;
- iotcon_resource_types_h list;
- iotcon_state_h ori_state;
- iotcon_state_h cloned_state = NULL;
- iotcon_representation_h cloned_repr, copied_repr;
-
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = iotcon_representation_create(&cloned_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return ret;
- }
-
- if (src->uri_path) {
- cloned_repr->uri_path = strdup(src->uri_path);
- if (NULL == cloned_repr->uri_path) {
- ERR("strdup() Fail");
- iotcon_representation_destroy(cloned_repr);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- }
-
- if (src->interfaces)
- cloned_repr->interfaces = src->interfaces;
-
- if (src->res_types) {
- ret = iotcon_resource_types_clone(src->res_types, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_clone() Fail");
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- cloned_repr->res_types = list;
- }
-
- for (node = g_list_first(src->children); node; node = node->next) {
- ret = iotcon_representation_clone((iotcon_representation_h)node->data,
- &copied_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_clone(child) Fail(%d)", ret);
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- cloned_repr->children = g_list_append(cloned_repr->children, copied_repr);
- }
-
- ori_state = src->state;
- if (ori_state->hash_table) {
- ret = iotcon_state_create(&cloned_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail");
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- g_hash_table_foreach(ori_state->hash_table, (GHFunc)icl_state_clone_foreach,
- cloned_state);
- ret = iotcon_representation_set_state(cloned_repr, cloned_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail");
- iotcon_state_destroy(cloned_state);
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- iotcon_state_destroy(cloned_state);
- }
-
- *dest = cloned_repr;
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_MANAGER_LIBRARY_REPRESENTATION_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__
-
-#include <glib.h>
-#include <tizen_type.h>
-
-#include "iotcon-struct.h"
-#include "icl-repr-value.h"
-
-struct icl_representation_s {
- char *uri_path;
- int ref_count;
- int interfaces;
- int visibility;
- GList *children;
- iotcon_resource_types_h res_types;
- struct icl_state_s *state;
-};
-
-struct icl_state_s {
- int ref_count;
- GHashTable *hash_table;
-};
-
-void icl_representation_inc_ref_count(iotcon_representation_h val);
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <glib.h>
+#include <tizen_type.h>
+
+#include "iotcon-struct.h"
+#include "iotcon-representation.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-resource.h"
+#include "icl-resource-types.h"
+#include "icl-response.h"
+#include "icl-list.h"
+#include "icl-value.h"
+#include "icl-state.h"
+#include "icl-representation.h"
+
+void icl_representation_inc_ref_count(iotcon_representation_h val)
+{
+ RET_IF(NULL == val);
+ RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count++;
+}
+
+
+static bool _icl_representation_dec_ref_count(iotcon_representation_h val)
+{
+ bool ret;
+
+ RETV_IF(NULL == val, -1);
+ RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count--;
+ if (0 == val->ref_count)
+ ret = true;
+ else
+ ret = false;
+
+ return ret;
+}
+
+
+API int iotcon_representation_create(iotcon_representation_h *ret_repr)
+{
+ errno = 0;
+ iotcon_representation_h repr;
+
+ RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ repr = calloc(1, sizeof(struct icl_representation_s));
+ if (NULL == repr) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ repr->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
+ icl_representation_inc_ref_count(repr);
+
+ *ret_repr = repr;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_representation_destroy(iotcon_representation_h repr)
+{
+ RET_IF(NULL == repr);
+
+ if (false == _icl_representation_dec_ref_count(repr))
+ return;
+
+ free(repr->uri_path);
+
+ /* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
+ g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
+
+ /* null COULD be allowed */
+ if (repr->res_types)
+ iotcon_resource_types_destroy(repr->res_types);
+
+ /* null COULD be allowed */
+ if (repr->state)
+ iotcon_state_destroy(repr->state);
+
+ free(repr);
+}
+
+
+API int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *uri_path = repr->uri_path;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_set_uri_path(iotcon_representation_h repr,
+ const char *uri_path)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ free(repr->uri_path);
+ repr->uri_path = NULL;
+
+ if (NULL == uri_path)
+ return IOTCON_ERROR_INVALID_PARAMETER;
+
+ repr->uri_path = strdup(uri_path);
+ if (NULL == repr->uri_path) {
+ ERR("strdup() Fail");
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_get_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h *types)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *types = repr->res_types;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_set_resource_types(iotcon_representation_h repr,
+ iotcon_resource_types_h types)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ iotcon_resource_types_destroy(repr->res_types);
+ repr->res_types = NULL;
+
+ if (types)
+ repr->res_types = icl_resource_types_ref(types);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
+ int *ifaces)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *ifaces = repr->interfaces;
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
+ int ifaces)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ RETV_IF(ifaces <= IOTCON_INTERFACE_NONE || IC_INTERFACE_MAX < ifaces,
+ IOTCON_ERROR_INVALID_PARAMETER);
+
+ repr->interfaces = ifaces;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_set_state(iotcon_representation_h repr,
+ iotcon_state_h state)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (repr->state) {
+ ERR("state already set. Remove first !");
+ return IOTCON_ERROR_ALREADY;
+ }
+
+ icl_state_inc_ref_count(state);
+ repr->state = state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_get_state(iotcon_representation_h repr,
+ iotcon_state_h *state)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *state = repr->state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_del_state(iotcon_representation_h repr)
+{
+ RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (repr->state)
+ iotcon_state_destroy(repr->state);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_append_child(iotcon_representation_h parent,
+ iotcon_representation_h child)
+{
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+
+ icl_representation_inc_ref_count(child);
+ parent->children = g_list_append(parent->children, child);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_remove_child(iotcon_representation_h parent,
+ iotcon_representation_h child)
+{
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+
+ parent->children = g_list_remove(parent->children, child);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_representation_foreach_children(iotcon_representation_h parent,
+ iotcon_children_cb cb, void *user_data)
+{
+ GList *list, *next;
+
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+
+ list = parent->children;
+ while (list) {
+ next = list->next;
+ if (IOTCON_FUNC_STOP == cb(list->data, user_data))
+ break;
+ list = next;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_get_children_count(iotcon_representation_h parent,
+ unsigned int *count)
+{
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *count = g_list_length(parent->children);
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
+ iotcon_representation_h *child)
+{
+ RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *child = g_list_nth_data(parent->children, pos);
+ if (NULL == *child) {
+ ERR("g_list_nth_data() Fail");
+ return IOTCON_ERROR_NO_DATA;
+ }
+
+ return IOTCON_ERROR_NONE;
+}
+
+API int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data)
+{
+ GHashTableIter iter;
+ gpointer key;
+
+ 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;
+}
+
+
+API int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count)
+{
+ RETV_IF(NULL == state, 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;
+}
+
+
+void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state)
+{
+ FN_CALL;
+ int type, ret;
+ iotcon_value_h value, copied_val;
+ iotcon_list_h child_list, copied_list;
+ iotcon_state_h child_state;
+ iotcon_state_h copied_state = NULL;
+
+ type = src_val->type;
+ switch (type) {
+ case IOTCON_TYPE_INT:
+ case IOTCON_TYPE_BOOL:
+ case IOTCON_TYPE_DOUBLE:
+ case IOTCON_TYPE_STR:
+ case IOTCON_TYPE_NULL:
+ 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);
+ break;
+ case IOTCON_TYPE_LIST:
+ ret = icl_value_get_list(src_val, &child_list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_list() Fail(%d)", ret);
+ return;
+ }
+
+ copied_list = icl_list_clone(child_list);
+ if (NULL == copied_list) {
+ ERR("icl_list_clone() Fail");
+ return;
+ }
+
+ value = icl_value_create_list(copied_list);
+ if (NULL == value) {
+ ERR("icl_value_create_list() Fail");
+ iotcon_list_destroy(copied_list);
+ return;
+ }
+
+ icl_state_set_value(dest_state, key, value);
+ break;
+ case IOTCON_TYPE_STATE:
+ ret = icl_value_get_state(src_val, &child_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_state() Fail(%d)", ret);
+ return;
+ }
+
+ g_hash_table_foreach(child_state->hash_table, (GHFunc)icl_state_clone_foreach,
+ copied_state);
+
+ value = icl_value_create_state(copied_state);
+ if (NULL == value) {
+ ERR("icl_value_create_state(%p) Fail", copied_state);
+ return;
+ }
+
+ icl_state_set_value(dest_state, key, value);
+ break;
+ default:
+ ERR("Invalid type(%d)", type);
+ return;
+ }
+}
+
+API int iotcon_representation_clone(const iotcon_representation_h src,
+ iotcon_representation_h *dest)
+{
+ FN_CALL;
+ int ret;
+ GList *node;
+ iotcon_resource_types_h list;
+ iotcon_state_h ori_state;
+ iotcon_state_h cloned_state = NULL;
+ iotcon_representation_h cloned_repr, copied_repr;
+
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = iotcon_representation_create(&cloned_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_create() Fail(%d)", ret);
+ return ret;
+ }
+
+ if (src->uri_path) {
+ cloned_repr->uri_path = strdup(src->uri_path);
+ if (NULL == cloned_repr->uri_path) {
+ ERR("strdup() Fail");
+ iotcon_representation_destroy(cloned_repr);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
+ if (src->interfaces)
+ cloned_repr->interfaces = src->interfaces;
+
+ if (src->res_types) {
+ ret = iotcon_resource_types_clone(src->res_types, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_clone() Fail");
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ cloned_repr->res_types = list;
+ }
+
+ for (node = g_list_first(src->children); node; node = node->next) {
+ ret = iotcon_representation_clone((iotcon_representation_h)node->data,
+ &copied_repr);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_clone(child) Fail(%d)", ret);
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ cloned_repr->children = g_list_append(cloned_repr->children, copied_repr);
+ }
+
+ ori_state = src->state;
+ if (ori_state->hash_table) {
+ ret = iotcon_state_create(&cloned_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail");
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ g_hash_table_foreach(ori_state->hash_table, (GHFunc)icl_state_clone_foreach,
+ cloned_state);
+ ret = iotcon_representation_set_state(cloned_repr, cloned_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_representation_set_state() Fail");
+ iotcon_state_destroy(cloned_state);
+ iotcon_representation_destroy(cloned_repr);
+ return ret;
+ }
+ iotcon_state_destroy(cloned_state);
+ }
+
+ *dest = cloned_repr;
+
+ return IOTCON_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_MANAGER_LIBRARY_REPRESENTATION_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__
+
+#include <glib.h>
+#include <tizen_type.h>
+
+#include "iotcon-struct.h"
+#include "icl-value.h"
+
+struct icl_representation_s {
+ char *uri_path;
+ int ref_count;
+ int interfaces;
+ int visibility;
+ GList *children;
+ iotcon_resource_types_h res_types;
+ struct icl_state_s *state;
+};
+
+struct icl_state_s {
+ int ref_count;
+ GHashTable *hash_table;
+};
+
+void icl_representation_inc_ref_count(iotcon_representation_h val);
+
+void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
#include "iotcon.h"
#include "ic-utils.h"
#include "icl.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-dbus.h"
#include "icl-request.h"
#include "icl-dbus-type.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
#include "icl-resource.h"
-#include "icl-repr.h"
+#include "icl-representation.h"
#include "icl-options.h"
#include "icl-request.h"
#include "icl-response.h"
--- /dev/null
+/* Copyright (c) 2015 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 <glib.h>
+
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "iotcon-representation.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-list.h"
+#include "icl-value.h"
+#include "icl-representation.h"
+#include "icl-state.h"
+
+void icl_state_inc_ref_count(iotcon_state_h val)
+{
+ RET_IF(NULL == val);
+ RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count++;
+}
+
+
+int icl_state_dec_ref_count(iotcon_state_h val)
+{
+ RETV_IF(NULL == val, -1);
+ RETVM_IF(val->ref_count <= 0, 0, "Invalid Count(%d)", val->ref_count);
+
+ val->ref_count--;
+
+ return val->ref_count;
+}
+
+
+API int iotcon_state_create(iotcon_state_h *ret_state)
+{
+ errno = 0;
+ iotcon_state_h state;
+
+ 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);
+ icl_state_inc_ref_count(state);
+
+ *ret_state = state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API void iotcon_state_destroy(iotcon_state_h state)
+{
+ RET_IF(NULL == state);
+
+ if (0 == icl_state_dec_ref_count(state)) {
+ g_hash_table_destroy(state->hash_table);
+ free(state);
+ }
+}
+
+
+int icl_state_del_value(iotcon_state_h state, const char *key)
+{
+ gboolean ret = FALSE;
+ iotcon_value_h value = NULL;
+
+ 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(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_set_int(iotcon_state_h state, const char *key, int val)
+{
+ iotcon_value_h value;
+
+ 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_unset(iotcon_state_h state, const char *key)
+{
+ int ret;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
+
+ ret = icl_state_del_value(state, key);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("icl_state_del_value() Fail(%d)", ret);
+
+ return ret;
+}
+
+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(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_set_bool(iotcon_state_h state, const char *key, bool val)
+{
+ iotcon_value_h value = NULL;
+
+ 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(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_set_double(iotcon_state_h state, const char *key, double val)
+{
+ iotcon_value_h value = NULL;
+
+ 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(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_set_str(iotcon_state_h state, const char *key, char *val)
+{
+ iotcon_value_h value = NULL;
+
+ 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_is_null(iotcon_state_h state, const char *key, bool *is_null)
+{
+ icl_basic_s *real = NULL;
+ iotcon_value_h value = NULL;
+
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == key, 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_set_null(iotcon_state_h state, const char *key)
+{
+ iotcon_value_h value = NULL;
+
+ 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(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_set_list(iotcon_state_h state, const char *key, iotcon_list_h list)
+{
+ iotcon_value_h value = NULL;
+
+ 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;
+ }
+ icl_list_inc_ref_count(list);
+
+ 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(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_set_state(iotcon_state_h state, const char *key, iotcon_state_h val)
+{
+ iotcon_value_h value = NULL;
+
+ 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;
+ }
+ icl_state_inc_ref_count(val);
+
+ 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, int *type)
+{
+ iotcon_value_h value = NULL;
+
+ 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;
+}
+
+
+int icl_state_clone(iotcon_state_h src, iotcon_state_h *dest)
+{
+ int ret;
+
+ iotcon_state_h cloned_state = NULL;
+
+ RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+
+ if (src->hash_table) {
+ ret = iotcon_state_create(&cloned_state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_state_create() Fail(%d)", ret);
+ return ret;
+ }
+
+ g_hash_table_foreach(src->hash_table, (GHFunc)icl_state_clone_foreach,
+ cloned_state);
+ }
+
+ *dest = cloned_state;
+
+ return IOTCON_ERROR_NONE;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_MANAGER_LIBRARY_STATE_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__
+
+#include "iotcon-struct.h"
+#include "iotcon-constant.h"
+#include "icl-value.h"
+
+void icl_state_inc_ref_count(iotcon_state_h val);
+int icl_state_dec_ref_count(iotcon_state_h val);
+
+int icl_state_del_value(iotcon_state_h state, const char *key);
+
+int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
+
+int icl_state_clone(iotcon_state_h src, iotcon_state_h *dest);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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 "iotcon-struct.h"
+#include "iotcon-representation.h"
+#include "ic-utils.h"
+#include "icl.h"
+#include "icl-representation.h"
+#include "icl-list.h"
+#include "icl-value.h"
+
+static iotcon_value_h _icl_value_create(int type)
+{
+ iotcon_value_h ret_val;
+
+ switch (type) {
+ case IOTCON_TYPE_INT:
+ case IOTCON_TYPE_BOOL:
+ case IOTCON_TYPE_DOUBLE:
+ case IOTCON_TYPE_STR:
+ case IOTCON_TYPE_NULL:
+ ret_val = calloc(1, sizeof(icl_basic_s));
+ break;
+ 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));
+ break;
+ default:
+ ERR("Invalid Type(%d)", type);
+ return NULL;
+ }
+
+ if (NULL == ret_val) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ ret_val->type = type;
+
+ return ret_val;
+}
+
+
+iotcon_value_h icl_value_create_null()
+{
+ iotcon_value_h value;
+
+ value = _icl_value_create(IOTCON_TYPE_NULL);
+ if (NULL == value) {
+ ERR("_icl_value_create(NULL) Fail");
+ return NULL;
+ }
+
+ return value;
+}
+
+iotcon_value_h icl_value_create_int(int val)
+{
+ icl_basic_s *value;
+
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_INT);
+ if (NULL == value) {
+ ERR("_icl_value_create(INT:%d) Fail", val);
+ return NULL;
+ }
+
+ value->val.i = val;
+
+ return (iotcon_value_h)value;
+}
+
+iotcon_value_h icl_value_create_bool(bool val)
+{
+ icl_basic_s *value;
+
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_BOOL);
+ if (NULL == value) {
+ ERR("_icl_value_create(BOOL:%d) Fail", val);
+ return NULL;
+ }
+
+ value->val.b = val;
+
+ return (iotcon_value_h)value;
+}
+
+iotcon_value_h icl_value_create_double(double val)
+{
+ icl_basic_s *value;
+
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_DOUBLE);
+ if (NULL == value) {
+ ERR("_icl_value_create(DOUBLE:%f) Fail", val);
+ return NULL;
+ }
+
+ value->val.d = val;
+
+ return (iotcon_value_h)value;
+}
+
+iotcon_value_h icl_value_create_str(const char *val)
+{
+ icl_basic_s *value;
+
+ RETV_IF(NULL == val, NULL);
+
+ value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_STR);
+ if (NULL == value) {
+ ERR("_icl_value_create(STR:%s) Fail", val);
+ return NULL;
+ }
+
+ value->val.s = ic_utils_strdup(val);
+
+ return (iotcon_value_h)value;
+}
+
+
+iotcon_value_h icl_value_create_list(iotcon_list_h val)
+{
+ icl_val_list_s *value;
+
+ value = (icl_val_list_s*)_icl_value_create(IOTCON_TYPE_LIST);
+ if (NULL == value) {
+ ERR("_icl_value_create(LIST) Fail");
+ return NULL;
+ }
+
+ value->list = val;
+
+ return (iotcon_value_h)value;
+}
+
+iotcon_value_h icl_value_create_state(iotcon_state_h val)
+{
+ icl_val_state_s *value;
+
+ value = (icl_val_state_s*)_icl_value_create(IOTCON_TYPE_STATE);
+ if (NULL == value) {
+ ERR("_icl_value_create(state) Fail");
+ return NULL;
+ }
+
+ value->state = val;
+
+ return (iotcon_value_h)value;
+}
+
+int icl_value_get_int(iotcon_value_h value, int *val)
+{
+ icl_basic_s *real = (icl_basic_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_INT != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *val = real->val.i;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_value_get_bool(iotcon_value_h value, bool *val)
+{
+ icl_basic_s *real = (icl_basic_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_BOOL != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *val = real->val.b;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_value_get_double(iotcon_value_h value, double *val)
+{
+ icl_basic_s *real = (icl_basic_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_DOUBLE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *val = real->val.d;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_value_get_str(iotcon_value_h value, char **val)
+{
+ icl_basic_s *real = (icl_basic_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_STR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *val = real->val.s;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list)
+{
+ icl_val_list_s *real = (icl_val_list_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_LIST != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *list = real->list;
+
+ return IOTCON_ERROR_NONE;
+}
+
+int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state)
+{
+ icl_val_state_s *real = (icl_val_state_s*)value;
+
+ RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
+ RETVM_IF(IOTCON_TYPE_STATE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
+ "Invalid Type(%d)", real->type);
+
+ *state = real->state;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+void icl_value_destroy(gpointer data)
+{
+ int ret;
+ iotcon_value_h value;
+ iotcon_list_h list;
+ iotcon_state_h state;
+
+ RET_IF(NULL == data);
+
+ value = data;
+
+ int type = value->type;
+ switch (type) {
+ case IOTCON_TYPE_STR:
+ free(((icl_basic_s*)value)->val.s);
+ case IOTCON_TYPE_INT:
+ case IOTCON_TYPE_BOOL:
+ case IOTCON_TYPE_DOUBLE:
+ case IOTCON_TYPE_NULL:
+ break;
+ case IOTCON_TYPE_LIST:
+ DBG("value is list");
+ ret = icl_value_get_list(value, &list);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_list() Fail(%d)", ret);
+ break;
+ }
+ iotcon_list_destroy(list);
+ break;
+ case IOTCON_TYPE_STATE:
+ DBG("value is Repr");
+ ret = icl_value_get_state(value, &state);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("icl_value_get_state() Fail(%d)", ret);
+ break;
+ }
+ iotcon_state_destroy(state);
+ break;
+ default:
+ ERR("Invalid type(%d)", type);
+ break;
+ }
+ free(value);
+}
+
+
+iotcon_value_h icl_value_clone(iotcon_value_h src)
+{
+ iotcon_value_h dest = NULL;
+ icl_basic_s *real = (icl_basic_s*)src;
+
+ RETV_IF(NULL == src, NULL);
+
+ switch (src->type) {
+ case IOTCON_TYPE_INT:
+ dest = icl_value_create_int(real->val.i);
+ break;
+ case IOTCON_TYPE_BOOL:
+ dest = icl_value_create_bool(real->val.b);
+ break;
+ case IOTCON_TYPE_DOUBLE:
+ dest = icl_value_create_double(real->val.d);
+ break;
+ case IOTCON_TYPE_STR:
+ dest = icl_value_create_str(ic_utils_strdup(real->val.s));
+ break;
+ case IOTCON_TYPE_NULL:
+ dest = icl_value_create_null();
+ break;
+ default:
+ ERR("Invalid type(%d)", src->type);
+ break;
+ }
+
+ if (NULL == dest)
+ ERR("ic_value_create_xxx(%d) Fail", src->type);
+
+ return dest;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_MANAGER_LIBRARY_VALUE_H__
+#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_VALUE_H__
+
+#include <glib.h>
+#include <tizen_type.h>
+
+#include "iotcon-struct.h"
+
+struct icl_value_s {
+ int type;
+};
+
+typedef struct {
+ int type;
+ union {
+ int i;
+ bool b;
+ double d;
+ char *s;
+ } val;
+} icl_basic_s;
+
+typedef struct {
+ int type;
+ struct icl_list_s *list;
+} icl_val_list_s;
+
+typedef struct {
+ int type;
+ struct icl_state_s *state;
+} icl_val_state_s;
+
+/**
+ * @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
+ * @brief The handle of representation value.
+ * @details iotcon_value_h is an opaque data structure to have variant datatype and
+ * store values along with information about the type of that value.\n
+ * The range of possible values is determined by the type.\n
+ * The type of iotcon_value_h should be one of them\n
+ * #IOTCON_TYPE_INT\n
+ * #IOTCON_TYPE_BOOL\n
+ * #IOTCON_TYPE_DOUBLE\n
+ * #IOTCON_TYPE_STR\n
+ * #IOTCON_TYPE_NULL\n
+ * #IOTCON_TYPE_LIST\n
+ * #IOTCON_TYPE_STATE
+ *
+ * @since_tizen 3.0
+ */
+typedef struct icl_value_s* iotcon_value_h;
+
+iotcon_value_h icl_value_create_null();
+iotcon_value_h icl_value_create_int(int val);
+iotcon_value_h icl_value_create_bool(bool val);
+iotcon_value_h icl_value_create_double(double val);
+iotcon_value_h icl_value_create_str(const char *val);
+iotcon_value_h icl_value_create_list(iotcon_list_h val);
+iotcon_value_h icl_value_create_state(iotcon_state_h val);
+
+
+int icl_value_get_int(iotcon_value_h value, int *val);
+int icl_value_get_bool(iotcon_value_h value, bool *val);
+int icl_value_get_double(iotcon_value_h value, double *val);
+int icl_value_get_str(iotcon_value_h value, char **val);
+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);
+
+void icl_value_destroy(gpointer data);
+
+iotcon_value_h icl_value_clone(iotcon_value_h src);
+
+#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_VALUE_H__ */