monitor: Start checking power off rules
In the system object, load the power off rules and start checking them.
It will check them in the following cases (if power is on):
* When the object is constructed
* When the JSON config is reloaded
* When fan presence or sensor functional state changes
* When the power state changes to on
When the power is turned off, it will cancel any running rules.
Previously, fan monitor was only designed to run with power on, and
there still may be more changes than just the ones added here to support
it always running.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I8be81612ae4997d7568678471ac0f6f854a0e758
diff --git a/monitor/system.hpp b/monitor/system.hpp
index 7c424a2..b1b80a5 100644
--- a/monitor/system.hpp
+++ b/monitor/system.hpp
@@ -16,6 +16,8 @@
#pragma once
#include "fan.hpp"
+#include "power_off_rule.hpp"
+#include "power_state.hpp"
#include "tach_sensor.hpp"
#include "trust_manager.hpp"
#include "types.hpp"
@@ -93,6 +95,17 @@
FanHealth _fanHealth;
/**
+ * @brief The object to watch the power state
+ */
+ std::unique_ptr<PowerState> _powerState;
+
+ /**
+ * @brief The power off rules, for shutting down the system
+ * due to fan failures.
+ */
+ std::vector<std::unique_ptr<PowerOffRule>> _powerOffRules;
+
+ /**
* @brief Retrieve the configured trust groups
*
* @param[in] jsonObj - JSON object to parse from
@@ -130,6 +143,21 @@
* @param[in] fan - The fan to update the health map with
*/
void updateFanHealth(const Fan& fan);
+
+ /**
+ * @brief The function that runs when the power state changes
+ *
+ * @param[in] powerStateOn - If power is now on or not
+ */
+ void powerStateChanged(bool powerStateOn);
+
+ /**
+ * @brief Reads the fault configuration from the JSON config
+ * file, such as the power off rule configuration.
+ *
+ * @param[in] jsonObj - JSON object to parse from
+ */
+ void setFaultConfig(const json& jsonObj);
};
} // namespace phosphor::fan::monitor