resource: Resolve dependency of HAL devices 08/283208/5
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 13 Oct 2022 03:23:24 +0000 (12:23 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 31 Oct 2022 02:21:11 +0000 (11:21 +0900)
To include resource device related features to the resource library,
this separates it from pass core.

Change-Id: I35327b1932de35f5af2a516f361552160215b088
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
include/util/devices.h
include/util/resource.h
src/monitor/request-handler.c
src/resource/resource-bus.c
src/resource/resource-cpu.c
src/resource/resource-disk.c
src/resource/resource-display.c
src/resource/resource-gpu.c
src/resource/resource-network.c
src/util/devices.c
src/util/resource.c

index 1a896ea..ef53f26 100644 (file)
@@ -51,6 +51,17 @@ enum device_ops_status {
        DEVICE_OPS_STATUS_MAX,
 };
 
+struct resource_device {
+       char *name;
+       int type;
+
+       /*
+        * Never initialize it by user of add_resource_device().
+        * It will be initialized by add_resource_device function automatically.
+        */
+       int index;
+};
+
 #define DEVICE_OPS_REGISTER(dev)       \
 static void __CONSTRUCTOR__ module_init(void)  \
 {      \
@@ -61,6 +72,11 @@ static void __DESTRUCTOR__ module_exit(void) \
        remove_device(dev);     \
 }
 
+int get_resource_device_count(int resource_type);
+const struct resource_device *find_resource_device(int resource_type, int resource_index);
+int add_resource_device(struct resource_device *resource_device);
+void remove_resource_device(struct resource_device *resource_device);
+
 void init_devices(void *data);
 void exit_devices(void *data);
 void add_device(const struct device_ops *dev);
index eb46610..f0e55d2 100644 (file)
@@ -138,17 +138,6 @@ struct resource {
        u_int64_t attr_supported;
 };
 
-struct resource_device {
-       char *name;
-       int type;
-
-       /*
-        * Never initialize it by user of add_resource_device().
-        * It will be initialized by add_resource_device function automatically.
-        */
-       int index;
-};
-
 #define RESOURCE_DRIVER_REGISTER(resource_driver)      \
 static void __CONSTRUCTOR__ module_init(void)  \
 {      \
@@ -160,15 +149,10 @@ static void __DESTRUCTOR__ module_exit(void)      \
 }
 
 /* Add/remove resource driver and device */
+const struct resource_driver *find_resource_driver(int resource_type);
 void add_resource_driver(const struct resource_driver *resource_driver);
 void remove_resource_driver(const struct resource_driver *resource_driver);
 
-int get_resource_device_count_all(void);
-int get_resource_device_count(int resource_type);
-const struct resource_device *find_resource_device(int resource_type, int resource_index);
-int add_resource_device(struct resource_device *resource_device);
-void remove_resource_device(struct resource_device *resource_device);
-
 /* Create/delete resource instance */
 int create_resource(struct resource **res, int resource_type);
 void delete_resource(struct resource *resource);
index 4059ddc..fe241b2 100644 (file)
@@ -25,6 +25,7 @@
 #include <glib.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 #include <util/thread.h>
@@ -204,6 +205,26 @@ static int handle_request_update_resource(struct request_client *client, char *a
        return 0;
 }
 
+static int get_resource_count(int resource_type)
+{
+       const struct resource_driver *driver;
+       int count = get_resource_device_count(resource_type);
+
+       if (count > 0)
+               return count;
+
+       driver = find_resource_driver(resource_type);
+       if (!driver)
+               return -EINVAL;
+
+       if (driver->flag & RESOURCE_FLAG_COUNT_ONLY_ONE)
+               return 1;
+       else if (driver->flag & RESOURCE_FLAG_PROCESS)
+               return -EINVAL;
+
+       return 0;
+}
+
 static int handle_request_get_resource_count(struct request_client *client, char *args, int *value)
 {
        int resource_type;
@@ -220,7 +241,7 @@ static int handle_request_get_resource_count(struct request_client *client, char
         */
        resource_type = atoi(args);
 
-       ret = get_resource_device_count(resource_type);
+       ret = get_resource_count(resource_type);
        if (ret < 0) {
                _E("failed to get resource device count, res:type(%d)\n", resource_type);
                return ret;
index 2cbba18..22807f6 100644 (file)
@@ -27,6 +27,7 @@
 #include <hal/hal-power.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 
index 2f316be..aa2d405 100644 (file)
@@ -27,6 +27,7 @@
 #include <hal/hal-power.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 
index 7c26c9b..02b08eb 100644 (file)
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 
index ed0f55e..8c2ccfc 100644 (file)
@@ -26,6 +26,7 @@
 #include <unistd.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 #include <util/gdbus-util.h>
index 8e6ac82..f112845 100644 (file)
@@ -27,6 +27,7 @@
 #include <hal/hal-power.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 
index 016820a..aabadb4 100644 (file)
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <util/common.h>
+#include <util/devices.h>
 #include <util/log.h>
 #include <util/resource.h>
 
index 0ad12dd..565db53 100644 (file)
 #include <util/log.h>
 
 static GList *dev_head;
+static GList *g_resource_device_head;
+
+int get_resource_device_count(int resource_type)
+{
+       GList *node;
+       struct resource_device *device;
+       int count = 0;
+
+       for (node = g_resource_device_head; node != NULL; node = node->next) {
+               device = node->data;
+               if (device->type == resource_type)
+                       count++;
+       }
+
+       return count;
+}
+
+const struct resource_device *find_resource_device(int resource_type,
+                                                  int resource_index)
+{
+       GList *node;
+       const struct resource_device *device;
+
+       for (node = g_resource_device_head; node != NULL; node = node->next) {
+               device = node->data;
+               if (device->type == resource_type &&
+                               device->index == resource_index)
+                       return device;
+       }
+
+       return NULL;
+}
+
+int add_resource_device(struct resource_device *device)
+{
+       int count;
+
+       if (!device)
+               return -EINVAL;
+
+       count = get_resource_device_count(device->type);
+       if (count < 0)
+               return count;
+
+       device->index = count;
+
+       g_resource_device_head =
+                       g_list_append(g_resource_device_head, (gpointer)device);
+
+       return 0;
+}
+
+void remove_resource_device(struct resource_device *device)
+{
+       if (!device)
+               return;
+
+       g_resource_device_head =
+                       g_list_remove(g_resource_device_head, (gpointer)device);
+}
 
 void add_device(const struct device_ops *dev)
 {
index 963bb83..75fb89e 100644 (file)
@@ -32,7 +32,6 @@
 #define RESOURCE_CTRL_INDEX(id)                        BIT64_INDEX(id)
 
 static GList *g_resource_driver_head;
-static GList *g_resource_device_head;
 
 static gint __compare_resource_type(gconstpointer data, gconstpointer input)
 {
@@ -44,7 +43,7 @@ static gint __compare_resource_type(gconstpointer data, gconstpointer input)
        return -1;
 }
 
-static const struct resource_driver *find_resource_driver(int resource_type)
+const struct resource_driver *find_resource_driver(int resource_type)
 {
        GList *node;
 
@@ -74,83 +73,6 @@ void remove_resource_driver(const struct resource_driver *driver)
                        g_list_remove(g_resource_driver_head, (gpointer)driver);
 }
 
-int get_resource_device_count_all(void)
-{
-       return g_list_length(g_resource_device_head);
-}
-
-int get_resource_device_count(int resource_type)
-{
-       GList *node;
-       struct resource_device *device;
-       const struct resource_driver *driver;
-       int count = 0;
-
-       for (node = g_resource_device_head; node != NULL; node = node->next) {
-               device = node->data;
-               if (device->type == resource_type)
-                       count++;
-       }
-
-       if (count > 0)
-               return count;
-
-       driver = find_resource_driver(resource_type);
-       if (!driver)
-               return -EINVAL;
-
-       if (driver->flag & RESOURCE_FLAG_COUNT_ONLY_ONE)
-               return 1;
-       else if (driver->flag & RESOURCE_FLAG_PROCESS)
-               return -EINVAL;
-
-       return 0;
-}
-
-const struct resource_device *find_resource_device(int resource_type,
-                                                  int resource_index)
-{
-       GList *node;
-       const struct resource_device *device;
-
-       for (node = g_resource_device_head; node != NULL; node = node->next) {
-               device = node->data;
-               if (device->type == resource_type &&
-                               device->index == resource_index)
-                       return device;
-       }
-
-       return NULL;
-}
-
-int add_resource_device(struct resource_device *device)
-{
-       int count;
-
-       if (!device)
-               return -EINVAL;
-
-       count = get_resource_device_count(device->type);
-       if (count < 0)
-               return count;
-
-       device->index = count;
-
-       g_resource_device_head =
-                       g_list_append(g_resource_device_head, (gpointer)device);
-
-       return 0;
-}
-
-void remove_resource_device(struct resource_device *device)
-{
-       if (!device)
-               return;
-
-       g_resource_device_head =
-                       g_list_remove(g_resource_device_head, (gpointer)device);
-}
-
 static void do_delete_resource(struct resource *resource)
 {
        if (!resource->name)