Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2020 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
| 18 | #include "config_base.hpp" |
| 19 | |
| 20 | #include <nlohmann/json.hpp> |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 21 | |
| 22 | namespace phosphor::fan::control::json |
| 23 | { |
| 24 | |
| 25 | using json = nlohmann::json; |
| 26 | |
| 27 | /** |
| 28 | * @class Group - Represents a group of dbus objects for configured events |
| 29 | * |
| 30 | * A group contains a list of dbus objects that are logically grouped together |
| 31 | * to be used within one-or-more configured fan control events. An event object |
| 32 | * is configured to apply a set of actions against a list of groups that could |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 33 | * result in a fan control target change. A group may also be configured against |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 34 | * a list of profiles(OPTIONAL) and or denote a specific service(OPTIONAL) that |
| 35 | * serves the list of dbus objects in the group. |
| 36 | * |
| 37 | * (When no profile for a group is given, the group defaults to always be used |
| 38 | * within the events its included in) |
| 39 | * |
| 40 | */ |
| 41 | class Group : public ConfigBase |
| 42 | { |
| 43 | public: |
| 44 | /* JSON file name for groups */ |
| 45 | static constexpr auto confFileName = "groups.json"; |
| 46 | |
| 47 | Group() = delete; |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 48 | Group(Group&&) = delete; |
| 49 | Group& operator=(const Group&) = delete; |
| 50 | Group& operator=(Group&&) = delete; |
| 51 | ~Group() = default; |
| 52 | |
| 53 | /** |
| 54 | * Constructor |
| 55 | * Parses and populates a configuration group from JSON object data |
| 56 | * |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 57 | * @param[in] jsonObj - JSON object |
| 58 | */ |
Matthew Barth | 9403a21 | 2021-05-17 09:31:50 -0500 | [diff] [blame] | 59 | Group(const json& jsonObj); |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 60 | |
| 61 | /** |
Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 62 | * Copy Constructor |
| 63 | * Creates a group from another group's originally parsed JSON object data |
| 64 | * |
| 65 | * @param[in] origObj - Original Group object to be created from |
| 66 | */ |
| 67 | Group(const Group& origObj); |
| 68 | |
| 69 | /** |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 70 | * @brief Get the members |
| 71 | * |
| 72 | * @return List of dbus paths representing the members of the group |
| 73 | */ |
| 74 | inline const auto& getMembers() const |
| 75 | { |
| 76 | return _members; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @brief Get the service |
| 81 | * |
| 82 | * @return Service name serving the members of the group |
| 83 | */ |
| 84 | inline const auto& getService() const |
| 85 | { |
| 86 | return _service; |
| 87 | } |
| 88 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 89 | /** |
| 90 | * @brief Set the dbus interface name for the group |
| 91 | */ |
Matthew Barth | 543e89e | 2021-04-06 11:42:33 -0500 | [diff] [blame] | 92 | inline void setInterface(const std::string& intf) |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 93 | { |
| 94 | _interface = intf; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @brief Get the group's dbus interface name |
| 99 | */ |
| 100 | inline const auto& getInterface() const |
| 101 | { |
| 102 | return _interface; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @brief Set the dbus property name for the group |
| 107 | */ |
Matthew Barth | 543e89e | 2021-04-06 11:42:33 -0500 | [diff] [blame] | 108 | inline void setProperty(const std::string& prop) |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 109 | { |
| 110 | _property = prop; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @brief Get the group's dbus property name |
| 115 | */ |
| 116 | inline const auto& getProperty() const |
| 117 | { |
| 118 | return _property; |
| 119 | } |
| 120 | |
Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 121 | /** |
| 122 | * @brief Set the dbus property's data type for the group |
| 123 | */ |
Matthew Barth | 543e89e | 2021-04-06 11:42:33 -0500 | [diff] [blame] | 124 | inline void setType(const std::optional<std::string>& type) |
Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 125 | { |
| 126 | _type = type; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @brief Get the group's dbus property's data type |
| 131 | */ |
| 132 | inline const auto& getType() const |
| 133 | { |
| 134 | return _type; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * @brief Set the dbus property's expected value for the group |
| 139 | */ |
Matthew Barth | 543e89e | 2021-04-06 11:42:33 -0500 | [diff] [blame] | 140 | inline void setValue(const std::optional<PropertyVariantType>& value) |
Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 141 | { |
| 142 | _value = value; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @brief Get the group's dbus property's expected value |
| 147 | */ |
| 148 | inline const auto& getValue() const |
| 149 | { |
| 150 | return _value; |
| 151 | } |
| 152 | |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 153 | private: |
| 154 | /* Members of the group */ |
| 155 | std::vector<std::string> _members; |
| 156 | |
| 157 | /* Service name serving all the members */ |
| 158 | std::string _service; |
| 159 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 160 | /* Dbus interface name for all the members */ |
| 161 | std::string _interface; |
| 162 | |
| 163 | /* Dbus property name for all the members */ |
| 164 | std::string _property; |
| 165 | |
Matthew Barth | e557860 | 2021-03-30 12:53:24 -0500 | [diff] [blame] | 166 | /* Optional property's data type for all members */ |
| 167 | std::optional<std::string> _type; |
| 168 | |
| 169 | /* Optional property value for all the members */ |
| 170 | std::optional<PropertyVariantType> _value; |
| 171 | |
Matthew Barth | dfd4a05 | 2020-09-02 16:31:51 -0500 | [diff] [blame] | 172 | /** |
| 173 | * @brief Parse and set the members list |
| 174 | * |
| 175 | * @param[in] jsonObj - JSON object for the group |
| 176 | * |
| 177 | * Sets the list of dbus paths making up the members of the group |
| 178 | */ |
| 179 | void setMembers(const json& jsonObj); |
| 180 | |
| 181 | /** |
| 182 | * @brief Parse and set the service name(OPTIONAL) |
| 183 | * |
| 184 | * @param[in] jsonObj - JSON object for the group |
| 185 | * |
| 186 | * Sets the service name serving the members. It is recommended this service |
| 187 | * name be provided for a group containing members served by the fan control |
| 188 | * application itself, otherwise they may not be mapped correctly into any |
| 189 | * configured events. |
| 190 | */ |
| 191 | void setService(const json& jsonObj); |
| 192 | }; |
| 193 | |
| 194 | } // namespace phosphor::fan::control::json |