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