Add try catch when getting the sensor values
When the driver of the source sensors is binding, the sensor service name
is available but the value property can be unavailable in short time.
Getting the sensor value without try catch can cause exception "sd_bus_call: \
org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable".
This commit catchs the exception when getting sensor value to cover that case.
Signed-off-by: Thu Ba Nguyen <thu@os.amperecomputing.com>
Change-Id: If946f20e38020767d418d6d80caf4e74db7b49ab
diff --git a/dbusSensor.hpp b/dbusSensor.hpp
index faba2c6..93e8e17 100644
--- a/dbusSensor.hpp
+++ b/dbusSensor.hpp
@@ -40,8 +40,15 @@
}
}
- return getDbusProperty<double>(bus, servName, path, sensorIntf,
- "Value");
+ try
+ {
+ return getDbusProperty<double>(bus, servName, path, sensorIntf,
+ "Value");
+ }
+ catch (const std::exception& e)
+ {
+ return std::numeric_limits<double>::quiet_NaN();
+ }
}
private: