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