From c8049f19542f232a733db965d151451b5acbcf1a Mon Sep 17 00:00:00 2001 From: Awawa Date: Sun, 28 Nov 2021 20:12:23 +0100 Subject: [PATCH] Fix race condition on signals for Philips Hue when reconnecting --- include/leddevice/LedDevice.h | 4 ++++ libsrc/leddevice/LedDevice.cpp | 15 +++++++++++++-- libsrc/leddevice/dev_net/ProviderUdpSSL.cpp | 8 ++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index 24ae4fd20..4864fa848 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -415,6 +415,10 @@ protected slots: /// virtual void setInError( const QString& errorMsg); +protected: + void enableDevice(bool toEmit); + void disableDevice(bool toEmit); + private: /// @brief Start a new refresh cycle diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index f25100684..0b865b49f 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -110,6 +110,11 @@ void LedDevice::setInError(const QString& errorMsg) } void LedDevice::enable() +{ + enableDevice(true); +} + +void LedDevice::enableDevice(bool toEmit) { if ( !_isEnabled ) { @@ -123,7 +128,7 @@ void LedDevice::enable() if ( _isDeviceReady ) { _isEnabled = true; - if ( switchOn() ) + if ( switchOn() && toEmit) { emit enableStateChanged(_isEnabled); } @@ -135,6 +140,11 @@ void LedDevice::enable() } void LedDevice::disable() +{ + disableDevice(true); +} + +void LedDevice::disableDevice(bool toEmit) { if ( _isEnabled ) { @@ -146,7 +156,8 @@ void LedDevice::disable() switchOff(); close(); - emit enableStateChanged(_isEnabled); + if (toEmit) + emit enableStateChanged(_isEnabled); } } diff --git a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp index 916c00bf8..09841680c 100644 --- a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp +++ b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp @@ -392,8 +392,12 @@ void ProviderUdpSSL::writeBytes(unsigned int size, const uint8_t* data, bool flu // hard reset locker.unlock(); - this->disable(); - this->enable(); + + this->disableDevice(false); + this->enableDevice(false); + + if (!_isOn) + emit enableStateChanged(false); } } }