blob: 96da3231d33d904819fefe525f36d52f66e5360e [file] [log] [blame]
Matthew Barth17d1fe22017-05-11 15:00:36 -05001#pragma once
2
3#include <algorithm>
4
5namespace phosphor
6{
7namespace fan
8{
9namespace control
10{
11namespace action
12{
13
14/**
15 * @brief An action to set the speed on a zone
Matthew Barth861d77c2017-05-22 14:18:25 -050016 * @details The zone is held at the given speed when a defined number of
Matthew Barth17d1fe22017-05-11 15:00:36 -050017 * 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 */
27auto 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 });
Matthew Barth861d77c2017-05-22 14:18:25 -050040 // Update group's fan control active allowed based on action results
41 zone.setActiveAllow(&group, !(numAtState >= count));
Matthew Barth17d1fe22017-05-11 15:00:36 -050042 if (numAtState >= count)
43 {
44 zone.setSpeed(speed);
45 }
46 };
47}
48
49} // namespace action
50} // namespace control
51} // namespace fan
52} // namespace phosphor