File: libvirt-gconfig-domain-capabilities-os.c

package info (click to toggle)
libvirt-glib 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,996 kB
  • sloc: ansic: 21,257; sh: 4,648; makefile: 825; xml: 288; python: 146; perl: 104
file content (115 lines) | stat: -rw-r--r-- 3,725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * libvirt-gconfig-domain-capabilities-os.c: libvirt OS domain capabilities
 *
 * 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 "libvirt-gconfig/libvirt-gconfig.h"
#include "libvirt-gconfig/libvirt-gconfig-private.h"

#define GVIR_CONFIG_DOMAIN_CAPABILITIES_OS_GET_PRIVATE(obj)                         \
        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CAPABILITIES_OS, GVirConfigDomainCapabilitiesOsPrivate))

struct _GVirConfigDomainCapabilitiesOsPrivate
{
    gboolean unused;
};

G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainCapabilitiesOs, gvir_config_domain_capabilities_os, GVIR_CONFIG_TYPE_OBJECT);

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);
}