[libosinfo PATCH 1/7] firmware: Add OsinfoFirmware

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

 



OsinfoFirmware has been created in order to represent the firmware types
supported by an OS.

The schema representation of this object is:
<firmware arch="arch name" type="bios|efi"/>

Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx>
---
 docs/reference/Libosinfo-docs.xml |   1 +
 osinfo/Makefile.am                |   2 +
 osinfo/libosinfo.syms             |   4 +
 osinfo/osinfo.h                   |   1 +
 osinfo/osinfo_firmware.c          | 202 ++++++++++++++++++++++++++++++
 osinfo/osinfo_firmware.h          |  73 +++++++++++
 po/POTFILES.in                    |   1 +
 7 files changed, 284 insertions(+)
 create mode 100644 osinfo/osinfo_firmware.c
 create mode 100644 osinfo/osinfo_firmware.h

diff --git a/docs/reference/Libosinfo-docs.xml b/docs/reference/Libosinfo-docs.xml
index c21efc5..df8dd36 100644
--- a/docs/reference/Libosinfo-docs.xml
+++ b/docs/reference/Libosinfo-docs.xml
@@ -31,6 +31,7 @@
     <xi:include href="xml/osinfo_entity.xml"/>
     <xi:include href="xml/osinfo_enum_types.xml"/>
     <xi:include href="xml/osinfo_filter.xml"/>
+    <xi:include href="xml/osinfo_firmware.xml"/>
     <xi:include href="xml/osinfo_image.xml"/>
     <xi:include href="xml/osinfo_imagelist.xml"/>
     <xi:include href="xml/osinfo_install_config.xml"/>
diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index cb1df8f..c722757 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -81,6 +81,7 @@ libosinfo_impl_include_HEADERS =		\
   osinfo_device_driverlist.h		\
   osinfo_entity.h			\
   osinfo_filter.h			\
+  osinfo_firmware.h			\
   osinfo_install_config.h		\
   osinfo_install_config_param.h		\
   osinfo_install_config_paramlist.h	\
@@ -119,6 +120,7 @@ libosinfo_c_files =		\
   osinfo_datamaplist.c			\
   osinfo_entity.c			\
   osinfo_filter.c			\
+  osinfo_firmware.c			\
   osinfo_list.c				\
   osinfo_device.c			\
   osinfo_devicelink.c			\
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 853acf5..cacaf71 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -570,6 +570,10 @@ LIBOSINFO_1.4.0 {
 
 LIBOSINFO_1.5.0 {
     global:
+	osinfo_firmware_get_architecture;
+	osinfo_firmware_get_firmware_type;
+	osinfo_firmware_get_type;
+
 	osinfo_image_get_os;
 	osinfo_image_get_os_variants;
 	osinfo_image_set_os;
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 20a8f3a..2063c73 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -40,6 +40,7 @@
 #include <osinfo/osinfo_devicelist.h>
 #include <osinfo/osinfo_devicelinklist.h>
 #include <osinfo/osinfo_devicelinkfilter.h>
+#include <osinfo/osinfo_firmware.h>
 #include <osinfo/osinfo_install_config.h>
 #include <osinfo/osinfo_install_config_param.h>
 #include <osinfo/osinfo_install_config_paramlist.h>
diff --git a/osinfo/osinfo_firmware.c b/osinfo/osinfo_firmware.c
new file mode 100644
index 0000000..c0476c4
--- /dev/null
+++ b/osinfo/osinfo_firmware.c
@@ -0,0 +1,202 @@
+/*
+ * libosinfo: A firmware representation for a (guest) OS
+ *
+ * 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 <config.h>
+
+#include <osinfo/osinfo.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n-lib.h>
+
+G_DEFINE_TYPE(OsinfoFirmware, osinfo_firmware, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_FIRMWARE_GET_PRIVATE(obj)                    \
+    (G_TYPE_INSTANCE_GET_PRIVATE((obj),                \
+                                  OSINFO_TYPE_FIRMWARE,     \
+                                  OsinfoFirmwarePrivate))
+
+/**
+ * SECTION:osinfo_firmware
+ * @short_description: A firmware representation for a (guest) OS
+ * @see_also: #OsinfoOs
+ *
+ * #OsinfoFirmware is an entity representing a firmware used to boot
+ * a (guest) operating system.
+ */
+
+struct _OsinfoFirmwarePrivate
+{
+    gboolean unused;
+};
+
+enum {
+    PROP_0,
+
+    PROP_ARCHITECTURE,
+    PROP_FIRMWARE_TYPE,
+};
+
+static void
+osinfo_firmware_get_property(GObject *object,
+                             guint property_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+    OsinfoFirmware *firmware = OSINFO_FIRMWARE(object);
+
+    switch (property_id) {
+    case PROP_ARCHITECTURE:
+        g_value_set_string(value, osinfo_firmware_get_architecture(firmware));
+        break;
+
+    case PROP_FIRMWARE_TYPE:
+        g_value_set_string(value, osinfo_firmware_get_firmware_type(firmware));
+        break;
+
+    default:
+        /* We don't have any other property... */
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+        break;
+    }
+}
+
+static void
+osinfo_firmware_set_property(GObject      *object,
+                             guint         property_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
+{
+    OsinfoFirmware *firmware = OSINFO_FIRMWARE(object);
+
+    switch (property_id) {
+    case PROP_ARCHITECTURE:
+        osinfo_entity_set_param(OSINFO_ENTITY(firmware),
+                                OSINFO_FIRMWARE_PROP_ARCHITECTURE,
+                                g_value_get_string(value));
+        break;
+
+    case PROP_FIRMWARE_TYPE:
+        osinfo_entity_set_param(OSINFO_ENTITY(firmware),
+                                OSINFO_FIRMWARE_PROP_TYPE,
+                                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_firmware_finalize(GObject *object)
+{
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS(osinfo_firmware_parent_class)->finalize(object);
+}
+
+/* Init functions */
+static void
+osinfo_firmware_class_init(OsinfoFirmwareClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS(klass);
+    GParamSpec *pspec;
+
+    g_klass->finalize = osinfo_firmware_finalize;
+    g_klass->get_property = osinfo_firmware_get_property;
+    g_klass->set_property = osinfo_firmware_set_property;
+    g_type_class_add_private(klass, sizeof(OsinfoFirmwarePrivate));
+
+    /**
+     * OsinfoFirmware:architecture:
+     *
+     * The target hardware architecture of this firmware.
+     */
+    pspec = g_param_spec_string("architecture",
+                                "ARCHITECTURE",
+                                _("CPU Architecture"),
+                                NULL /* default value */,
+                                G_PARAM_READWRITE |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_ARCHITECTURE, pspec);
+
+    /**
+     * OsinfoFirmware:firmware-type:
+     *
+     * The firmware type.
+     */
+    pspec = g_param_spec_string("type",
+                                "TYPE",
+                                _("The firmware type"),
+                                NULL /* default value */,
+                                G_PARAM_READWRITE |
+                                G_PARAM_STATIC_STRINGS);
+    g_object_class_install_property(g_klass, PROP_FIRMWARE_TYPE, pspec);
+}
+
+static void
+osinfo_firmware_init(OsinfoFirmware *firmware)
+{
+    firmware->priv = OSINFO_FIRMWARE_GET_PRIVATE(firmware);
+}
+
+OsinfoFirmware *osinfo_firmware_new(const gchar *id,
+                                    const gchar *architecture,
+                                    const gchar *type)
+{
+    OsinfoFirmware *firmware;
+
+    firmware = g_object_new(OSINFO_TYPE_FIRMWARE,
+                            "id", id,
+                            OSINFO_FIRMWARE_PROP_ARCHITECTURE, architecture,
+                            OSINFO_FIRMWARE_PROP_TYPE, type,
+                            NULL);
+
+    return firmware;
+}
+
+/**
+ * osinfo_firmware_get_architecture:
+ * @firmware: an #OsinfoFirmware instance
+ *
+ * Retrieves the target hardware architecture of the OS @firmware provides.
+ *
+ * Returns: (transfer none): the hardware architecture, or NULL
+ */
+const gchar *osinfo_firmware_get_architecture(OsinfoFirmware *firmware)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(firmware),
+                                         OSINFO_FIRMWARE_PROP_ARCHITECTURE);
+}
+
+/**
+ * osinfo_firmware_get_format:
+ * @firmware: an #OsinfoFirmware instance
+ *
+ * The format of the @firmware
+ *
+ * Returns: (transfer none): the format, or NULL
+ */
+const gchar *osinfo_firmware_get_firmware_type(OsinfoFirmware *firmware)
+{
+    return osinfo_entity_get_param_value(OSINFO_ENTITY(firmware),
+                                         OSINFO_FIRMWARE_PROP_TYPE);
+}
diff --git a/osinfo/osinfo_firmware.h b/osinfo/osinfo_firmware.h
new file mode 100644
index 0000000..c085e22
--- /dev/null
+++ b/osinfo/osinfo_firmware.h
@@ -0,0 +1,73 @@
+/*
+ * libosinfo: A firmware representation for a (guest) OS
+ *
+ * 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 <glib-object.h>
+#include <gio/gio.h>
+#include <osinfo/osinfo_entity.h>
+
+#ifndef __OSINFO_FIRMWARE_H__
+#define __OSINFO_FIRMWARE_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_FIRMWARE                  (osinfo_firmware_get_type ())
+#define OSINFO_FIRMWARE(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_FIRMWARE, OsinfoFirmware))
+#define OSINFO_IS_FIRMWARE(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_FIRMWARE))
+#define OSINFO_FIRMWARE_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_FIRMWARE, OsinfoFirmwareClass))
+#define OSINFO_IS_FIRMWARE_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_FIRMWARE))
+#define OSINFO_FIRMWARE_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_FIRMWARE, OsinfoFirmwareClass))
+
+#define OSINFO_FIRMWARE_PROP_ARCHITECTURE   "architecture"
+#define OSINFO_FIRMWARE_PROP_TYPE           "type"
+#define OSINFO_FIRMWARE_PROP_SUPPORTED      "supported"
+
+typedef struct _OsinfoFirmware          OsinfoFirmware;
+typedef struct _OsinfoFirmwareClass     OsinfoFirmwareClass;
+typedef struct _OsinfoFirmwarePrivate   OsinfoFirmwarePrivate;
+
+/* object */
+struct _OsinfoFirmware
+{
+    OsinfoEntity parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoFirmwarePrivate *priv;
+};
+
+/* class */
+struct _OsinfoFirmwareClass
+{
+    /*< private >*/
+    OsinfoEntityClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_firmware_get_type(void);
+
+OsinfoFirmware *osinfo_firmware_new(const gchar *id, const gchar *architecture, const gchar *type);
+const gchar *osinfo_firmware_get_architecture(OsinfoFirmware *firmware);
+const gchar *osinfo_firmware_get_firmware_type(OsinfoFirmware *firmware);
+gboolean osinfo_firmware_is_supported(OsinfoFirmware *firmware);
+
+#endif /* __OSINFO_FIRMWARE_H__ */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2a714df..3d9660e 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_firmware.c
 osinfo/osinfo_image.c
 osinfo/osinfo_install_config_param.c
 osinfo/osinfo_install_script.c
-- 
2.21.0

_______________________________________________
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