Fix resource bind problem accepted/tizen/mobile/20151223.110657 accepted/tizen/tv/20151223.110646 accepted/tizen/wearable/20151223.110752 submit/tizen/20151223.091434
authoryoungman <yman.jung@samsung.com>
Fri, 18 Dec 2015 05:25:41 +0000 (14:25 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 22 Dec 2015 08:21:50 +0000 (17:21 +0900)
Change-Id: Ie2bda7e1b32cf6fea41cc8893653277051d7f93e
Signed-off-by: youngman <yman.jung@samsung.com>
lib/icl-resource.c

index 86b3a46..277c018 100644 (file)
@@ -288,6 +288,11 @@ API int iotcon_resource_bind_interface(iotcon_resource_h resource,
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
+       if (resource->ifaces & iface) {
+               ERR("iface(%d) is already contained.", iface);
+               return IOTCON_ERROR_INVALID_PARAMETER;
+       }
+
        ic_dbus_call_bind_interface_sync(icl_dbus_get_object(), resource->handle,
                        iface, &ret, NULL, &error);
        if (error) {
@@ -301,6 +306,7 @@ API int iotcon_resource_bind_interface(iotcon_resource_h resource,
                ERR("iotcon-daemon Fail(%d)", ret);
                return icl_dbus_convert_daemon_error(ret);
        }
+       resource->ifaces |= iface;
 
        return ret;
 }
@@ -311,34 +317,48 @@ API int iotcon_resource_bind_type(iotcon_resource_h resource, const char *resour
        FN_CALL;
        int ret;
        GError *error = NULL;
+       iotcon_resource_types_h resource_types;
 
        RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
-       if (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type)) {
-               ERR("Invalid resource_type(%s)", resource_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
-       }
-
        if (0 == resource->sub_id) {
                ERR("Invalid Resource handle");
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
+       ret = iotcon_resource_types_clone(resource->types, &resource_types);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_types_clone() Fail(%d)", ret);
+               return ret;
+       }
+
+       ret = iotcon_resource_types_add(resource_types, resource_type);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("iotcon_resource_types_add() Fail(%d)", ret);
+               iotcon_resource_types_destroy(resource_types);
+               return ret;
+       }
+
        ic_dbus_call_bind_type_sync(icl_dbus_get_object(), resource->handle, resource_type,
                        &ret, NULL, &error);
        if (error) {
                ERR("ic_dbus_call_bind_type_sync() Fail(%s)", error->message);
                ret = icl_dbus_convert_dbus_error(error->code);
                g_error_free(error);
+               iotcon_resource_types_destroy(resource_types);
                return ret;
        }
 
        if (IOTCON_ERROR_NONE != ret) {
                ERR("iotcon-daemon Fail(%d)", ret);
+               iotcon_resource_types_destroy(resource_types);
                return icl_dbus_convert_daemon_error(ret);
        }
 
+       iotcon_resource_types_destroy(resource->types);
+       resource->types = resource_types;
+
        return ret;
 }