blob: 22943c9fb59b87e16bbcdb90e3050f1d02982346 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2#include <Utils.hpp>
3#include <nlohmann/json.hpp>
4
James Feist251c7822018-09-12 12:54:15 -07005struct Sensor;
James Feist6714a252018-09-10 15:26:18 -07006namespace thresholds
7{
8enum Level
9{
10 WARNING,
11 CRITICAL
12};
13enum Direction
14{
15 HIGH,
16 LOW
17};
18struct Threshold
19{
James Feistd8705872019-02-08 13:26:09 -080020 Threshold(const Level& lev, const Direction& dir, const double& val,
James Feist6714a252018-09-10 15:26:18 -070021 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 Feist251c7822018-09-12 12:54:15 -070030 bool asserted = false;
Jae Hyun Yoo95b8a2d2019-02-25 20:15:09 -080031
32 bool operator==(const Threshold& rhs) const
33 {
34 return (level == rhs.level && direction == rhs.direction &&
35 value == rhs.value);
36 }
James Feist6714a252018-09-10 15:26:18 -070037};
38
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070039bool parseThresholdsFromConfig(
James Feistd8705872019-02-08 13:26:09 -080040 const SensorData& sensorData,
41 std::vector<thresholds::Threshold>& thresholdVector,
42 const std::string* matchLabel = nullptr);
James Feist6714a252018-09-10 15:26:18 -070043
James Feistd8705872019-02-08 13:26:09 -080044bool parseThresholdsFromAttr(std::vector<thresholds::Threshold>& thresholds,
45 const std::string& inputPath,
46 const double& scaleFactor);
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070047bool hasCriticalInterface(
James Feistd8705872019-02-08 13:26:09 -080048 const std::vector<thresholds::Threshold>& thresholdVector);
James Feist251c7822018-09-12 12:54:15 -070049
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070050bool hasWarningInterface(
James Feistd8705872019-02-08 13:26:09 -080051 const std::vector<thresholds::Threshold>& thresholdVector);
James Feist6714a252018-09-10 15:26:18 -070052
James Feistd8705872019-02-08 13:26:09 -080053void persistThreshold(const std::string& baseInterface, const std::string& path,
54 const thresholds::Threshold& threshold,
James Feista222ba72019-03-01 15:57:51 -080055 std::shared_ptr<sdbusplus::asio::connection>& conn,
56 size_t thresholdCount);
James Feist251c7822018-09-12 12:54:15 -070057
Jae Hyun Yoo95b8a2d2019-02-25 20:15:09 -080058void updateThresholds(Sensor* sensor);
James Feistdc6c55f2018-10-31 12:53:20 -070059// returns false if a critical threshold has been crossed, true otherwise
James Feistd8705872019-02-08 13:26:09 -080060bool checkThresholds(Sensor* sensor);
61void assertThresholds(Sensor* sensor, thresholds::Level level,
James Feist251c7822018-09-12 12:54:15 -070062 thresholds::Direction direction, bool assert);
James Feist6714a252018-09-10 15:26:18 -070063} // namespace thresholds