summaryrefslogtreecommitdiff
path: root/osinfo/osinfo_device_driver.c
blob: b2302b4cf49c8c6f8618d655d868366525d1d89e (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * libosinfo: Device driver
 *
 * Copyright (C) 2009-2012 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:
 *   Zeeshan Ali <zeenix@redhat.com>
 */

#include <config.h>

#include <osinfo/osinfo.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>

#include "osinfo_device_driver_private.h"

G_DEFINE_TYPE (OsinfoDeviceDriver, osinfo_device_driver, OSINFO_TYPE_ENTITY);

#define OSINFO_DEVICE_DRIVER_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
                                      OSINFO_TYPE_DEVICE_DRIVER, \
                                      OsinfoDeviceDriverPrivate))

/**
 * SECTION:osinfo_device_driver
 * @short_description: Information about device driver
 * @see_also: #OsinfoOs
 *
 * #OsinfoDeviceDriver is an entity representing device drivers for an (guest)
 * operating system.
 */

struct _OsinfoDeviceDriverPrivate
{
    OsinfoDeviceList *devices;
};

static void
osinfo_device_driver_finalize (GObject *object)
{
    OsinfoDeviceDriver *driver = OSINFO_DEVICE_DRIVER (object);

    g_object_unref(driver->priv->devices);

    /* Chain up to the parent class */
    G_OBJECT_CLASS (osinfo_device_driver_parent_class)->finalize (object);
}

/* Init functions */
static void
osinfo_device_driver_class_init (OsinfoDeviceDriverClass *klass)
{
    GObjectClass *g_klass = G_OBJECT_CLASS (klass);

    g_klass->finalize = osinfo_device_driver_finalize;
    g_type_class_add_private (klass, sizeof (OsinfoDeviceDriverPrivate));
}

static void
osinfo_device_driver_init (OsinfoDeviceDriver *driver)
{
    driver->priv = OSINFO_DEVICE_DRIVER_GET_PRIVATE(driver);
    driver->priv->devices = osinfo_devicelist_new ();
}

OsinfoDeviceDriver *osinfo_device_driver_new(const gchar *id)
{
    OsinfoDeviceDriver *driver;

    driver = g_object_new (OSINFO_TYPE_DEVICE_DRIVER,
                           "id", id,
                           NULL);

    return driver;
}

/**
 * osinfo_device_driver_get_architecture:
 * @driver: an #OsinfoDeviceDriver instance
 *
 * Retrieves the target hardware architecture of @driver.
 *
 * Returns: (transfer none): the hardware architecture.
 */
const gchar *osinfo_device_driver_get_architecture(OsinfoDeviceDriver *driver)
{
    return osinfo_entity_get_param_value(OSINFO_ENTITY(driver),
                                         OSINFO_DEVICE_DRIVER_PROP_ARCHITECTURE);
}

/**
 * osinfo_device_driver_get_location:
 * @driver: an #OsinfoDeviceDriver instance
 *
 * Retrieves the location of the @driver as a URL.
 *
 * Returns: (transfer none): the location of the driver.
 */
const gchar *osinfo_device_driver_get_location(OsinfoDeviceDriver *driver)
{
    return osinfo_entity_get_param_value(OSINFO_ENTITY(driver),
                                         OSINFO_DEVICE_DRIVER_PROP_LOCATION);
}

/**
 * osinfo_device_driver_get_files:
 * @driver: an #OsinfoDeviceDriver instance
 *
 * Retrieves the names of driver files under the location returned by
 * #osinfo_device_driver_get_location.
 *
 * Returns: (transfer container) (element-type utf8): The list of driver files.
 */
GList *osinfo_device_driver_get_files(OsinfoDeviceDriver *driver)
{
    return osinfo_entity_get_param_value_list(OSINFO_ENTITY(driver),
                                              OSINFO_DEVICE_DRIVER_PROP_FILE);
}

/**
 * osinfo_device_driver_get_pre_installable:
 * @driver: an #OsinfoDeviceDriver instance
 *
 * Returns: TRUE if @driver is pre-installable, FALSE otherwise.
 */
gboolean osinfo_device_driver_get_pre_installable(OsinfoDeviceDriver *driver)
{
    return osinfo_entity_get_param_value_boolean
                (OSINFO_ENTITY(driver),
                 OSINFO_DEVICE_DRIVER_PROP_PRE_INSTALLABLE);
}

/**
 * osinfo_device_driver_get_devices:
 * @driver: an #OsinfoDeviceDriver instance
 *
 * Returns: (transfer none): The list of devices supported by this driver.
 */
OsinfoDeviceList *osinfo_device_driver_get_devices(OsinfoDeviceDriver *driver)
{
    g_return_val_if_fail(OSINFO_IS_DEVICE_DRIVER(driver), NULL);

    return driver->priv->devices;
}

void osinfo_device_driver_add_device(OsinfoDeviceDriver *driver,
                                     OsinfoDevice *device)
{
    g_return_if_fail(OSINFO_IS_DEVICE_DRIVER(driver));
    g_return_if_fail(OSINFO_IS_DEVICE(device));

    osinfo_list_add(OSINFO_LIST(driver->priv->devices),
                    OSINFO_ENTITY(device));
}

/*
 * Local variables:
 *  indent-tabs-mode: nil
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 */