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

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

 



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 |  11 +++
 libvirt-designer/libvirt-designer.sym      |   2 +
 5 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index b361f7b..ffe6760 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_CANONICAL_HOST
 AM_SILENT_RULES([yes])
 
 LIBOSINFO_REQUIRED=0.2.6
-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 1e9f78a..b874a90 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -568,6 +568,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;
 
     if (arch_str) {
         gvir_designer_domain_setup_container_full(domain, arch_str, &error);
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index df8f0cb..1222d21 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -351,6 +351,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 83bc0e5..96e9ed6 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;
@@ -111,6 +118,10 @@ 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);
+
 gboolean gvir_designer_domain_setup_resources(GVirDesignerDomain *design,
                                               GVirDesignerDomainResources req,
                                               GError **error);
diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
index 750ebb2..12c9912 100644
--- a/libvirt-designer/libvirt-designer.sym
+++ b/libvirt-designer/libvirt-designer.sym
@@ -5,6 +5,7 @@ LIBVIRT_DESIGNER_0.0.1 {
 
 	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;
@@ -15,6 +16,7 @@ LIBVIRT_DESIGNER_0.0.1 {
 
 	gvir_designer_domain_add_disk_file;
 	gvir_designer_domain_add_disk_device;
+	gvir_designer_domain_add_graphics;
 	gvir_designer_domain_add_interface_network;
 	gvir_designer_domain_setup_resources;
 	gvir_designer_domain_resources_get_type;
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]