blob: 09c1dacf26c1c6e9033aa71d3b61074bfd21846c [file] [log] [blame]
Matthew Barth4f0d3b72020-08-27 14:32:15 -05001/**
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 Barth216229c2020-09-24 13:47:33 -050019#include "types.hpp"
Matthew Barth4f0d3b72020-08-27 14:32:15 -050020
21#include <nlohmann/json.hpp>
Matthew Barth4f0d3b72020-08-27 14:32:15 -050022
Matthew Barth651f03a2020-08-27 16:15:11 -050023#include <any>
24#include <functional>
25#include <map>
26#include <tuple>
27
Matthew Barth4f0d3b72020-08-27 14:32:15 -050028namespace phosphor::fan::control::json
29{
30
31using json = nlohmann::json;
32
Matthew Barth651f03a2020-08-27 16:15:11 -050033/* Interface property handler function */
Matthew Barth216229c2020-09-24 13:47:33 -050034using propHandler = std::function<ZoneHandler(const json&, bool)>;
Matthew Barth651f03a2020-08-27 16:15:11 -050035
Matthew Barth4f0d3b72020-08-27 14:32:15 -050036/**
37 * @class Zone - Represents a configured fan control zone
38 *
39 * A zone object contains the configured attributes for a zone that groups
40 * a number of fans together to be under the same speed control. These
41 * configuration attributes include, but are not limited to, the full speed
42 * of the fans within the zone, a default floor speed, the delay between speed
43 * increases, a decrease interval, and any profiles(OPTIONAL) the zone should
44 * be included in.
45 *
46 * (When no profile for a zone is given, the zone defaults to always exist)
47 *
48 */
49class Zone : public ConfigBase
50{
51 public:
52 /* JSON file name for zones */
53 static constexpr auto confFileName = "zones.json";
Matthew Barth216229c2020-09-24 13:47:33 -050054 static constexpr auto thermModeIntf =
55 "xyz.openbmc_project.Control.ThermalMode";
56 static constexpr auto supportedProp = "Supported";
57 static constexpr auto currentProp = "Current";
Matthew Barth651f03a2020-08-27 16:15:11 -050058
Matthew Barth4f0d3b72020-08-27 14:32:15 -050059 Zone() = delete;
60 Zone(const Zone&) = delete;
61 Zone(Zone&&) = delete;
62 Zone& operator=(const Zone&) = delete;
63 Zone& operator=(Zone&&) = delete;
64 ~Zone() = default;
65
66 /**
67 * Constructor
68 * Parses and populates a zone from JSON object data
69 *
Matthew Barth4f0d3b72020-08-27 14:32:15 -050070 * @param[in] jsonObj - JSON object
71 */
Matthew Barth391ade02021-01-15 14:33:21 -060072 Zone(const json& jsonObj);
Matthew Barth4f0d3b72020-08-27 14:32:15 -050073
74 /**
75 * @brief Get the full speed
76 *
77 * Full speed is the speed set to the fans within this zone unless there
78 * are events configured that alter the fan speeds.
79 *
80 * @return Full speed of this zone
81 */
82 inline const auto& getFullSpeed() const
83 {
84 return _fullSpeed;
85 }
86
87 /**
88 * @brief Get the default floor speed
89 *
90 * The default floor speed is the lowest speed the fans within this zone
91 * are allowed to decrease to. The zone's floor speed defaults to this
92 * unless changed by some configured event.
93 *
94 * @return Default floor speed
95 */
96 inline const auto& getDefaultFloor() const
97 {
98 return _defaultFloor;
99 }
100
101 /**
102 * @brief Get the speed increase delay(OPTIONAL)
103 *
104 * The speed increase delay is the amount of time(in seconds) increases
105 * to a target speed are delayed before being made. The default is 0, which
106 * results in immediate speed increase requests when any events result in
107 * a change to the target speed.
108 *
109 * It is recommend a value other than 0 is configured, but that inherently
110 * depends on the fan controller and configured speed increases.
111 *
112 * @return Speed increase delay(in seconds)
113 */
114 inline const auto& getIncDelay() const
115 {
116 return _incDelay;
117 }
118
119 /**
120 * @brief Get the speed decrease interval
121 *
122 * Speed decreases happen on a set interval when no requests for an increase
123 * in fan speeds exists. This is the interval(in seconds) at which the fans
124 * within the zone are decreased if events exist that result in a target
125 * speed decrease.
126 *
127 * @return Speed decrease interval(in seconds)
128 */
129 inline const auto& getDecInterval() const
130 {
131 return _decInterval;
132 }
133
Matthew Barth651f03a2020-08-27 16:15:11 -0500134 /**
Matthew Barth216229c2020-09-24 13:47:33 -0500135 * @brief Get the configuration of zone interface handlers
Matthew Barth651f03a2020-08-27 16:15:11 -0500136 *
137 * Interfaces hosted by a zone can optionally be configured to set their
138 * property values and/or persistency. These interfaces must be supported
139 * by the zone object they are configured for.
140 *
Matthew Barth216229c2020-09-24 13:47:33 -0500141 * @return List of zone interface handler functions that set an interface's
142 * property values and persistency states
Matthew Barth651f03a2020-08-27 16:15:11 -0500143 */
Matthew Barth216229c2020-09-24 13:47:33 -0500144 inline const auto& getZoneHandlers() const
Matthew Barth651f03a2020-08-27 16:15:11 -0500145 {
Matthew Barth216229c2020-09-24 13:47:33 -0500146 return _zoneHandlers;
Matthew Barth651f03a2020-08-27 16:15:11 -0500147 }
148
Matthew Barth4f0d3b72020-08-27 14:32:15 -0500149 private:
150 /* The zone's full speed value for fans */
151 uint64_t _fullSpeed;
152
153 /* The zone's default floor speed value for fans */
154 uint64_t _defaultFloor;
155
156 /* Zone's speed increase delay(in seconds) (OPTIONAL) */
157 uint64_t _incDelay;
158
159 /* Zone's speed decrease interval(in seconds) */
160 uint64_t _decInterval;
161
Matthew Barth216229c2020-09-24 13:47:33 -0500162 /**
163 * Zone interface handler functions for its
164 * configured interfaces (OPTIONAL)
165 */
166 std::vector<ZoneHandler> _zoneHandlers;
Matthew Barth651f03a2020-08-27 16:15:11 -0500167
Matthew Barth216229c2020-09-24 13:47:33 -0500168 /* Interface to property mapping of their associated handler function */
169 static const std::map<std::string, std::map<std::string, propHandler>>
170 _intfPropHandlers;
Matthew Barth651f03a2020-08-27 16:15:11 -0500171
Matthew Barth4f0d3b72020-08-27 14:32:15 -0500172 /**
173 * @brief Parse and set the zone's full speed value
174 *
175 * @param[in] jsonObj - JSON object for the zone
176 *
177 * Sets the full speed value for the zone from the JSON configuration object
178 */
179 void setFullSpeed(const json& jsonObj);
180
181 /**
182 * @brief Parse and set the zone's default floor speed value
183 *
184 * @param[in] jsonObj - JSON object for the zone
185 *
186 * Sets the default floor speed value for the zone from the JSON
187 * configuration object
188 */
189 void setDefaultFloor(const json& jsonObj);
190
191 /**
192 * @brief Parse and set the zone's decrease interval(in seconds)
193 *
194 * @param[in] jsonObj - JSON object for the zone
195 *
196 * Sets the speed decrease interval(in seconds) for the zone from the JSON
197 * configuration object
198 */
199 void setDecInterval(const json& jsonObj);
Matthew Barth651f03a2020-08-27 16:15:11 -0500200
201 /**
Matthew Barth216229c2020-09-24 13:47:33 -0500202 * @brief Parse and set the interfaces served by the zone(OPTIONAL)
Matthew Barth651f03a2020-08-27 16:15:11 -0500203 *
204 * @param[in] jsonObj - JSON object for the zone
205 *
Matthew Barth216229c2020-09-24 13:47:33 -0500206 * Constructs any zone interface handler functions for interfaces that the
207 * zone serves which contains the interface's property's value and
208 * persistency state (OPTIONAL). A property's "persist" state is defaulted
209 * to not be persisted when not given.
Matthew Barth651f03a2020-08-27 16:15:11 -0500210 */
211 void setInterfaces(const json& jsonObj);
Matthew Barth4f0d3b72020-08-27 14:32:15 -0500212};
213
Matthew Barth651f03a2020-08-27 16:15:11 -0500214/**
215 * Properties of interfaces supported by the zone configuration
216 */
217namespace zone::property
218{
219
220/**
Matthew Barth216229c2020-09-24 13:47:33 -0500221 * @brief "Supported" property on the "xyz.openbmc_project.Control.ThermalMode"
222 * interface
Matthew Barth651f03a2020-08-27 16:15:11 -0500223 *
224 * @param[in] jsonObj - JSON object for the "Supported" property
Matthew Barth216229c2020-09-24 13:47:33 -0500225 * @param[in] persist - Whether to persist the value or not
Matthew Barth651f03a2020-08-27 16:15:11 -0500226 *
Matthew Barth216229c2020-09-24 13:47:33 -0500227 * @return Zone interface handler function for the property
Matthew Barth651f03a2020-08-27 16:15:11 -0500228 */
Matthew Barth216229c2020-09-24 13:47:33 -0500229ZoneHandler supported(const json& jsonObj, bool persist);
Matthew Barth651f03a2020-08-27 16:15:11 -0500230
231/**
Matthew Barth216229c2020-09-24 13:47:33 -0500232 * @brief "Current" property on the "xyz.openbmc_project.Control.ThermalMode"
233 * interface
Matthew Barth651f03a2020-08-27 16:15:11 -0500234 *
235 * @param[in] jsonObj - JSON object for the "Current" property
Matthew Barth216229c2020-09-24 13:47:33 -0500236 * @param[in] persist - Whether to persist the value or not
Matthew Barth651f03a2020-08-27 16:15:11 -0500237 *
Matthew Barth216229c2020-09-24 13:47:33 -0500238 * @return Zone interface handler function for the property
Matthew Barth651f03a2020-08-27 16:15:11 -0500239 */
Matthew Barth216229c2020-09-24 13:47:33 -0500240ZoneHandler current(const json& jsonObj, bool persist);
Matthew Barth651f03a2020-08-27 16:15:11 -0500241
242} // namespace zone::property
243
Matthew Barth4f0d3b72020-08-27 14:32:15 -0500244} // namespace phosphor::fan::control::json