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 held at 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         // Update group's fan control active allowed based on action results
41         zone.setActiveAllow(&group, !(numAtState >= count));
42         if (numAtState >= count)
43         {
44             zone.setSpeed(speed);
45         }
46     };
47 }
48 
49 } // namespace action
50 } // namespace control
51 } // namespace fan
52 } // namespace phosphor
53