iotcon_remote_resource_h resource;
} icl_on_observe_s;
+static GList *icl_cru_cb_list = NULL;
+static GList *icl_delete_cb_list = NULL;
+
+void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource)
+{
+ GList *c;
+ for (c = icl_cru_cb_list; c; c = c->next) {
+ icl_on_cru_s *cb_container = c->data;
+ if (NULL == cb_container) {
+ ERR("cb_container is NULL");
+ continue;
+ }
+ if (cb_container->resource == resource)
+ cb_container->cb = NULL;
+ }
+
+ for (c = icl_delete_cb_list; c; c = c->next) {
+ icl_on_delete_s *cb_container = c->data;
+ if (NULL == cb_container) {
+ ERR("cb_container is NULL");
+ continue;
+ }
+ if (cb_container->resource == resource)
+ cb_container->cb = NULL;
+ }
+}
+
static void _icl_on_cru_cb(GVariant *result, icl_on_cru_s *cb_container)
{
g_variant_get(result, "(a(qs)vi)", &options, &repr_gvar, &res);
+ icl_cru_cb_list = g_list_remove(icl_cru_cb_list, cb_container);
+
if (IOTCON_ERROR_NONE == res && g_variant_iter_n_children(options)) {
ret = iotcon_options_create(&header_options);
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_options_create() Fail(%d)", ret);
+ free(cb_container);
return;
}
ERR("icl_representation_from_gvariant() Fail");
if (header_options)
iotcon_options_destroy(header_options);
-
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (header_options)
iotcon_options_destroy(header_options);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
}
if (error) {
ERR("ic_dbus_call_get_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (error) {
ERR("ic_dbus_call_put_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (error) {
ERR("ic_dbus_call_post_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
iotcon_query_h query, iotcon_remote_resource_cru_cb cb, void *user_data)
{
- int ret;
GVariant *arg_query;
GVariant *arg_remote_resource;
icl_on_cru_s *cb_container;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail");
- free(cb_container);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
+ cb_container->resource = resource;
cb_container->cb = cb;
cb_container->user_data = user_data;
ic_dbus_call_get(icl_dbus_get_object(), arg_remote_resource, arg_query, NULL,
_icl_on_get_cb, cb_container);
+ icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container);
+
return IOTCON_ERROR_NONE;
}
iotcon_remote_resource_cru_cb cb,
void *user_data)
{
- int ret;
GVariant *arg_repr;
GVariant *arg_remote_resource;
GVariant *arg_query;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail");
- free(cb_container);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
+ cb_container->resource = resource;
cb_container->cb = cb;
cb_container->user_data = user_data;
arg_repr = icl_representation_to_gvariant(repr);
if (NULL == arg_repr) {
ERR("icl_representation_to_gvariant() Fail");
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return IOTCON_ERROR_REPRESENTATION;
}
ic_dbus_call_put(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
NULL, _icl_on_put_cb, cb_container);
+ icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container);
+
return IOTCON_ERROR_NONE;
}
iotcon_remote_resource_cru_cb cb,
void *user_data)
{
- int ret;
GVariant *arg_repr;
GVariant *arg_query;
GVariant *arg_remote_resource;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail");
- free(cb_container);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
+ cb_container->resource = resource;
cb_container->cb = cb;
cb_container->user_data = user_data;
arg_repr = icl_representation_to_gvariant(repr);
if (NULL == arg_repr) {
ERR("icl_representation_to_gvariant() Fail");
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return IOTCON_ERROR_REPRESENTATION;
}
ic_dbus_call_post(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
NULL, _icl_on_post_cb, cb_container);
+ icl_cru_cb_list = g_list_append(icl_cru_cb_list, cb_container);
+
return IOTCON_ERROR_NONE;
}
icl_on_delete_s *cb_container = user_data;
iotcon_remote_resource_delete_cb cb = cb_container->cb;
+ icl_delete_cb_list = g_list_remove(icl_delete_cb_list, cb_container);
+
ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error);
if (error) {
ERR("ic_dbus_call_delete_finish() Fail(%s)", error->message);
g_error_free(error);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_options_create() Fail(%d)", ret);
g_variant_iter_free(options);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (header_options)
iotcon_options_destroy(header_options);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
}
API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
iotcon_remote_resource_delete_cb cb, void *user_data)
{
- int ret;
GVariant *arg_remote_resource;
icl_on_delete_s *cb_container;
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail");
- free(cb_container);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
+ cb_container->resource = resource;
cb_container->cb = cb;
cb_container->user_data = user_data;
ic_dbus_call_delete(icl_dbus_get_object(), arg_remote_resource, NULL,
_icl_on_delete_cb, cb_container);
+ icl_delete_cb_list = g_list_append(icl_delete_cb_list, cb_container);
+
return IOTCON_ERROR_NONE;
}
if (IOTCON_ERROR_NONE != ret) {
ERR("iotcon_options_create() Fail(%d)", ret);
g_variant_iter_free(options);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
if (header_options)
iotcon_options_destroy(header_options);
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return;
}
{
cb_container->resource->observe_handle = 0;
cb_container->resource->observe_sub_id = 0;
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
}
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
+ RETV_IF(resource->observe_handle || resource->observe_sub_id, IOTCON_ERROR_ALREADY);
signal_number = icl_dbus_generate_signal_number();
return IOTCON_ERROR_OUT_OF_MEMORY;
}
- ret = iotcon_remote_resource_ref(resource, &cb_container->resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail");
- free(cb_container);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
+ cb_container->resource = resource;
cb_container->cb = cb;
cb_container->user_data = user_data;
_icl_observe_conn_cleanup, _icl_on_observe_cb);
if (0 == sub_id) {
ERR("icl_dbus_subscribe_signal() Fail");
- iotcon_remote_resource_destroy(cb_container->resource);
free(cb_container);
return IOTCON_ERROR_DBUS;
}
resource->types = icl_resource_types_ref(resource_types);
resource->ifaces = resource_ifs;
- resource->ref_count = 1;
-
*resource_handle = resource;
return IOTCON_ERROR_NONE;
{
RET_IF(NULL == resource);
- resource->ref_count--;
+ if (resource->observe_handle)
+ iotcon_remote_resource_observer_stop(resource);
- if (0 < resource->ref_count)
- return;
+ icl_remote_resource_crud_stop(resource);
free(resource->uri_path);
free(resource->host);
free(resource);
}
+static int _icl_remote_resource_header_foreach_cb(unsigned short id,
+ const char *data, void *user_data)
+{
+ int ret;
+ iotcon_remote_resource_h resource = user_data;
+
+ RETV_IF(NULL == resource, IOTCON_FUNC_STOP);
+
+ if (NULL == resource->header_options) {
+ ret = iotcon_options_create(&resource->header_options);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("resource->header_options() Fail(%d)", ret);
+ return IOTCON_FUNC_STOP;
+ }
+ }
-API int iotcon_remote_resource_ref(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest)
+ ret = iotcon_options_insert(resource->header_options, id, data);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_insert() Fail(%d)", ret);
+ return IOTCON_FUNC_STOP;
+ }
+
+ return IOTCON_FUNC_CONTINUE;
+}
+
+API int iotcon_remote_resource_clone(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest)
{
+ int ret;
+ iotcon_remote_resource_h resource = NULL;
+
RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(src->ref_count <= 0, IOTCON_ERROR_INVALID_PARAMETER);
- src->ref_count++;
+ resource = calloc(1, sizeof(struct icl_remote_resource));
+ if (NULL == resource) {
+ ERR("calloc() Fail(%d)", errno);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+
+ resource->uri_path = ic_utils_strdup(src->uri_path);
+ resource->host = ic_utils_strdup(src->host);
+ resource->device_id = ic_utils_strdup(src->device_id);
+ resource->is_secure = src->is_secure;
+ resource->is_observable = src->is_observable;
+
+ if (src->header_options) {
+ ret = iotcon_options_foreach(src->header_options,
+ _icl_remote_resource_header_foreach_cb, resource);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_options_foreach() Fail(%d)", ret);
+ iotcon_remote_resource_destroy(resource);
+ return ret;
+ }
+ }
+
+ if (src->types) {
+ ret = iotcon_resource_types_clone(src->types, &resource->types);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_resource_types_clone() Fail(%d)", ret);
+ iotcon_remote_resource_destroy(resource);
+ return ret;
+ }
+ }
+
+ resource->ifaces = src->ifaces;
+ resource->conn_type = src->conn_type;
- *dest = src;
+ *dest = resource;
return IOTCON_ERROR_NONE;
}
ERR("iotcon_remote_resource_create() Fail");
return NULL;
}
- resource->ref_count = 1;
resource->device_id = strdup(device_id);
if (NULL == resource->device_id) {
static int i = 0;
i++;
- if (2 == i)
+ if (2 == i) {
iotcon_remote_resource_observer_stop(resource);
+ iotcon_remote_resource_destroy(resource);
+ }
}
static void _on_delete(iotcon_remote_resource_h resource, iotcon_options_h header_options,
if (IOTCON_ERROR_NONE != ret)
ERR("iotcon_remote_resource_observer_start() Fail(%d)", ret);
- iotcon_remote_resource_destroy(door_resource);
+ iotcon_remote_resource_destroy(resource);
}
static void _on_post(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr,
return;
}
- ret = iotcon_remote_resource_ref(resource, &door_resource);
+ ret = iotcon_remote_resource_clone(resource, &door_resource);
if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_ref() Fail(%d)", ret);
+ ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
iotcon_remote_resource_destroy(new_door_resource);
return;
}
return;
}
- iotcon_remote_resource_destroy(new_door_resource);
+ iotcon_remote_resource_destroy(resource);
}
static void _on_put(iotcon_remote_resource_h resource, iotcon_representation_h recv_repr,
int ret, resource_interfaces;
iotcon_presence_h presence_handle;
iotcon_resource_types_h resource_types;
+ iotcon_remote_resource_h resource_clone = NULL;
if (NULL == resource)
return;
return;
}
+ ret = iotcon_remote_resource_clone(resource, &resource_clone);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
+ iotcon_query_destroy(query);
+ device_id_list = g_list_remove(device_id_list, door_resource_device_id);
+ free(door_resource_device_id);
+ return;
+ }
+
/* send GET Request */
- ret = iotcon_remote_resource_get(resource, query, _on_get, NULL);
+ ret = iotcon_remote_resource_get(resource_clone, query, _on_get, NULL);
if (IOTCON_ERROR_NONE != ret)
ERR("iotcon_remote_resource_get() Fail(%d)", ret);