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(a)redhat.com>
---
src/qemu/qemu_command.c | 46 +++++++++++++++++++++++++++++------------
src/qemu/qemu_command.h | 3 +++
src/qemu/qemu_domain.c | 18 ++++------------
3 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ed9dda4feb..babe21245f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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 *
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index dbdf3a4793..180988fa1a 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -254,3 +254,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);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1f7d71bf0f..fbe2036556 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3490,20 +3490,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;
}
}
}
--
2.34.1