Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 1 | #pragma once |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 2 | #include <chrono> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 3 | #include <vector> |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 4 | #include <cassert> |
Matthew Barth | e0ca13e | 2017-06-13 16:29:09 -0500 | [diff] [blame] | 5 | #include <algorithm> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 7 | #include <sdeventplus/event.hpp> |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 8 | #include "fan.hpp" |
| 9 | #include "types.hpp" |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 10 | #include "timer.hpp" |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace fan |
| 15 | { |
| 16 | namespace control |
| 17 | { |
| 18 | |
| 19 | /** |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 20 | * The mode fan control will run in: |
| 21 | * - init - only do the initialization steps |
| 22 | * - control - run normal control algorithms |
| 23 | */ |
| 24 | enum class Mode |
| 25 | { |
| 26 | init, |
| 27 | control |
| 28 | }; |
| 29 | |
| 30 | /** |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 31 | * @class Represents a fan control zone, which is a group of fans |
| 32 | * that behave the same. |
| 33 | */ |
| 34 | class Zone |
| 35 | { |
| 36 | public: |
| 37 | |
| 38 | Zone() = delete; |
| 39 | Zone(const Zone&) = delete; |
Matthew Barth | 0081fdb | 2017-11-14 14:02:34 -0600 | [diff] [blame] | 40 | Zone(Zone&&) = delete; |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 41 | Zone& operator=(const Zone&) = delete; |
| 42 | Zone& operator=(Zone&&) = delete; |
| 43 | ~Zone() = default; |
| 44 | |
| 45 | /** |
| 46 | * Constructor |
| 47 | * Creates the appropriate fan objects based on |
| 48 | * the zone definition data passed in. |
| 49 | * |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 50 | * @param[in] mode - mode of fan control |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 51 | * @param[in] bus - the dbus object |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 52 | * @param[in] event - Event loop reference |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 53 | * @param[in] def - the fan zone definition data |
| 54 | */ |
Matthew Barth | 1418413 | 2017-05-19 14:37:30 -0500 | [diff] [blame] | 55 | Zone(Mode mode, |
| 56 | sdbusplus::bus::bus& bus, |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 57 | const sdeventplus::Event& event, |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 58 | const ZoneDefinition& def); |
| 59 | |
| 60 | /** |
| 61 | * Sets all fans in the zone to the speed |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 62 | * passed in when the zone is active |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 63 | * |
| 64 | * @param[in] speed - the fan speed |
| 65 | */ |
| 66 | void setSpeed(uint64_t speed); |
| 67 | |
| 68 | /** |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 69 | * Sets the zone to full speed regardless of zone's active state |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 70 | */ |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 71 | void setFullSpeed(); |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 72 | |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 73 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 74 | * @brief Sets the automatic fan control allowed active state |
| 75 | * |
| 76 | * @param[in] group - A group that affects the active state |
| 77 | * @param[in] isActiveAllow - Active state according to group |
| 78 | */ |
| 79 | void setActiveAllow(const Group* group, bool isActiveAllow); |
| 80 | |
| 81 | /** |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 82 | * @brief Sets the floor change allowed state |
| 83 | * |
| 84 | * @param[in] group - A group that affects floor changes |
| 85 | * @param[in] isAllow - Allow state according to group |
| 86 | */ |
| 87 | inline void setFloorChangeAllow(const Group* group, bool isAllow) |
| 88 | { |
| 89 | _floorChange[*(group)] = isAllow; |
| 90 | } |
| 91 | |
| 92 | /** |
Matthew Barth | e4338cd | 2017-12-14 11:14:30 -0600 | [diff] [blame] | 93 | * @brief Sets the decrease allowed state of a group |
| 94 | * |
| 95 | * @param[in] group - A group that affects speed decreases |
| 96 | * @param[in] isAllow - Allow state according to group |
| 97 | */ |
| 98 | inline void setDecreaseAllow(const Group* group, bool isAllow) |
| 99 | { |
| 100 | _decAllowed[*(group)] = isAllow; |
| 101 | } |
| 102 | |
| 103 | /** |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 104 | * @brief Sets a given object's property value |
| 105 | * |
| 106 | * @param[in] object - Name of the object containing the property |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 107 | * @param[in] interface - Interface name containing the property |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 108 | * @param[in] property - Property name |
| 109 | * @param[in] value - Property value |
| 110 | */ |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 111 | template <typename T> |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 112 | void setPropertyValue(const char* object, |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 113 | const char* interface, |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 114 | const char* property, |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 115 | T value) |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 116 | { |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 117 | _properties[object][interface][property] = value; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 118 | }; |
| 119 | |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 120 | /** |
| 121 | * @brief Get the value of an object's property |
| 122 | * |
| 123 | * @param[in] object - Name of the object containing the property |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 124 | * @param[in] interface - Interface name containing the property |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 125 | * @param[in] property - Property name |
| 126 | * |
| 127 | * @return - The property value |
| 128 | */ |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 129 | template <typename T> |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 130 | inline auto getPropertyValue(const std::string& object, |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 131 | const std::string& interface, |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 132 | const std::string& property) |
| 133 | { |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 134 | return sdbusplus::message::variant_ns::get<T>( |
Matthew Barth | bc65160 | 2017-08-10 16:59:43 -0500 | [diff] [blame] | 135 | _properties.at(object).at(interface).at(property)); |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 136 | }; |
| 137 | |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 138 | /** |
Matthew Barth | 604329e | 2017-08-04 11:18:28 -0500 | [diff] [blame] | 139 | * @brief Get the object's property variant |
| 140 | * |
| 141 | * @param[in] object - Name of the object containing the property |
| 142 | * @param[in] interface - Interface name containing the property |
| 143 | * @param[in] property - Property name |
| 144 | * |
| 145 | * @return - The property variant |
| 146 | */ |
| 147 | inline auto getPropValueVariant(const std::string& object, |
| 148 | const std::string& interface, |
| 149 | const std::string& property) |
| 150 | { |
| 151 | return _properties.at(object).at(interface).at(property); |
| 152 | }; |
| 153 | |
| 154 | /** |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 155 | * @brief Remove an object's interface |
| 156 | * |
| 157 | * @param[in] object - Name of the object with the interface |
| 158 | * @param[in] interface - Interface name to remove |
| 159 | */ |
Matthew Barth | 30abbef | 2018-04-12 09:40:54 -0500 | [diff] [blame] | 160 | inline void removeObjectInterface(const char* object, |
| 161 | const char* interface) |
Matthew Barth | 1499a5c | 2018-03-20 15:52:33 -0500 | [diff] [blame] | 162 | { |
| 163 | auto it = _properties.find(object); |
| 164 | if (it != std::end(_properties)) |
| 165 | { |
| 166 | _properties[object].erase(interface); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | /** |
Matthew Barth | 55dea64 | 2017-11-06 13:34:32 -0600 | [diff] [blame] | 171 | * @brief Remove a service associated to a group |
| 172 | * |
| 173 | * @param[in] group - Group associated with service |
| 174 | * @param[in] name - Service name to remove |
| 175 | */ |
| 176 | void removeService(const Group* group, |
| 177 | const std::string& name); |
| 178 | |
| 179 | /** |
Matthew Barth | e59fdf7 | 2017-09-27 09:33:42 -0500 | [diff] [blame] | 180 | * @brief Set or update a service name owner in use |
| 181 | * |
| 182 | * @param[in] group - Group associated with service |
| 183 | * @param[in] name - Service name |
| 184 | * @param[in] hasOwner - Whether the service is owned or not |
| 185 | */ |
| 186 | void setServiceOwner(const Group* group, |
| 187 | const std::string& name, |
| 188 | const bool hasOwner); |
| 189 | |
| 190 | /** |
Matthew Barth | 480787c | 2017-11-06 11:00:00 -0600 | [diff] [blame] | 191 | * @brief Set or update all services for a group |
| 192 | * |
| 193 | * @param[in] group - Group to get service names for |
| 194 | */ |
| 195 | void setServices(const Group* group); |
| 196 | |
| 197 | /** |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 198 | * @brief Get the group's list of service names |
| 199 | * |
| 200 | * @param[in] group - Group to get service names for |
| 201 | * |
| 202 | * @return - The list of service names |
| 203 | */ |
| 204 | inline auto getGroupServices(const Group* group) |
| 205 | { |
| 206 | return _services.at(*group); |
| 207 | } |
| 208 | |
| 209 | /** |
Matthew Barth | 604329e | 2017-08-04 11:18:28 -0500 | [diff] [blame] | 210 | * @brief Initialize a set speed event properties and actions |
| 211 | * |
| 212 | * @param[in] event - Set speed event |
| 213 | */ |
| 214 | void initEvent(const SetSpeedEvent& event); |
| 215 | |
| 216 | /** |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 217 | * @brief Removes all the set speed event properties and actions |
| 218 | * |
| 219 | * @param[in] event - Set speed event |
| 220 | */ |
| 221 | void removeEvent(const SetSpeedEvent& event); |
| 222 | |
| 223 | /** |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 224 | * @brief Get the default floor speed |
| 225 | * |
| 226 | * @return - The defined default floor speed |
| 227 | */ |
| 228 | inline auto getDefFloor() |
| 229 | { |
| 230 | return _defFloorSpeed; |
| 231 | }; |
| 232 | |
Matthew Barth | 4af419c | 2017-06-12 13:39:31 -0500 | [diff] [blame] | 233 | /** |
Matthew Barth | e0ca13e | 2017-06-13 16:29:09 -0500 | [diff] [blame] | 234 | * @brief Get the ceiling speed |
| 235 | * |
| 236 | * @return - The current ceiling speed |
| 237 | */ |
| 238 | inline auto& getCeiling() const |
| 239 | { |
| 240 | return _ceilingSpeed; |
| 241 | }; |
| 242 | |
| 243 | /** |
| 244 | * @brief Set the ceiling speed to the given speed |
| 245 | * |
| 246 | * @param[in] speed - Speed to set the ceiling to |
| 247 | */ |
| 248 | inline void setCeiling(uint64_t speed) |
| 249 | { |
| 250 | _ceilingSpeed = speed; |
| 251 | }; |
| 252 | |
| 253 | /** |
| 254 | * @brief Swaps the ceiling key value with what's given and |
| 255 | * returns the value that was swapped. |
| 256 | * |
| 257 | * @param[in] keyValue - New ceiling key value |
| 258 | * |
| 259 | * @return - Ceiling key value prior to swapping |
| 260 | */ |
| 261 | inline auto swapCeilingKeyValue(int64_t keyValue) |
| 262 | { |
| 263 | std::swap(_ceilingKeyValue, keyValue); |
| 264 | return keyValue; |
| 265 | }; |
| 266 | |
Matthew Barth | 2462352 | 2017-06-21 14:09:57 -0500 | [diff] [blame] | 267 | /** |
| 268 | * @brief Get the increase speed delta |
| 269 | * |
| 270 | * @return - The current increase speed delta |
| 271 | */ |
| 272 | inline auto& getIncSpeedDelta() const |
| 273 | { |
| 274 | return _incSpeedDelta; |
| 275 | }; |
| 276 | |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 277 | /** |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 278 | * @brief Get the decrease speed delta |
| 279 | * |
| 280 | * @return - The current decrease speed delta |
| 281 | */ |
| 282 | inline auto& getDecSpeedDelta() const |
| 283 | { |
| 284 | return _decSpeedDelta; |
| 285 | }; |
| 286 | |
| 287 | /** |
Matthew Barth | b4a7cb9 | 2017-06-28 15:29:50 -0500 | [diff] [blame] | 288 | * @brief Set the floor speed to the given speed and increase target |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 289 | * speed to the floor when target is below floor where floor changes |
| 290 | * are allowed. |
Matthew Barth | b4a7cb9 | 2017-06-28 15:29:50 -0500 | [diff] [blame] | 291 | * |
| 292 | * @param[in] speed - Speed to set the floor to |
| 293 | */ |
| 294 | void setFloor(uint64_t speed); |
| 295 | |
| 296 | /** |
Matthew Barth | 1bfdc42 | 2017-09-14 16:23:28 -0500 | [diff] [blame] | 297 | * @brief Set the requested speed base to be used as the speed to |
| 298 | * base a new requested speed target from |
| 299 | * |
| 300 | * @param[in] speedBase - Base speed value to use |
| 301 | */ |
| 302 | inline void setRequestSpeedBase(uint64_t speedBase) |
| 303 | { |
| 304 | _requestSpeedBase = speedBase; |
| 305 | }; |
| 306 | |
| 307 | /** |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 308 | * @brief Calculate the requested target speed from the given delta |
| 309 | * and increase the fan speeds, not going above the ceiling. |
| 310 | * |
| 311 | * @param[in] targetDelta - The delta to increase the target speed by |
| 312 | */ |
| 313 | void requestSpeedIncrease(uint64_t targetDelta); |
| 314 | |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 315 | /** |
| 316 | * @brief Calculate the requested target speed from the given delta |
| 317 | * and increase the fan speeds, not going above the ceiling. |
| 318 | * |
| 319 | * @param[in] targetDelta - The delta to increase the target speed by |
| 320 | */ |
| 321 | void requestSpeedDecrease(uint64_t targetDelta); |
| 322 | |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 323 | /** |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 324 | * @brief Callback function for the increase timer that delays |
| 325 | * processing of requested speed increases while fans are increasing |
| 326 | */ |
| 327 | void incTimerExpired(); |
| 328 | |
| 329 | /** |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 330 | * @brief Callback function for the decrease timer that processes any |
| 331 | * requested speed decreases if allowed |
| 332 | */ |
| 333 | void decTimerExpired(); |
| 334 | |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 335 | /** |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 336 | * @brief Get the event loop used with this zone's timers |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 337 | * |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 338 | * @return - The event loop for timers |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 339 | */ |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 340 | inline auto& getEventLoop() |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 341 | { |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 342 | return _eventLoop; |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /** |
| 346 | * @brief Get the list of timer events |
| 347 | * |
| 348 | * @return - List of timer events |
| 349 | */ |
| 350 | inline auto& getTimerEvents() |
| 351 | { |
| 352 | return _timerEvents; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * @brief Find the first instance of a timer event |
| 357 | * |
| 358 | * @param[in] eventGroup - Group associated with a timer |
| 359 | * @param[in] eventActions - List of actions associated with a timer |
| 360 | * |
| 361 | * @return - Iterator to the timer event |
| 362 | */ |
| 363 | std::vector<TimerEvent>::iterator findTimer( |
| 364 | const Group& eventGroup, |
| 365 | const std::vector<Action>& eventActions); |
| 366 | |
| 367 | /** |
| 368 | * @brief Add a timer to the list of timer based events |
| 369 | * |
William A. Kennington III | 94fe1a0 | 2018-10-30 19:00:27 -0700 | [diff] [blame] | 370 | * @param[in] group - Group associated with a timer |
| 371 | * @param[in] actions - List of actions associated with a timer |
| 372 | * @param[in] tConf - Configuration for the new timer |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 373 | */ |
William A. Kennington III | 94fe1a0 | 2018-10-30 19:00:27 -0700 | [diff] [blame] | 374 | void addTimer(const Group& group, |
| 375 | const std::vector<Action>& actions, |
| 376 | const TimerConf& tConf); |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * @brief Remove the given timer event |
| 380 | * |
| 381 | * @param[in] teIter - Iterator pointing to the timer event to remove |
| 382 | */ |
| 383 | inline void removeTimer(std::vector<TimerEvent>::iterator& teIter) |
| 384 | { |
| 385 | assert(teIter != std::end(_timerEvents)); |
| 386 | std::get<timerEventDataPos>(*teIter).reset(); |
| 387 | std::get<timerTimerPos>(*teIter).reset(); |
| 388 | _timerEvents.erase(teIter); |
| 389 | } |
| 390 | |
| 391 | /** |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 392 | * @brief Callback function for event timers that processes the given |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 393 | * actions for a group |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 394 | * |
Matthew Barth | f9201ab | 2017-09-11 16:07:58 -0500 | [diff] [blame] | 395 | * @param[in] eventGroup - Group to process actions on |
| 396 | * @param[in] eventActions - List of event actions to run |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 397 | */ |
William A. Kennington III | c0c5f07 | 2018-10-30 19:11:01 -0700 | [diff] [blame] | 398 | void timerExpired(const Group& eventGroup, |
| 399 | const std::vector<Action>& eventActions); |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 400 | |
Matthew Barth | a603ed0 | 2018-01-19 16:56:26 -0600 | [diff] [blame] | 401 | /** |
| 402 | * @brief Get the service for a given path and interface from cached |
| 403 | * dataset and add a service that's not found |
| 404 | * |
| 405 | * @param[in] path - Path to get service for |
| 406 | * @param[in] intf - Interface to get service for |
| 407 | * |
| 408 | * @return - The service name |
| 409 | */ |
| 410 | const std::string& getService(const std::string& path, |
| 411 | const std::string& intf); |
| 412 | |
| 413 | /** |
| 414 | * @brief Add a set of services for a path and interface |
| 415 | * by retrieving all the path subtrees to the given depth |
| 416 | * from root for the interface |
| 417 | * |
| 418 | * @param[in] path - Path to add services for |
| 419 | * @param[in] intf - Interface to add services for |
| 420 | * @param[in] depth - Depth of tree traversal from root path |
| 421 | * |
| 422 | * @return - The associated service to the given path and interface |
| 423 | * or empty string for no service found |
| 424 | */ |
| 425 | const std::string& addServices(const std::string& path, |
| 426 | const std::string& intf, |
| 427 | int32_t depth); |
| 428 | |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 429 | private: |
| 430 | |
| 431 | /** |
| 432 | * The dbus object |
| 433 | */ |
| 434 | sdbusplus::bus::bus& _bus; |
| 435 | |
| 436 | /** |
| 437 | * Full speed for the zone |
| 438 | */ |
| 439 | const uint64_t _fullSpeed; |
| 440 | |
| 441 | /** |
| 442 | * The zone number |
| 443 | */ |
| 444 | const size_t _zoneNum; |
| 445 | |
| 446 | /** |
Matthew Barth | 1de6662 | 2017-06-12 13:13:02 -0500 | [diff] [blame] | 447 | * The default floor speed for the zone |
| 448 | */ |
| 449 | const uint64_t _defFloorSpeed; |
| 450 | |
| 451 | /** |
Matthew Barth | e0ca13e | 2017-06-13 16:29:09 -0500 | [diff] [blame] | 452 | * The default ceiling speed for the zone |
| 453 | */ |
| 454 | const uint64_t _defCeilingSpeed; |
| 455 | |
| 456 | /** |
Matthew Barth | 4af419c | 2017-06-12 13:39:31 -0500 | [diff] [blame] | 457 | * The floor speed to not go below |
| 458 | */ |
| 459 | uint64_t _floorSpeed = _defFloorSpeed; |
| 460 | |
| 461 | /** |
Matthew Barth | e0ca13e | 2017-06-13 16:29:09 -0500 | [diff] [blame] | 462 | * The ceiling speed to not go above |
| 463 | */ |
| 464 | uint64_t _ceilingSpeed = _defCeilingSpeed; |
| 465 | |
| 466 | /** |
| 467 | * The previous sensor value for calculating the ceiling |
| 468 | */ |
| 469 | int64_t _ceilingKeyValue = 0; |
| 470 | |
| 471 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 472 | * Automatic fan control active state |
| 473 | */ |
| 474 | bool _isActive = true; |
| 475 | |
| 476 | /** |
Matthew Barth | 240397b | 2017-06-22 11:23:30 -0500 | [diff] [blame] | 477 | * Target speed for this zone |
| 478 | */ |
| 479 | uint64_t _targetSpeed = _fullSpeed; |
| 480 | |
| 481 | /** |
Matthew Barth | 2462352 | 2017-06-21 14:09:57 -0500 | [diff] [blame] | 482 | * Speed increase delta |
| 483 | */ |
| 484 | uint64_t _incSpeedDelta = 0; |
| 485 | |
| 486 | /** |
Matthew Barth | 0ce99d8 | 2017-06-22 15:07:29 -0500 | [diff] [blame] | 487 | * Speed decrease delta |
| 488 | */ |
| 489 | uint64_t _decSpeedDelta = 0; |
| 490 | |
| 491 | /** |
Matthew Barth | 1bfdc42 | 2017-09-14 16:23:28 -0500 | [diff] [blame] | 492 | * Requested speed base |
| 493 | */ |
| 494 | uint64_t _requestSpeedBase = 0; |
| 495 | |
| 496 | /** |
Matthew Barth | a956184 | 2017-06-29 11:43:45 -0500 | [diff] [blame] | 497 | * Speed increase delay in seconds |
| 498 | */ |
| 499 | std::chrono::seconds _incDelay; |
| 500 | |
| 501 | /** |
| 502 | * Speed decrease interval in seconds |
| 503 | */ |
| 504 | std::chrono::seconds _decInterval; |
| 505 | |
| 506 | /** |
Matthew Barth | 1ee48f2 | 2017-06-27 15:14:48 -0500 | [diff] [blame] | 507 | * The increase timer object |
| 508 | */ |
| 509 | phosphor::fan::util::Timer _incTimer; |
| 510 | |
| 511 | /** |
Matthew Barth | 8600d9a | 2017-06-23 14:38:05 -0500 | [diff] [blame] | 512 | * The decrease timer object |
| 513 | */ |
| 514 | phosphor::fan::util::Timer _decTimer; |
| 515 | |
| 516 | /** |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 517 | * Event loop used on set speed event timers |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 518 | */ |
William A. Kennington III | 1cfc2f1 | 2018-10-19 17:29:46 -0700 | [diff] [blame] | 519 | sdeventplus::Event _eventLoop; |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 520 | |
| 521 | /** |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 522 | * The vector of fans in this zone |
| 523 | */ |
| 524 | std::vector<std::unique_ptr<Fan>> _fans; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 525 | |
| 526 | /** |
| 527 | * @brief Map of object property values |
| 528 | */ |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 529 | std::map<std::string, |
| 530 | std::map<std::string, |
| 531 | std::map<std::string, |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame] | 532 | PropertyVariantType>>> _properties; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 533 | |
| 534 | /** |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 535 | * @brief Map of active fan control allowed by groups |
| 536 | */ |
Matthew Barth | 60b0076 | 2017-08-15 13:39:06 -0500 | [diff] [blame] | 537 | std::map<const Group, bool> _active; |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 538 | |
| 539 | /** |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 540 | * @brief Map of floor change allowed by groups |
| 541 | */ |
| 542 | std::map<const Group, bool> _floorChange; |
| 543 | |
| 544 | /** |
Matthew Barth | e4338cd | 2017-12-14 11:14:30 -0600 | [diff] [blame] | 545 | * @brief Map of groups controlling decreases allowed |
| 546 | */ |
| 547 | std::map<const Group, bool> _decAllowed; |
| 548 | |
| 549 | /** |
Matthew Barth | e59fdf7 | 2017-09-27 09:33:42 -0500 | [diff] [blame] | 550 | * @brief Map of group service names |
| 551 | */ |
| 552 | std::map<const Group, std::vector<Service>> _services; |
| 553 | |
| 554 | /** |
Matthew Barth | a603ed0 | 2018-01-19 16:56:26 -0600 | [diff] [blame] | 555 | * @brief Map tree of paths to services of interfaces |
| 556 | */ |
| 557 | std::map<std::string, |
| 558 | std::map<std::string, |
| 559 | std::vector<std::string>>> _servTree; |
| 560 | |
| 561 | /** |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 562 | * @brief List of signal event arguments and Dbus matches for callbacks |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 563 | */ |
Matthew Barth | f6b76d8 | 2017-08-04 12:58:02 -0500 | [diff] [blame] | 564 | std::vector<SignalEvent> _signalEvents; |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 565 | |
| 566 | /** |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 567 | * @brief List of timers for events |
| 568 | */ |
Matthew Barth | bfb1a56 | 2017-10-05 17:03:40 -0500 | [diff] [blame] | 569 | std::vector<TimerEvent> _timerEvents; |
Matthew Barth | 9014980 | 2017-08-15 10:51:37 -0500 | [diff] [blame] | 570 | |
| 571 | /** |
Matthew Barth | 4e72854 | 2017-09-14 16:47:55 -0500 | [diff] [blame] | 572 | * @brief Get the request speed base if defined, otherwise the |
| 573 | * the current target speed is returned |
| 574 | * |
| 575 | * @return - The request speed base or current target speed |
| 576 | */ |
| 577 | inline auto getRequestSpeedBase() const |
| 578 | { |
| 579 | return (_requestSpeedBase != 0) ? _requestSpeedBase : _targetSpeed; |
| 580 | }; |
| 581 | |
| 582 | /** |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 583 | * @brief Dbus signal change callback handler |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 584 | * |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 585 | * @param[in] msg - Expanded sdbusplus message data |
| 586 | * @param[in] eventData - The single event's data |
Matthew Barth | 38a93a8 | 2017-05-11 14:12:27 -0500 | [diff] [blame] | 587 | */ |
Matthew Barth | 34f1bda | 2017-05-31 13:45:36 -0500 | [diff] [blame] | 588 | void handleEvent(sdbusplus::message::message& msg, |
| 589 | const EventData* eventData); |
Matt Spinler | 7f88fe6 | 2017-04-10 14:39:02 -0500 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | } |
| 593 | } |
| 594 | } |