platform-mc: Simplify numeric sensor event handler
Instead of a double nested switch/case handling
the state transition from previousEventState to
eventState and their possible intermediate states,
walk up/down a list of states from previousEventState
to eventState and use maps to translate required values.
This method is less error prone and allows with very
minimal work to fully add support to the newly enabled
HardShutdown threshold levels.
Tested:
Trigger sensor event from remote PLDM controller
and ensure that we are getting the appropriate
event triggers. Also unit tests pass.
Change-Id: I1813ccaefcaa0cc133916eba23939dd9d9661427
Signed-off-by: Amithash Prasad <amithash@meta.com>
diff --git a/platform-mc/event_manager.hpp b/platform-mc/event_manager.hpp
index 083725d..0eb52d7 100644
--- a/platform-mc/event_manager.hpp
+++ b/platform-mc/event_manager.hpp
@@ -21,6 +21,13 @@
using HandlerFuncs = std::vector<HandlerFunc>;
using EventMap = std::map<EventType, HandlerFuncs>;
+using NumericSensorThresholdHandler = std::function<int(
+ pldm::utils::Level, pldm::utils::Direction direction, double, bool, bool)>;
+
+int triggerNumericSensorThresholdEvent(NumericSensorThresholdHandler handler,
+ uint8_t previousEventState,
+ uint8_t nextEventState, double value);
+
/**
* @brief EventManager
*