[Libosinfo] [libosinfo PATCH 25/31] os: Make os aware of Guest Features

Fabiano Fidêncio fidencio at redhat.com
Fri Nov 23 10:15:14 UTC 2018


This commit only adds *one* new API that will allow OsinfoLoader to add
Guest Features to the OS. Further in this series APIs for retrieving
Guest Features will be added.

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

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index be59fc7..0425ab5 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -552,8 +552,13 @@ LIBOSINFO_1.3.0 {
 	osinfo_linklist_get_targets;
 	osinfo_linklist_get_type;
 
+	osinfo_os_add_feature;
 	osinfo_os_add_maximum_resources;
 	osinfo_os_get_all_device_links;
+	osinfo_os_get_all_feature_links;
+	osinfo_os_get_all_features;
+	osinfo_os_get_feature_links;
+	osinfo_os_get_features;
 	osinfo_os_get_maximum_resources;
 } LIBOSINFO_0.2.13;
 
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
index 7170984..64aa887 100644
--- a/osinfo/osinfo_os.c
+++ b/osinfo/osinfo_os.c
@@ -52,6 +52,9 @@ struct _OsinfoOsPrivate
     // Value: List of device_link structs
     GList *deviceLinks;
 
+    // Value: List of feature_link structs
+    GList *featureLinks;
+
     OsinfoMediaList *medias;
     OsinfoTreeList *trees;
     OsinfoOsVariantList *variants;
@@ -117,6 +120,8 @@ osinfo_os_finalize(GObject *object)
 
     g_list_foreach(os->priv->deviceLinks, osinfo_link_free, NULL);
     g_list_free(os->priv->deviceLinks);
+    g_list_foreach(os->priv->featureLinks, osinfo_link_free, NULL);
+    g_list_free(os->priv->featureLinks);
     g_object_unref(os->priv->medias);
     g_object_unref(os->priv->trees);
     g_object_unref(os->priv->variants);
@@ -183,6 +188,7 @@ osinfo_os_init(OsinfoOs *os)
     os->priv = OSINFO_OS_GET_PRIVATE(os);
 
     os->priv->deviceLinks = NULL;
+    os->priv->featureLinks = NULL;
     os->priv->medias = osinfo_medialist_new();
     os->priv->trees = osinfo_treelist_new();
     os->priv->variants = osinfo_os_variantlist_new();
@@ -246,6 +252,8 @@ osinfo_os_get_targets_internal(OsinfoOs *os,
 
     if (OSINFO_IS_DEVICELIST(list)) {
         tmp = os->priv->deviceLinks;
+    } else if (OSINFO_IS_FEATURELIST(list)) {
+        tmp = os->priv->featureLinks;
     } else {
         g_return_if_reached();
     }
@@ -300,6 +308,8 @@ static void get_all_targets_cb(OsinfoProduct *product, gpointer user_data)
 
     if (OSINFO_IS_DEVICELIST(foreach_data->targets)) {
         targets = OSINFO_LIST(osinfo_devicelist_new());
+    } else if (OSINFO_IS_FEATURELIST(foreach_data->targets)) {
+        targets = OSINFO_LIST(osinfo_featurelist_new());
     } else {
         g_return_if_reached();
     }
@@ -349,6 +359,12 @@ osinfo_os_get_all_targets(OsinfoOs *os,
         unsupported_links = OSINFO_LINKLIST(osinfo_devicelinklist_new());
         unsupported_targets = OSINFO_LIST(osinfo_devicelist_new());
         new_list = OSINFO_LIST(osinfo_devicelist_new());
+    } else if (OSINFO_IS_FEATURELIST(data->targets)) {
+        links = OSINFO_LINKLIST(osinfo_featurelinklist_new());
+        tmp_links = OSINFO_LINKLIST(osinfo_featurelinklist_new());
+        unsupported_links = OSINFO_LINKLIST(osinfo_featurelinklist_new());
+        unsupported_targets = OSINFO_LIST(osinfo_featurelist_new());
+        new_list = OSINFO_LIST(osinfo_featurelist_new());
     } else {
         g_return_val_if_reached(NULL);
     }
@@ -457,6 +473,8 @@ osinfo_os_get_links_internal(OsinfoOs *os,
 
     if (OSINFO_IS_DEVICELINKLIST(list)) {
         tmp = os->priv->deviceLinks;
+    } else if (OSINFO_IS_FEATURELINKLIST(list)) {
+        tmp = os->priv->featureLinks;
     } else {
         g_return_if_reached();
     }
@@ -513,6 +531,8 @@ static void get_all_links_cb(OsinfoProduct *product, gpointer user_data)
 
     if (OSINFO_IS_DEVICELINKLIST(foreach_data->links)) {
         links = OSINFO_LINKLIST(osinfo_devicelinklist_new());
+    } else if (OSINFO_IS_FEATURELINKLIST(foreach_data->links)) {
+        links = OSINFO_LINKLIST(osinfo_featurelinklist_new());
     } else {
         g_return_if_reached();
     }
@@ -551,6 +571,8 @@ osinfo_os_get_all_links_internal(OsinfoOs *os,
 
     if (OSINFO_IS_DEVICELINKLIST(foreach_data.links)) {
         new_links = OSINFO_LINKLIST(osinfo_devicelinklist_new());
+    } else if (OSINFO_IS_FEATURELINKLIST(foreach_data.links)) {
+        new_links = OSINFO_LINKLIST(osinfo_featurelinklist_new());
     } else {
         g_return_val_if_reached(NULL);
     }
@@ -615,6 +637,109 @@ OsinfoDeviceLink *osinfo_os_add_device(OsinfoOs *os, OsinfoDevice *dev)
     return devlink;
 }
 
+/**
+ * osinfo_os_get_all_feature_links:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional feature property filter
+ *
+ * Get all featurelinks matching a given filter but unlike
+ * osinfo_os_get_feature_links this function also retrieves features from all
+ * derived and cloned operating systems.
+ *
+ * Returns: (transfer full): A list of OsinfoFeatureLink
+ */
+OsinfoFeatureLinkList *osinfo_os_get_all_feature_links(OsinfoOs *os, OsinfoFilter *filter)
+{
+    OsinfoFeatureLinkList *links = osinfo_featurelinklist_new();
+    return OSINFO_FEATURELINKLIST(osinfo_os_get_all_links_internal(os,
+                                                                   filter,
+                                                                   FALSE,
+                                                                   OSINFO_LINKLIST(links)));
+}
+
+/**
+ * osinfo_os_get_feature_links:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional feature property filter
+ *
+ * Get all features matching a given filter. The filter
+ * matches against the links, not the features.
+ *
+ * Returns: (transfer full): A list of feature links
+ */
+OsinfoFeatureLinkList *osinfo_os_get_feature_links(OsinfoOs *os, OsinfoFilter *filter)
+{
+    OsinfoFeatureLinkList *list = osinfo_featurelinklist_new();
+    osinfo_os_get_links_internal(os,
+                                 filter,
+                                 FALSE,
+                                 OSINFO_LINKLIST(list));
+    return list;
+}
+
+/**
+ * osinfo_os_get_all_features:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional feature property filter
+ *
+ * Get all features matching a given filter but unlike osinfo_os_get_features
+ * this function also retrieves features from all derived and cloned operating
+ * systems.
+ *
+ * Returns: (transfer full): A list of features
+ */
+OsinfoFeatureList *osinfo_os_get_all_features(OsinfoOs *os, OsinfoFilter *filter)
+{
+    struct GetAllTargetsData foreach_data = {
+        .filter = filter,
+        .targets = OSINFO_LIST(osinfo_featurelist_new()),
+    };
+
+    return OSINFO_FEATURELIST(osinfo_os_get_all_targets(os, filter, &foreach_data));
+
+}
+
+/**
+ * osinfo_os_get_features:
+ * @os: an operating system
+ * @filter: (allow-none)(transfer none): an optional feature property filter
+ *
+ * Get all features matching a given filter
+ *
+ * Returns: (transfer full): A list of features
+ */
+OsinfoFeatureList *osinfo_os_get_features(OsinfoOs *os, OsinfoFilter *filter)
+{
+    OsinfoFeatureList *list = osinfo_featurelist_new();
+
+    osinfo_os_get_targets_internal(os, filter, FALSE, OSINFO_LIST(list));
+    return list;
+
+}
+
+/**
+ * osinfo_os_add_feature:
+ * @os: an operating system
+ * @dev: (transfer none): the feature to associate with
+ *
+ * Associated a feature with an operating system.  The
+ * returned #OsinfoFeatureLink can be used to record
+ * extra metadata against the link
+ *
+ * Returns: (transfer none): the feature association
+ */
+OsinfoFeatureLink *osinfo_os_add_feature(OsinfoOs *os, OsinfoFeature *feature)
+{
+    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
+    g_return_val_if_fail(OSINFO_IS_FEATURE(feature), NULL);
+
+    OsinfoFeatureLink *featurelink = osinfo_featurelink_new(feature);
+
+    os->priv->featureLinks = g_list_append(os->priv->featureLinks, featurelink);
+
+    return featurelink;
+}
+
 /**
  * osinfo_os_get_family:
  * @os: an #OsinfoOs
diff --git a/osinfo/osinfo_os.h b/osinfo/osinfo_os.h
index ed132b8..40c31d6 100644
--- a/osinfo/osinfo_os.h
+++ b/osinfo/osinfo_os.h
@@ -34,6 +34,8 @@
 #include <osinfo/osinfo_tree.h>
 #include <osinfo/osinfo_resources.h>
 #include <osinfo/osinfo_resourceslist.h>
+#include <osinfo/osinfo_feature.h>
+#include <osinfo/osinfo_featurelink.h>
 
 #ifndef __OSINFO_OS_H__
 #define __OSINFO_OS_H__
@@ -133,6 +135,12 @@ 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);
 
+OsinfoFeatureLink *osinfo_os_add_feature(OsinfoOs *os, OsinfoFeature *feature);
+OsinfoFeatureList *osinfo_os_get_all_features(OsinfoOs *os, OsinfoFilter *filter);
+OsinfoFeatureList *osinfo_os_get_features(OsinfoOs *os, OsinfoFilter *filter);
+OsinfoFeatureLinkList *osinfo_os_get_all_feature_links(OsinfoOs *os, OsinfoFilter *filter);
+OsinfoFeatureLinkList *osinfo_os_get_feature_links(OsinfoOs *os, OsinfoFilter *filter);
+
 #endif /* __OSINFO_OS_H__ */
 /*
  * Local variables:
-- 
2.19.1




More information about the Libosinfo mailing list