From 51e9db0bcf2b7c81305bd22702868769d30e0240 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 19 Jul 2022 12:27:22 +0900 Subject: [PATCH] util: resource: Add get_resource_attr_name and get_resource_controL_name function Add get_resource_attr_name and get_resource_controL_name function to get the attribute name and control name. Function prototype as following: - const char *get_resource_attr_name(struct resource *resource, u_int64_t attr_id) - const char *get_resource_control_name(struct resource *resource, u_int64_t ctrl_id) Change-Id: Id77a7f07f8129fc14d693b32f35f94e8b4c93f3a Signed-off-by: Chanwoo Choi --- include/util/resource.h | 2 ++ src/util/resource.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/util/resource.h b/include/util/resource.h index e96d3ba..2569ccb 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -135,6 +135,7 @@ void delete_resource(struct resource *resource); /* Handle resource control */ int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const void *data); +const char *get_resource_control_name(struct resource *resource, u_int64_t ctrl_id); /* Handle resource attribute */ int update_resource_attrs(struct resource *resource); @@ -167,6 +168,7 @@ int get_resource_attr_ptr(struct resource *resource, u_int64_t attr_id, void **d int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mask); int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_mask); bool is_resource_attr_interested(struct resource *resource, u_int64_t interest_mask); +const char *get_resource_attr_name(struct resource *resource, u_int64_t attr_id); const char *get_resource_name(struct resource *resource); void *get_resource_privdata(struct resource *resource); diff --git a/src/util/resource.c b/src/util/resource.c index 4f74cc0..a07cace 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -242,6 +242,18 @@ int set_resource_control(struct resource *resource, u_int64_t ctrl_id, const voi return 0; } +const char *get_resource_control_name(struct resource *resource, u_int64_t ctrl_id) +{ + const struct resource_control *ctrl; + int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id); + + if (!resource) + return NULL; + ctrl = &resource->ctrls[ctrl_index]; + + return ctrl->name; +} + static int update_resource_attr(struct resource *resource, u_int64_t attr_id) { int attr_index = RESOURCE_ATTR_INDEX(attr_id); @@ -974,6 +986,17 @@ bool is_resource_attr_interested(struct resource *resource, u_int64_t interest_m return true; } +const char *get_resource_attr_name(struct resource *resource, u_int64_t attr_id) +{ + const struct resource_attribute *attr; + + attr = get_resource_attr(resource, attr_id); + if (!attr) + return NULL; + + return attr->name; +} + const char *get_resource_name(struct resource *resource) { return resource ? resource->name : NULL; -- 2.7.4