[libosinfo PATCH v2 06/12] os: Make os aware of Guest Features

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit adds the whole machinery needed for dealing with Guest
Features for an Os object.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/libosinfo.syms |   2 +
 osinfo/osinfo_os.c    | 107 ++++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_os.h    |   6 ++-
 3 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 28b229f..1f1000f 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -558,9 +558,11 @@ LIBOSINFO_1.3.0 {
 
 	osinfo_media_supports_installer_script;
 
+	osinfo_os_add_feature;
 	osinfo_os_add_image;
 	osinfo_os_add_maximum_resources;
 	osinfo_os_get_all_device_links;
+	osinfo_os_get_feature_list;
 	osinfo_os_get_image_list;
 	osinfo_os_get_maximum_resources;
 
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 01d2e01..a082ec2 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -29,6 +29,7 @@
 #include "osinfo/osinfo_product_private.h"
 #include "osinfo/osinfo_os_private.h"
 #include "osinfo/osinfo_resources_private.h"
+#include "osinfo/osinfo_feature_private.h"
 #include <glib/gi18n-lib.h>
 
 G_DEFINE_TYPE(OsinfoOs, osinfo_os, OSINFO_TYPE_PRODUCT);
@@ -59,6 +60,7 @@ struct _OsinfoOsPrivate
     OsinfoResourcesList *minimum;
     OsinfoResourcesList *recommended;
     OsinfoResourcesList *maximum;
+    OsinfoFeatureList *features;
 
     OsinfoInstallScriptList *scripts;
 
@@ -119,6 +121,7 @@ osinfo_os_finalize(GObject *object)
     g_object_unref(os->priv->minimum);
     g_object_unref(os->priv->recommended);
     g_object_unref(os->priv->maximum);
+    g_object_unref(os->priv->features);
 
     g_object_unref(os->priv->scripts);
 
@@ -186,6 +189,7 @@ osinfo_os_init(OsinfoOs *os)
     os->priv->minimum = osinfo_resourceslist_new();
     os->priv->recommended = osinfo_resourceslist_new();
     os->priv->maximum = osinfo_resourceslist_new();
+    os->priv->features = osinfo_featurelist_new();
     os->priv->scripts = osinfo_install_scriptlist_new();
     os->priv->device_drivers = osinfo_device_driverlist_new();
 }
@@ -553,6 +557,109 @@ OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev)
     return devlink;
 }
 
+struct GetAllFeaturesData {
+    OsinfoOs *os;
+    OsinfoFeatureList *feature_list;
+    OsinfoFeatureList *unsupported_list;
+};
+
+static void get_all_features_cb(OsinfoProduct *product, gpointer user_data)
+{
+    OsinfoFeatureList *filtered_out;
+    OsinfoFeatureList *unsupported_list;
+    OsinfoFeatureList *new_list;
+    OsinfoFeatureList *new_unsupported_list;
+    OsinfoOs *os;
+    struct GetAllFeaturesData *foreach_data = (struct GetAllFeaturesData *)user_data;
+    gsize featurelist_len;
+    gsize i;
+
+    g_return_if_fail(OSINFO_IS_OS(product));
+    os = OSINFO_OS(product);
+
+    filtered_out = osinfo_featurelist_new();
+    unsupported_list = osinfo_featurelist_new();
+
+    featurelist_len = osinfo_list_get_length(OSINFO_LIST(os->priv->features));
+    for (i = 0; i < featurelist_len; i++) {
+        OsinfoFeature *feature = OSINFO_FEATURE(osinfo_list_get_nth(OSINFO_LIST(os->priv->features), i));
+
+        if (!osinfo_feature_get_supported(feature)) {
+            osinfo_list_add(OSINFO_LIST(unsupported_list), OSINFO_ENTITY(feature));
+            continue;
+        }
+
+        if (foreach_data->unsupported_list != NULL &&
+            osinfo_list_find_by_id(OSINFO_LIST(foreach_data->unsupported_list),
+                                   osinfo_feature_get_name(feature)) != NULL)
+            continue;
+
+        osinfo_list_add(OSINFO_LIST(filtered_out), OSINFO_ENTITY(feature));
+    }
+
+    if (os == foreach_data->os) {
+        foreach_data->feature_list = filtered_out;
+        foreach_data->unsupported_list = unsupported_list;
+        return;
+    }
+
+    new_list = OSINFO_FEATURELIST(osinfo_list_new_union(OSINFO_LIST(foreach_data->feature_list),
+                                                        OSINFO_LIST(filtered_out)));
+
+    new_unsupported_list = OSINFO_FEATURELIST(osinfo_list_new_union(OSINFO_LIST(foreach_data->unsupported_list),
+                                              OSINFO_LIST(unsupported_list)));
+
+    g_object_unref(filtered_out);
+    g_object_unref(foreach_data->feature_list);
+    g_object_unref(foreach_data->unsupported_list);
+    foreach_data->feature_list = new_list;
+    foreach_data->unsupported_list = new_unsupported_list;
+}
+
+/**
+ * osinfo_os_get_feature_list:
+ * @os: an operating system
+ *
+ * Get all features matching a given filter and taking into consideration
+ * all features previous set in all OSes from which @os derived and/or cloned.
+ *
+ * Returns: (transfer full): A list of OsinfoFeature
+ */
+OsinfoFeatureList *osinfo_os_get_feature_list(OsinfoOs *os)
+{
+    struct GetAllFeaturesData foreach_data = {
+        .os = os,
+        .feature_list = NULL,
+        .unsupported_list = NULL,
+    };
+
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+
+    osinfo_product_foreach_related(OSINFO_PRODUCT(os),
+                                   OSINFO_PRODUCT_FOREACH_FLAG_DERIVES_FROM |
+                                   OSINFO_PRODUCT_FOREACH_FLAG_CLONES,
+                                   get_all_features_cb,
+                                   &foreach_data);
+
+    if (foreach_data.unsupported_list != NULL)
+        g_object_unref(foreach_data.unsupported_list);
+    return foreach_data.feature_list;
+}
+
+/** osinfo_os_add_feature:
+ * @os: an operating system
+ * @feature: (transfer none): the feature to associate with
+ *
+ * Adds @feature to list of features of operating system @os.
+ */
+void osinfo_os_add_feature(OsinfoOs *os, OsinfoFeature *feature)
+{
+    g_return_if_fail(OSINFO_IS_OS(os));
+    g_return_if_fail(OSINFO_IS_FEATURE(feature));
+
+    osinfo_list_add(OSINFO_LIST(os->priv->features), OSINFO_ENTITY(feature));
+}
+
 /**
  * osinfo_os_get_family:
  * @os: an #OsinfoOs
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index 4eb4b1b..5a3127c 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -34,6 +34,7 @@
 #include <osinfo/osinfo_tree.h>
 #include <osinfo/osinfo_resources.h>
 #include <osinfo/osinfo_resourceslist.h>
+#include <osinfo/osinfo_feature.h>
 #include <osinfo/osinfo_image.h>
 #include <osinfo/osinfo_imagelist.h>
 
@@ -110,8 +111,8 @@ OsinfoDeviceList *osinfo_os_get_devices_by_property(OsinfoOs *os,
                                                     gboolean inherited);
 OsinfoDeviceLinkList *osinfo_os_get_device_links(OsinfoOs *os, OsinfoFilter *filter);
 OsinfoDeviceLinkList *osinfo_os_get_all_device_links(OsinfoOs *os, OsinfoFilter *filter);
-
 OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev);
+
 const gchar *osinfo_os_get_family(OsinfoOs *os);
 const gchar *osinfo_os_get_distro(OsinfoOs *os);
 int osinfo_os_get_release_status(OsinfoOs *os);
@@ -137,6 +138,9 @@ void osinfo_os_add_install_script(OsinfoOs *os, OsinfoInstallScript *script);
 OsinfoDeviceDriverList *osinfo_os_get_device_drivers(OsinfoOs *os);
 void osinfo_os_add_device_driver(OsinfoOs *os, OsinfoDeviceDriver *driver);
 
+OsinfoFeatureList *osinfo_os_get_feature_list(OsinfoOs *os);
+void osinfo_os_add_feature(OsinfoOs *os, OsinfoFeature *feature);
+
 #endif /* __OSINFO_OS_H__ */
 /*
  * Local variables:
-- 
2.19.2

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux