[Libosinfo] [libosinfo PATCH 02/31] osinfo: Introduce OsinfoFeature

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


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 at redhat.com>
---
 osinfo/Makefile.am      |   2 +
 osinfo/libosinfo.syms   |   4 +
 osinfo/osinfo.h         |   1 +
 osinfo/osinfo_feature.c | 159 ++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_feature.h |  81 ++++++++++++++++++++
 po/POTFILES.in          |   1 +
 6 files changed, 248 insertions(+)
 create mode 100644 osinfo/osinfo_feature.c
 create mode 100644 osinfo/osinfo_feature.h

diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index a9a6542..f03e02c 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		\
@@ -125,6 +126,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 5396c72..48dbd44 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_os_add_maximum_resources;
 	osinfo_os_get_all_device_links;
 	osinfo_os_get_maximum_resources;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 8d0a595..d4a06a2 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..8a1dd87
--- /dev/null
+++ b/osinfo/osinfo_feature.c
@@ -0,0 +1,159 @@
+/*
+ * 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 at redhat.com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include <glib/gi18n-lib.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 unused;
+};
+
+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);
+}
+
+const gchar *osinfo_feature_get_name(OsinfoFeature *dev)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(dev), OSINFO_FEATURE_PROP_NAME);
+}
+
+/*
+ * 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..67ba9da
--- /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 at redhat.com>
+ */
+
+#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 *dev);
+
+#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 fc81f42..a5d4559 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_install_config_param.c
 osinfo/osinfo_install_script.c
 osinfo/osinfo_list.c
-- 
2.19.1




More information about the Libosinfo mailing list