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
This commit is contained in:
Peter Krempa 2013-04-22 15:13:46 +02:00
parent 66135c7208
commit bd15ee89a7
2 changed files with 19 additions and 20 deletions

View File

@ -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,

View File

@ -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;
}
/*