qemu: Drop qemuAudioDriver enumeration

This mostly overlaps with virDomainAudioType, but in a couple of
cases the string representations are different.

Right now we're doing that in a somewhat sketchy way, in that we
store values of one enumeration and then convert them to strings
using TypeToString() implementation for the other enumeration;
when converting from string, we open-code the handling of the
special values mentioned above.

Drop the second enumeration and introduce two helpers to deal
with conversion. Most calling sites don't need to be changed, and
one can even be simplified significantly.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Andrea Bolognani 2022-01-17 16:07:38 +01:00
parent 9827614378
commit cb81263c22
3 changed files with 40 additions and 27 deletions

View File

@ -130,19 +130,39 @@ VIR_ENUM_IMPL(qemuNumaPolicy,
"restrictive",
);
VIR_ENUM_DECL(qemuAudioDriver);
VIR_ENUM_IMPL(qemuAudioDriver,
VIR_DOMAIN_AUDIO_TYPE_LAST,
"none",
"alsa",
"coreaudio",
"jack",
"oss",
"pa",
"sdl",
"spice",
"wav",
);
const char *
qemuAudioDriverTypeToString(virDomainAudioType type)
{
switch (type) {
case VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO:
return "pa";
case VIR_DOMAIN_AUDIO_TYPE_FILE:
return "wav";
case VIR_DOMAIN_AUDIO_TYPE_NONE:
case VIR_DOMAIN_AUDIO_TYPE_ALSA:
case VIR_DOMAIN_AUDIO_TYPE_COREAUDIO:
case VIR_DOMAIN_AUDIO_TYPE_JACK:
case VIR_DOMAIN_AUDIO_TYPE_OSS:
case VIR_DOMAIN_AUDIO_TYPE_SDL:
case VIR_DOMAIN_AUDIO_TYPE_SPICE:
case VIR_DOMAIN_AUDIO_TYPE_LAST:
break;
}
return virDomainAudioTypeTypeToString(type);
}
virDomainAudioType
qemuAudioDriverTypeFromString(const char *str)
{
if (STREQ(str, "pa")) {
return VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO;
} else if (STREQ(str, "wav")) {
return VIR_DOMAIN_AUDIO_TYPE_FILE;
}
return virDomainAudioTypeTypeFromString(str);
}
static const char *

View File

@ -256,3 +256,6 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,
int *cancelfd)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4) G_GNUC_NO_INLINE;
const char * qemuAudioDriverTypeToString(virDomainAudioType type);
virDomainAudioType qemuAudioDriverTypeFromString(const char *str);

View File

@ -3482,20 +3482,10 @@ qemuDomainDefSuggestDefaultAudioBackend(virQEMUDriver *driver,
if (audioenv == NULL) {
*addAudio = false;
} else {
/*
* QEMU audio driver names are mostly the same as
* libvirt XML audio backend names
*/
if (STREQ(audioenv, "pa")) {
*audioBackend = VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO;
} else if (STREQ(audioenv, "wav")) {
*audioBackend = VIR_DOMAIN_AUDIO_TYPE_FILE;
} else {
if (((*audioBackend) = virDomainAudioTypeTypeFromString(audioenv)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown QEMU_AUDIO_DRV setting %s"), audioenv);
return -1;
}
if (((*audioBackend) = qemuAudioDriverTypeFromString(audioenv)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown QEMU_AUDIO_DRV setting %s"), audioenv);
return -1;
}
}
}