util: resource: Add detailed error log for debugging 80/278380/5 accepted/tizen/unified/20220722.031019 submit/tizen/20220721.102406
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 19 Jul 2022 08:29:37 +0000 (17:29 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 21 Jul 2022 02:06:37 +0000 (11:06 +0900)
Change-Id: Id740972f6baf00b3675a414b336f7e62cc9a2b63
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/util/resource.c

index a07cace..0e4f9bb 100644 (file)
@@ -185,8 +185,11 @@ struct resource *create_resource(int resource_type)
        int i, ret;
 
        driver = find_resource_driver(resource_type);
-       if (!driver)
+       if (!driver) {
+               _E("failed to find resource driver, res:type(%d)\n",
+                                               resource_type);
                return NULL;
+       }
 
        resource = calloc(1, sizeof(*resource));
        if (!resource)
@@ -214,6 +217,8 @@ struct resource *create_resource(int resource_type)
        if (driver->ops.init) {
                ret = driver->ops.init(resource);
                if (ret < 0) {
+                       _E("failed to initialize resource driver, res:type(%s)id(%d)\n",
+                                               resource->name, resource->id);
                        do_delete_resource(resource);
                        return NULL;
                }
@@ -228,8 +233,10 @@ int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const voi
        int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
        int ret;
 
-       if (!resource)
+       if (!resource) {
+               _E("Invalid parameter\n");
                return -EINVAL;
+       }
 
        ctrl = &resource->ctrls[ctrl_index];
        if (!ctrl->ops.set)
@@ -261,19 +268,29 @@ static int update_resource_attr(struct resource *resource, u_int64_t attr_id)
        struct resource_attribute_value *attr_value = NULL;
        int ret;
 
-       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
+               _E("Invalid parameter\n");
                return -EINVAL;
+       }
 
        attr = &resource->attrs[attr_index];
 
-       if (!attr->ops.get)
+       if (!attr->ops.get) {
+               _E("don't support get ops of resource attribute value, res:type(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+                               resource->name, resource->id,
+                               attr->name, attr_id);
                return -EINVAL;
+       }
 
        attr_value = &resource->attrs_value[attr_index];
 
        ret = attr->ops.get(resource, attr, attr_value->data);
-       if (ret < 0)
+       if (ret < 0) {
+               _E("failed to get resource attribute value, res:type(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+                               resource->name, resource->id,
+                               attr->name, attr_id);
                return ret;
+       }
 
        return 0;
 }
@@ -289,8 +306,11 @@ int update_resource_attrs(struct resource *resource)
 
        if (resource->driver && resource->driver->ops.prepare_update) {
                ret = resource->driver->ops.prepare_update(resource);
-               if (ret < 0)
+               if (ret < 0) {
+                       _E("failed to prepare_update resource driver, res:type(%s)id(%d)\n",
+                                       resource->name, resource->id);
                        return ret;
+               }
        }
 
        for (i = 0; i < resource->num_attrs; i++) {
@@ -298,8 +318,9 @@ int update_resource_attrs(struct resource *resource)
                        continue;
                ret = update_resource_attr(resource, resource->attrs[i].id);
                if (ret < 0) {
-                       _E("failed to update resource attr (%s)\n",
-                                       resource->attrs[i].name);
+                       _E("failed to update resource attribute, res:type(%s)id(%d) | attr:name(%s)id(%"PRId64")\n",
+                               resource->name, resource->id,
+                               resource->attrs[i].name, resource->attrs[i].id);
                }
        }
 
@@ -313,8 +334,10 @@ get_resource_attr(struct resource *resource, u_int64_t attr_id)
 {
        int attr_index = RESOURCE_ATTR_INDEX(attr_id);
 
-       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
+               _E("Invalid parameter\n");
                return NULL;
+       }
 
        return &resource->attrs[attr_index];
 }
@@ -324,8 +347,10 @@ get_resource_attr_value(struct resource *resource, u_int64_t attr_id)
 {
        int attr_index = RESOURCE_ATTR_INDEX(attr_id);
 
-       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
+               _E("Invalid parameter\n");
                return NULL;
+       }
 
        return &resource->attrs_value[attr_index];
 }
@@ -337,8 +362,10 @@ bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id)
        int ret;
        bool is_supported = false;
 
-       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+       if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
+               _E("Invalid parameter\n");
                return false;
+       }
 
        attr = &resource->attrs[attr_index];
 
@@ -368,11 +395,25 @@ static bool check_attr_validate(struct resource *resource, u_int64_t attr_id, in
 {
        const struct resource_attribute *attr = get_resource_attr(resource, attr_id);
 
-       if (!attr || attr->type != type)
+       if (!attr) {
+               _E("Invalid parameter\n");
+               return false;
+       }
+
+       if (attr->type != type) {
+               _E("Invalid data type(%d), res:type(%s)id(%d) | attr:name(%s)id(%"PRId64",%d)\n",
+                               type,
+                               resource->name, resource->id,
+                               attr->name, attr->id, attr->type);
                return false;
+       }
 
-       if (!(attr->id & resource->attr_interest))
+       if (!(attr->id & resource->attr_interest)) {
+               _E("Invalid interest state, res:type(%s)id(%d) | attr:name(%s)id(%"PRId64")type(%d)\n",
+                               resource->name, resource->id,
+                               attr->name, attr->id, attr->type);
                return false;
+       }
 
        return true;
 }
@@ -788,12 +829,16 @@ int get_resource_attr_string(struct resource *resource, u_int64_t attr_id, char
 {
        struct resource_attribute_value *attr_value = NULL;
 
-       if (!check_attr_validate(resource, attr_id, DATA_TYPE_STRING))
+       if (!check_attr_validate(resource, attr_id, DATA_TYPE_STRING)) {
+               _E("Invalid parameter\n");
                return -EINVAL;
+       }
 
        attr_value = get_resource_attr_value(resource, attr_id);
-       if (!attr_value)
+       if (!attr_value) {
+               _E("failed to get attribute value\n");
                return -EINVAL;
+       }
 
        strncpy(data, (char *)attr_value->data, BUFF_MAX);
 
@@ -851,7 +896,7 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas
 
                attr_value = get_resource_attr_value(resource, resource->attrs[i].id);
                if (!attr_value) {
-                       _E("failed to get attribute value: resource: %s, attribute: %s",
+                       _E("failed to get attribute value, res:type(%s) | attr:name(%s)",
                                        resource->name, resource->attrs[i].name);
                        ret = -EINVAL;
                        goto err;
@@ -887,13 +932,13 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas
                                attr_value->data = calloc(1, sizeof(struct array_value));
                                break;
                        default:
-                               _E("Not supported data type: %d", attr_value->type);
+                               _E("Not supported data type(%d)", attr_value->type);
                                ret = -EINVAL;
                                goto err;
                        }
 
                        if (!attr_value->data) {
-                               _E("failed to allocate attr_value memory: resource: %s, attribute: %s",
+                               _E("failed to allocate attr_value memory, res:type(%s) | attr:name(%s)",
                                        resource->name, resource->attrs[i].name);
                                ret = -ENOMEM;
                                goto err;
@@ -937,7 +982,7 @@ int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_m
 
                attr_value = get_resource_attr_value(resource, resource->attrs[i].id);
                if (!attr_value) {
-                       _E("failed to get attribute value: resource: %s, attribute: %s",
+                       _E("failed to get attribute value, res:type(%s) | attr:name(%s)",
                                        resource->name, resource->attrs[i].name);
                        return -EINVAL;
                }
@@ -964,7 +1009,7 @@ int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_m
                                attr_value->data = NULL;
                                break;
                        default:
-                               _E("Not supported data type: %d", attr_value->type);
+                               _E("Not supported data type(%d)", attr_value->type);
                                return -EINVAL;
                        }
                }