Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -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 | |
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 | { |
| 45 | public: |
| 46 | /* JSON file name for fans */ |
| 47 | static constexpr auto confFileName = "fans.json"; |
| 48 | |
| 49 | Fan() = delete; |
| 50 | Fan(const Fan&) = delete; |
| 51 | Fan(Fan&&) = delete; |
| 52 | Fan& operator=(const Fan&) = delete; |
| 53 | Fan& operator=(Fan&&) = delete; |
| 54 | ~Fan() = default; |
| 55 | |
| 56 | /** |
| 57 | * Constructor |
| 58 | * Parses and populates a zone fan from JSON object data |
| 59 | * |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 60 | * @param[in] jsonObj - JSON object |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 61 | * @param[in] bus - sdbusplus bus object |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 62 | */ |
Matthew Barth | 603ef16 | 2021-03-24 15:34:53 -0500 | [diff] [blame] | 63 | Fan(const json& jsonObj, sdbusplus::bus::bus& bus); |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 64 | |
| 65 | /** |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 66 | * @brief Get the zone |
| 67 | * |
| 68 | * @return Zone this fan belongs in |
| 69 | */ |
| 70 | inline const auto& getZone() const |
| 71 | { |
| 72 | return _zone; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @brief Get the list of sensors |
| 77 | * |
| 78 | * @return List of sensors with `Target` property |
| 79 | */ |
| 80 | inline const auto& getSensors() const |
| 81 | { |
| 82 | return _sensors; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @brief Get the sensors' interface |
| 87 | * |
| 88 | * @return Interface containing `Target` to use on sensors |
| 89 | */ |
| 90 | inline const auto& getInterface() const |
| 91 | { |
| 92 | return _interface; |
| 93 | } |
| 94 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 95 | /** |
| 96 | * @brief Get the current fan target |
| 97 | * |
| 98 | * @return - The current target of the fan |
| 99 | */ |
| 100 | inline auto getTarget() const |
| 101 | { |
| 102 | return _target; |
| 103 | } |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 104 | |
| 105 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 106 | * Sets the target value on all contained sensors |
| 107 | * |
| 108 | * @param[in] target - The value to set |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 109 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 110 | void setTarget(uint64_t target); |
| 111 | |
| 112 | private: |
| 113 | /* The sdbusplus bus object */ |
| 114 | sdbusplus::bus::bus& _bus; |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Interface containing the `Target` property |
Matthew Barth | e47c958 | 2021-03-09 14:24:02 -0600 | [diff] [blame] | 118 | * to use in controlling the fan's target |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 119 | */ |
| 120 | std::string _interface; |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 121 | |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 122 | /* Target for this fan */ |
| 123 | uint64_t _target; |
| 124 | |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 125 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 126 | * Map of sensors containing the `Target` property on |
| 127 | * dbus to the service providing them that make up the fan |
| 128 | */ |
| 129 | std::map<std::string, std::string> _sensors; |
| 130 | |
| 131 | /* The zone this fan belongs to */ |
| 132 | std::string _zone; |
| 133 | |
| 134 | /** |
| 135 | * @brief Parse and set the fan's sensor interface |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 136 | * |
| 137 | * @param[in] jsonObj - JSON object for the fan |
| 138 | * |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 139 | * Sets the sensor interface to use when setting the `Target` property |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 140 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 141 | void setInterface(const json& jsonObj); |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * @brief Parse and set the fan's sensor list |
| 145 | * |
| 146 | * @param[in] jsonObj - JSON object for the fan |
| 147 | * |
| 148 | * Sets the list of sensors that contain a `Target` property on dbus |
| 149 | * that make up this fan. |
| 150 | */ |
| 151 | void setSensors(const json& jsonObj); |
| 152 | |
| 153 | /** |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 154 | * @brief Parse and set the fan's zone |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 155 | * |
| 156 | * @param[in] jsonObj - JSON object for the fan |
| 157 | * |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 158 | * Sets the zone this fan is included in. |
Matthew Barth | bff1080 | 2020-08-25 10:07:57 -0500 | [diff] [blame] | 159 | */ |
Matthew Barth | a3a8cc5 | 2021-01-15 12:40:25 -0600 | [diff] [blame] | 160 | void setZone(const json& jsonObj); |
Matthew Barth | fcfa052 | 2020-08-24 16:40:24 -0500 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | } // namespace phosphor::fan::control::json |