Rearrange thresholds to be pair based
It was pointed out in another review that the way the dbus interfaces
are set up, they are all pair-wise, with a positive and negative end
of the interface. This changes the data structures to match that
reality, inventing a "ThresholdDefinition" object. This reduces the
code, and allows us to promote the level definitions up to a higher
scope in the structure.
This greatly simplifies the thresProp structure to remove a number of
elements that were redundant, and allows adding new thresholds easier
in the future.
Tested: Tested on Vegman system; Thresholds work as designed.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic9d5ba8282f78fe928689cb7fbd98d575a570200
diff --git a/include/Thresholds.hpp b/include/Thresholds.hpp
index 50075a2..fb266d0 100644
--- a/include/Thresholds.hpp
+++ b/include/Thresholds.hpp
@@ -112,7 +112,7 @@
std::list<TimerPair> timers;
};
-bool findOrder(Level lev, Direction dir);
+bool isValidLevel(Level lev);
bool parseThresholdsFromConfig(
const SensorData& sensorData,
@@ -124,6 +124,19 @@
const double& scaleFactor,
const double& offset = 0);
+struct ThresholdDefinition
+{
+ Level level;
+ uint8_t sevOrder;
+ const char* levelName;
+};
+
+constexpr static std::array<thresholds::ThresholdDefinition, 4> thresProp = {
+ {{Level::WARNING, 0, "Warning"},
+ {Level::CRITICAL, 1, "Critical"},
+ {Level::SOFTSHUTDOWN, 2, "SoftShutdown"},
+ {Level::HARDSHUTDOWN, 3, "HardShutdown"}}};
+
std::string getInterface(const Level level);
void persistThreshold(const std::string& baseInterface, const std::string& path,