James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <Utils.hpp> |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 5 | struct Sensor; |
James Feist | 6714a25 | 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 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 20 | Threshold(const Level& lev, const Direction& dir, const double& val, |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 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 | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 30 | bool asserted = false; |
Jae Hyun Yoo | 95b8a2d | 2019-02-25 20:15:09 -0800 | [diff] [blame] | 31 | |
| 32 | bool operator==(const Threshold& rhs) const |
| 33 | { |
| 34 | return (level == rhs.level && direction == rhs.direction && |
| 35 | value == rhs.value); |
| 36 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 39 | bool parseThresholdsFromConfig( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 40 | const SensorData& sensorData, |
| 41 | std::vector<thresholds::Threshold>& thresholdVector, |
| 42 | const std::string* matchLabel = nullptr); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 43 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 44 | bool parseThresholdsFromAttr(std::vector<thresholds::Threshold>& thresholds, |
| 45 | const std::string& inputPath, |
| 46 | const double& scaleFactor); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 47 | bool hasCriticalInterface( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 48 | const std::vector<thresholds::Threshold>& thresholdVector); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 49 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 50 | bool hasWarningInterface( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 51 | const std::vector<thresholds::Threshold>& thresholdVector); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 52 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 53 | void persistThreshold(const std::string& baseInterface, const std::string& path, |
| 54 | const thresholds::Threshold& threshold, |
James Feist | a222ba7 | 2019-03-01 15:57:51 -0800 | [diff] [blame^] | 55 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 56 | size_t thresholdCount); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 57 | |
Jae Hyun Yoo | 95b8a2d | 2019-02-25 20:15:09 -0800 | [diff] [blame] | 58 | void updateThresholds(Sensor* sensor); |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 59 | // returns false if a critical threshold has been crossed, true otherwise |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 60 | bool checkThresholds(Sensor* sensor); |
| 61 | void assertThresholds(Sensor* sensor, thresholds::Level level, |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 62 | thresholds::Direction direction, bool assert); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 63 | } // namespace thresholds |