Skip to content

Commit

Permalink
Fix race condition on signals for Philips Hue when reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Nov 28, 2021
1 parent aab5eb5 commit c8049f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/leddevice/LedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions libsrc/leddevice/LedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ void LedDevice::setInError(const QString& errorMsg)
}

void LedDevice::enable()
{
enableDevice(true);
}

void LedDevice::enableDevice(bool toEmit)
{
if ( !_isEnabled )
{
Expand All @@ -123,7 +128,7 @@ void LedDevice::enable()
if ( _isDeviceReady )
{
_isEnabled = true;
if ( switchOn() )
if ( switchOn() && toEmit)
{
emit enableStateChanged(_isEnabled);
}
Expand All @@ -135,6 +140,11 @@ void LedDevice::enable()
}

void LedDevice::disable()
{
disableDevice(true);
}

void LedDevice::disableDevice(bool toEmit)
{
if ( _isEnabled )
{
Expand All @@ -146,7 +156,8 @@ void LedDevice::disable()
switchOff();
close();

emit enableStateChanged(_isEnabled);
if (toEmit)
emit enableStateChanged(_isEnabled);
}
}

Expand Down
8 changes: 6 additions & 2 deletions libsrc/leddevice/dev_net/ProviderUdpSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit c8049f1

Please sign in to comment.