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