[libvirt PATCH 1/2] conf: add helper for comparing virDomainAudioDef objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is useful to be able to deeply check them for equality.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 144 +++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |   3 +
 src/libvirt_private.syms |   1 +
 3 files changed, 148 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index da0c64b460..f919d3f7a0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29842,6 +29842,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,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ab9a7d66f8..cf880ccb3c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -4015,6 +4015,9 @@ bool
 virDomainSoundModelSupportsCodecs(virDomainSoundDef *def);
 bool
 virDomainAudioIOCommonIsSet(virDomainAudioIOCommon *common);
+bool
+virDomainAudioIsEqual(virDomainAudioDef *this,
+                      virDomainAudioDef *that);
 
 const char *virDomainChrSourceDefGetPath(virDomainChrSourceDef *chr);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9ee8fda25f..a369d9c113 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -231,6 +231,7 @@ virDomainAudioDefFree;
 virDomainAudioFormatTypeFromString;
 virDomainAudioFormatTypeToString;
 virDomainAudioIOCommonIsSet;
+virDomainAudioIsEqual;
 virDomainAudioSDLDriverTypeFromString;
 virDomainAudioSDLDriverTypeToString;
 virDomainAudioTypeTypeFromString;
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux