Commit 2807a409 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Connect/disconnect from SensorDaemonInterface when Sensor::enabled changes

setSensorId only connects when the sensor is enabled, which means we may
not yet be connected if the sensor is created in a disabled context.
Rather than always connecting, make the connections explicit only
enabled when the sensor is enabled, so we do not do unneccessary work.
parent f0512a6a
...@@ -248,12 +248,17 @@ void Sensor::onValueChanged(const QString &sensorId, const QVariant &value) ...@@ -248,12 +248,17 @@ void Sensor::onValueChanged(const QString &sensorId, const QVariant &value)
void Sensor::onEnabledChanged() void Sensor::onEnabledChanged()
{ {
if (enabled()) { if (enabled()) {
connect(SensorDaemonInterface::instance(), &SensorDaemonInterface::metaDataChanged, this, &Sensor::onMetaDataChanged, Qt::UniqueConnection);
connect(SensorDaemonInterface::instance(), &SensorDaemonInterface::valueChanged, this, &Sensor::onValueChanged, Qt::UniqueConnection);
SensorDaemonInterface::instance()->subscribe(d->id); SensorDaemonInterface::instance()->subscribe(d->id);
// Force an update of metadata and data, since that may have changed // Force an update of metadata and data, since that may have changed
// while we were disabled. // while we were disabled.
SensorDaemonInterface::instance()->requestMetaData(d->id); SensorDaemonInterface::instance()->requestMetaData(d->id);
SensorDaemonInterface::instance()->requestValue(d->id); SensorDaemonInterface::instance()->requestValue(d->id);
} else { } else {
disconnect(SensorDaemonInterface::instance(), &SensorDaemonInterface::metaDataChanged, this, &Sensor::onMetaDataChanged);
disconnect(SensorDaemonInterface::instance(), &SensorDaemonInterface::valueChanged, this, &Sensor::onValueChanged);
SensorDaemonInterface::instance()->unsubscribe(d->id); SensorDaemonInterface::instance()->unsubscribe(d->id);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment