diff options
author | Chanwoo Choi <cw00.choi@samsung.com> | 2022-08-22 16:59:08 +0900 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2022-08-22 17:35:34 +0900 |
commit | 5f56fe2eddb0625b622ee6ba4cd1b96ae183c211 (patch) | |
tree | f1247609a29552e2d159aa6eb0a3d6aa8eb95762 | |
parent | 476a97b39e0a3f30e9ef52a0b01c87d55d1ed077 (diff) | |
download | pass-5f56fe2eddb0625b622ee6ba4cd1b96ae183c211.tar.gz pass-5f56fe2eddb0625b622ee6ba4cd1b96ae183c211.tar.bz2 pass-5f56fe2eddb0625b622ee6ba4cd1b96ae183c211.zip |
lib: resource-monitor: Change pass_resourced_monitor_is_resource_attr_supported prototypesubmit/tizen/20220822.102536submit/tizen/20220822.094833accepted/tizen/unified/20220823.005726
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>
-rw-r--r-- | include/util/resource.h | 2 | ||||
-rw-r--r-- | lib/resource-monitor/resource-monitor.c | 10 | ||||
-rw-r--r-- | lib/resource-monitor/resource-monitor.h | 5 | ||||
-rw-r--r-- | src/monitor/request-handler.c | 12 | ||||
-rw-r--r-- | src/util/resource.c | 19 | ||||
-rw-r--r-- | tests/integration-test/resource-monitor-tests.cpp | 58 | ||||
-rw-r--r-- | tools/resource-monitor/resource-monitor.c | 23 |
7 files changed, 95 insertions, 34 deletions
diff --git a/include/util/resource.h b/include/util/resource.h index 888943e..596f414 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -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, diff --git a/lib/resource-monitor/resource-monitor.c b/lib/resource-monitor/resource-monitor.c index 8fa81e9..b36006a 100644 --- a/lib/resource-monitor/resource-monitor.c +++ b/lib/resource-monitor/resource-monitor.c @@ -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 diff --git a/lib/resource-monitor/resource-monitor.h b/lib/resource-monitor/resource-monitor.h index b32c452..84d3e9f 100644 --- a/lib/resource-monitor/resource-monitor.h +++ b/lib/resource-monitor/resource-monitor.h @@ -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 diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index 2497a15..c81bce4 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -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: diff --git a/src/util/resource.c b/src/util/resource.c index 59f22aa..fa68256 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -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; } diff --git a/tests/integration-test/resource-monitor-tests.cpp b/tests/integration-test/resource-monitor-tests.cpp index 2901648..654fbc8 100644 --- a/tests/integration-test/resource-monitor-tests.cpp +++ b/tests/integration-test/resource-monitor-tests.cpp @@ -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; diff --git a/tools/resource-monitor/resource-monitor.c b/tools/resource-monitor/resource-monitor.c index c3d9701..ff7a9a4 100644 --- a/tools/resource-monitor/resource-monitor.c +++ b/tools/resource-monitor/resource-monitor.c @@ -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); |