Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -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" |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 19 | #include "fan.hpp" |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 20 | #include "xyz/openbmc_project/Control/ThermalMode/server.hpp" |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 21 | |
| 22 | #include <nlohmann/json.hpp> |
Matthew Barth | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 23 | #include <sdbusplus/bus.hpp> |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 24 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 25 | #include <any> |
| 26 | #include <functional> |
| 27 | #include <map> |
| 28 | #include <tuple> |
| 29 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 30 | namespace phosphor::fan::control::json |
| 31 | { |
| 32 | |
| 33 | using json = nlohmann::json; |
| 34 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 35 | /* Extend the Control::ThermalMode interface */ |
| 36 | using ThermalObject = sdbusplus::server::object::object< |
| 37 | sdbusplus::xyz::openbmc_project::Control::server::ThermalMode>; |
| 38 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 39 | /** |
| 40 | * @class Zone - Represents a configured fan control zone |
| 41 | * |
| 42 | * A zone object contains the configured attributes for a zone that groups |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 43 | * a number of fans together to be under the same target control. These |
| 44 | * configuration attributes include, but are not limited to, the default ceiling |
| 45 | * of the fans within the zone, a default floor, the delay between increases, a |
| 46 | * decrease interval, and any profiles(OPTIONAL) the zone should be included in. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 47 | * |
| 48 | * (When no profile for a zone is given, the zone defaults to always exist) |
| 49 | * |
| 50 | */ |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 51 | class Zone : public ConfigBase, public ThermalObject |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 52 | { |
| 53 | public: |
| 54 | /* JSON file name for zones */ |
| 55 | static constexpr auto confFileName = "zones.json"; |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 56 | static constexpr auto thermModeIntf = |
| 57 | "xyz.openbmc_project.Control.ThermalMode"; |
| 58 | static constexpr auto supportedProp = "Supported"; |
| 59 | static constexpr auto currentProp = "Current"; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 60 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 61 | Zone() = delete; |
| 62 | Zone(const Zone&) = delete; |
| 63 | Zone(Zone&&) = delete; |
| 64 | Zone& operator=(const Zone&) = delete; |
| 65 | Zone& operator=(Zone&&) = delete; |
| 66 | ~Zone() = default; |
| 67 | |
| 68 | /** |
| 69 | * Constructor |
| 70 | * Parses and populates a zone from JSON object data |
| 71 | * |
Matthew Barth | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 72 | * @param[in] bus - sdbusplus bus object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 73 | * @param[in] jsonObj - JSON object |
| 74 | */ |
Matthew Barth | acd737c | 2021-03-04 11:04:01 -0600 | [diff] [blame] | 75 | Zone(sdbusplus::bus::bus& bus, const json& jsonObj); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 76 | |
| 77 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 78 | * @brief Get the default ceiling |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 79 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 80 | * Default ceiling is the highest target the fans within this zone is |
| 81 | * allowed to increase to. The zone's ceiling defaults to this unless |
| 82 | * changed by some configured event. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 83 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 84 | * @return Default ceiling of this zone |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 85 | */ |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 86 | inline const auto& getDefaultCeiling() const |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 87 | { |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 88 | return _defaultCeiling; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 92 | * @brief Get the default floor |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 93 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 94 | * The default floor is the lowest target the fans within this zone |
| 95 | * are allowed to decrease to. The zone's floor defaults to this |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 96 | * unless changed by some configured event. |
| 97 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 98 | * @return Default floor |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 99 | */ |
| 100 | inline const auto& getDefaultFloor() const |
| 101 | { |
| 102 | return _defaultFloor; |
| 103 | } |
| 104 | |
| 105 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 106 | * @brief Get the increase delay(OPTIONAL) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 107 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 108 | * The increase delay is the amount of time(in seconds) increases |
| 109 | * to a target are delayed before being made. The default is 0, which |
| 110 | * results in immediate increase requests when any events result in |
| 111 | * a change to the target. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 112 | * |
| 113 | * It is recommend a value other than 0 is configured, but that inherently |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 114 | * depends on the fan controller and configured increases. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 115 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 116 | * @return Increase delay(in seconds) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 117 | */ |
| 118 | inline const auto& getIncDelay() const |
| 119 | { |
| 120 | return _incDelay; |
| 121 | } |
| 122 | |
| 123 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 124 | * @brief Get the decrease interval |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 125 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 126 | * Decreases happen on a set interval when no requests for an increase |
| 127 | * in fan targets exists. This is the interval(in seconds) at which the fans |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 128 | * within the zone are decreased if events exist that result in a target |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 129 | * decrease. |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 130 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 131 | * @return Decrease interval(in seconds) |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 132 | */ |
| 133 | inline const auto& getDecInterval() const |
| 134 | { |
| 135 | return _decInterval; |
| 136 | } |
| 137 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 138 | /** |
Matthew Barth | dc776c8 | 2021-02-25 16:06:16 -0600 | [diff] [blame] | 139 | * @brief Get the target increase delta |
| 140 | * |
| 141 | * @return - The current target increase delta |
| 142 | */ |
| 143 | inline auto& getIncDelta() const |
| 144 | { |
| 145 | return _incDelta; |
| 146 | }; |
| 147 | |
| 148 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 149 | * @brief Get the target decrease delta |
| 150 | * |
| 151 | * @return - The current target decrease delta |
| 152 | */ |
| 153 | inline auto& getDecDelta() const |
| 154 | { |
| 155 | return _decDelta; |
| 156 | }; |
| 157 | |
| 158 | /** |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 159 | * @brief Add a fan object to the zone |
| 160 | * |
| 161 | * @param[in] fan - Unique pointer to a fan object that will be moved into |
| 162 | * the zone |
| 163 | * |
| 164 | * Adds a fan object to the list of fans that make up the zone by moving the |
| 165 | * fan object into the list. |
| 166 | */ |
| 167 | void addFan(std::unique_ptr<Fan> fan); |
| 168 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 169 | /** |
Matthew Barth | 8ba715e | 2021-03-05 09:00:05 -0600 | [diff] [blame] | 170 | * Sets all fans in the zone to the target given when the zone is active |
| 171 | * |
| 172 | * @param[in] target - Target for fans |
| 173 | */ |
| 174 | void setTarget(uint64_t target); |
| 175 | |
| 176 | /** |
| 177 | * @brief Sets the automatic fan control allowed active state |
| 178 | * |
| 179 | * @param[in] ident - An identifier that affects the active state |
| 180 | * @param[in] isActiveAllow - Active state according to group |
| 181 | */ |
| 182 | void setActiveAllow(const std::string& ident, bool isActiveAllow); |
| 183 | |
| 184 | /** |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 185 | * @brief Set the floor to the given target and increase target to the floor |
| 186 | * when the target is below the floor value when floor changes are allowed. |
| 187 | * |
| 188 | * @param[in] target - Target to set the floor to |
| 189 | */ |
| 190 | void setFloor(uint64_t target); |
| 191 | |
| 192 | /** |
| 193 | * @brief Sets the floor change allowed state |
| 194 | * |
| 195 | * @param[in] ident - An identifier that affects floor changes |
| 196 | * @param[in] isAllow - Allow state according to the identifier |
| 197 | */ |
| 198 | inline void setFloorChangeAllow(const std::string& ident, bool isAllow) |
| 199 | { |
| 200 | _floorChange[ident] = isAllow; |
| 201 | } |
| 202 | |
| 203 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 204 | * @brief Sets the decrease allowed state of a group |
| 205 | * |
| 206 | * @param[in] ident - An identifier that affects speed decreases |
| 207 | * @param[in] isAllow - Allow state according to the identifier |
| 208 | */ |
| 209 | inline void setDecreaseAllow(const std::string& ident, bool isAllow) |
| 210 | { |
| 211 | _decAllowed[ident] = isAllow; |
| 212 | } |
| 213 | |
| 214 | /** |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 215 | * @brief Calculate the requested target from the given delta and increases |
| 216 | * the fans, not going above the ceiling. |
| 217 | * |
| 218 | * @param[in] targetDelta - The delta to increase the target by |
| 219 | */ |
| 220 | void requestIncrease(uint64_t targetDelta); |
| 221 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 222 | /** |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 223 | * @brief Calculate the lowest requested decrease target from the given |
| 224 | * delta within a decrease interval. |
| 225 | * |
| 226 | * @param[in] targetDelta - The delta to decrease the target by |
| 227 | */ |
| 228 | void requestDecrease(uint64_t targetDelta); |
| 229 | |
| 230 | /** |
Matthew Barth | 07fecfc | 2021-01-29 09:04:43 -0600 | [diff] [blame] | 231 | * @brief Set the requested target base to be used as the target to base a |
| 232 | * new requested target from |
| 233 | * |
| 234 | * @param[in] targetBase - Base target value to use |
| 235 | */ |
| 236 | inline void setRequestTargetBase(uint64_t targetBase) |
| 237 | { |
| 238 | _requestTargetBase = targetBase; |
| 239 | }; |
| 240 | |
| 241 | /** |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 242 | * @brief Set a property to be persisted |
| 243 | * |
| 244 | * @param[in] intf - Interface containing property |
| 245 | * @param[in] prop - Property to be persisted |
| 246 | */ |
| 247 | void setPersisted(const std::string& intf, const std::string& prop); |
| 248 | |
| 249 | /** |
| 250 | * @brief Overridden thermal object's set 'Current' property function |
| 251 | * |
| 252 | * @param[in] value - Value to set 'Current' to |
| 253 | * |
| 254 | * @return - The updated value of the 'Current' property |
| 255 | */ |
| 256 | std::string current(std::string value) override; |
| 257 | |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 258 | /** |
| 259 | * @brief A handler function to set/update a property on a zone |
| 260 | * @details Sets or updates a zone's dbus property to the given value using |
| 261 | * the provided base dbus object's set property function |
| 262 | * |
| 263 | * @param[in] intf - Interface on zone object |
| 264 | * @param[in] prop - Property on interface |
| 265 | * @param[in] func - Zone object's set property function pointer |
| 266 | * @param[in] value - Value to set property to |
| 267 | * @param[in] persist - Persist property value or not |
| 268 | * |
| 269 | * @return Lambda function |
| 270 | * A lambda function to set/update the zone's dbus property |
| 271 | */ |
| 272 | template <typename T> |
| 273 | static auto setProperty(const char* intf, const char* prop, |
| 274 | T (Zone::*func)(T), T&& value, bool persist) |
| 275 | { |
| 276 | return [=, value = std::forward<T>(value)](Zone* zone) { |
| 277 | (zone->*func)(value); |
| 278 | if (persist) |
| 279 | { |
| 280 | zone->setPersisted(intf, prop); |
| 281 | } |
| 282 | }; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * @brief A handler function to set/update a zone's dbus property's persist |
| 287 | * state |
| 288 | * @details Sets or updates a zone's dbus property's persist state where the |
| 289 | * value of the property is to be left unchanged |
| 290 | * |
| 291 | * @param[in] intf - Interface on zone object |
| 292 | * @param[in] prop - Property on interface |
| 293 | * @param[in] persist - Persist property value or not |
| 294 | * |
| 295 | * @return Lambda function |
| 296 | * A lambda function to set/update the zone's dbus property's persist |
| 297 | * state |
| 298 | */ |
| 299 | static auto setPropertyPersist(const char* intf, const char* prop, |
| 300 | bool persist) |
| 301 | { |
| 302 | return [=](Zone* zone) { |
| 303 | if (persist) |
| 304 | { |
| 305 | zone->setPersisted(intf, prop); |
| 306 | } |
| 307 | }; |
| 308 | } |
| 309 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 310 | private: |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 311 | /* The zone's default ceiling value for fans */ |
| 312 | uint64_t _defaultCeiling; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 313 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 314 | /* The zone's default floor value for fans */ |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 315 | uint64_t _defaultFloor; |
| 316 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 317 | /* Zone's increase delay(in seconds) (OPTIONAL) */ |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 318 | uint64_t _incDelay; |
| 319 | |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 320 | /* Zone's decrease interval(in seconds) */ |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 321 | uint64_t _decInterval; |
| 322 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 323 | /* The floor target to not go below */ |
| 324 | uint64_t _floor; |
| 325 | |
| 326 | /* Target for this zone */ |
| 327 | uint64_t _target; |
| 328 | |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 329 | /* Zone increase delta */ |
| 330 | uint64_t _incDelta; |
| 331 | |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 332 | /* Zone decrease delta */ |
| 333 | uint64_t _decDelta; |
| 334 | |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 335 | /* The ceiling target to not go above */ |
| 336 | uint64_t _ceiling; |
| 337 | |
| 338 | /* Requested target base */ |
| 339 | uint64_t _requestTargetBase; |
| 340 | |
Matthew Barth | 12cb125 | 2021-03-08 16:47:30 -0600 | [diff] [blame] | 341 | /* Map of whether floor changes are allowed by a string identifier */ |
| 342 | std::map<std::string, bool> _floorChange; |
| 343 | |
Matthew Barth | 45c44ea | 2021-03-03 13:16:14 -0600 | [diff] [blame] | 344 | /* Map of controlling decreases allowed by a string identifer */ |
| 345 | std::map<std::string, bool> _decAllowed; |
| 346 | |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 347 | /* Map of interfaces to persisted properties the zone hosts*/ |
| 348 | std::map<std::string, std::vector<std::string>> _propsPersisted; |
| 349 | |
Matthew Barth | 8ba715e | 2021-03-05 09:00:05 -0600 | [diff] [blame] | 350 | /* Automatic fan control active state */ |
| 351 | bool _isActive; |
| 352 | |
| 353 | /* Map of active fan control allowed by a string identifier */ |
| 354 | std::map<std::string, bool> _active; |
| 355 | |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 356 | /* Interface to property mapping of their associated set property handler |
| 357 | * function */ |
| 358 | static const std::map< |
| 359 | std::string, |
| 360 | std::map<std::string, |
| 361 | std::function<std::function<void(Zone*)>(const json&, bool)>>> |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 362 | _intfPropHandlers; |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 363 | |
Matthew Barth | de90fb4 | 2021-03-04 16:34:28 -0600 | [diff] [blame] | 364 | /* List of fans included in this zone */ |
| 365 | std::vector<std::unique_ptr<Fan>> _fans; |
| 366 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 367 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 368 | * @brief Parse and set the zone's default ceiling value |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 369 | * |
| 370 | * @param[in] jsonObj - JSON object for the zone |
| 371 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 372 | * Sets the default ceiling value for the zone from the JSON configuration |
| 373 | * object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 374 | */ |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 375 | void setDefaultCeiling(const json& jsonObj); |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 376 | |
| 377 | /** |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 378 | * @brief Parse and set the zone's default floor value |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 379 | * |
| 380 | * @param[in] jsonObj - JSON object for the zone |
| 381 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 382 | * Sets the default floor value for the zone from the JSON configuration |
| 383 | * object |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 384 | */ |
| 385 | void setDefaultFloor(const json& jsonObj); |
| 386 | |
| 387 | /** |
| 388 | * @brief Parse and set the zone's decrease interval(in seconds) |
| 389 | * |
| 390 | * @param[in] jsonObj - JSON object for the zone |
| 391 | * |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 392 | * Sets the decrease interval(in seconds) for the zone from the JSON |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 393 | * configuration object |
| 394 | */ |
| 395 | void setDecInterval(const json& jsonObj); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 396 | |
| 397 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 398 | * @brief Parse and set the interfaces served by the zone(OPTIONAL) |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 399 | * |
| 400 | * @param[in] jsonObj - JSON object for the zone |
| 401 | * |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 402 | * Constructs any zone interface handler functions for interfaces that the |
| 403 | * zone serves which contains the interface's property's value and |
| 404 | * persistency state (OPTIONAL). A property's "persist" state is defaulted |
| 405 | * to not be persisted when not given. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 406 | */ |
| 407 | void setInterfaces(const json& jsonObj); |
Matthew Barth | a0dd135 | 2021-03-09 11:10:49 -0600 | [diff] [blame] | 408 | |
| 409 | /** |
| 410 | * @brief Is the property persisted |
| 411 | * |
| 412 | * @param[in] intf - Interface containing property |
| 413 | * @param[in] prop - Property to check if persisted |
| 414 | * |
| 415 | * @return - True if property is to be persisted, false otherwise |
| 416 | */ |
| 417 | bool isPersisted(const std::string& intf, const std::string& prop); |
| 418 | |
| 419 | /** |
| 420 | * @brief Save the thermal control current mode property to persisted |
| 421 | * storage |
| 422 | */ |
| 423 | void saveCurrentMode(); |
Matthew Barth | 2b3253e | 2021-03-09 14:51:16 -0600 | [diff] [blame] | 424 | |
| 425 | /** |
| 426 | * @brief Get the request target base if defined, otherwise the the current |
| 427 | * target is returned |
| 428 | * |
| 429 | * @return - The request target base or current target |
| 430 | */ |
| 431 | inline auto getRequestTargetBase() const |
| 432 | { |
| 433 | return (_requestTargetBase != 0) ? _requestTargetBase : _target; |
| 434 | }; |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 435 | }; |
| 436 | |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 437 | /** |
| 438 | * Properties of interfaces supported by the zone configuration |
| 439 | */ |
| 440 | namespace zone::property |
| 441 | { |
| 442 | |
| 443 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 444 | * @brief "Supported" property on the "xyz.openbmc_project.Control.ThermalMode" |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 445 | * interface parser. Also creates the handler function for the Zone object to |
| 446 | * initialize the property according to what's parsed from the configuration. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 447 | * |
| 448 | * @param[in] jsonObj - JSON object for the "Supported" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 449 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 450 | * |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 451 | * @return Zone interface set property handler function for the "Supported" |
| 452 | * property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 453 | */ |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 454 | std::function<void(Zone*)> supported(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 455 | |
| 456 | /** |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 457 | * @brief "Current" property on the "xyz.openbmc_project.Control.ThermalMode" |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 458 | * interface parser. Also creates the handler function for the Zone object to |
| 459 | * initialize the property according to what's parsed from the configuration. |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 460 | * |
| 461 | * @param[in] jsonObj - JSON object for the "Current" property |
Matthew Barth | 216229c | 2020-09-24 13:47:33 -0500 | [diff] [blame] | 462 | * @param[in] persist - Whether to persist the value or not |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 463 | * |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 464 | * @return Zone interface set property handler function for the "Current" |
| 465 | * property |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 466 | */ |
Matthew Barth | b584d81 | 2021-03-11 15:55:04 -0600 | [diff] [blame] | 467 | std::function<void(Zone*)> current(const json& jsonObj, bool persist); |
Matthew Barth | 651f03a | 2020-08-27 16:15:11 -0500 | [diff] [blame] | 468 | |
| 469 | } // namespace zone::property |
| 470 | |
Matthew Barth | 4f0d3b7 | 2020-08-27 14:32:15 -0500 | [diff] [blame] | 471 | } // namespace phosphor::fan::control::json |