}
-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)
{
GList *cur = NULL;
}
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:
- case IOTCON_TYPE_BYTE_STR:
- 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;
-}