Preserve original discrete trigger value
Currently, there are no 'real' discrete sensors, so discrete trigger is
working with numeric ones. Dbus api is using string as thresholdValue,
but internally service is converting it to double. This resulted in
side-effect of malformed value of Thresholds property, e.g., 90.0 being
represented as 90.000000. This change stores original value in order to
not confuse potential users.
Additionally, check was added to validate whole string of thesholdValue.
Now, it must consist only of numeric characters, values like '12.3FOO'
will be rejected on AddTrigger call.
Testing done:
- UTs added and are passing,
- dbus get-property on Thresholds confirms unchanged initial value.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Iec3514ac1479587e610f8da31ecf9ba6fc0bdb62
diff --git a/src/discrete_threshold.hpp b/src/discrete_threshold.hpp
index 2a51a1a..545a980 100644
--- a/src/discrete_threshold.hpp
+++ b/src/discrete_threshold.hpp
@@ -24,8 +24,8 @@
DiscreteThreshold(
boost::asio::io_context& ioc, Sensors sensors,
std::vector<std::unique_ptr<interfaces::TriggerAction>> actions,
- Milliseconds dwellTime, double thresholdValue, const std::string& name,
- const discrete::Severity severity);
+ Milliseconds dwellTime, const std::string& thresholdValue,
+ const std::string& name, const discrete::Severity severity);
DiscreteThreshold(const DiscreteThreshold&) = delete;
DiscreteThreshold(DiscreteThreshold&&) = delete;
@@ -38,7 +38,8 @@
boost::asio::io_context& ioc;
const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
const Milliseconds dwellTime;
- const double thresholdValue;
+ const std::string thresholdValue;
+ const double numericThresholdValue;
const std::string name;
const discrete::Severity severity;
bool initialized = false;