Add a way to access the <enum name="firmware"/> element's conent from
<os/>.
Signed-off-by: Fabiano FidĂȘncio <fidencio(a)redhat.com>
---
.../libvirt-gconfig-domain-capabilities-os.c | 74 ++++++++++++++++++-
.../libvirt-gconfig-domain-capabilities-os.h | 7 +-
libvirt-gconfig/libvirt-gconfig.sym | 1 +
3 files changed, 80 insertions(+), 2 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c
b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c
index d3b6e3c..98a1bff 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.c
@@ -33,11 +33,83 @@ struct _GVirConfigDomainCapabilitiesOsPrivate
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilitiesOs,
gvir_config_domain_capabilities_os, GVIR_CONFIG_TYPE_OBJECT);
-static void
gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass
G_GNUC_UNUSED)
+static GList *
+_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os);
+
+static void
gvir_config_domain_capabilities_os_class_init(GVirConfigDomainCapabilitiesOsClass *klass)
{
+ klass->get_firmwares = _gvir_config_domain_capabilities_os_get_firmwares;
}
static void gvir_config_domain_capabilities_os_init(GVirConfigDomainCapabilitiesOs *os)
{
os->priv = GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(os);
}
+
+static gboolean add_firmwares(xmlNodePtr node, gpointer opaque)
+{
+ GList **firmwares = opaque;
+ GVirConfigDomainOsFirmware firmware;
+
+ if (node == NULL || node->children == NULL)
+ return TRUE;
+
+ firmware = gvir_config_genum_get_value
+ (GVIR_CONFIG_TYPE_DOMAIN_OS_FIRMWARE,
+ (const gchar *)node->children->content,
+ GVIR_CONFIG_DOMAIN_OS_FIRMWARE_BIOS);
+ *firmwares = g_list_append(*firmwares, GINT_TO_POINTER(firmware));
+
+ return TRUE;
+}
+
+static gboolean search_firmwares(xmlNodePtr node, gpointer opaque)
+{
+ const gchar *content;
+
+ if (!g_str_equal(node->name, "enum"))
+ return TRUE;
+
+ content = gvir_config_xml_get_attribute_content(node, "name");
+ if (content == NULL)
+ return TRUE;
+
+ if (!g_str_equal(content, "firmware"))
+ return TRUE;
+
+ gvir_config_xml_foreach_child(node,
+ add_firmwares,
+ opaque);
+
+ return TRUE;
+}
+
+static GList *
+_gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os)
+{
+ GList *firmwares = NULL;
+
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CAPABILITIES_OS(os), NULL);
+
+ gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(os),
+ NULL,
+ search_firmwares,
+ &firmwares);
+
+ return firmwares;
+}
+
+/**
+ * gvir_config_domain_capabilities_os_get_firmwares:
+ *
+ * Gets the firmwares supported by @os. The returned list should be freed with
+ * g_list_free().
+ *
+ * Returns: (element-type LibvirtGConfig.DomainOsFirmware) (transfer container):
+ * a newly allocated #GList of #GVirConfigDomainOsFirmware.
+ */
+GList *
+gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os)
+{
+ return GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_CLASS(os)->get_firmwares(os);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h
b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h
index dba8572..ce36be2 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-capabilities-os.h
@@ -51,11 +51,16 @@ struct _GVirConfigDomainCapabilitiesOsClass
{
GVirConfigObjectClass parent_class;
- gpointer padding[20];
+ GList *(*get_firmwares)(GVirConfigDomainCapabilitiesOs *os);
+
+ gpointer padding[19];
};
GType gvir_config_domain_capabilities_os_get_type(void);
+GList *
+gvir_config_domain_capabilities_os_get_firmwares(GVirConfigDomainCapabilitiesOs *os);
+
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_DOMAIN_CAPABILITIES_OS_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 783b0d7..d40bb7b 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -778,6 +778,7 @@ global:
gvir_config_domain_capabilities_get_type;
gvir_config_domain_capabilities_new;
gvir_config_domain_capabilities_new_from_xml;
+ gvir_config_domain_capabilities_os_get_firmwares;
gvir_config_domain_capabilities_os_get_type;
gvir_config_domain_os_firmware_get_type;
gvir_config_domain_os_set_firmware;
--
2.21.0