]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: add helper for comparing virDomainAudioDef objects
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 10 Nov 2021 17:58:18 +0000 (17:58 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 1 Dec 2021 11:40:17 +0000 (11:40 +0000)
It is useful to be able to deeply check them for equality.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms

index f88405ab02c2a62f7ef2d5f6ab6283af01c8e6a5..d34b1ac653cbb8fa495f94e62a9bcbc31057c3f9 100644 (file)
@@ -29828,6 +29828,150 @@ virDomainAudioIOCommonIsSet(virDomainAudioIOCommon *common)
         common->bufferLength;
 }
 
+
+static bool
+virDomainAudioIOCommonIsEqual(virDomainAudioIOCommon *this,
+                              virDomainAudioIOCommon *that)
+{
+    return this->mixingEngine == that->mixingEngine &&
+        this->fixedSettings == that->fixedSettings &&
+        this->frequency == that->frequency &&
+        this->channels == that->channels &&
+        this->voices == that->voices &&
+        this->format == that->format &&
+        this->bufferLength == that->bufferLength;
+}
+
+static bool
+virDomainAudioIOALSAIsEqual(virDomainAudioIOALSA *this,
+                            virDomainAudioIOALSA *that)
+{
+    return STREQ_NULLABLE(this->dev, that->dev);
+}
+
+static bool
+virDomainAudioIOCoreAudioIsEqual(virDomainAudioIOCoreAudio *this,
+                                 virDomainAudioIOCoreAudio *that)
+{
+    return this->bufferCount == that->bufferCount;
+}
+
+static bool
+virDomainAudioIOJackIsEqual(virDomainAudioIOJack *this,
+                            virDomainAudioIOJack *that)
+{
+    return STREQ_NULLABLE(this->serverName, that->serverName) &&
+         STREQ_NULLABLE(this->clientName, that->clientName) &&
+         STREQ_NULLABLE(this->connectPorts, that->connectPorts) &&
+        this->exactName == that->exactName;
+}
+
+static bool
+virDomainAudioIOOSSIsEqual(virDomainAudioIOOSS *this,
+                           virDomainAudioIOOSS *that)
+{
+    return STREQ_NULLABLE(this->dev, that->dev) &&
+        this->bufferCount == that->bufferCount &&
+        this->tryPoll == that->tryPoll;
+}
+
+static bool
+virDomainAudioIOPulseAudioIsEqual(virDomainAudioIOPulseAudio *this,
+                                  virDomainAudioIOPulseAudio *that)
+{
+        return STREQ_NULLABLE(this->name, that->name) &&
+            STREQ_NULLABLE(this->streamName, that->streamName) &&
+            this->latency == that->latency;
+}
+
+static bool
+virDomainAudioIOSDLIsEqual(virDomainAudioIOSDL *this,
+                           virDomainAudioIOSDL *that)
+{
+    return this->bufferCount == that->bufferCount;
+}
+
+
+static bool
+virDomainAudioBackendIsEqual(virDomainAudioDef *this,
+                             virDomainAudioDef *that)
+{
+    if (this->type != that->type)
+        return false;
+
+    switch (this->type) {
+    case VIR_DOMAIN_AUDIO_TYPE_NONE:
+        return true;
+
+    case VIR_DOMAIN_AUDIO_TYPE_ALSA:
+        return virDomainAudioIOALSAIsEqual(&this->backend.alsa.input,
+                                           &that->backend.alsa.input) &&
+            virDomainAudioIOALSAIsEqual(&this->backend.alsa.output,
+                                        &that->backend.alsa.output);
+
+    case VIR_DOMAIN_AUDIO_TYPE_COREAUDIO:
+        return virDomainAudioIOCoreAudioIsEqual(&this->backend.coreaudio.input,
+                                                &that->backend.coreaudio.input) &&
+            virDomainAudioIOCoreAudioIsEqual(&this->backend.coreaudio.output,
+                                             &that->backend.coreaudio.output);
+
+    case VIR_DOMAIN_AUDIO_TYPE_JACK:
+        return virDomainAudioIOJackIsEqual(&this->backend.jack.input,
+                                           &that->backend.jack.input) &&
+            virDomainAudioIOJackIsEqual(&this->backend.jack.output,
+                                        &that->backend.jack.output);
+
+    case VIR_DOMAIN_AUDIO_TYPE_OSS:
+        return virDomainAudioIOOSSIsEqual(&this->backend.oss.input,
+                                          &that->backend.oss.input) &&
+            virDomainAudioIOOSSIsEqual(&this->backend.oss.output,
+                                       &that->backend.oss.output) &&
+            this->backend.oss.tryMMap == that->backend.oss.tryMMap &&
+            this->backend.oss.exclusive == that->backend.oss.exclusive &&
+            this->backend.oss.dspPolicySet == that->backend.oss.dspPolicySet &&
+            this->backend.oss.dspPolicy == that->backend.oss.dspPolicy;
+
+    case VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO:
+        return virDomainAudioIOPulseAudioIsEqual(&this->backend.pulseaudio.input,
+                                                 &that->backend.pulseaudio.input) &&
+            virDomainAudioIOPulseAudioIsEqual(&this->backend.pulseaudio.output,
+                                              &that->backend.pulseaudio.output) &&
+            STREQ_NULLABLE(this->backend.pulseaudio.serverName,
+                           that->backend.pulseaudio.serverName);
+
+    case VIR_DOMAIN_AUDIO_TYPE_SDL:
+        return virDomainAudioIOSDLIsEqual(&this->backend.sdl.input,
+                                          &that->backend.sdl.input) &&
+            virDomainAudioIOSDLIsEqual(&this->backend.sdl.output,
+                                       &that->backend.sdl.output) &&
+            this->backend.sdl.driver == that->backend.sdl.driver;
+
+    case VIR_DOMAIN_AUDIO_TYPE_SPICE:
+        return true;
+
+    case VIR_DOMAIN_AUDIO_TYPE_FILE:
+        return STREQ_NULLABLE(this->backend.file.path, that->backend.file.path);
+
+    case VIR_DOMAIN_AUDIO_TYPE_LAST:
+    default:
+        return false;
+    }
+}
+
+
+bool
+virDomainAudioIsEqual(virDomainAudioDef *this,
+                      virDomainAudioDef *that)
+{
+    return this->type == that->type &&
+        this->id == that->id &&
+        this->timerPeriod == that->timerPeriod &&
+        virDomainAudioIOCommonIsEqual(&this->input, &that->input) &&
+        virDomainAudioIOCommonIsEqual(&this->output, &that->output) &&
+        virDomainAudioBackendIsEqual(this, that);
+}
+
+
 char *
 virDomainObjGetMetadata(virDomainObj *vm,
                         int type,
index c4a8dcc2ea35beff828580b8b0cbfcdd8a95edbb..c0c07ea6ba24c3c1554e00422c812f698467ee73 100644 (file)
@@ -4016,6 +4016,9 @@ bool
 virDomainSoundModelSupportsCodecs(virDomainSoundDef *def);
 bool
 virDomainAudioIOCommonIsSet(virDomainAudioIOCommon *common);
+bool
+virDomainAudioIsEqual(virDomainAudioDef *this,
+                      virDomainAudioDef *that);
 
 const char *virDomainChrSourceDefGetPath(virDomainChrSourceDef *chr);
 
index b98cb0f66df26cd47727778abb4b1380baaa904b..1d4b4aeef25fb9ecd2c69bb9fe45a862c9034770 100644 (file)
@@ -231,6 +231,7 @@ virDomainAudioDefFree;
 virDomainAudioFormatTypeFromString;
 virDomainAudioFormatTypeToString;
 virDomainAudioIOCommonIsSet;
+virDomainAudioIsEqual;
 virDomainAudioSDLDriverTypeFromString;
 virDomainAudioSDLDriverTypeToString;
 virDomainAudioTypeTypeFromString;