lib: resource-monitor: Change pass_resourced_monitor_is_resource_attr_supported prototype 11/280011/2 accepted/tizen/unified/20220823.005726 submit/tizen/20220822.094833 submit/tizen/20220822.102536
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 22 Aug 2022 07:59:08 +0000 (16:59 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Mon, 22 Aug 2022 08:35:34 +0000 (17:35 +0900)
Change pass_resourced_monitor_is_resource_attr_supported prototype
to express the various error case and then get the value from l-value
style parameter.

[Before]
bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id);

[After]
int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported);

Change-Id: If4943e034db0a180807a85700ac2db7c87ecef5a
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
include/util/resource.h
lib/resource-monitor/resource-monitor.c
lib/resource-monitor/resource-monitor.h
src/monitor/request-handler.c
src/util/resource.c
tests/integration-test/resource-monitor-tests.cpp
tools/resource-monitor/resource-monitor.c

index 888943e..596f414 100644 (file)
@@ -156,7 +156,7 @@ int update_resource_attrs(struct resource *resource);
 const struct resource_attribute *get_resource_attr(struct resource *resource, u_int64_t attr_id);
 struct resource_attribute_value *
 get_resource_attr_value(struct resource *resource, u_int64_t attr_id);
-bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id);
+int is_resource_attr_supported(struct resource *resource, u_int64_t attr_id, bool *supported);
 
 static inline bool
 resource_attr_supported_always(struct resource *resource,
index 8fa81e9..b36006a 100644 (file)
@@ -200,6 +200,7 @@ static inline int handle_request(struct request_data *data)
                        ret = TIZEN_ERROR_INVALID_PARAMETER;
                break;
        case REQUEST_GET_VALUE_UINT:
+       case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
                if (sscanf(buffer, "%d$%u$%d", &response_req,
                                        &data->value_uint32, &response_ret) < 3)
                        ret = TIZEN_ERROR_INVALID_PARAMETER;
@@ -234,7 +235,6 @@ static inline int handle_request(struct request_data *data)
        case REQUEST_DELETE_RESOURCE:
        case REQUEST_CREATE_RESOURCE:
        case REQUEST_SET_RESOURCE_CTRL:
-       case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
        case REQUEST_SET_RESOURCE_ATTR:
        case REQUEST_UNSET_RESOURCE_ATTR:
        case REQUEST_IS_RESOURCE_ATTR_SET:
@@ -424,7 +424,7 @@ int pass_resource_monitor_unset_resource_attr(int id, int resource_id, u_int64_t
 }
 
 EXPORT
-bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id)
+int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported)
 {
        struct request_data request = {
                .request        = REQUEST_IS_RESOURCE_ATTR_SUPPORTED,
@@ -435,7 +435,11 @@ bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u
        int ret;
 
        ret = handle_request(&request);
-       return (ret < 0) ? false : (bool)ret;
+       if (ret < 0)
+               return ret;
+
+       *supported = (bool)request.value_uint32;
+       return TIZEN_ERROR_NONE;
 }
 
 EXPORT
index b32c452..84d3e9f 100644 (file)
@@ -245,9 +245,10 @@ bool pass_resource_monitor_is_resource_attr_set(int id, int resource_id, u_int64
  * @param[in] Resource monitor id
  * @param[in] Resource id
  * @param[in] Resource attribute id
- * @return @c true on success, otherwise false
+ * @param[out] Resource attribute is either supported or not
+ * @return @c 0 on success, otherwise false
  */
-bool pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id);
+int pass_resource_monitor_is_resource_attr_supported(int id, int resource_id, u_int64_t attr_id, bool *supported);
 
 /**
  * @brief Update value of the interested attributes for all created resource
index 2497a15..c81bce4 100644 (file)
@@ -250,7 +250,7 @@ static int handle_request_set_resource_attr(struct request_client *client, char
        return ret;
 }
 
-static int handle_request_is_resource_attr_supported(struct request_client *client, char *args)
+static int handle_request_is_resource_attr_supported(struct request_client *client, char *args, bool *supported)
 {
        struct resource *res;
        int resource_id;
@@ -278,7 +278,7 @@ static int handle_request_is_resource_attr_supported(struct request_client *clie
                return -EINVAL;
        }
 
-       return (int)is_resource_attr_supported(res, attr_id);
+       return is_resource_attr_supported(res, attr_id, supported);
 }
 
 static int handle_request_set_resource_ctrl(struct request_client *client, char *args)
@@ -773,7 +773,13 @@ static int handle_request(struct request_client *client, char *request)
                ret = handle_request_set_resource_attr(client, args, request_type);
                break;
        case REQUEST_IS_RESOURCE_ATTR_SUPPORTED:
-               ret = handle_request_is_resource_attr_supported(client, args);
+               {
+                       bool supported;
+
+                       ret = handle_request_is_resource_attr_supported(client, args, &supported);
+
+                       ADD_RESPONSE(response, buffer_len, "%u$", (u_int32_t)supported);
+               }
                break;
        case REQUEST_GET_RESOURCE_JSON:
        case REQUEST_GET_VALUE_JSON:
index 59f22aa..fa68256 100644 (file)
@@ -401,7 +401,7 @@ get_resource_attr_value(struct resource *resource, u_int64_t attr_id)
        return &resource->attrs_value[attr_index];
 }
 
-bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id)
+int is_resource_attr_supported(struct resource *resource, u_int64_t attr_id, bool *supported)
 {
        const struct resource_attribute *attr = NULL;
        int attr_index = RESOURCE_ATTR_INDEX(attr_id);
@@ -410,13 +410,13 @@ bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id)
 
        if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
                _E("Invalid parameter\n");
-               return false;
+               return -EINVAL;
        }
 
        attr = &resource->attrs[attr_index];
 
        if (attr->id & resource->attr_supported) {
-               return true;
+               is_supported = true;
        } else if (attr->ops.is_supported) {
                is_supported = attr->ops.is_supported(resource, attr);
        } else if (attr->ops.get) {
@@ -434,7 +434,9 @@ bool is_resource_attr_supported(struct resource *resource, u_int64_t attr_id)
        if (is_supported)
                resource->attr_supported |= attr->id;
 
-       return is_supported;
+       *supported = is_supported;
+
+       return 0;
 }
 
 static bool check_attr_validate(struct resource *resource, u_int64_t attr_id, int type)
@@ -927,6 +929,7 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas
 {
        struct resource_attribute_value *attr_value;
        int i, ret;
+       bool supported;
 
        if (!resource)
                return -EINVAL;
@@ -935,8 +938,12 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas
                if (!(resource->attrs[i].id & interest_mask))
                        continue;
 
-               if (!is_resource_attr_supported(resource, resource->attrs[i].id)) {
-                       ret = -EINVAL;
+               ret = is_resource_attr_supported(resource, resource->attrs[i].id,
+                                               &supported);
+               if (ret < 0) {
+                       goto err;
+               } else if (!supported){
+                       ret = -ENOTSUP;
                        goto err;
                }
 
index 2901648..654fbc8 100644 (file)
@@ -133,19 +133,27 @@ TEST_F(ResourceMonitorTest,
                EXPECT_EQ(ret, 0);
 
                for (j = 0; j < (int)ARRAY_SIZE(res_attr_ids); j++) {
-                       bool supported = pass_resource_monitor_is_resource_attr_supported(
+                       bool supported;
+
+                       ret = pass_resource_monitor_is_resource_attr_supported(
                                                        id, res_id,
-                                                       res_attr_ids[j]);
+                                                       res_attr_ids[j],
+                                                       &supported);
+                       EXPECT_EQ(ret, 0);
                        EXPECT_EQ(supported, false);
 
-                       supported = pass_resource_monitor_is_resource_attr_supported(
+                       ret = pass_resource_monitor_is_resource_attr_supported(
                                                        UNKNOWN_ID, res_id,
-                                                       res_attr_ids[j]);
+                                                       res_attr_ids[j],
+                                                       &supported);
+                       EXPECT_EQ(ret, 0);
                        EXPECT_EQ(supported, false);
 
-                       supported = pass_resource_monitor_is_resource_attr_supported(
+                       ret = pass_resource_monitor_is_resource_attr_supported(
                                                        id, UNKNOWN_ID,
-                                                       res_attr_ids[j]);
+                                                       res_attr_ids[j],
+                                                       &supported);
+                       EXPECT_EQ(ret, 0);
                        EXPECT_EQ(supported, false);
                }
 
@@ -452,8 +460,14 @@ static int __pass_resource_monitor_set_resource_attr(int mon_id, int res_id, int
        u_int64_t mask = 0;
 
        for (i = 0; i < num_attrs; i++) {
-               bool supported = pass_resource_monitor_is_resource_attr_supported(
-                                               mon_id, res_id, attrs[i].attr_id);
+               bool supported;
+
+               ret = pass_resource_monitor_is_resource_attr_supported(
+                                               mon_id, res_id,
+                                               attrs[i].attr_id,
+                                               &supported);
+               EXPECT_EQ(ret, 0);
+
                if (supported)
                        mask |= attrs[i].attr_id;
        }
@@ -471,8 +485,14 @@ static int __pass_resource_monitor_unset_resource_attr(int mon_id, int res_id, i
        u_int64_t mask = 0;
 
        for (i = 0; i < num_attrs; i++) {
-               bool supported = pass_resource_monitor_is_resource_attr_supported(
-                                               mon_id, res_id, attrs[i].attr_id);
+               bool supported;
+
+               ret = pass_resource_monitor_is_resource_attr_supported(
+                                               mon_id, res_id,
+                                               attrs[i].attr_id,
+                                               &supported);
+               EXPECT_EQ(ret, 0);
+
                if (supported)
                        mask |= attrs[i].attr_id;
        }
@@ -490,8 +510,14 @@ static bool __pass_resource_monitor_is_resource_attr_set(int mon_id, int res_id,
        u_int64_t mask = 0;
 
        for (i = 0; i < num_attrs; i++) {
-               bool supported = pass_resource_monitor_is_resource_attr_supported(
-                                               mon_id, res_id, attrs[i].attr_id);
+               bool supported;
+
+               ret = pass_resource_monitor_is_resource_attr_supported(
+                                               mon_id, res_id,
+                                               attrs[i].attr_id,
+                                               &supported);
+               EXPECT_EQ(ret, 0);
+
                if (supported)
                        mask |= attrs[i].attr_id;
        }
@@ -673,8 +699,12 @@ static int __pass_resource_monitor_get_value(int mon_id, int res_id, int num_att
        int i, ret, err_count = 0;
 
        for (i = 0; i < num_attrs; i++) {
-               bool supported = pass_resource_monitor_is_resource_attr_supported(
-                                               mon_id, res_id, attrs[i].attr_id);
+               bool supported;
+
+               ret = pass_resource_monitor_is_resource_attr_supported(
+                                               mon_id, res_id,
+                                               attrs[i].attr_id,
+                                               &supported);
                if (!supported)
                        continue;
 
index c3d9701..ff7a9a4 100644 (file)
@@ -256,7 +256,8 @@ struct __resource_type {
 
 static inline void create_resource_and_set_attrs(struct resource_data *res, int ctrl_val)
 {
-       int i;
+       int i, ret;
+       bool supported;
 
        if (!res)
                return;
@@ -268,8 +269,13 @@ static inline void create_resource_and_set_attrs(struct resource_data *res, int
                                res->mon_id, res->res_id, res->ctrl_id, ctrl_val);
 
        for (i = 0; i < res->num_attrs; i++) {
-               if (pass_resource_monitor_is_resource_attr_supported(
-                               res->mon_id, res->res_id, res->attrs[i].id))
+               ret = pass_resource_monitor_is_resource_attr_supported(
+                               res->mon_id, res->res_id, res->attrs[i].id,
+                               &supported);
+               if (ret < 0)
+                       continue;
+
+               if (supported)
                        res->mask |= res->attrs[i].id;
        }
 
@@ -335,9 +341,16 @@ static inline void get_resource_attr_value(struct resource_data *res, int i)
        bool supported;
        int ret = 0;
 
-       supported = pass_resource_monitor_is_resource_attr_supported(
+       ret = pass_resource_monitor_is_resource_attr_supported(
                                                res->mon_id, res->res_id,
-                                               res->attrs[i].id);
+                                               res->attrs[i].id,
+                                               &supported);
+       if(ret < 0) {
+               printf("%40s | %-5s | %s", "Not Implemented",
+                               res->attrs[i].unit, res->attrs[i].desc);
+               return;
+       }
+
        if (!supported) {
                printf("%40s | %-5s | %s", "Not Supported",
                                res->attrs[i].unit, res->attrs[i].desc);