[libvirt] [libvirt-glib 3/3] Add GVirConfigDomainRedirdev

Marc-André Lureau marcandre.lureau at gmail.com
Wed Mar 14 11:49:04 UTC 2012


ack

On Tue, Mar 6, 2012 at 5:38 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> This is used to add the SPICE USB redirection channel. Even if
> the libvirt doc doesn't document it with the other devices deriving
> from GVirConfigDomainChardev, I think it makes sense to have this
> class derivers from GVirConfigDomainChardev too since it needs a
> GVirConfigDomainChardevSource, and it's documented as using a
> character device for redirection.
> ---
>  libvirt-gconfig/Makefile.am                       |    2 +
>  libvirt-gconfig/libvirt-gconfig-domain-redirdev.c |   82 +++++++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig-domain-redirdev.h |   73 ++++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig.h                 |    1 +
>  libvirt-gconfig/libvirt-gconfig.sym               |    6 ++
>  libvirt-gconfig/tests/test-domain-create.c        |   14 ++++
>  6 files changed, 178 insertions(+), 0 deletions(-)
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-redirdev.h
>
> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> index d9e87b5..181ec57 100644
> --- a/libvirt-gconfig/Makefile.am
> +++ b/libvirt-gconfig/Makefile.am
> @@ -35,6 +35,7 @@ GCONFIG_HEADER_FILES = \
>                        libvirt-gconfig-domain-memballoon.h \
>                        libvirt-gconfig-domain-os.h \
>                        libvirt-gconfig-domain-parallel.h \
> +                       libvirt-gconfig-domain-redirdev.h \
>                        libvirt-gconfig-domain-seclabel.h \
>                        libvirt-gconfig-domain-serial.h \
>                        libvirt-gconfig-domain-snapshot.h \
> @@ -87,6 +88,7 @@ GCONFIG_SOURCE_FILES = \
>                        libvirt-gconfig-domain-memballoon.c \
>                        libvirt-gconfig-domain-os.c \
>                        libvirt-gconfig-domain-parallel.c \
> +                       libvirt-gconfig-domain-redirdev.c \
>                        libvirt-gconfig-domain-seclabel.c \
>                        libvirt-gconfig-domain-serial.c \
>                        libvirt-gconfig-domain-snapshot.c \
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
> new file mode 100644
> index 0000000..30c370a
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.c
> @@ -0,0 +1,82 @@
> +/*
> + * libvirt-gconfig-domain-redirdev.c: libvirt domain redirdev configuration
> + *
> + * Copyright (C) 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, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Author: Christophe Fergeau <cfergeau at redhat.com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_DOMAIN_REDIRDEV_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV, GVirConfigDomainRedirdevPrivate))
> +
> +struct _GVirConfigDomainRedirdevPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigDomainRedirdev, gvir_config_domain_redirdev, GVIR_CONFIG_TYPE_DOMAIN_CHARDEV);
> +
> +
> +static void gvir_config_domain_redirdev_class_init(GVirConfigDomainRedirdevClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigDomainRedirdevPrivate));
> +}
> +
> +
> +static void gvir_config_domain_redirdev_init(GVirConfigDomainRedirdev *redirdev)
> +{
> +    g_debug("Init GVirConfigDomainRedirdev=%p", redirdev);
> +
> +    redirdev->priv = GVIR_CONFIG_DOMAIN_REDIRDEV_GET_PRIVATE(redirdev);
> +}
> +
> +
> +GVirConfigDomainRedirdev *gvir_config_domain_redirdev_new(void)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV,
> +                                    "redirdev", NULL);
> +    return GVIR_CONFIG_DOMAIN_REDIRDEV(object);
> +}
> +
> +GVirConfigDomainRedirdev *gvir_config_domain_redirdev_new_from_xml(const gchar *xml,
> +                                                                       GError **error)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV,
> +                                             "redirdev", NULL, xml, error);
> +    return GVIR_CONFIG_DOMAIN_REDIRDEV(object);
> +}
> +
> +void gvir_config_domain_redirdev_set_bus(GVirConfigDomainRedirdev *redirdev,
> +                                         GVirConfigDomainRedirdevBus bus)
> +{
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_REDIRDEV(redirdev));
> +
> +    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(redirdev),
> +                                               "bus",
> +                                               GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV_BUS,
> +                                               bus,
> +                                               NULL);
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h
> new file mode 100644
> index 0000000..99585bb
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-redirdev.h
> @@ -0,0 +1,73 @@
> +/*
> + * libvirt-gconfig-domain-redirdev.h: libvirt domain redirdev configuration
> + *
> + * Copyright (C) 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, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Author: Christophe Fergeau <cfergeau at redhat.com>
> + */
> +
> +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
> +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
> +#endif
> +
> +#ifndef __LIBVIRT_GCONFIG_DOMAIN_REDIRDEV_H__
> +#define __LIBVIRT_GCONFIG_DOMAIN_REDIRDEV_H__
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV            (gvir_config_domain_redirdev_get_type ())
> +#define GVIR_CONFIG_DOMAIN_REDIRDEV(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV, GVirConfigDomainRedirdev))
> +#define GVIR_CONFIG_DOMAIN_REDIRDEV_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV, GVirConfigDomainRedirdevClass))
> +#define GVIR_CONFIG_IS_DOMAIN_REDIRDEV(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV))
> +#define GVIR_CONFIG_IS_DOMAIN_REDIRDEV_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV))
> +#define GVIR_CONFIG_DOMAIN_REDIRDEV_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_REDIRDEV, GVirConfigDomainRedirdevClass))
> +
> +typedef struct _GVirConfigDomainRedirdev GVirConfigDomainRedirdev;
> +typedef struct _GVirConfigDomainRedirdevPrivate GVirConfigDomainRedirdevPrivate;
> +typedef struct _GVirConfigDomainRedirdevClass GVirConfigDomainRedirdevClass;
> +
> +struct _GVirConfigDomainRedirdev
> +{
> +    GVirConfigDomainChardev parent;
> +
> +    GVirConfigDomainRedirdevPrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigDomainRedirdevClass
> +{
> +    GVirConfigDomainChardevClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +typedef enum {
> +    GVIR_CONFIG_DOMAIN_REDIRDEV_BUS_USB
> +} GVirConfigDomainRedirdevBus;
> +
> +GType gvir_config_domain_redirdev_get_type(void);
> +
> +GVirConfigDomainRedirdev *gvir_config_domain_redirdev_new(void);
> +GVirConfigDomainRedirdev *gvir_config_domain_redirdev_new_from_xml(const gchar *xml,
> +                                                                   GError **error);
> +void gvir_config_domain_redirdev_set_bus(GVirConfigDomainRedirdev *redirdev,
> +                                         GVirConfigDomainRedirdevBus bus);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_DOMAIN_REDIRDEV_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> index b1eede2..2fcc4ba 100644
> --- a/libvirt-gconfig/libvirt-gconfig.h
> +++ b/libvirt-gconfig/libvirt-gconfig.h
> @@ -52,6 +52,7 @@
>  #include <libvirt-gconfig/libvirt-gconfig-domain-memballoon.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-os.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-parallel.h>
> +#include <libvirt-gconfig/libvirt-gconfig-domain-redirdev.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-serial.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index ffde0bc..717c3c9 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -197,6 +197,12 @@ LIBVIRT_GCONFIG_0.0.4 {
>        gvir_config_domain_parallel_new;
>        gvir_config_domain_parallel_new_from_xml;
>
> +       gvir_config_domain_redirdev_get_type;
> +       gvir_config_domain_redirdev_bus_get_type;
> +       gvir_config_domain_redirdev_new;
> +       gvir_config_domain_redirdev_new_from_xml;
> +       gvir_config_domain_redirdev_set_bus;
> +
>        gvir_config_domain_seclabel_get_type;
>        gvir_config_domain_seclabel_type_get_type;
>        gvir_config_domain_seclabel_new;
> diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
> index b24d133..fd936e6 100644
> --- a/libvirt-gconfig/tests/test-domain-create.c
> +++ b/libvirt-gconfig/tests/test-domain-create.c
> @@ -194,6 +194,20 @@ int main(int argc, char **argv)
>     g_object_unref(G_OBJECT(spicevmc));
>     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel));
>
> +    /* spice usb redirection */
> +    GVirConfigDomainRedirdev *redirdev;
> +
> +    redirdev = gvir_config_domain_redirdev_new();
> +    gvir_config_domain_redirdev_set_bus(redirdev,
> +                                        GVIR_CONFIG_DOMAIN_REDIRDEV_BUS_USB);
> +    gvir_config_domain_channel_set_target_type(channel,
> +                                               GVIR_CONFIG_DOMAIN_CHANNEL_TARGET_VIRTIO);
> +    spicevmc = gvir_config_domain_chardev_source_spicevmc_new();
> +    gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(redirdev),
> +                                          GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(spicevmc));
> +    g_object_unref(G_OBJECT(spicevmc));
> +    devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev));
> +
>
>     gvir_config_domain_set_devices(domain, devices);
>     g_list_foreach(devices, (GFunc)g_object_unref, NULL);
> --
> 1.7.7.6
>
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list



-- 
Marc-André Lureau




More information about the libvir-list mailing list