[Libosinfo] [libosinfo PATCH 2/4] os: Deal with "maximum" resources

Fabiano Fidêncio fidencio at redhat.com
Wed Nov 14 15:54:13 UTC 2018


In the samw way OSes have minimum and recommended resources, let's add
support for "maximum" resources.

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

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/libosinfo.syms  |  3 +++
 osinfo/osinfo_loader.c |  8 ++++++++
 osinfo/osinfo_os.c     | 40 ++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_os.h     |  2 ++
 4 files changed, 53 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index db9b8b2..5443f85 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -532,6 +532,9 @@ LIBOSINFO_0.2.13 {
 LIBOSINFO_1.3.0 {
     global:
 	osinfo_error_quark;
+
+	osinfo_os_add_maximum_resources;
+	osinfo_os_get_maximum_resources;
 } LIBOSINFO_0.2.13;
 
 /* Symbols in next release...
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index d1bf61d..2937736 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -1326,6 +1326,14 @@ static void osinfo_loader_resources_list(OsinfoLoader *loader,
     if (resources != NULL)
         osinfo_os_add_recommended_resources(os, resources);
 
+    g_clear_object(&resources);
+    resources = osinfo_loader_resources(loader, ctxt, root, id, "maximum", err);
+    if (error_is_set(err))
+        goto EXIT;
+
+    if (resources != NULL)
+        osinfo_os_add_recommended_resources(os, resources);
+
 EXIT:
     g_clear_object(&resources);
 }
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 2b870c4..b8f3114 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -55,6 +55,7 @@ struct _OsinfoOsPrivate
     OsinfoOsVariantList *variants;
     OsinfoResourcesList *minimum;
     OsinfoResourcesList *recommended;
+    OsinfoResourcesList *maximum;
 
     OsinfoInstallScriptList *scripts;
 
@@ -119,6 +120,7 @@ osinfo_os_finalize(GObject *object)
     g_object_unref(os->priv->variants);
     g_object_unref(os->priv->minimum);
     g_object_unref(os->priv->recommended);
+    g_object_unref(os->priv->maximum);
 
     g_object_unref(os->priv->scripts);
 
@@ -184,6 +186,7 @@ osinfo_os_init(OsinfoOs *os)
     os->priv->variants = osinfo_os_variantlist_new();
     os->priv->minimum = osinfo_resourceslist_new();
     os->priv->recommended = osinfo_resourceslist_new();
+    os->priv->maximum = osinfo_resourceslist_new();
     os->priv->scripts = osinfo_install_scriptlist_new();
     os->priv->device_drivers = osinfo_device_driverlist_new();
 }
@@ -567,6 +570,26 @@ OsinfoResourcesList *osinfo_os_get_recommended_resources(OsinfoOs *os)
     return newList;
 }
 
+/**
+ * osinfo_os_get_maximum_resources:
+ * @os: an operating system
+ *
+ * Get the list of maximum resources for the operating system @os.
+ *
+ * Returns: (transfer full): A list of resources
+ */
+OsinfoResourcesList *osinfo_os_get_maximum_resources(OsinfoOs *os)
+{
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+    OsinfoResourcesList *newList = osinfo_resourceslist_new();
+
+    osinfo_list_add_all(OSINFO_LIST(newList),
+                        OSINFO_LIST(os->priv->maximum));
+
+    return newList;
+}
+
 /**
  * osinfo_os_add_minimum_resources:
  * @os: an operating system
@@ -599,6 +622,23 @@ void osinfo_os_add_recommended_resources(OsinfoOs *os,
                     OSINFO_ENTITY(resources));
 }
 
+/**
+ * osinfo_os_add_maximum_resources:
+ * @os: an operating system
+ * @resources: (transfer none): the resources to add
+ *
+ * Adds @resources to list of maximum resources of operating system @os.
+ */
+void osinfo_os_add_maximum_resources(OsinfoOs *os,
+                                     OsinfoResources *resources)
+{
+    g_return_if_fail(OSINFO_IS_OS(os));
+    g_return_if_fail(OSINFO_IS_RESOURCES(resources));
+
+    osinfo_list_add(OSINFO_LIST(os->priv->maximum),
+                    OSINFO_ENTITY(resources));
+}
+
 /**
  * osinfo_os_find_install_script:
  * @os:      an operating system
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 96bd6e3..77deb39 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -120,8 +120,10 @@ OsinfoOsVariantList *osinfo_os_get_variant_list(OsinfoOs *os);
 void osinfo_os_add_variant(OsinfoOs *os, OsinfoOsVariant *variant);
 OsinfoResourcesList *osinfo_os_get_minimum_resources(OsinfoOs *os);
 OsinfoResourcesList *osinfo_os_get_recommended_resources(OsinfoOs *os);
+OsinfoResourcesList *osinfo_os_get_maximum_resources(OsinfoOs *os);
 void osinfo_os_add_minimum_resources(OsinfoOs *os, OsinfoResources *resources);
 void osinfo_os_add_recommended_resources(OsinfoOs *os, OsinfoResources *resources);
+void osinfo_os_add_maximum_resources(OsinfoOs *os, OsinfoResources *resources);
 
 OsinfoInstallScript *osinfo_os_find_install_script(OsinfoOs *os, const gchar *profile);
 OsinfoInstallScriptList *osinfo_os_get_install_script_list(OsinfoOs *os);
-- 
2.19.1




More information about the Libosinfo mailing list