[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [libvirt-designer PATCHv3 4/9] Implement gvir_designer_domain_add_graphics()



On 04.06.2013 16:33, Christophe Fergeau wrote:
> This allows to choose between SPICE, VNC or a local display, which
> will go through SDL or 'desktop' depending on the hypervisor.
> ---
>  configure.ac                               |   2 +-
>  examples/virtxml.c                         |   4 ++
>  libvirt-designer/libvirt-designer-domain.c | 111 +++++++++++++++++++++++++++++
>  libvirt-designer/libvirt-designer-domain.h |  10 +++
>  libvirt-designer/libvirt-designer.sym      |   2 +
>  5 files changed, 128 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 228a85c..bad199b 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -11,7 +11,7 @@ AC_CANONICAL_HOST
>  AM_SILENT_RULES([yes])
>  
>  LIBOSINFO_REQUIRED=0.2.7
> -LIBVIRT_GCONFIG_REQUIRED=0.0.9
> +LIBVIRT_GCONFIG_REQUIRED=0.1.7
>  LIBVIRT_GOBJECT_REQUIRED=0.1.3
>  GOBJECT_INTROSPECTION_REQUIRED=0.10.8
>  
> diff --git a/examples/virtxml.c b/examples/virtxml.c
> index d127406..46fb551 100644
> --- a/examples/virtxml.c
> +++ b/examples/virtxml.c
> @@ -641,6 +641,10 @@ main(int argc, char *argv[])
>  
>      gvir_designer_domain_setup_machine(domain, &error);
>      CHECK_ERROR;
> +    g_object_unref(gvir_designer_domain_add_graphics(domain,
> +                                                     GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE,
> +                                                     &error));
> +    CHECK_ERROR;

I'd rather let users to choose if they want VNC or SPICE or ...

>  
>      g_object_unref(gvir_designer_domain_add_sound(domain, &error));
>      CHECK_ERROR;
> diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
> index 36fc8ed..a1914dd 100644
> --- a/libvirt-designer/libvirt-designer-domain.c
> +++ b/libvirt-designer/libvirt-designer-domain.c
> @@ -348,6 +348,117 @@ static void gvir_designer_domain_add_clock(GVirDesignerDomain *design)
>      g_object_unref(G_OBJECT(clock));
>  }
>  
> +
> +static GVirConfigDomainGraphics *
> +gvir_designer_domain_create_graphics_desktop(GVirDesignerDomain *design,
> +                                             GError **error)
> +{
> +    int virt_type;
> +
> +    virt_type = gvir_config_domain_get_virt_type(design->priv->config);
> +
> +    switch (virt_type) {
> +    case GVIR_CONFIG_DOMAIN_VIRT_QEMU:
> +    case GVIR_CONFIG_DOMAIN_VIRT_KQEMU:
> +    case GVIR_CONFIG_DOMAIN_VIRT_KVM: {
> +        GVirConfigDomainGraphicsSdl *sdl;
> +        sdl = gvir_config_domain_graphics_sdl_new();
> +        return GVIR_CONFIG_DOMAIN_GRAPHICS(sdl);
> +    }
> +    case GVIR_CONFIG_DOMAIN_VIRT_VBOX: {
> +        GVirConfigDomainGraphicsDesktop *desktop;
> +        desktop = gvir_config_domain_graphics_desktop_new();
> +        return GVIR_CONFIG_DOMAIN_GRAPHICS(desktop);
> +    }
> +    default:
> +        g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0,
> +                    "Virt type %d does not support this graphics output",
> +                    virt_type);
> +        return NULL;
> +    }
> +}
> +
> +/**
> + * gvir_designer_domain_add_graphics:
> + * @design: (transfer none): the domain designer instance
> + * @error: return location for a #GError, or NULL
> + *
> + * Add a new graphical framebuffer to @design. This allows
> + * to see what the VM displays.
> + * Remote display protocols will only be listening on localhost, and the
> + * port will be automatically allocated when the VM starts (usually
> + * starting at 5900). You can manipulate further the returned
> + * #GVirConfigDomainGraphics if you want a different behaviour.
> + * When setting up a SPICE display, the SPICE agent channel will be
> + * automatically added to the VM if it's supported and not already
> + * present.
> + *
> + * Returns: (transfer full): the pointer to the new graphical framebuffer
> + * configuration object.
> + */
> +GVirConfigDomainGraphics *
> +gvir_designer_domain_add_graphics(GVirDesignerDomain *design,
> +                                  GVirDesignerDomainGraphics type,
> +                                  GError **error)
> +{
> +    GVirConfigDomainGraphics *graphics;
> +
> +    g_return_val_if_fail(GVIR_DESIGNER_IS_DOMAIN(design), NULL);
> +    g_return_val_if_fail(!error_is_set(error), NULL);
> +
> +    switch (type) {
> +    case GVIR_DESIGNER_DOMAIN_GRAPHICS_DESKTOP: {
> +        graphics = gvir_designer_domain_create_graphics_desktop(design, error);
> +        if (graphics == NULL)
> +            return NULL;
> +    }
> +
> +    case GVIR_DESIGNER_DOMAIN_GRAPHICS_RDP: {
> +        GVirConfigDomainGraphicsRdp *rdp;
> +
> +        rdp = gvir_config_domain_graphics_rdp_new();
> +        gvir_config_domain_graphics_rdp_set_autoport(rdp, TRUE);
> +        graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(rdp);
> +
> +        break;
> +    }
> +
> +    case GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE: {
> +        GVirConfigDomainGraphicsSpice *spice;
> +
> +        spice = gvir_config_domain_graphics_spice_new();
> +        gvir_config_domain_graphics_spice_set_autoport(spice, TRUE);
> +        /* FIXME: Should only be done for local domains */
> +        gvir_config_domain_graphics_spice_set_image_compression(spice,
> +                                                                GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_IMAGE_COMPRESSION_OFF);
> +        graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(spice);
> +
> +        break;
> +    }
> +
> +    case GVIR_DESIGNER_DOMAIN_GRAPHICS_VNC: {
> +        GVirConfigDomainGraphicsVnc *vnc;
> +
> +        vnc = gvir_config_domain_graphics_vnc_new();
> +        gvir_config_domain_graphics_vnc_set_autoport(vnc, TRUE);
> +        graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(vnc);
> +
> +        break;
> +    }
> +
> +    default:
> +        g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0,
> +                    "Unknown graphics type: %d", type);
> +        g_return_val_if_reached(NULL);
> +    }
> +
> +    gvir_config_domain_add_device(design->priv->config,
> +                                  GVIR_CONFIG_DOMAIN_DEVICE(graphics));
> +
> +    return graphics;
> +}
> +
> +
>  static void gvir_designer_domain_add_power_management(GVirDesignerDomain *design)
>  {
>      GVirConfigDomainPowerManagement *pm;
> diff --git a/libvirt-designer/libvirt-designer-domain.h b/libvirt-designer/libvirt-designer-domain.h
> index c0d06e8..1399bd4 100644
> --- a/libvirt-designer/libvirt-designer-domain.h
> +++ b/libvirt-designer/libvirt-designer-domain.h
> @@ -44,6 +44,13 @@ typedef enum {
>      GVIR_DESIGNER_DOMAIN_RESOURCES_RECOMMENDED,
>  } GVirDesignerDomainResources;
>  
> +typedef enum {
> +    GVIR_DESIGNER_DOMAIN_GRAPHICS_DESKTOP,
> +    GVIR_DESIGNER_DOMAIN_GRAPHICS_RDP,
> +    GVIR_DESIGNER_DOMAIN_GRAPHICS_SPICE,
> +    GVIR_DESIGNER_DOMAIN_GRAPHICS_VNC,
> +} GVirDesignerDomainGraphics;
> +
>  typedef struct _GVirDesignerDomain GVirDesignerDomain;
>  typedef struct _GVirDesignerDomainPrivate GVirDesignerDomainPrivate;
>  typedef struct _GVirDesignerDomainClass GVirDesignerDomainClass;
> @@ -125,6 +132,9 @@ GVirConfigDomainInterface *gvir_designer_domain_add_interface_network(GVirDesign
>                                                                        const char *network,
>                                                                        GError **error);
>  
> +GVirConfigDomainGraphics *gvir_designer_domain_add_graphics(GVirDesignerDomain *design,
> +                                                            GVirDesignerDomainGraphics type,
> +                                                            GError **error);
>  GVirConfigDomainSound *gvir_designer_domain_add_sound(GVirDesignerDomain *design, GError **error);
>  
>  gboolean gvir_designer_domain_setup_resources(GVirDesignerDomain *design,
> diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
> index 0a8b49e..9a73993 100644
> --- a/libvirt-designer/libvirt-designer.sym
> +++ b/libvirt-designer/libvirt-designer.sym
> @@ -5,6 +5,7 @@ LIBVIRT_DESIGNER_0.0.2 {
>  
>  	gvir_designer_domain_new;
>  	gvir_designer_domain_get_type;
> +	gvir_designer_domain_graphics_get_type;
>  	gvir_designer_domain_get_config;
>  	gvir_designer_domain_get_os;
>  	gvir_designer_domain_get_platform;
> @@ -19,6 +20,7 @@ LIBVIRT_DESIGNER_0.0.2 {
>  	gvir_designer_domain_add_disk_device;
>  	gvir_designer_domain_add_floppy_file;
>  	gvir_designer_domain_add_floppy_device;
> +	gvir_designer_domain_add_graphics;
>  	gvir_designer_domain_add_interface_network;
>  	gvir_designer_domain_add_sound;
>  	gvir_designer_domain_setup_resources;
> 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]