[libvirt] [PATCH 3/7] qemu: Use switch instead of ifs in qemuBuildGraphicsCommandLine

Peter Krempa pkrempa at redhat.com
Tue Apr 23 13:46:10 UTC 2013


Switch the function from a bunch of ifs to a switch statement with
correct type and reflow some code.

Also fix comment in enum describing possible graphics types
---
 src/conf/domain_conf.h  |  2 +-
 src/qemu/qemu_command.c | 37 ++++++++++++++++++-------------------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f1f01fa..5b069b6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1230,7 +1230,7 @@ struct _virDomainVideoDef {
     virDomainDeviceInfo info;
 };

-/* 3 possible graphics console modes */
+/* graphics console modes */
 enum virDomainGraphicsType {
     VIR_DOMAIN_GRAPHICS_TYPE_SDL,
     VIR_DOMAIN_GRAPHICS_TYPE_VNC,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 66b2ba8..ed8e73e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5723,24 +5723,19 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
                              virQEMUCapsPtr qemuCaps,
                              virDomainGraphicsDefPtr graphics)
 {
-    if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
-        if (qemuBuildGraphicsVNCCommandLine(cfg, cmd, def, qemuCaps, graphics) < 0)
-            goto error;
-    } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
+    switch ((enum virDomainGraphicsType) graphics->type) {
+    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
         if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_0_10) &&
             !virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("sdl not supported by '%s'"),
-                           def->emulator);
-            goto error;
+                           _("sdl not supported by '%s'"), def->emulator);
+            return -1;
         }

         if (graphics->data.sdl.xauth)
-            virCommandAddEnvPair(cmd, "XAUTHORITY",
-                                 graphics->data.sdl.xauth);
+            virCommandAddEnvPair(cmd, "XAUTHORITY", graphics->data.sdl.xauth);
         if (graphics->data.sdl.display)
-            virCommandAddEnvPair(cmd, "DISPLAY",
-                                 graphics->data.sdl.display);
+            virCommandAddEnvPair(cmd, "DISPLAY", graphics->data.sdl.display);
         if (graphics->data.sdl.fullscreen)
             virCommandAddArg(cmd, "-full-screen");

@@ -5757,20 +5752,24 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
         if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL))
             virCommandAddArg(cmd, "-sdl");

-    } else if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
-        if (qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics) < 0)
-            goto error;
-    } else {
+        break;
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+        return qemuBuildGraphicsVNCCommandLine(cfg, cmd, def, qemuCaps, graphics);
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
+        return qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics);
+
+    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
+    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported graphics type '%s'"),
                        virDomainGraphicsTypeToString(graphics->type));
-        goto error;
+        return -1;
     }

     return 0;
-
-error:
-    return -1;
 }

 /*
-- 
1.8.2.1




More information about the libvir-list mailing list