diff options
| author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-06 15:30:23 -0500 |
|---|---|---|
| committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-17 20:35:53 -0500 |
| commit | e0b7d05103c97e676851aae2376d2f667f7a66db (patch) | |
| tree | f5fda9c2a1cd70c89308bb3b915f538eaf3f5f7c /mainloop.cpp | |
| parent | e228acc0b609bd5eca9ed2f1cd7336d01605802a (diff) | |
| download | phosphor-hwmon-e0b7d05103c97e676851aae2376d2f667f7a66db.tar.gz phosphor-hwmon-e0b7d05103c97e676851aae2376d2f667f7a66db.zip | |
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
Diffstat (limited to 'mainloop.cpp')
| -rw-r--r-- | mainloop.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
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 @@ void MainLoop::run() 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 @@ void MainLoop::run() 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; + } } } } |

