Blame libvirt-gconfig/libvirt-gconfig-domain-device.c

Packit a07778
/*
Packit a07778
 * libvirt-gconfig-domain-device.c: libvirt domain device configuration
Packit a07778
 *
Packit a07778
 * Copyright (C) 2011 Red Hat, Inc.
Packit a07778
 *
Packit a07778
 * This library is free software; you can redistribute it and/or
Packit a07778
 * modify it under the terms of the GNU Lesser General Public
Packit a07778
 * License as published by the Free Software Foundation; either
Packit a07778
 * version 2.1 of the License, or (at your option) any later version.
Packit a07778
 *
Packit a07778
 * This library is distributed in the hope that it will be useful,
Packit a07778
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a07778
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a07778
 * Lesser General Public License for more details.
Packit a07778
 *
Packit a07778
 * You should have received a copy of the GNU Lesser General Public
Packit a07778
 * License along with this library. If not, see
Packit a07778
 * <http://www.gnu.org/licenses/>.
Packit a07778
 *
Packit a07778
 * Author: Christophe Fergeau <cfergeau@gmail.com>
Packit a07778
 */
Packit a07778
Packit a07778
#include <config.h>
Packit a07778
Packit a07778
#include "libvirt-gconfig/libvirt-gconfig.h"
Packit a07778
#include "libvirt-gconfig/libvirt-gconfig-private.h"
Packit a07778
Packit a07778
#define GVIR_CONFIG_DOMAIN_DEVICE_GET_PRIVATE(obj)                         \
Packit a07778
        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_DEVICE, GVirConfigDomainDevicePrivate))
Packit a07778
Packit a07778
struct _GVirConfigDomainDevicePrivate
Packit a07778
{
Packit a07778
    gboolean unused;
Packit a07778
};
Packit a07778
Packit a07778
G_DEFINE_TYPE_WITH_PRIVATE(GVirConfigDomainDevice, gvir_config_domain_device, GVIR_CONFIG_TYPE_OBJECT);
Packit a07778
Packit a07778
Packit a07778
static void gvir_config_domain_device_class_init(GVirConfigDomainDeviceClass *klass G_GNUC_UNUSED)
Packit a07778
{
Packit a07778
}
Packit a07778
Packit a07778
Packit a07778
static void gvir_config_domain_device_init(GVirConfigDomainDevice *device)
Packit a07778
{
Packit a07778
    device->priv = GVIR_CONFIG_DOMAIN_DEVICE_GET_PRIVATE(device);
Packit a07778
}
Packit a07778
Packit a07778
G_GNUC_INTERNAL GVirConfigDomainDevice *
Packit a07778
gvir_config_domain_device_new_from_tree(GVirConfigXmlDoc *doc,
Packit a07778
                                        xmlNodePtr tree)
Packit a07778
{
Packit a07778
    GType type;
Packit a07778
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_XML_DOC(doc), NULL);
Packit a07778
    g_return_val_if_fail(tree != NULL, NULL);
Packit a07778
    g_return_val_if_fail(tree->name != NULL, NULL);
Packit a07778
Packit a07778
    if (xmlStrEqual(tree->name, (xmlChar*)"disk")) {
Packit a07778
        return gvir_config_domain_disk_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"filesystem")) {
Packit a07778
        return gvir_config_domain_filesys_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"controller")) {
Packit a07778
        return gvir_config_domain_controller_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"lease")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_DEVICE;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"hostdev")) {
Packit a07778
        return gvir_config_domain_hostdev_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"redirdev")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"smartcard")) {
Packit a07778
      return gvir_config_domain_smartcard_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"interface")) {
Packit a07778
        return gvir_config_domain_interface_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"input")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_INPUT;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"hub")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_DEVICE;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"graphics")) {
Packit a07778
        return gvir_config_domain_graphics_new_from_tree(doc, tree);
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"video")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_VIDEO;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"parallel")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_PARALLEL;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"serial")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_SERIAL;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"console")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_CONSOLE;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"channel")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_CHANNEL;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"watchdog")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_DEVICE;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"sound")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_SOUND;
Packit a07778
    } else if (xmlStrEqual(tree->name, (xmlChar*)"memballoon")) {
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_MEMBALLOON;
Packit a07778
    } else {
Packit a07778
        g_debug("Unknown device node: %s", tree->name);
Packit a07778
        type = GVIR_CONFIG_TYPE_DOMAIN_DEVICE;
Packit a07778
    }
Packit a07778
Packit a07778
    g_return_val_if_fail(g_type_is_a(type, GVIR_CONFIG_TYPE_DOMAIN_DEVICE), NULL);
Packit a07778
Packit a07778
    if (type == GVIR_CONFIG_TYPE_DOMAIN_DEVICE)
Packit a07778
        g_debug("Proper support for '%s' device nodes is not yet implemented", tree->name);
Packit a07778
Packit a07778
    return GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(type, doc, NULL, tree));
Packit a07778
}
Packit a07778
Packit a07778
Packit a07778
const gchar *gvir_config_domain_device_get_alias(GVirConfigDomainDevice *dev)
Packit a07778
{
Packit a07778
    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DEVICE(dev), NULL);
Packit a07778
Packit a07778
    return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(dev),
Packit a07778
                                            "alias", "name");
Packit a07778
}