[Libosinfo] [libosinfo PATCH v3 02/12] osinfo: Introduce OsinfoFeature
Fabiano Fidêncio
fidencio at redhat.com
Fri Jan 18 12:30:37 UTC 2019
OsinfoFeature is a new type intended to represent *guest* features. Its
XML representation is something towards the lines of:
<features arch="all">
<feature>cpu-hotplug</feature>
</features>
<features arch="x86_64">
<feature state="on">hyperv-spinlocks</feature>
<feature state="on">hyperv-vapic</feature>
</features>
<features arch="i686">
<feature supported="false">cpu-hotplug</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 | 8 +
osinfo/osinfo.h | 1 +
osinfo/osinfo_feature.c | 313 ++++++++++++++++++++++++++++++++
osinfo/osinfo_feature.h | 90 +++++++++
osinfo/osinfo_feature_private.h | 38 ++++
po/POTFILES.in | 1 +
7 files changed, 453 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..0162081 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -533,6 +533,14 @@ LIBOSINFO_1.3.0 {
global:
osinfo_error_quark;
+ osinfo_feature_get_architecture;
+ osinfo_feature_get_name;
+ osinfo_feature_get_state;
+ osinfo_feature_get_type;
+ osinfo_feature_new;
+ osinfo_feature_set_state;
+ osinfo_feature_state_get_type;
+
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..6d77dda
--- /dev/null
+++ b/osinfo/osinfo_feature.c
@@ -0,0 +1,313 @@
+/*
+ * 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/>.
+ */
+
+#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 unused;
+};
+
+enum {
+ PROP_0,
+
+ PROP_ARCHITECTURE,
+ PROP_NAME,
+ PROP_STATE
+};
+
+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_ARCHITECTURE:
+ osinfo_entity_set_param(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_ARCHITECTURE,
+ g_value_get_string(value));
+ break;
+
+ case PROP_NAME:
+ osinfo_entity_set_param(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_NAME,
+ g_value_get_string(value));
+ break;
+
+ case PROP_STATE:
+ osinfo_entity_set_param_enum(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_STATE,
+ g_value_get_enum(value),
+ OSINFO_TYPE_FEATURE_STATE);
+ 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_ARCHITECTURE:
+ g_value_set_string(value, osinfo_feature_get_architecture(feature));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string(value, osinfo_feature_get_name(feature));
+ break;
+
+ case PROP_STATE:
+ g_value_set_enum(value, osinfo_feature_get_state(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:architecture:
+ *
+ * The target hardware architecture to which this feature applies.
+ */
+ pspec = g_param_spec_string("architecture",
+ "CPU Architecture",
+ _("CPU Architecture"),
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property(g_klass, PROP_ARCHITECTURE, pspec);
+
+ /**
+ * OsinfoFeature:name:
+ *
+ * The name of the feature
+ */
+ pspec = g_param_spec_string("name",
+ "Name",
+ _("Feature's name"),
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property(g_klass, PROP_NAME, pspec);
+
+ /**
+ * OsinfoFeature:state:
+ *
+ * The state of the feature, which is only valid for hyperv features.
+ */
+ pspec = g_param_spec_enum("state",
+ "State",
+ _("Feature's state"),
+ OSINFO_TYPE_FEATURE_STATE,
+ OSINFO_FEATURE_STATE_ABSENT,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property(g_klass, PROP_STATE, 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 *id,
+ const gchar *name,
+ const gchar *architecture)
+{
+ return g_object_new(OSINFO_TYPE_FEATURE,
+ "id", id,
+ OSINFO_FEATURE_PROP_NAME, name,
+ OSINFO_FEATURE_PROP_ARCHITECTURE, architecture,
+ 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_architecture:
+ * @feature: an #OsinfoFeature instance
+ *
+ * Retrieves the target hardware architecture to which the @feature applies.
+ * Some operating systems specify the same features for all architectures. In
+ * such cases, the string returned by this call will be
+ * #OSINFO_ARCHITECTURE_ALL.
+ *
+ * Returns: (transfer none): the hardware architecture.
+ */
+const gchar *osinfo_feature_get_architecture(OsinfoFeature *feature)
+{
+ g_return_val_if_fail(OSINFO_IS_FEATURE(feature), NULL);
+
+ return osinfo_entity_get_param_value(OSINFO_ENTITY(feature), OSINFO_FEATURE_PROP_ARCHITECTURE);
+}
+
+/**
+ * osinfo_feature_get_state:
+ * @feature: an #OsinfoFeature instance
+ *
+ * Returns: the state of the hyperv @feature
+ */
+OsinfoFeatureState osinfo_feature_get_state(OsinfoFeature *feature)
+{
+ g_return_val_if_fail(OSINFO_IS_FEATURE(feature), OSINFO_FEATURE_STATE_ABSENT);
+
+ return osinfo_entity_get_param_value_enum(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_STATE,
+ OSINFO_TYPE_FEATURE_STATE,
+ OSINFO_FEATURE_STATE_ABSENT);
+}
+
+/**
+ * osinfo_feature_set_state:
+ * @feature: an #OsinfoFeature instance
+ * @state: one of the possible states for the @feature:
+ * OSINFO_FEATURE_STATE_ABSENT
+ * OSINFO_FEATURE_STATE_ON
+ * OSINFO_FEATURE_STATE_OFF
+ *
+ * Note: @state only makes sense and only should be used with hyperv related
+ * features.
+ *
+ * Set the @state of a hyperv @feature.
+ */
+void osinfo_feature_set_state(OsinfoFeature *feature, OsinfoFeatureState state)
+{
+ g_return_if_fail(OSINFO_IS_FEATURE(feature));
+
+ osinfo_entity_set_param_enum(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_STATE,
+ state,
+ OSINFO_TYPE_FEATURE_STATE);
+}
+
+/**
+ * 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 osinfo_entity_get_param_value_boolean_with_default(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_SUPPORTED,
+ TRUE);
+}
+
+/**
+ * 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));
+
+ osinfo_entity_set_param_boolean(OSINFO_ENTITY(feature),
+ OSINFO_FEATURE_PROP_SUPPORTED,
+ 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..c669574
--- /dev/null
+++ b/osinfo/osinfo_feature.h
@@ -0,0 +1,90 @@
+/*
+ * 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_ARCHITECTURE "architecture"
+#define OSINFO_FEATURE_PROP_NAME "name"
+#define OSINFO_FEATURE_PROP_STATE "state"
+
+typedef enum {
+ OSINFO_FEATURE_STATE_ABSENT,
+ OSINFO_FEATURE_STATE_ON,
+ OSINFO_FEATURE_STATE_OFF,
+} OsinfoFeatureState;
+
+/* 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 *id, const gchar *name, const gchar *architecture);
+
+const gchar *osinfo_feature_get_architecture(OsinfoFeature *feature);
+const gchar *osinfo_feature_get_name(OsinfoFeature *feature);
+OsinfoFeatureState osinfo_feature_get_state(OsinfoFeature *feature);
+void osinfo_feature_set_state(OsinfoFeature *feature, OsinfoFeatureState state);
+
+#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..46dc16e
--- /dev/null
+++ b/osinfo/osinfo_feature_private.h
@@ -0,0 +1,38 @@
+/*
+ * 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__
+
+#define OSINFO_FEATURE_PROP_SUPPORTED "supported"
+
+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
More information about the Libosinfo
mailing list