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 |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 16 | * @details The zone is held at the given speed when a defined number of |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 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 | */ |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame^] | 27 | template <typename T> |
| 28 | auto count_state_before_speed(size_t count, T&& state, uint64_t speed) |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 29 | { |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame^] | 30 | return [count, |
| 31 | speed, |
| 32 | state = std::forward<T>(state)](auto& zone, auto& group) |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 33 | { |
| 34 | size_t numAtState = std::count_if( |
| 35 | group.begin(), |
| 36 | group.end(), |
| 37 | [&zone, &state](auto const& entry) |
| 38 | { |
Matthew Barth | 9e741ed | 2017-06-02 16:29:09 -0500 | [diff] [blame^] | 39 | return zone.template getPropertyValue<T>( |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 40 | entry.first, |
Matthew Barth | cec5ab7 | 2017-06-02 15:20:56 -0500 | [diff] [blame] | 41 | std::get<intfPos>(entry.second), |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 42 | std::get<propPos>(entry.second)) == state; |
| 43 | }); |
Matthew Barth | 861d77c | 2017-05-22 14:18:25 -0500 | [diff] [blame] | 44 | // Update group's fan control active allowed based on action results |
| 45 | zone.setActiveAllow(&group, !(numAtState >= count)); |
Matthew Barth | 17d1fe2 | 2017-05-11 15:00:36 -0500 | [diff] [blame] | 46 | if (numAtState >= count) |
| 47 | { |
| 48 | zone.setSpeed(speed); |
| 49 | } |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | } // namespace action |
| 54 | } // namespace control |
| 55 | } // namespace fan |
| 56 | } // namespace phosphor |