[Libosinfo] [libosinfo PATCH 2/3] os: Add support for Resources inheritance

Fabiano Fidêncio fidencio at redhat.com
Mon Nov 12 14:07:23 UTC 2018


In the same way that devices can be inherited between OSes that
derive-from/clone another OS, the resources should do the same.

https://gitlab.com/libosinfo/osinfo-db/issues/15

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/osinfo_os.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 4246069..19deae1 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -551,6 +551,47 @@ osinfo_os_get_minimum_resources_without_inheritance(OsinfoOs *os)
     return newList;
 }
 
+struct GetAllResourcesData {
+    OsinfoResourcesList *resources;
+    OsinfoResourcesList *(*get_resources)(OsinfoOs *);
+};
+
+static void get_all_resources_cb(OsinfoProduct *product, gpointer user_data)
+{
+    OsinfoResourcesList *resources;
+    OsinfoList *tmp_list;
+    struct GetAllResourcesData *foreach_data = (struct GetAllResourcesData *)user_data;
+
+    g_return_if_fail(OSINFO_IS_OS(product));
+
+    resources = foreach_data->get_resources(OSINFO_OS(product));
+    tmp_list = osinfo_list_new_union(OSINFO_LIST(foreach_data->resources),
+                                     OSINFO_LIST(resources));
+    g_object_unref(foreach_data->resources);
+    g_object_unref(resources);
+    foreach_data->resources = OSINFO_RESOURCESLIST(tmp_list);
+}
+
+
+static OsinfoResourcesList *
+osinfo_os_get_resources_internal(OsinfoOs *os,
+                                 OsinfoResourcesList *(*get_resources)(OsinfoOs *))
+{
+    struct GetAllResourcesData foreach_data = {
+        .resources = osinfo_resourceslist_new(),
+        .get_resources = get_resources,
+    };
+
+    osinfo_product_foreach_related(OSINFO_PRODUCT(os),
+                                   OSINFO_PRODUCT_FOREACH_FLAG_DERIVES_FROM |
+                                   OSINFO_PRODUCT_FOREACH_FLAG_CLONES,
+                                   get_all_resources_cb,
+                                   &foreach_data);
+
+    return foreach_data.resources;
+}
+
+
 /**
  * osinfo_os_get_minimum_resources:
  * @os: an operating system
@@ -561,7 +602,8 @@ osinfo_os_get_minimum_resources_without_inheritance(OsinfoOs *os)
  */
 OsinfoResourcesList *osinfo_os_get_minimum_resources(OsinfoOs *os)
 {
-    return osinfo_os_get_minimum_resources_without_inheritance(os);
+    return osinfo_os_get_resources_internal
+            (os, osinfo_os_get_minimum_resources_without_inheritance);
 }
 
 /**
@@ -597,7 +639,9 @@ osinfo_os_get_recommended_resources_without_inheritance(OsinfoOs *os)
  */
 OsinfoResourcesList *osinfo_os_get_recommended_resources(OsinfoOs *os)
 {
-    return osinfo_os_get_recommended_resources_without_inheritance(os);
+    return osinfo_os_get_resources_internal
+            (os, osinfo_os_get_recommended_resources_without_inheritance);
+
 }
 
 /**
-- 
2.19.1




More information about the Libosinfo mailing list