Add double support for sensor interface
Add support for reading sensors that produce a double
as the value. Use a visitor to pull out the sensor value
so type doesn't matter.
Change-Id: I37c05e7077ead6f3084ab9704a1b2c62becb5e19
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/dbus/util.hpp b/dbus/util.hpp
index 72cf4e3..5b1522f 100644
--- a/dbus/util.hpp
+++ b/dbus/util.hpp
@@ -5,7 +5,7 @@
struct SensorProperties
{
int64_t scale;
- int64_t value;
+ double value;
std::string unit;
};
@@ -76,3 +76,20 @@
throw std::invalid_argument("Cannot translate type to float");
}
};
+
+struct VariantToDoubleVisitor
+{
+ template <typename T>
+ std::enable_if_t<std::is_arithmetic<T>::value, double>
+ operator()(const T &t) const
+ {
+ return static_cast<double>(t);
+ }
+
+ template <typename T>
+ std::enable_if_t<!std::is_arithmetic<T>::value, double>
+ operator()(const T &t) const
+ {
+ throw std::invalid_argument("Cannot translate type to double");
+ }
+};