control: Add creating config object without a dbus object

For those configuration objects that do not need a dbus object, create
them using a similar method without requiring a dbus object to be given.
Updated each object to correctly reflect their current need of a dbus
object which was driven by moving the creation of the available group
objects to within the event.

Change-Id: I8ce4ea7baf4cfd1ad86268b760a334fcf0a4f25e
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index e7a7bfb..94f860c 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -15,6 +15,9 @@
  */
 #include "event.hpp"
 
+#include "group.hpp"
+#include "json_parser.hpp"
+
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/bus.hpp>
@@ -25,8 +28,11 @@
 using json = nlohmann::json;
 using namespace phosphor::logging;
 
+const std::map<configKey, std::unique_ptr<Group>> Event::_availGrps =
+    getConfig<Group>(true);
+
 Event::Event(sdbusplus::bus::bus& bus, const json& jsonObj) :
-    ConfigBase(jsonObj)
+    ConfigBase(jsonObj), _bus(bus)
 {
     if (jsonObj.contains("profiles"))
     {
diff --git a/control/json/event.hpp b/control/json/event.hpp
index 5230fbb..3bc41ae 100644
--- a/control/json/event.hpp
+++ b/control/json/event.hpp
@@ -16,6 +16,8 @@
 #pragma once
 
 #include "config_base.hpp"
+#include "group.hpp"
+#include "json_parser.hpp"
 #include "types.hpp"
 
 #include <nlohmann/json.hpp>
@@ -111,6 +113,12 @@
     }
 
   private:
+    /* Mapping of available group names & profiles to their group object */
+    static const std::map<configKey, std::unique_ptr<Group>> _availGrps;
+
+    /* The sdbusplus bus object */
+    sdbusplus::bus::bus& _bus;
+
     /* A precondition the event has in order to be enabled */
     Precondition _precond;
 
diff --git a/control/json/group.cpp b/control/json/group.cpp
index a022338..f193ef7 100644
--- a/control/json/group.cpp
+++ b/control/json/group.cpp
@@ -17,7 +17,6 @@
 
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
 
 namespace phosphor::fan::control::json
 {
@@ -25,8 +24,7 @@
 using json = nlohmann::json;
 using namespace phosphor::logging;
 
-Group::Group(sdbusplus::bus::bus& bus, const json& jsonObj) :
-    ConfigBase(jsonObj), _service("")
+Group::Group(const json& jsonObj) : ConfigBase(jsonObj), _service("")
 {
     if (jsonObj.contains("profiles"))
     {
diff --git a/control/json/group.hpp b/control/json/group.hpp
index 7cc84e9..e8d607f 100644
--- a/control/json/group.hpp
+++ b/control/json/group.hpp
@@ -18,7 +18,6 @@
 #include "config_base.hpp"
 
 #include <nlohmann/json.hpp>
-#include <sdbusplus/bus.hpp>
 
 namespace phosphor::fan::control::json
 {
@@ -56,10 +55,9 @@
      * Constructor
      * Parses and populates a configuration group from JSON object data
      *
-     * @param[in] bus - sdbusplus bus object
      * @param[in] jsonObj - JSON object
      */
-    Group(sdbusplus::bus::bus& bus, const json& jsonObj);
+    Group(const json& jsonObj);
 
     /**
      * @brief Get the members
diff --git a/control/json/profile.cpp b/control/json/profile.cpp
index 696716e..0778820 100644
--- a/control/json/profile.cpp
+++ b/control/json/profile.cpp
@@ -19,7 +19,6 @@
 
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
 
 #include <algorithm>
 #include <iterator>
@@ -35,8 +34,7 @@
 const std::map<std::string, methodHandler> Profile::_methods = {
     {"all_of", Profile::allOf}};
 
-Profile::Profile(sdbusplus::bus::bus& bus, const json& jsonObj) :
-    ConfigBase(jsonObj), _bus(bus), _active(false)
+Profile::Profile(const json& jsonObj) : ConfigBase(jsonObj), _active(false)
 {
     setActive(jsonObj);
 }
diff --git a/control/json/profile.hpp b/control/json/profile.hpp
index eacb1dc..dd0aed0 100644
--- a/control/json/profile.hpp
+++ b/control/json/profile.hpp
@@ -18,7 +18,6 @@
 #include "config_base.hpp"
 
 #include <nlohmann/json.hpp>
-#include <sdbusplus/bus.hpp>
 
 namespace phosphor::fan::control::json
 {
@@ -57,7 +56,7 @@
      * @param[in] bus - sdbusplus bus object
      * @param[in] jsonObj - JSON object
      */
-    Profile(sdbusplus::bus::bus& bus, const json& jsonObj);
+    Profile(const json& jsonObj);
 
     /**
      * @brief Get the active state
@@ -70,9 +69,6 @@
     }
 
   private:
-    /* The sdbusplus bus object */
-    sdbusplus::bus::bus& _bus;
-
     /* Active state of the profile */
     bool _active;
 
diff --git a/control/json/zone.cpp b/control/json/zone.cpp
index 33ab048..dd0dbfb 100644
--- a/control/json/zone.cpp
+++ b/control/json/zone.cpp
@@ -22,7 +22,6 @@
 
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
 
 #include <iterator>
 #include <map>
@@ -41,8 +40,7 @@
                                 {{supportedProp, zone::property::supported},
                                  {currentProp, zone::property::current}}}};
 
-Zone::Zone(sdbusplus::bus::bus& bus, const json& jsonObj) :
-    ConfigBase(jsonObj), _incDelay(0)
+Zone::Zone(const json& jsonObj) : ConfigBase(jsonObj), _incDelay(0)
 {
     if (jsonObj.contains("profiles"))
     {
diff --git a/control/json/zone.hpp b/control/json/zone.hpp
index 4f7742c..09c1dac 100644
--- a/control/json/zone.hpp
+++ b/control/json/zone.hpp
@@ -19,7 +19,6 @@
 #include "types.hpp"
 
 #include <nlohmann/json.hpp>
-#include <sdbusplus/bus.hpp>
 
 #include <any>
 #include <functional>
@@ -68,10 +67,9 @@
      * Constructor
      * Parses and populates a zone from JSON object data
      *
-     * @param[in] bus - sdbusplus bus object
      * @param[in] jsonObj - JSON object
      */
-    Zone(sdbusplus::bus::bus& bus, const json& jsonObj);
+    Zone(const json& jsonObj);
 
     /**
      * @brief Get the full speed