Remove ICL_CONTAINED_RESOURCES_MAX 23/65223/8
authoryoungman <yman.jung@samsung.com>
Fri, 8 Apr 2016 02:42:52 +0000 (11:42 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 20 Apr 2016 04:20:08 +0000 (21:20 -0700)
Change-Id: Ie656c841a185a53a35a098939111b23039087c03
Signed-off-by: youngman <yman.jung@samsung.com>
lib/icl-ioty.c
lib/icl-representation.c
lib/icl-resource.c
lib/icl-resource.h

index 342ba344de21566679fc533c093e2cb55df6ce23..a1103d6f66b60dec67db9a3455366c9d27398b05 100644 (file)
@@ -1433,48 +1433,33 @@ int icl_ioty_resource_bind_child_resource(iotcon_resource_h parent,
                iotcon_resource_h child)
 {
        FN_CALL;
-       int i, ret;
+       OCStackResult ret;
        OCResourceHandle handle_parent, handle_child;
 
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(parent == child, IOTCON_ERROR_INVALID_PARAMETER);
 
-       for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
-               if (child == parent->children[i]) {
-                       ERR("Child resource was already bound to parent resource.");
-                       return IOTCON_ERROR_ALREADY;
-               }
-       }
-
        handle_parent = IC_INT64_TO_POINTER(parent->handle);
        handle_child = IC_INT64_TO_POINTER(child->handle);
 
-       for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
-               if (NULL == parent->children[i]) {
-                       icl_ioty_csdk_lock();
-                       ret = OCBindResource(handle_parent, handle_child);
-                       icl_ioty_csdk_unlock();
-
-                       if (OC_STACK_OK != ret) {
-                               ERR("OCBindResource() Fail(%d)", ret);
-                               return ic_ioty_parse_oic_error(ret);
-                       }
+       icl_ioty_csdk_lock();
+       ret = OCBindResource(handle_parent, handle_child);
+       icl_ioty_csdk_unlock();
 
-                       parent->children[i] = child;
-                       return IOTCON_ERROR_NONE;
-               }
+       if (OC_STACK_OK != ret) {
+               ERR("OCBindResource() Fail(%d)", ret);
+               return ic_ioty_parse_oic_error(ret);
        }
 
-       ERR("There is no slot to bind a child resource");
-       return IOTCON_ERROR_OUT_OF_MEMORY;
+       return IOTCON_ERROR_NONE;
 }
 
 int icl_ioty_resource_unbind_child_resource(iotcon_resource_h parent,
                iotcon_resource_h child)
 {
        FN_CALL;
-       int i, ret;
+       OCStackResult ret;
        OCResourceHandle handle_parent, handle_child;
 
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
@@ -1492,11 +1477,6 @@ int icl_ioty_resource_unbind_child_resource(iotcon_resource_h parent,
                return ic_ioty_parse_oic_error(ret);
        }
 
-       for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
-               if (child == parent->children[i])
-                       parent->children[i] = NULL;
-       }
-
        return IOTCON_ERROR_NONE;
 }
 
index 637ba7ebe48ba11fa2bb08d1c57839b39f34181b..41085c102881a9b07e03b326d62bd3c196088cdd 100644 (file)
@@ -282,10 +282,7 @@ API int iotcon_representation_get_children_count(iotcon_representation_h parent,
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == count, IOTCON_ERROR_INVALID_PARAMETER);
 
-       if (NULL == parent->children)
-               *count = 0;
-       else
-               *count = g_list_length(parent->children);
+       *count = g_list_length(parent->children);
 
        return IOTCON_ERROR_NONE;
 }
@@ -293,17 +290,22 @@ API int iotcon_representation_get_children_count(iotcon_representation_h parent,
 API int iotcon_representation_get_nth_child(iotcon_representation_h parent,
                int pos, iotcon_representation_h *child)
 {
+       iotcon_representation_h repr;
+
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        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);
+       RETV_IF(pos < 0, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == parent->children, IOTCON_ERROR_NO_DATA);
 
-       *child = g_list_nth_data(parent->children, pos);
-       if (NULL == *child) {
+       repr = g_list_nth_data(parent->children, pos);
+       if (NULL == repr) {
                ERR("g_list_nth_data() Fail");
                return IOTCON_ERROR_NO_DATA;
        }
 
+       *child = repr;
+
        return IOTCON_ERROR_NONE;
 }
 
index 81ec1e2b6d314b99b40369096d9cb1d89086fc47..11dcfaf8db1821da1bc84602177233ff72abaac4 100644 (file)
@@ -243,7 +243,7 @@ API int iotcon_resource_set_request_handler(iotcon_resource_h resource,
 API int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
                iotcon_resource_h child)
 {
-       int i, ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(), IOTCON_ERROR_PERMISSION_DENIED);
@@ -251,27 +251,18 @@ API int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
        RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(parent == child, IOTCON_ERROR_INVALID_PARAMETER);
 
-       for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
-               if (child == parent->children[i]) {
-                       ERR("Child resource was already bound to parent resource.");
-                       return IOTCON_ERROR_ALREADY;
-               }
+       if (g_list_find(parent->children, child)) {
+               ERR("Child resource was already bound to parent resource.");
+               return IOTCON_ERROR_ALREADY;
        }
 
-       connectivity_type = parent->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_resource_bind_child_resource(parent, child);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_resource_bind_child_resource() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       ret = icl_ioty_resource_bind_child_resource(parent, child);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_resource_bind_child_resource() Fail(%d)", ret);
+               return ret;
        }
+       parent->children = g_list_append(parent->children, child);
+
        return IOTCON_ERROR_NONE;
 }
 
@@ -279,28 +270,31 @@ API int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
 API int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
                iotcon_resource_h child)
 {
-       int ret, connectivity_type;
+       int ret;
 
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(false == ic_utils_check_permission(), IOTCON_ERROR_PERMISSION_DENIED);
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
 
-       connectivity_type = parent->connectivity_type;
-
-       switch (connectivity_type) {
-       case IOTCON_CONNECTIVITY_ALL:
-               ret = icl_ioty_resource_unbind_child_resource(parent, child);
-               if (IOTCON_ERROR_NONE != ret) {
-                       ERR("icl_ioty_resource_unbind_child_resource() Fail(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               ERR("Invalid Connectivity Type(%d)", connectivity_type);
+       if (NULL == g_list_find(parent->children, child)) {
+               ERR("child resource is not bound to parent resource.");
                return IOTCON_ERROR_INVALID_PARAMETER;
        }
 
+       ret = icl_ioty_resource_unbind_child_resource(parent, child);
+       if (IOTCON_ERROR_NONE != ret) {
+               ERR("icl_ioty_resource_unbind_child_resource() Fail(%d)", ret);
+               return ret;
+       }
+
+       parent->children = g_list_remove(parent->children, child);
+
+       if (0 == g_list_length(parent->children)) {
+               g_list_free(parent->children);
+               parent->children = NULL;
+       }
+
        return IOTCON_ERROR_NONE;
 }
 
@@ -308,17 +302,11 @@ API int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
 API int iotcon_resource_get_number_of_children(iotcon_resource_h resource,
                int *number)
 {
-       int i;
-
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == number, IOTCON_ERROR_INVALID_PARAMETER);
 
-       *number = 0;
-       for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
-               if (resource->children[i])
-                       *number += 1;
-       }
+       *number = g_list_length(resource->children);
 
        return IOTCON_ERROR_NONE;
 }
@@ -327,16 +315,21 @@ API int iotcon_resource_get_number_of_children(iotcon_resource_h resource,
 API int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
                iotcon_resource_h *child)
 {
+       iotcon_resource_h resource;
+
        RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
        RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-       if ((index < 0) || (ICL_CONTAINED_RESOURCES_MAX <= index)) {
-               ERR("Invalid index(%d)", index);
-               return IOTCON_ERROR_INVALID_PARAMETER;
+       RETV_IF(index < 0, IOTCON_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == parent->children, IOTCON_ERROR_NO_DATA);
+
+       resource = g_list_nth_data(parent->children, index);
+       if (NULL == resource) {
+               ERR("g_list_nth_data() Fail");
+               return IOTCON_ERROR_NO_DATA;
        }
-       RETV_IF(NULL == parent->children[index], IOTCON_ERROR_NO_DATA);
 
-       *child = parent->children[index];
+       *child = resource;
 
        return IOTCON_ERROR_NONE;
 }
index 6f3cb744564f816e142dfcd63c140c92ac4c9dd1..9f99edfcaafdbca5fcaf33c7fad42132a705a752 100644 (file)
 #define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__
 
 #include <stdint.h>
+#include <glib.h>
 
 #include "iotcon-types.h"
 
-/**
- * @brief The maximum number of children resources which can be held in a parent resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_CONTAINED_RESOURCES_MAX 5
-
 /**
  * @brief The maximum length of uri_path which can be held in a resource.
  *
@@ -47,9 +41,9 @@ struct icl_resource {
        iotcon_request_handler_cb cb;
        void *user_data;
        int64_t handle;
-       iotcon_resource_h children[ICL_CONTAINED_RESOURCES_MAX];
        iotcon_observers_h observers;
        iotcon_connectivity_type_e connectivity_type;
+       GList *children;
 };
 
 bool icl_resource_check_uri_path(const char *uri_path);