control: Group configuration parsing

Groups are a list of dbus object paths that are to be used within
one-or-more configured fan control events. For fan control, groups are
generally comprised of one-or-more temperature sensors or inventory
objects that exist on the same base object path and implement the same
interface and property to be used in a configured fan control event.
The interface and property to be used on the members of the group are
given within each event.

ex.)
> Group made up of 4 fan inventory objects:

"name": "air_cooled_zone0_fans",
"description": "Group of fan inventory objects for air cooled zone 0",
"type": "/xyz/openbmc_project/inventory",
"members": [
    "/system/chassis/motherboard/fan0",
    "/system/chassis/motherboard/fan1",
    "/system/chassis/motherboard/fan2",
    "/system/chassis/motherboard/fan3"
]

> Event using this group that sets fans to 10500 RPMS when 1 of the
> fans in the group is changes to not present:

"name": "missing_fans_before_high_speed_air",
"groups": [
{
    "name": "air_cooled_zone0_fans",
    "interface": "xyz.openbmc_project.Inventory.Item",
    "property": {
        "name": "Present",
        "type": "bool"
    }
}],
"triggers": [
{
    "name": "signal",
    "signal": "propertiesChanged",
    "handler": "setProperty"
}],
"actions": [
{
    "name": "count_state_before_speed",
    "count": 1,
    "property": {
        "value": false,
        "type": "bool"
    },
    "speed": {
        "value": 10500,
        "type": "uint64_t"
    }
}]

Tested:
    Group objects created for each entry in "groups.json"
    A "groups.json" configuration is required
    Members are parsed and stored within the group object
    Service name is optional and stored in the group object when given

Change-Id: I258c14f4d4d5f6aeb1add3ba880cf403779564d8
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/group.cpp b/control/json/group.cpp
new file mode 100644
index 0000000..a022338
--- /dev/null
+++ b/control/json/group.cpp
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+#include "group.hpp"
+
+#include <nlohmann/json.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor::fan::control::json
+{
+
+using json = nlohmann::json;
+using namespace phosphor::logging;
+
+Group::Group(sdbusplus::bus::bus& bus, const json& jsonObj) :
+    ConfigBase(jsonObj), _service("")
+{
+    if (jsonObj.contains("profiles"))
+    {
+        for (const auto& profile : jsonObj["profiles"])
+        {
+            _profiles.emplace_back(profile.get<std::string>());
+        }
+    }
+    setMembers(jsonObj);
+    // Setting the group's service name is optional
+    if (jsonObj.contains("service"))
+    {
+        setService(jsonObj);
+    }
+}
+
+void Group::setMembers(const json& jsonObj)
+{
+    if (!jsonObj.contains("members"))
+    {
+        log<level::ERR>("Missing required group's members",
+                        entry("JSON=%s", jsonObj.dump().c_str()));
+        throw std::runtime_error("Missing required group's members");
+    }
+    for (const auto& member : jsonObj["members"])
+    {
+        _members.emplace_back(member.get<std::string>());
+    }
+}
+
+void Group::setService(const json& jsonObj)
+{
+    _service = jsonObj["service"].get<std::string>();
+}
+
+} // namespace phosphor::fan::control::json