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.hpp b/control/json/group.hpp
new file mode 100644
index 0000000..7cc84e9
--- /dev/null
+++ b/control/json/group.hpp
@@ -0,0 +1,113 @@
+/**
+ * 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 Group - Represents a group of dbus objects for configured events
+ *
+ * A group contains a list of dbus objects that are logically grouped together
+ * to be used within one-or-more configured fan control events. An event object
+ * is configured to apply a set of actions against a list of groups that could
+ * result in a fan control speed change. A group may also be configured against
+ * a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that
+ * serves the list of dbus objects in the group.
+ *
+ * (When no profile for a group is given, the group defaults to always be used
+ * within the events its included in)
+ *
+ */
+class Group : public ConfigBase
+{
+ public:
+ /* JSON file name for groups */
+ static constexpr auto confFileName = "groups.json";
+
+ Group() = delete;
+ Group(const Group&) = delete;
+ Group(Group&&) = delete;
+ Group& operator=(const Group&) = delete;
+ Group& operator=(Group&&) = delete;
+ ~Group() = default;
+
+ /**
+ * 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);
+
+ /**
+ * @brief Get the members
+ *
+ * @return List of dbus paths representing the members of the group
+ */
+ inline const auto& getMembers() const
+ {
+ return _members;
+ }
+
+ /**
+ * @brief Get the service
+ *
+ * @return Service name serving the members of the group
+ */
+ inline const auto& getService() const
+ {
+ return _service;
+ }
+
+ private:
+ /* Members of the group */
+ std::vector<std::string> _members;
+
+ /* Service name serving all the members */
+ std::string _service;
+
+ /**
+ * @brief Parse and set the members list
+ *
+ * @param[in] jsonObj - JSON object for the group
+ *
+ * Sets the list of dbus paths making up the members of the group
+ */
+ void setMembers(const json& jsonObj);
+
+ /**
+ * @brief Parse and set the service name(OPTIONAL)
+ *
+ * @param[in] jsonObj - JSON object for the group
+ *
+ * Sets the service name serving the members. It is recommended this service
+ * name be provided for a group containing members served by the fan control
+ * application itself, otherwise they may not be mapped correctly into any
+ * configured events.
+ */
+ void setService(const json& jsonObj);
+};
+
+} // namespace phosphor::fan::control::json