control: Add profile configuration class framework
The profile class will contain the configuration for each profile that
is configured within the "profiles.json" file. Profiles are optional,
therefore the "profiles.json" file is optionally present. When no
profiles exist, all configured fan control events are used, however if
one-or-more profiles exist, events configured for the specific profile
are used along with any events not configured under a profile.
Tested:
"profiles.json" file parsed and profile name retrieved
Change-Id: Ia450bc2a3f94f1449eb61c8ce46e6fe17aecf464
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/Makefile.am b/control/json/Makefile.am
index 84be4a4..b87b0db 100644
--- a/control/json/Makefile.am
+++ b/control/json/Makefile.am
@@ -13,4 +13,4 @@
libfan_control_json_la_SOURCES = \
manager.cpp \
- profiles.cpp
+ profile.cpp
diff --git a/control/json/profiles.cpp b/control/json/profile.cpp
similarity index 73%
rename from control/json/profiles.cpp
rename to control/json/profile.cpp
index 289d77f..f7f80b1 100644
--- a/control/json/profiles.cpp
+++ b/control/json/profile.cpp
@@ -13,20 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "profiles.hpp"
+#include "profile.hpp"
-#include "json_config.hpp"
-#include "json_parser.hpp"
-
+#include <nlohmann/json.hpp>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
namespace phosphor::fan::control::json
{
-Profiles::Profiles(sdbusplus::bus::bus& bus)
-{
- _jsonObj = fan::JsonConfig::load(
- fan::JsonConfig::getConfFile(bus, confAppName, confFileName));
-}
+using json = nlohmann::json;
+using namespace phosphor::logging;
+
+Profile::Profile(sdbusplus::bus::bus& bus, const json& jsonObj) :
+ ConfigBase(jsonObj), _bus(bus)
+{}
} // namespace phosphor::fan::control::json
diff --git a/control/json/profile.hpp b/control/json/profile.hpp
new file mode 100644
index 0000000..ed80226
--- /dev/null
+++ b/control/json/profile.hpp
@@ -0,0 +1,66 @@
+/**
+ * Copyright © 2020 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include "config_base.hpp"
+
+#include <nlohmann/json.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor::fan::control::json
+{
+
+using json = nlohmann::json;
+
+/**
+ * @class Profile - Represents a configured fan control profile
+ *
+ * Fan control profiles are optional, therefore the "profiles.json" file is
+ * also optional. A profile can be used to load specific fan control events
+ * based on the configuration of the profile. Fan control events configured
+ * with no profile(s) are always used and events configured for a specified
+ * profile are included when that profile is enabled.
+ *
+ * When no profiles exist, all configured fan control events are used.
+ */
+class Profile : public ConfigBase
+{
+ public:
+ /* JSON file name for profiles */
+ static constexpr auto confFileName = "profiles.json";
+
+ Profile() = delete;
+ Profile(const Profile&) = delete;
+ Profile(Profile&&) = delete;
+ Profile& operator=(const Profile&) = delete;
+ Profile& operator=(Profile&&) = delete;
+ ~Profile() = default;
+
+ /**
+ * Constructor
+ * Parses and populates a zone profile from JSON object data
+ *
+ * @param[in] bus - sdbusplus bus object
+ * @param[in] jsonObj - JSON object
+ */
+ Profile(sdbusplus::bus::bus& bus, const json& jsonObj);
+
+ private:
+ /* The sdbusplus bus object */
+ sdbusplus::bus::bus& _bus;
+};
+
+} // namespace phosphor::fan::control::json
diff --git a/control/json/profiles.hpp b/control/json/profiles.hpp
deleted file mode 100644
index f6ba56e..0000000
--- a/control/json/profiles.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright © 2020 IBM Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <nlohmann/json.hpp>
-#include <sdbusplus/bus.hpp>
-
-namespace phosphor::fan::control::json
-{
-
-using json = nlohmann::json;
-
-class Profiles
-{
- public:
- Profiles() = delete;
- Profiles(const Profiles&) = delete;
- Profiles(Profiles&&) = delete;
- Profiles& operator=(const Profiles&) = delete;
- Profiles& operator=(Profiles&&) = delete;
- ~Profiles() = default;
-
- /**
- * Constructor
- * Parses and populates the zone profiles from a json file
- *
- * @param[in] bus - sdbusplus bus object
- */
- explicit Profiles(sdbusplus::bus::bus& bus);
-
- private:
- /* JSON file name for profiles */
- static constexpr auto confFileName = "profiles.json";
-
- /* The parsed JSON object */
- json _jsonObj;
-};
-
-} // namespace phosphor::fan::control::json