Added discrete threshold trigger support
Implemented discrete threshold logic
Discrete trigger with empty threshold array is handled as 'onChange'
Added unit tests coverage for discrete trigger
Supported scenarios:
-discrete threshold with value and dwell time
-discrete threshold with value, without dwell time
-discrete trigger without threshold ('onChange')
Tests:
-Unit tests passed
Change-Id: Id60a48f4113bd955d97e154888c00d1b6e5490af
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
diff --git a/src/on_change_threshold.cpp b/src/on_change_threshold.cpp
new file mode 100644
index 0000000..0365ef4
--- /dev/null
+++ b/src/on_change_threshold.cpp
@@ -0,0 +1,42 @@
+#include "on_change_threshold.hpp"
+
+#include <phosphor-logging/log.hpp>
+
+OnChangeThreshold::OnChangeThreshold(
+ std::vector<std::shared_ptr<interfaces::Sensor>> sensorsIn,
+ std::vector<std::string> sensorNamesIn,
+ std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) :
+ sensors(std::move(sensorsIn)),
+ sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn))
+{}
+
+void OnChangeThreshold::initialize()
+{
+ for (auto& sensor : sensors)
+ {
+ sensor->registerForUpdates(weak_from_this());
+ }
+}
+
+void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
+ uint64_t timestamp)
+{}
+
+void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
+ uint64_t timestamp, double value)
+{
+ auto it =
+ std::find_if(sensors.begin(), sensors.end(),
+ [&sensor](const auto& x) { return &sensor == x.get(); });
+ auto index = std::distance(sensors.begin(), it);
+ commit(sensorNames.at(index), timestamp, value);
+}
+
+void OnChangeThreshold::commit(const std::string& sensorName,
+ uint64_t timestamp, double value)
+{
+ for (const auto& action : actions)
+ {
+ action->commit(sensorName, timestamp, value);
+ }
+}