util: resource: Encapsulate struct resource by hiding from user 46/277446/4
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 4 Jul 2022 21:16:35 +0000 (06:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 8 Jul 2022 09:03:24 +0000 (18:03 +0900)
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 <cw00.choi@samsung.com>
include/util/resource.h
src/util/resource.c

index 79f9bbd..d9b62f7 100644 (file)
@@ -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;
index 207eb6b..feea4d1 100644 (file)
 #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;
+}