James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <Utils.hpp> |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame^] | 5 | struct Sensor; |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | namespace thresholds |
| 7 | { |
| 8 | enum Level |
| 9 | { |
| 10 | WARNING, |
| 11 | CRITICAL |
| 12 | }; |
| 13 | enum Direction |
| 14 | { |
| 15 | HIGH, |
| 16 | LOW |
| 17 | }; |
| 18 | struct Threshold |
| 19 | { |
| 20 | Threshold(const Level &lev, const Direction &dir, const double &val, |
| 21 | bool write = true) : |
| 22 | level(lev), |
| 23 | direction(dir), value(val), writeable(write) |
| 24 | { |
| 25 | } |
| 26 | Level level; |
| 27 | Direction direction; |
| 28 | double value; |
| 29 | bool writeable; |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame^] | 30 | bool asserted = false; |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | bool ParseThresholdsFromConfig( |
| 34 | const SensorData &sensorData, |
| 35 | std::vector<thresholds::Threshold> &thresholdVector, |
| 36 | const std::string *matchLabel = nullptr); |
| 37 | |
| 38 | bool ParseThresholdsFromAttr(std::vector<thresholds::Threshold> &thresholds, |
| 39 | const std::string &input_path, |
| 40 | const double scale_factor); |
| 41 | bool HasCriticalInterface( |
| 42 | const std::vector<thresholds::Threshold> &threshold_vector); |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame^] | 43 | |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 44 | bool HasWarningInterface( |
| 45 | const std::vector<thresholds::Threshold> &threshold_vector); |
| 46 | |
| 47 | void persistThreshold(const std::string &baseInterface, const std::string &path, |
| 48 | const thresholds::Threshold &threshold, |
| 49 | std::shared_ptr<sdbusplus::asio::connection> &conn); |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame^] | 50 | |
| 51 | void checkThresholds(Sensor *sensor); |
| 52 | void assertThresholds(Sensor *sensor, thresholds::Level level, |
| 53 | thresholds::Direction direction, bool assert); |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 54 | } // namespace thresholds |