Enable sensor thresholds
Create the threshold interfaces at startup and check
for exceeded bounds on each poll.
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: I5a567813a1821071b99af67c0aa6f24abc56bf2d
diff --git a/mainloop.cpp b/mainloop.cpp
index e8cf0ee..9934d8a 100644
--- a/mainloop.cpp
+++ b/mainloop.cpp
@@ -25,6 +25,7 @@
#include "mainloop.hpp"
#include "util.hpp"
#include "env.hpp"
+#include "thresholds.hpp"
using namespace std::literals::chrono_literals;
@@ -149,6 +150,9 @@
ObjectInfo info(&_bus, std::move(objectPath), Object());
auto valueInterface = addValue(i.first, _path, info);
+ auto sensorValue = valueInterface->value();
+ addThreshold<WarningObject>(i.first, sensorValue, info);
+ addThreshold<CriticalObject>(i.first, sensorValue, info);
auto value = std::make_tuple(
std::move(i.second),
@@ -186,13 +190,29 @@
auto& objInfo = std::get<ObjectInfo>(i.second);
auto& obj = std::get<Object>(objInfo);
- auto iface = obj.find(InterfaceType::VALUE);
- if (iface != obj.end())
+ for (auto& iface : obj)
{
- auto realIface = std::experimental::any_cast<std::shared_ptr<ValueObject>>
- (iface->second);
- realIface->value(value);
+ auto valueIface = std::shared_ptr<ValueObject>();
+ auto warnIface = std::shared_ptr<WarningObject>();
+ auto critIface = std::shared_ptr<CriticalObject>();
+
+ switch (iface.first)
+ {
+ case InterfaceType::VALUE:
+ valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>>
+ (iface.second);
+ valueIface->value(value);
+ break;
+ case InterfaceType::WARN:
+ checkThresholds<WarningObject>(iface.second, value);
+ break;
+ case InterfaceType::CRIT:
+ checkThresholds<CriticalObject>(iface.second, value);
+ break;
+ default:
+ break;
+ }
}
}
}