control: Set fans to `poweron_target` at poweron
Utilize the PowerState object to subscribe to power state changes so
fans can be set to their configured `poweron_target` values when the
system is powered on. When a system is powered off, by design, nothing
is done to the fan speeds, that is left up to the configuration of
events to change the fans when a system is powered off, if desired.
Also, for any reason that fan control is restarted when the system is
already powered on, it will not change the fan targets to the
`poweron_target` value. Fan control will pick up on controlling the
configured fans from their current target.
Change-Id: I4e4e619b91e5d64b9b06378a37d9a062f10ace6b
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 78d30f3..22c11f1 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -22,6 +22,7 @@
#include "fan.hpp"
#include "group.hpp"
#include "json_config.hpp"
+#include "power_state.hpp"
#include "profile.hpp"
#include "sdbusplus.hpp"
#include "zone.hpp"
@@ -55,7 +56,11 @@
Manager::_objects;
Manager::Manager(const sdeventplus::Event& event) :
- _bus(util::SDBusPlus::getBus()), _event(event)
+ _bus(util::SDBusPlus::getBus()), _event(event),
+ _powerState(std::make_unique<PGoodState>(
+ util::SDBusPlus::getBus(),
+ std::bind(std::mem_fn(&Manager::powerStateChanged), this,
+ std::placeholders::_1)))
{
load();
}
@@ -141,6 +146,16 @@
[](const auto& entry) { entry.second->enable(); });
}
+void Manager::powerStateChanged(bool powerStateOn)
+{
+ if (powerStateOn)
+ {
+ std::for_each(_zones.begin(), _zones.end(), [](const auto& entry) {
+ entry.second->setTarget(entry.second->getPoweronTarget());
+ });
+ }
+}
+
const std::vector<std::string>& Manager::getActiveProfiles()
{
return _activeProfiles;
diff --git a/control/json/manager.hpp b/control/json/manager.hpp
index c5b591d..9f57ac9 100644
--- a/control/json/manager.hpp
+++ b/control/json/manager.hpp
@@ -20,6 +20,7 @@
#include "event.hpp"
#include "group.hpp"
#include "json_config.hpp"
+#include "power_state.hpp"
#include "profile.hpp"
#include "sdbusplus.hpp"
#include "zone.hpp"
@@ -410,6 +411,16 @@
*/
unsigned int getPowerOnDelay();
+ /**
+ * @brief Is the power state on
+ *
+ * @return Current power state of the system
+ */
+ inline bool isPowerOn() const
+ {
+ return _powerState->isPowerOn();
+ }
+
private:
/* JSON file name for manager configuration attributes */
static constexpr auto confFileName = "manager.json";
@@ -427,6 +438,9 @@
*/
sdeventplus::Event _event;
+ /* The system's power state determination object */
+ std::unique_ptr<PowerState> _powerState;
+
/* List of profiles configured */
std::map<configKey, std::unique_ptr<Profile>> _profiles;
@@ -468,6 +482,16 @@
void load();
/**
+ * @brief Callback for power state changes
+ *
+ * @param[in] powerStateOn - Whether the power state is on or not
+ *
+ * Callback function bound to the PowerState object instance to handle each
+ * time the power state changes.
+ */
+ void powerStateChanged(bool powerStateOn);
+
+ /**
* @brief Find the service name for a given path and interface from the
* cached dataset
*
diff --git a/control/json/zone.hpp b/control/json/zone.hpp
index f209b4a..677c210 100644
--- a/control/json/zone.hpp
+++ b/control/json/zone.hpp
@@ -76,6 +76,19 @@
Zone(const json& jsonObj, const sdeventplus::Event& event, Manager* mgr);
/**
+ * @brief Get the poweron target
+ *
+ * Poweron target is the target the fans within this zone should be set to
+ * when the system is powered on.
+ *
+ * @return Poweron target of this zone
+ */
+ inline const auto& getPoweronTarget() const
+ {
+ return _poweronTarget;
+ }
+
+ /**
* @brief Get the default ceiling
*
* Default ceiling is the highest target the fans within this zone is