control: Create manager object for JSON configs
Begin to transition to separate JSON vs YAMl source objects by creating
a manager object that will contain all the cached data to be used across
all events & zones of a system. This will remove the issue in the YAML
based source where the zone objects contained the cache and essentially
restricted a system to having a single zone object.
Also, include parsing of any configured profiles of the system on the
manager object. These profiles will be used to determine which
configurations are to be used on a system given the active state of any
profiles configured.
Change-Id: I817210f8bb763f03b922651192231529bc48a306
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 0ec0d0d..264eb25 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -17,15 +17,18 @@
#include "json_config.hpp"
#include "json_parser.hpp"
+#include "profile.hpp"
#include <sdbusplus/bus.hpp>
#include <filesystem>
+#include <vector>
namespace phosphor::fan::control::json
{
-Manager::Manager(sdbusplus::bus::bus& bus)
+Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event) :
+ _profiles(getConfig<Profile>(true))
{
// Manager JSON config file is optional
auto confFile =
@@ -34,6 +37,16 @@
{
_jsonObj = fan::JsonConfig::load(confFile);
}
+
+ // Ensure all configurations use the same set of active profiles
+ // (In case a profile's active state changes during configuration)
+ for (const auto& profile : _profiles)
+ {
+ if (profile.second->isActive())
+ {
+ _activeProfiles.emplace_back(profile.first.first);
+ }
+ }
}
unsigned int Manager::getPowerOnDelay()
diff --git a/control/json/manager.hpp b/control/json/manager.hpp
index 30669eb..597fdd9 100644
--- a/control/json/manager.hpp
+++ b/control/json/manager.hpp
@@ -15,8 +15,12 @@
*/
#pragma once
+#include "json_parser.hpp"
+#include "profile.hpp"
+
#include <nlohmann/json.hpp>
#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
namespace phosphor::fan::control::json
{
@@ -50,8 +54,9 @@
* Parses and populates the fan control manager attributes from a json file
*
* @param[in] bus - sdbusplus bus object
+ * @param[in] event - sdeventplus event loop
*/
- explicit Manager(sdbusplus::bus::bus& bus);
+ Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
/**
* @brief Get the configured power on delay(OPTIONAL)
@@ -67,6 +72,12 @@
/* The parsed JSON object */
json _jsonObj;
+
+ /* List of profiles configured */
+ const std::map<configKey, std::unique_ptr<Profile>> _profiles;
+
+ /* List of active profiles */
+ std::vector<std::string> _activeProfiles;
};
} // namespace phosphor::fan::control::json
diff --git a/control/json_parser.cpp b/control/json_parser.cpp
index b69bab1..74d6707 100644
--- a/control/json_parser.cpp
+++ b/control/json_parser.cpp
@@ -147,9 +147,10 @@
return zoneGrps;
}
-const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus)
+const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus,
+ const sdeventplus::Event& event)
{
- json::Manager mgr{bus};
+ json::Manager mgr{bus, event};
return mgr.getPowerOnDelay();
}
diff --git a/control/json_parser.hpp b/control/json_parser.hpp
index adeacbe..b7d2202 100644
--- a/control/json_parser.hpp
+++ b/control/json_parser.hpp
@@ -144,6 +144,7 @@
* @return Time to delay in seconds
* Amount of time to delay in seconds after a power on
*/
-const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus);
+const unsigned int getPowerOnDelay(sdbusplus::bus::bus& bus,
+ const sdeventplus::Event& event);
} // namespace phosphor::fan::control
diff --git a/control/main.cpp b/control/main.cpp
index 05dce98..98edfb9 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -16,6 +16,9 @@
#include "argument.hpp"
#include "manager.hpp"
#include "sdbusplus.hpp"
+#ifdef CONTROL_USE_JSON
+#include "json/manager.hpp"
+#endif
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
@@ -28,8 +31,9 @@
{
auto event = sdeventplus::Event::get_default();
auto bus = sdbusplus::bus::new_default();
- phosphor::fan::util::ArgumentParser args(argc, argv);
+#ifndef CONTROL_USE_JSON
+ phosphor::fan::util::ArgumentParser args(argc, argv);
if (argc != 2)
{
args.usage(argv);
@@ -51,6 +55,7 @@
args.usage(argv);
return 1;
}
+#endif
// Attach the event object to the bus object so we can
// handle both sd_events (for the timers) and dbus signals.
@@ -58,15 +63,18 @@
try
{
+#ifdef CONTROL_USE_JSON
+ json::Manager manager(bus, event);
+#else
Manager manager(bus, event, mode);
// Init mode will just set fans to max and delay
if (mode == Mode::init)
{
- manager.doInit();
+ manager.doInit(event);
return 0;
}
-
+#endif
return event.loop();
}
// Log the useful metadata on these exceptions and let the app
diff --git a/control/manager.cpp b/control/manager.cpp
index bdea542..053861b 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -138,14 +138,14 @@
}
}
-void Manager::doInit()
+void Manager::doInit(const sdeventplus::Event& event)
{
for (auto& z : _zones)
{
z.second->setFullSpeed();
}
#ifdef CONTROL_USE_JSON
- auto delay = getPowerOnDelay(_bus);
+ auto delay = getPowerOnDelay(_bus, event);
#else
auto delay = _powerOnDelay;
#endif
diff --git a/control/manager.hpp b/control/manager.hpp
index a2e44f5..496b343 100644
--- a/control/manager.hpp
+++ b/control/manager.hpp
@@ -50,7 +50,7 @@
* setting fans to full, delaying so they
* can get there, and starting a target.
*/
- void doInit();
+ void doInit(const sdeventplus::Event& event);
private:
/**