Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <algorithm> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace fan |
| 8 | { |
| 9 | namespace control |
| 10 | { |
| 11 | namespace action |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @brief An action to set the speed on a zone |
| 16 | * @details The zone is set to the given speed when a defined number of |
| 17 | * properties in the group are set to the given state |
| 18 | * |
| 19 | * @param[in] count - Number of properties |
| 20 | * @param[in] state - Value the property(s) needed to be set at |
| 21 | * @param[in] speed - Speed to set the zone to |
| 22 | * |
| 23 | * @return Lambda function |
| 24 | * A lambda function to set the zone speed when the number of properties |
| 25 | * within the group are at a certain value |
| 26 | */ |
| 27 | auto count_state_before_speed(size_t count, bool state, uint64_t speed) |
| 28 | { |
| 29 | return [=](auto& zone, auto& group) |
| 30 | { |
| 31 | size_t numAtState = std::count_if( |
| 32 | group.begin(), |
| 33 | group.end(), |
| 34 | [&zone, &state](auto const& entry) |
| 35 | { |
| 36 | return zone.getPropertyValue( |
| 37 | entry.first, |
| 38 | std::get<propPos>(entry.second)) == state; |
| 39 | }); |
| 40 | if (numAtState >= count) |
| 41 | { |
| 42 | zone.setSpeed(speed); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | } // namespace action |
| 48 | } // namespace control |
| 49 | } // namespace fan |
| 50 | } // namespace phosphor |