graphics: use enums instead of int

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2016-05-02 17:45:23 +02:00
parent fb377701f2
commit 76ee92562e
6 changed files with 43 additions and 16 deletions

View File

@ -1240,7 +1240,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def)
if (!def) if (!def)
return; return;
switch ((virDomainGraphicsType)def->type) { switch (def->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC: case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
VIR_FREE(def->data.vnc.socket); VIR_FREE(def->data.vnc.socket);
VIR_FREE(def->data.vnc.keymap); VIR_FREE(def->data.vnc.keymap);
@ -10650,7 +10650,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
char *address = virXMLPropString(node, "address"); char *address = virXMLPropString(node, "address");
char *network = virXMLPropString(node, "network"); char *network = virXMLPropString(node, "network");
char *fromConfig = virXMLPropString(node, "fromConfig"); char *fromConfig = virXMLPropString(node, "fromConfig");
int tmp; int tmp, typeVal;
if (!type) { if (!type) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
@ -10658,11 +10658,12 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
goto error; goto error;
} }
if ((def->type = virDomainGraphicsListenTypeFromString(type)) < 0) { if ((typeVal = virDomainGraphicsListenTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown graphics listen type '%s'"), type); _("unknown graphics listen type '%s'"), type);
goto error; goto error;
} }
def->type = typeVal;
/* address is recognized if either type='address', or if /* address is recognized if either type='address', or if
* type='network' and we're looking at live XML (i.e. *not* * type='network' and we're looking at live XML (i.e. *not*
@ -11288,6 +11289,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
{ {
virDomainGraphicsDefPtr def; virDomainGraphicsDefPtr def;
char *type = NULL; char *type = NULL;
int typeVal;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
return NULL; return NULL;
@ -11299,13 +11301,14 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
goto error; goto error;
} }
if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) { if ((typeVal = virDomainGraphicsTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown graphics device type '%s'"), type); _("unknown graphics device type '%s'"), type);
goto error; goto error;
} }
def->type = typeVal;
switch ((virDomainGraphicsType)def->type) { switch (def->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC: case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
if (virDomainGraphicsDefParseXMLVNC(def, node, ctxt, flags) < 0) if (virDomainGraphicsDefParseXMLVNC(def, node, ctxt, flags) < 0)
goto error; goto error;
@ -21519,6 +21522,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, flags); virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, flags);
break; break;
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
break;
} }
for (i = 0; i < def->nListens; i++) { for (i = 0; i < def->nListens; i++) {

View File

@ -1552,7 +1552,7 @@ typedef enum {
typedef struct _virDomainGraphicsListenDef virDomainGraphicsListenDef; typedef struct _virDomainGraphicsListenDef virDomainGraphicsListenDef;
typedef virDomainGraphicsListenDef *virDomainGraphicsListenDefPtr; typedef virDomainGraphicsListenDef *virDomainGraphicsListenDefPtr;
struct _virDomainGraphicsListenDef { struct _virDomainGraphicsListenDef {
int type; /* enum virDomainGraphicsListenType */ virDomainGraphicsListenType type;
char *address; char *address;
char *network; char *network;
bool fromConfig; /* true if the @address is config file originated */ bool fromConfig; /* true if the @address is config file originated */
@ -1564,7 +1564,7 @@ struct _virDomainGraphicsDef {
* Value 0 means port wasn't specified in XML at all. * Value 0 means port wasn't specified in XML at all.
* Positive value is actual port number given in XML. * Positive value is actual port number given in XML.
*/ */
int type; virDomainGraphicsType type;
union { union {
struct { struct {
int port; int port;
@ -1597,20 +1597,20 @@ struct _virDomainGraphicsDef {
int tlsPort; int tlsPort;
bool portReserved; bool portReserved;
bool tlsPortReserved; bool tlsPortReserved;
int mousemode; virDomainGraphicsSpiceMouseMode mousemode;
char *keymap; char *keymap;
virDomainGraphicsAuthDef auth; virDomainGraphicsAuthDef auth;
bool autoport; bool autoport;
int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST];
int defaultMode; /* enum virDomainGraphicsSpiceChannelMode */ virDomainGraphicsSpiceChannelMode defaultMode;
int image; int image;
int jpeg; int jpeg;
int zlib; int zlib;
int playback; int playback;
int streaming; int streaming;
int copypaste; /* enum virTristateBool */ virTristateBool copypaste;
int filetransfer; /* enum virTristateBool */ virTristateBool filetransfer;
int gl; /* enum virTristateBool */ virTristateBool gl;
} spice; } spice;
} data; } data;
/* nListens, listens, and *port are only useful if type is vnc, /* nListens, listens, and *port are only useful if type is vnc,

View File

@ -1463,6 +1463,12 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
if (VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0) if (VIR_STRDUP(x_vfb->keymap, l_vfb->data.vnc.keymap) < 0)
return -1; return -1;
break; break;
case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
break;
} }
return 0; return 0;
@ -1579,6 +1585,8 @@ libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports,
case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER: case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER:
libxl_defbool_set(&b_info->u.hvm.spice.agent_mouse, false); libxl_defbool_set(&b_info->u.hvm.spice.agent_mouse, false);
break; break;
case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_LAST:
break;
} }
#ifdef LIBXL_HAVE_SPICE_VDAGENT #ifdef LIBXL_HAVE_SPICE_VDAGENT

View File

@ -7445,6 +7445,10 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
if (VIR_STRDUP(gListen->address, netAddr) < 0) if (VIR_STRDUP(gListen->address, netAddr) < 0)
goto error; goto error;
break; break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
} }
} }
@ -7602,6 +7606,10 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
if (VIR_STRDUP(gListen->address, listenAddr) < 0) if (VIR_STRDUP(gListen->address, listenAddr) < 0)
goto error; goto error;
break; break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
} }
} }
@ -7727,7 +7735,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
} }
} }
if (graphics->data.spice.gl == VIR_TRISTATE_SWITCH_ON) { if (graphics->data.spice.gl == VIR_TRISTATE_BOOL_YES) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_GL)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_GL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU doesn't support spice OpenGL")); _("This QEMU doesn't support spice OpenGL"));
@ -7782,7 +7790,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
virDomainGraphicsDefPtr graphics, virDomainGraphicsDefPtr graphics,
const char *domainLibDir) const char *domainLibDir)
{ {
switch ((virDomainGraphicsType) graphics->type) { switch (graphics->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_SDL: case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SDL)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -9320,6 +9328,10 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver,
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
++spice; ++spice;
break; break;
case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
break;
} }
} }

View File

@ -2633,7 +2633,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
switch ((virDomainGraphicsListenType) newlisten->type) { switch (newlisten->type) {
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
if (STRNEQ_NULLABLE(newlisten->address, oldlisten->address)) { if (STRNEQ_NULLABLE(newlisten->address, oldlisten->address)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",

View File

@ -929,6 +929,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
virDomainGraphicsDefPtr graphics = NULL; virDomainGraphicsDefPtr graphics = NULL;
const struct sexpr *cur, *node; const struct sexpr *cur, *node;
const char *tmp; const char *tmp;
int typeVal;
/* append network devices and framebuffer */ /* append network devices and framebuffer */
for (cur = root; cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) { for (cur = root; cur->kind == SEXPR_CONS; cur = cur->u.s.cdr) {
@ -949,11 +950,12 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto error; goto error;
if ((graphics->type = virDomainGraphicsTypeFromString(tmp)) < 0) { if ((typeVal = virDomainGraphicsTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown graphics type '%s'"), tmp); _("unknown graphics type '%s'"), tmp);
goto error; goto error;
} }
graphics->type = typeVal;
if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
const char *display = sexpr_node(node, "device/vfb/display"); const char *display = sexpr_node(node, "device/vfb/display");