#include "icl-value.h"
#include "icl-list.h"
-void icl_list_inc_ref_count(iotcon_list_h val)
+iotcon_list_h icl_list_ref(iotcon_list_h list)
{
- 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)
-{
- RETV_IF(NULL == val, false);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+ RETV_IF(NULL == list, NULL);
+ RETV_IF(list->ref_count <= 0, NULL);
- val->ref_count--;
- if (0 == val->ref_count)
- return true;
+ list->ref_count++;
- return false;
+ return list;
}
-static int _icl_list_create(iotcon_type_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_type_e type, iotcon_list_h *ret_list)
{
- int ret;
iotcon_list_h list;
RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
return IOTCON_ERROR_INVALID_TYPE;
}
- ret = _icl_list_create(type, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_create() Fail");
- return ret;
+ list = calloc(1, sizeof(struct icl_list_s));
+ if (NULL == list) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
}
+ list->ref_count = 1;
+ list->type = type;
+
*ret_list = list;
return IOTCON_ERROR_NONE;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- icl_list_inc_ref_count(val);
-
return icl_list_insert(list, value, pos);
}
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);
}
{
RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == length, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
-
- *length = g_list_length(list->list);
+ if (NULL == list->list)
+ *length = 0;
+ else
+ *length = g_list_length(list->list);
return IOTCON_ERROR_NONE;
}
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))
+ list->ref_count--;
+
+ if (0 != list->ref_count)
return;
cur = list->list;
iotcon_list_h icl_list_clone(iotcon_list_h list);
-void icl_list_inc_ref_count(iotcon_list_h val);
+iotcon_list_h icl_list_ref(iotcon_list_h list);
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__ */
gpointer key, value;
iotcon_value_h res_value, src_value;
+ if (NULL == res_state) {
+ DBG("resource_state is NULL");
+ return IOTCON_ERROR_NONE;
+ }
+
g_hash_table_iter_init(&iter, state->hash_table);
while (g_hash_table_iter_next(&iter, &key, &value)) {
res_value = g_hash_table_lookup(res_state->hash_table, key);
response->result = response_result;
response->oic_request_h = oic_request_h;
response->oic_resource_h = oic_resource_h;
- response->repr = repr;
- icl_representation_inc_ref_count(response->repr);
+ if (repr)
+ response->repr = icl_representation_ref(repr);
ret = iotcon_response_send(response);
if (IOTCON_ERROR_NONE != ret) {
return;
}
- iotcon_state_destroy(resource->state);
+ if (resource->state)
+ iotcon_state_destroy(resource->state);
free(resource->uri_path);
free(resource);
}
resource->properties = properties;
resource->uri_path = ic_utils_strdup(uri_path);
-
- ret = icl_state_clone(state, &(resource->state));
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_state_clone() Fail(%d)", ret);
- free(resource->uri_path);
- free(resource);
- return ret;
- }
+ if (state)
+ resource->state = icl_state_ref(state);
snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
signal_number);
_icl_lite_resource_conn_cleanup, _icl_lite_resource_request_handler);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
- iotcon_state_destroy(resource->state);
+ if (resource->state)
+ iotcon_state_destroy(resource->state);
free(resource->uri_path);
free(resource);
return IOTCON_ERROR_DBUS;
iotcon_state_h state)
{
int ret;
- iotcon_state_h cloned_state = NULL;
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- ret = icl_state_clone(state, &cloned_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_state_clone() Fail(%d)", ret);
- return ret;
- }
+ if (state)
+ state = icl_state_ref(state);
- iotcon_state_destroy(resource->state);
+ if (resource->state)
+ iotcon_state_destroy(resource->state);
- resource->state = cloned_state;
+ resource->state = state;
ret = _icl_lite_resource_notify(resource);
if (IOTCON_ERROR_NONE != ret)
#include "ic-utils.h"
#include "icl.h"
#include "icl-representation.h"
+#include "icl-state.h"
#include "icl-list.h"
#include "icl-value.h"
#include "icl-resource-types.h"
{
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
+ if (options)
+ options = icl_options_ref(options);
+
if (resource->header_options)
iotcon_options_destroy(resource->header_options);
- if (options)
- resource->header_options = icl_options_ref(options);
- else
- resource->header_options = NULL;
+ resource->header_options = options;
return IOTCON_ERROR_NONE;
}
#include "icl-state.h"
#include "icl-representation.h"
-void icl_representation_inc_ref_count(iotcon_representation_h val)
+iotcon_representation_h icl_representation_ref(iotcon_representation_h repr)
{
- RET_IF(NULL == val);
- RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+ RETV_IF(NULL == repr, NULL);
+ RETV_IF(repr->ref_count <= 0, NULL);
- val->ref_count++;
-}
-
-
-static bool _icl_representation_dec_ref_count(iotcon_representation_h val)
-{
- RETV_IF(NULL == val, false);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+ repr->ref_count++;
- val->ref_count--;
- if (0 == val->ref_count)
- return true;
-
- return false;
+ return repr;
}
}
repr->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
- icl_representation_inc_ref_count(repr);
+ repr->ref_count = 1;
*ret_repr = repr;
{
RET_IF(NULL == repr);
- if (false == _icl_representation_dec_ref_count(repr))
+ repr->ref_count--;
+
+ if (0 != repr->ref_count)
return;
free(repr->uri_path);
{
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);
+ types = icl_resource_types_ref(types);
+
+ if (repr->res_types)
+ iotcon_resource_types_destroy(repr->res_types);
+
+ repr->res_types = types;
return IOTCON_ERROR_NONE;
}
{
RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- if (state == repr->state)
- return IOTCON_ERROR_NONE;
+ if (state)
+ state = icl_state_ref(state);
- if (repr->state) {
+ if (repr->state)
iotcon_state_destroy(repr->state);
- repr->state = NULL;
- }
-
- if (state)
- icl_state_inc_ref_count(state);
repr->state = state;
API int iotcon_representation_add_child(iotcon_representation_h parent,
iotcon_representation_h child)
{
+ iotcon_representation_h repr;
+
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);
+ repr = icl_representation_ref(child);
+
+ parent->children = g_list_append(parent->children, repr);
return IOTCON_ERROR_NONE;
}
parent->children = g_list_remove(parent->children, child);
+ iotcon_representation_destroy(child);
+
return IOTCON_ERROR_NONE;
}
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 == count, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
-
- *count = g_hash_table_size(state->hash_table);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-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)
struct icl_state_s *state;
};
-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);
+iotcon_representation_h icl_representation_ref(iotcon_representation_h repr);
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
{
RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+ resp->iface = iface;
+
+ if (repr)
+ repr = icl_representation_ref(repr);
+
if (resp->repr)
iotcon_representation_destroy(resp->repr);
- resp->iface = iface;
+
resp->repr = repr;
- if (repr)
- icl_representation_inc_ref_count(resp->repr);
return IOTCON_ERROR_NONE;
}
{
RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
+ if (options)
+ options = icl_options_ref(options);
+
if (resp->header_options)
iotcon_options_destroy(resp->header_options);
- if (options)
- resp->header_options = icl_options_ref(options);
- else
- resp->header_options = NULL;
+ resp->header_options = options;
return IOTCON_ERROR_NONE;
}
#include "icl-representation.h"
#include "icl-state.h"
-void icl_state_inc_ref_count(iotcon_state_h val)
+iotcon_state_h icl_state_ref(iotcon_state_h state)
{
- RET_IF(NULL == val);
- RETM_IF(val->ref_count < 0, "Invalid Count(%d)", val->ref_count);
+ RETV_IF(NULL == state, NULL);
+ RETV_IF(state->ref_count <= 0, NULL);
- val->ref_count++;
-}
-
-
-static bool _icl_state_dec_ref_count(iotcon_state_h val)
-{
- RETV_IF(NULL == val, false);
- RETVM_IF(val->ref_count <= 0, false, "Invalid Count(%d)", val->ref_count);
+ state->ref_count++;
- val->ref_count--;
- if (0 == val->ref_count)
- return true;
-
- return false;
+ return state;
}
state->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
icl_value_destroy);
- icl_state_inc_ref_count(state);
+ state->ref_count = 1;
*ret_state = state;
{
RET_IF(NULL == state);
- if (false == _icl_state_dec_ref_count(state))
+ state->ref_count--;
+
+ if (0 != state->ref_count)
return;
g_hash_table_destroy(state->hash_table);
free(state);
}
-API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone)
-{
- int ret;
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state_clone, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icl_state_clone(state, state_clone);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_state_clone() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
int icl_state_del_value(iotcon_state_h state, const char *key)
{
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);
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);
}
-int icl_state_clone(iotcon_state_h src, iotcon_state_h *dest)
+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 == count, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
+
+ *count = g_hash_table_size(state->hash_table);
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone)
{
int ret;
- iotcon_state_h cloned_state = NULL;
+ iotcon_state_h temp = NULL;
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == state_clone, IOTCON_ERROR_INVALID_PARAMETER);
- if (src->hash_table) {
- ret = iotcon_state_create(&cloned_state);
+ if (state->hash_table) {
+ ret = iotcon_state_create(&temp);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_state_create() Fail(%d)", ret);
return ret;
}
- g_hash_table_foreach(src->hash_table, (GHFunc)icl_state_clone_foreach,
- cloned_state);
+ g_hash_table_foreach(state->hash_table, (GHFunc)icl_state_clone_foreach, temp);
+ }
+
+ *state_clone = temp;
+
+ return IOTCON_ERROR_NONE;
+}
+
+
+void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state)
+{
+ FN_CALL;
+ 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;
}
+}
- *dest = cloned_state;
+
+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;
}
+
#include "icl-value.h"
#include "icl-representation.h"
-void icl_state_inc_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);
+void icl_state_clone_foreach(char *key, iotcon_value_h src_val,
+ iotcon_state_h dest_state);
+
+iotcon_state_h icl_state_ref(iotcon_state_h state);
#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__ */
#include "icl.h"
#include "icl-representation.h"
#include "icl-list.h"
+#include "icl-state.h"
#include "icl-value.h"
static iotcon_value_h _icl_value_create(int type)
return NULL;
}
- value->list = val;
+ value->list = icl_list_ref(val);
return (iotcon_value_h)value;
}
return NULL;
}
- value->state = val;
+ value->state = icl_state_ref(val);
return (iotcon_value_h)value;
}