[libosinfo PATCH v2 02/12] osinfo: Introduce OsinfoFeature

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

 



OsinfoFeature is a new type intended to represent *guest* features. Its
XML representation is something towards the lines of:

<features>
  <feature supported="false">cpu-hotplug</feature>
  <feature>pci-device-hotplug</feature>
  <feature>numa</feature>
</features>

Where supported is an optional attribute which has "true" as its default
value.

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 osinfo/Makefile.am              |   2 +
 osinfo/libosinfo.syms           |   4 +
 osinfo/osinfo.h                 |   1 +
 osinfo/osinfo_feature.c         | 202 ++++++++++++++++++++++++++++++++
 osinfo/osinfo_feature.h         |  81 +++++++++++++
 osinfo/osinfo_feature_private.h |  36 ++++++
 po/POTFILES.in                  |   1 +
 7 files changed, 327 insertions(+)
 create mode 100644 osinfo/osinfo_feature.c
 create mode 100644 osinfo/osinfo_feature.h
 create mode 100644 osinfo/osinfo_feature_private.h

diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index b43e32b..d553ecc 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -80,6 +80,7 @@ libosinfo_impl_include_HEADERS =		\
   osinfo_device_driver.h		\
   osinfo_device_driverlist.h		\
   osinfo_entity.h			\
+  osinfo_feature.h			\
   osinfo_filter.h			\
   osinfo_install_config.h		\
   osinfo_install_config_param.h		\
@@ -127,6 +128,7 @@ libosinfo_c_files =		\
   osinfo_devicelinkfilter.c		\
   osinfo_device_driver.c		\
   osinfo_device_driverlist.c		\
+  osinfo_feature.c			\
   osinfo_install_config.c		\
   osinfo_install_config_param.c		\
   osinfo_install_config_paramlist.c	\
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 56cf9a5..ef0db99 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -533,6 +533,10 @@ LIBOSINFO_1.3.0 {
     global:
 	osinfo_error_quark;
 
+	osinfo_feature_get_name;
+	osinfo_feature_get_type;
+	osinfo_feature_new;
+
 	osinfo_image_get_architecture;
 	osinfo_image_get_cloud_init;
 	osinfo_image_get_format;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 81c0daf..ff7f2e5 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -31,6 +31,7 @@
 #include <osinfo/osinfo_datamaplist.h>
 #include <osinfo/osinfo_enum_types.h>
 #include <osinfo/osinfo_entity.h>
+#include <osinfo/osinfo_feature.h>
 #include <osinfo/osinfo_filter.h>
 #include <osinfo/osinfo_list.h>
 #include <osinfo/osinfo_device.h>
diff --git a/osinfo/osinfo_feature.c b/osinfo/osinfo_feature.c
new file mode 100644
index 0000000..520fa14
--- /dev/null
+++ b/osinfo/osinfo_feature.c
@@ -0,0 +1,202 @@
+/*
+ * libosinfo: A single guest feature
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Fabiano Fidêncio <fidencio@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include <glib/gi18n-lib.h>
+
+#include "osinfo/osinfo_feature_private.h"
+
+G_DEFINE_TYPE(OsinfoFeature, osinfo_feature, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_FEATURE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OSINFO_TYPE_FEATURE, OsinfoFeaturePrivate))
+
+/**
+ * SECTION:osinfo_feature
+ * @short_description: A guest feature
+ * @see_also: #OsinfoOs, #OsinfoPlatform
+ *
+ * #OsinfoFeature is an entity representing some kind of guest
+ * feature. Features can be associated with operating systems
+ * and platforms.
+ */
+
+struct _OsinfoFeaturePrivate
+{
+    gboolean unsupported;
+};
+
+enum {
+    PROP_0,
+
+    PROP_NAME
+};
+
+static void
+osinfo_feature_set_property(GObject *object,
+                            guint property_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+    OsinfoFeature *feature = OSINFO_FEATURE(object);
+
+    switch(property_id) {
+        case PROP_NAME:
+            osinfo_entity_set_param(OSINFO_ENTITY(feature),
+                                    OSINFO_FEATURE_PROP_NAME,
+                                    g_value_get_string(value));
+            break;
+
+        default:
+            /* We don't have any other property ... */
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+            break;
+    }
+}
+
+static void
+osinfo_feature_get_property(GObject *object,
+                            guint property_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+    OsinfoFeature *feature = OSINFO_FEATURE(object);
+
+    switch(property_id) {
+        case PROP_NAME:
+            g_value_set_string(value, osinfo_feature_get_name(feature));
+            break;
+
+        default:
+            /* We don't have any other property ... */
+            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+            break;
+    }
+}
+
+static void osinfo_feature_finalize(GObject *object);
+
+static void
+osinfo_feature_finalize(GObject *object)
+{
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS(osinfo_feature_parent_class)->finalize(object);
+}
+
+/* Init functions */
+static void
+osinfo_feature_class_init(OsinfoFeatureClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS(klass);
+    GParamSpec *pspec;
+
+    g_klass->set_property = osinfo_feature_set_property;
+    g_klass->get_property = osinfo_feature_get_property;
+
+    /**
+     * OsinfoFeature:name:
+     *
+     * The name of the feature
+     */
+    pspec = g_param_spec_string("name",
+                                "Name",
+                                _("Feature name"),
+                                NULL,
+                                G_PARAM_WRITABLE |
+                                G_PARAM_READABLE |
+                                G_PARAM_CONSTRUCT_ONLY |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_NAME, pspec);
+
+    g_klass->finalize = osinfo_feature_finalize;
+    g_type_class_add_private(klass, sizeof(OsinfoFeaturePrivate));
+}
+
+static void
+osinfo_feature_init(OsinfoFeature *feature)
+{
+    feature->priv = OSINFO_FEATURE_GET_PRIVATE(feature);
+}
+
+OsinfoFeature *osinfo_feature_new(const gchar *name)
+{
+    return g_object_new(OSINFO_TYPE_FEATURE,
+                        "id", name,
+                        "name", name,
+                        NULL);
+}
+
+/**
+ * osinfo_feature_get_name:
+ * @feature: an #OsinfoFeature instance
+ *
+ * Return the name of the feature.
+ *
+ * Returns: (transfer none): the name of the feature
+ */
+const gchar *osinfo_feature_get_name(OsinfoFeature *feature)
+{
+    g_return_val_if_fail(OSINFO_IS_FEATURE(feature), NULL);
+
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(feature), OSINFO_FEATURE_PROP_NAME);
+}
+
+/**
+ * osinfo_feature_get_supported:
+ * @feature: an #OsinfoFeature instance
+ *
+ * Mind that this method is *private*!
+ *
+ * Return whether the feature is supported or not.
+ */
+gboolean osinfo_feature_get_supported(OsinfoFeature *feature)
+{
+    g_return_val_if_fail(OSINFO_IS_FEATURE(feature), FALSE);
+
+    return !feature->priv->unsupported;
+}
+
+/**
+ * osinfo_feature_set_supported
+ * @feature: an #OsinfoFeature instance
+ * @supported: boolean value
+ *
+ * Mind that this method is *private*!
+ *
+ * Set whether a feature is supported or not.
+ */
+void osinfo_feature_set_supported(OsinfoFeature *feature, gboolean supported)
+{
+    g_return_if_fail(OSINFO_IS_FEATURE(feature));
+
+    feature->priv->unsupported = !supported;
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_feature.h b/osinfo/osinfo_feature.h
new file mode 100644
index 0000000..c4fca30
--- /dev/null
+++ b/osinfo/osinfo_feature.h
@@ -0,0 +1,81 @@
+/*
+ * libosinfo: A single guest feature
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *   Fabiano Fidêncio <fidencio@xxxxxxxxxx>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_entity.h>
+
+#ifndef __OSINFO_FEATURE_H__
+#define __OSINFO_FEATURE_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_FEATURE                  (osinfo_feature_get_type ())
+#define OSINFO_FEATURE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_FEATURE, OsinfoFeature))
+#define OSINFO_IS_FEATURE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_FEATURE))
+#define OSINFO_FEATURE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_FEATURE, OsinfoFeatureClass))
+#define OSINFO_IS_FEATURE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_FEATURE))
+#define OSINFO_FEATURE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_FEATURE, OsinfoFeatureClass))
+
+typedef struct _OsinfoFeature        OsinfoFeature;
+
+typedef struct _OsinfoFeatureClass   OsinfoFeatureClass;
+
+typedef struct _OsinfoFeaturePrivate OsinfoFeaturePrivate;
+
+#define OSINFO_FEATURE_PROP_NAME       "name"
+
+/* object */
+struct _OsinfoFeature
+{
+    OsinfoEntity parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoFeaturePrivate *priv;
+};
+
+/* class */
+struct _OsinfoFeatureClass
+{
+    /*< private >*/
+    OsinfoEntityClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_feature_get_type(void);
+
+OsinfoFeature *osinfo_feature_new(const gchar *name);
+
+const gchar *osinfo_feature_get_name(OsinfoFeature *feature);
+
+#endif /* __OSINFO_FEATURE_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_feature_private.h b/osinfo/osinfo_feature_private.h
new file mode 100644
index 0000000..132c661
--- /dev/null
+++ b/osinfo/osinfo_feature_private.h
@@ -0,0 +1,36 @@
+/*
+ * libosinfo: A single guest feature
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <osinfo/osinfo_feature.h>
+
+#ifndef __OSINFO_FEATURE_PRIVATE_H__
+#define __OSINFO_FEATURE_PRIVATE_H__
+
+gboolean osinfo_feature_get_supported(OsinfoFeature *feature);
+void osinfo_feature_set_supported(OsinfoFeature *feature, gboolean supported);
+
+#endif /* __OSINFO_FEATURE_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2a714df..86f7090 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@ osinfo/osinfo_deployment.c
 osinfo/osinfo_devicelink.c
 osinfo/osinfo_devicelinkfilter.c
 osinfo/osinfo_entity.c
+osinfo/osinfo_feature.c
 osinfo/osinfo_image.c
 osinfo/osinfo_install_config_param.c
 osinfo/osinfo_install_script.c
-- 
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