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" |
| 19 | |
| 20 | #include <nlohmann/json.hpp> |
| 21 | #include <sdbusplus/bus.hpp> |
| 22 | |
| 23 | namespace phosphor::fan::control::json |
| 24 | { |
| 25 | |
| 26 | using json = nlohmann::json; |
| 27 | |
| 28 | /** |
| 29 | * @class Zone - Represents a configured fan control zone |
| 30 | * |
| 31 | * A zone object contains the configured attributes for a zone that groups |
| 32 | * a number of fans together to be under the same speed control. These |
| 33 | * configuration attributes include, but are not limited to, the full speed |
| 34 | * of the fans within the zone, a default floor speed, the delay between speed |
| 35 | * increases, a decrease interval, and any profiles(OPTIONAL) the zone should |
| 36 | * be included in. |
| 37 | * |
| 38 | * (When no profile for a zone is given, the zone defaults to always exist) |
| 39 | * |
| 40 | */ |
| 41 | class Zone : public ConfigBase |
| 42 | { |
| 43 | public: |
| 44 | /* JSON file name for zones */ |
| 45 | static constexpr auto confFileName = "zones.json"; |
| 46 | |
| 47 | Zone() = delete; |
| 48 | Zone(const Zone&) = delete; |
| 49 | Zone(Zone&&) = delete; |
| 50 | Zone& operator=(const Zone&) = delete; |
| 51 | Zone& operator=(Zone&&) = delete; |
| 52 | ~Zone() = default; |
| 53 | |
| 54 | /** |
| 55 | * Constructor |
| 56 | * Parses and populates a zone from JSON object data |
| 57 | * |
| 58 | * @param[in] bus - sdbusplus bus object |
| 59 | * @param[in] jsonObj - JSON object |
| 60 | */ |
| 61 | Zone(sdbusplus::bus::bus& bus, const json& jsonObj); |
| 62 | |
| 63 | /** |
| 64 | * @brief Get the full speed |
| 65 | * |
| 66 | * Full speed is the speed set to the fans within this zone unless there |
| 67 | * are events configured that alter the fan speeds. |
| 68 | * |
| 69 | * @return Full speed of this zone |
| 70 | */ |
| 71 | inline const auto& getFullSpeed() const |
| 72 | { |
| 73 | return _fullSpeed; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @brief Get the default floor speed |
| 78 | * |
| 79 | * The default floor speed is the lowest speed the fans within this zone |
| 80 | * are allowed to decrease to. The zone's floor speed defaults to this |
| 81 | * unless changed by some configured event. |
| 82 | * |
| 83 | * @return Default floor speed |
| 84 | */ |
| 85 | inline const auto& getDefaultFloor() const |
| 86 | { |
| 87 | return _defaultFloor; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief Get the speed increase delay(OPTIONAL) |
| 92 | * |
| 93 | * The speed increase delay is the amount of time(in seconds) increases |
| 94 | * to a target speed are delayed before being made. The default is 0, which |
| 95 | * results in immediate speed increase requests when any events result in |
| 96 | * a change to the target speed. |
| 97 | * |
| 98 | * It is recommend a value other than 0 is configured, but that inherently |
| 99 | * depends on the fan controller and configured speed increases. |
| 100 | * |
| 101 | * @return Speed increase delay(in seconds) |
| 102 | */ |
| 103 | inline const auto& getIncDelay() const |
| 104 | { |
| 105 | return _incDelay; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @brief Get the speed decrease interval |
| 110 | * |
| 111 | * Speed decreases happen on a set interval when no requests for an increase |
| 112 | * in fan speeds exists. This is the interval(in seconds) at which the fans |
| 113 | * within the zone are decreased if events exist that result in a target |
| 114 | * speed decrease. |
| 115 | * |
| 116 | * @return Speed decrease interval(in seconds) |
| 117 | */ |
| 118 | inline const auto& getDecInterval() const |
| 119 | { |
| 120 | return _decInterval; |
| 121 | } |
| 122 | |
| 123 | private: |
| 124 | /* The zone's full speed value for fans */ |
| 125 | uint64_t _fullSpeed; |
| 126 | |
| 127 | /* The zone's default floor speed value for fans */ |
| 128 | uint64_t _defaultFloor; |
| 129 | |
| 130 | /* Zone's speed increase delay(in seconds) (OPTIONAL) */ |
| 131 | uint64_t _incDelay; |
| 132 | |
| 133 | /* Zone's speed decrease interval(in seconds) */ |
| 134 | uint64_t _decInterval; |
| 135 | |
| 136 | /** |
| 137 | * @brief Parse and set the zone's full speed value |
| 138 | * |
| 139 | * @param[in] jsonObj - JSON object for the zone |
| 140 | * |
| 141 | * Sets the full speed value for the zone from the JSON configuration object |
| 142 | */ |
| 143 | void setFullSpeed(const json& jsonObj); |
| 144 | |
| 145 | /** |
| 146 | * @brief Parse and set the zone's default floor speed value |
| 147 | * |
| 148 | * @param[in] jsonObj - JSON object for the zone |
| 149 | * |
| 150 | * Sets the default floor speed value for the zone from the JSON |
| 151 | * configuration object |
| 152 | */ |
| 153 | void setDefaultFloor(const json& jsonObj); |
| 154 | |
| 155 | /** |
| 156 | * @brief Parse and set the zone's decrease interval(in seconds) |
| 157 | * |
| 158 | * @param[in] jsonObj - JSON object for the zone |
| 159 | * |
| 160 | * Sets the speed decrease interval(in seconds) for the zone from the JSON |
| 161 | * configuration object |
| 162 | */ |
| 163 | void setDecInterval(const json& jsonObj); |
| 164 | }; |
| 165 | |
| 166 | } // namespace phosphor::fan::control::json |