From: Chanwoo Choi Date: Mon, 4 Jul 2022 21:16:35 +0000 (+0900) Subject: util: resource: Encapsulate struct resource by hiding from user X-Git-Tag: accepted/tizen/unified/20220715.141323~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F277446%2F4;p=platform%2Fcore%2Fsystem%2Fpass.git util: resource: Encapsulate struct resource by hiding from user Move 'struct resource' into src/util/resource.c for hiding it and add missing getter/setter for encapsulation to access the fiels of 'struct resource'. Change-Id: Ib20b3de6f5ac68f20c14da82dedef38bbe26d2e8 Signed-off-by: Chanwoo Choi --- diff --git a/include/util/resource.h b/include/util/resource.h index 79f9bbd..d9b62f7 100644 --- a/include/util/resource.h +++ b/include/util/resource.h @@ -109,25 +109,6 @@ struct resource_device { int index; }; -struct resource { - int id; - char *name; - const struct resource_driver *driver; - int type; - void *priv; - - int num_attrs; - const struct resource_attribute *attrs; - struct resource_attribute_value *attrs_value; - int num_ctrls; - const struct resource_control *ctrls; - u_int64_t attr_interest; - u_int64_t attr_supported; - - int64_t ts_start; - int64_t ts_end; -}; - #define RESOURCE_DRIVER_REGISTER(resource_driver) \ static void __CONSTRUCTOR__ module_init(void) \ { \ @@ -187,6 +168,14 @@ int set_resource_attr_interest(struct resource *resource, u_int64_t interest_mas int unset_resource_attr_interest(struct resource *resource, u_int64_t interest_mask); bool is_resource_attr_interested(const struct resource *resource, u_int64_t interest_mask); +const char *get_resource_name(struct resource *resource); +void *get_resource_privdata(struct resource *resource); +int get_resource_id(struct resource *resource); +int get_resource_type(struct resource *resource); +int get_resource_ts(struct resource *resource, int64_t *ts_start, int64_t *ts_end); + +int set_resource_privdata(struct resource *resource, void *priv); + inline __attribute__((always_inline)) int64_t get_time_now(void) { struct timeval tv; diff --git a/src/util/resource.c b/src/util/resource.c index 207eb6b..feea4d1 100644 --- a/src/util/resource.c +++ b/src/util/resource.c @@ -29,6 +29,25 @@ #define RESOURCE_ATTR_INDEX(id) BIT64_INDEX(id) #define RESOURCE_CTRL_INDEX(id) BIT64_INDEX(id) +struct resource { + int id; + char *name; + const struct resource_driver *driver; + int type; + void *priv; + + int num_attrs; + const struct resource_attribute *attrs; + struct resource_attribute_value *attrs_value; + int num_ctrls; + const struct resource_control *ctrls; + u_int64_t attr_interest; + u_int64_t attr_supported; + + int64_t ts_start; + int64_t ts_end; +}; + static int g_resource_id; static GList *g_resource_driver_head; static GList *g_resource_device_head; @@ -954,3 +973,44 @@ bool is_resource_attr_interested(const struct resource *resource, u_int64_t inte return true; } + +const char *get_resource_name(struct resource *resource) +{ + return resource ? resource->name : NULL; +} + +void *get_resource_privdata(struct resource *resource) +{ + return resource ? resource->priv : NULL; +} + +int get_resource_id(struct resource *resource) +{ + return resource ? resource->id : -EINVAL; +} + +int get_resource_type(struct resource *resource) +{ + return resource ? resource->type : -EINVAL; +} + +int get_resource_ts(struct resource *resource, int64_t *ts_start, int64_t *ts_end) +{ + if (!resource) + return -EINVAL; + + *ts_start = resource->ts_start; + *ts_end = resource->ts_end; + + return 0; +} + +int set_resource_privdata(struct resource *resource, void *priv) +{ + if (!resource) + return -EINVAL; + + resource->priv = priv; + + return 0; +}