Added support for Enabled property
Enabled property is added so that user can select via dbus interface if
Readings are updated and signal on Readings update is emitted, moreover
Metric calculation on received sensor data is active only when Enabled
is set to true
Tested:
- New unit tests were created, ran all new and previous UTs, all passed
- Tested under QEMU by adding reports for single and multiple sensors,
changing Enabled property and emitting signal of value change for
sensors added into the report, checking if Readings is accordingly
updated or not updated
- Verified persistency, if Enabled property is successfully stored and
restored after Telemetry service restart and also checked if after the
restart dependencies of Enabled (Readings, Metric calculation) are
properly initiated
Signed-off-by: Lukasz Kazmierczak <lukasz.kazmierczak@intel.com>
Change-Id: I29cf13693a48d15cb16d2ad6707f483f67f4879b
diff --git a/src/sensor.cpp b/src/sensor.cpp
index 26cadb7..f26a964 100644
--- a/src/sensor.cpp
+++ b/src/sensor.cpp
@@ -75,6 +75,22 @@
}
}
+void Sensor::unregisterFromUpdates(
+ const std::weak_ptr<interfaces::SensorListener>& weakListener)
+{
+ if (auto listener = weakListener.lock())
+ {
+ listeners.erase(
+ std::remove_if(
+ listeners.begin(), listeners.end(),
+ [listenerToUnregister = listener.get()](const auto& listener) {
+ return (listener.expired() ||
+ listener.lock().get() == listenerToUnregister);
+ }),
+ listeners.end());
+ }
+}
+
void Sensor::updateValue(double newValue)
{
timestamp = std::time(0);