Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 1 | /** |
Mike Capps | 70c26b2 | 2021-10-07 15:24:29 -0400 | [diff] [blame] | 2 | * Copyright © 2022 IBM Corporation |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 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 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 23 | #include <map> |
| 24 | |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 25 | namespace phosphor::fan::control::json |
| 26 | { |
| 27 | |
| 28 | using json = nlohmann::json; |
| 29 | |
| 30 | /** |
| 31 | * @class Fan - Represents a configured fan control fan object |
| 32 | * |
| 33 | * A fan object contains the configured attributes for a fan within the system |
| 34 | * that will be controlled by the fan control application. These configuration |
| 35 | * attributes include, but are not limited to, the cooling zone in which the |
| 36 | * fan is included, what sensors make up the fan, the target interface to be |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 37 | * used in setting a target, and any profiles(OPTIONAL) the fan should be |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 38 | * included in. |
| 39 | * |
| 40 | * (When no profile for a fan is given, the fan defaults to always be included) |
| 41 | * |
| 42 | */ |
| 43 | class Fan : public ConfigBase |
| 44 | { |
Mike Capps | 762e858 | 2021-10-07 15:33:23 -0400 | [diff] [blame] | 45 | friend class Zone; |
| 46 | |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 47 | public: |
| 48 | /* JSON file name for fans */ |
| 49 | static constexpr auto confFileName = "fans.json"; |
| 50 | |
| 51 | Fan() = delete; |
| 52 | Fan(const Fan&) = delete; |
| 53 | Fan(Fan&&) = delete; |
| 54 | Fan& operator=(const Fan&) = delete; |
| 55 | Fan& operator=(Fan&&) = delete; |
| 56 | ~Fan() = default; |
| 57 | |
| 58 | /** |
| 59 | * Constructor |
| 60 | * Parses and populates a zone fan from JSON object data |
| 61 | * |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 62 | * @param[in] jsonObj - JSON object |
| 63 | */ |
Matt Spinler | 9b06243 | 2023-01-26 14:38:50 -0600 | [diff] [blame] | 64 | explicit Fan(const json& jsonObj); |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 65 | |
| 66 | /** |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 67 | * @brief Get the zone |
| 68 | * |
| 69 | * @return Zone this fan belongs in |
| 70 | */ |
| 71 | inline const auto& getZone() const |
| 72 | { |
| 73 | return _zone; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @brief Get the list of sensors |
| 78 | * |
| 79 | * @return List of sensors with `Target` property |
| 80 | */ |
| 81 | inline const auto& getSensors() const |
| 82 | { |
| 83 | return _sensors; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @brief Get the sensors' interface |
| 88 | * |
| 89 | * @return Interface containing `Target` to use on sensors |
| 90 | */ |
| 91 | inline const auto& getInterface() const |
| 92 | { |
| 93 | return _interface; |
| 94 | } |
| 95 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 96 | /** |
| 97 | * @brief Get the current fan target |
| 98 | * |
| 99 | * @return - The current target of the fan |
| 100 | */ |
| 101 | inline auto getTarget() const |
| 102 | { |
| 103 | return _target; |
| 104 | } |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 105 | |
| 106 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 107 | * Sets the target value on all contained sensors |
| 108 | * |
| 109 | * @param[in] target - The value to set |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 110 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 111 | void setTarget(uint64_t target); |
| 112 | |
Matt Spinler | 2541f99 | 2022-08-16 16:00:04 -0500 | [diff] [blame] | 113 | /** |
| 114 | * @brief Returns the fan's locked targets. |
| 115 | * |
| 116 | * @return - vector of locked targets |
| 117 | */ |
| 118 | const std::vector<uint64_t>& getLockedTargets() const |
| 119 | { |
| 120 | return _lockedTargets; |
| 121 | } |
| 122 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 123 | private: |
Mike Capps | 70c26b2 | 2021-10-07 15:24:29 -0400 | [diff] [blame] | 124 | /** |
| 125 | * Forces all contained sensors to the target (if this target is the |
| 126 | * highest. May be overridden by existing or subsequent higher values), |
| 127 | * ignoring subsequent setTarget() commands |
| 128 | * |
| 129 | * @param[in] target - The target lock to set/add |
| 130 | */ |
| 131 | void lockTarget(uint64_t target); |
| 132 | |
| 133 | /** |
| 134 | * Removes the provided target lock from the list of locks. Fan will unlock |
| 135 | * (become eligible for setTarget()) when all locks are removed from the |
| 136 | * list. |
| 137 | */ |
| 138 | void unlockTarget(uint64_t target); |
| 139 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 140 | /* The sdbusplus bus object */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 141 | sdbusplus::bus_t& _bus; |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Interface containing the `Target` property |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 145 | * to use in controlling the fan's target |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 146 | */ |
| 147 | std::string _interface; |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 148 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 149 | /* Target for this fan */ |
| 150 | uint64_t _target; |
| 151 | |
Mike Capps | 70c26b2 | 2021-10-07 15:24:29 -0400 | [diff] [blame] | 152 | /* list of locked targets active on this fan */ |
| 153 | std::vector<uint64_t> _lockedTargets; |
| 154 | |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 155 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 156 | * Map of sensors containing the `Target` property on |
| 157 | * dbus to the service providing them that make up the fan |
| 158 | */ |
| 159 | std::map<std::string, std::string> _sensors; |
| 160 | |
| 161 | /* The zone this fan belongs to */ |
| 162 | std::string _zone; |
| 163 | |
| 164 | /** |
| 165 | * @brief Parse and set the fan's sensor interface |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 166 | * |
| 167 | * @param[in] jsonObj - JSON object for the fan |
| 168 | * |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 169 | * Sets the sensor interface to use when setting the `Target` property |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 170 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 171 | void setInterface(const json& jsonObj); |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * @brief Parse and set the fan's sensor list |
| 175 | * |
| 176 | * @param[in] jsonObj - JSON object for the fan |
| 177 | * |
| 178 | * Sets the list of sensors that contain a `Target` property on dbus |
| 179 | * that make up this fan. |
| 180 | */ |
| 181 | void setSensors(const json& jsonObj); |
| 182 | |
| 183 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 184 | * @brief Parse and set the fan's zone |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 185 | * |
| 186 | * @param[in] jsonObj - JSON object for the fan |
| 187 | * |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 188 | * Sets the zone this fan is included in. |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 189 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 190 | void setZone(const json& jsonObj); |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | } // namespace phosphor::fan::control::json |