From bd15ee89a796f95ea21da4a03383a966b397c432 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 22 Apr 2013 15:13:46 +0200 Subject: [PATCH] qemu: Use switch instead of ifs in qemuBuildGraphicsCommandLine 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 f1f01fa467..5b069b681c 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 e5c1a80505..b1d3d1bb69 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5804,24 +5804,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"); @@ -5838,20 +5833,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; } /*