blob: 8a2675b3caa4931f8f587946ef9262c360bc172d [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 */
Matthew Barth9e741ed2017-06-02 16:29:09 -050027template <typename T>
28auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
Matthew Barth17d1fe22017-05-11 15:00:36 -050029{
Matthew Barth9e741ed2017-06-02 16:29:09 -050030 return [count,
31 speed,
32 state = std::forward<T>(state)](auto& zone, auto& group)
Matthew Barth17d1fe22017-05-11 15:00:36 -050033 {
34 size_t numAtState = std::count_if(
35 group.begin(),
36 group.end(),
37 [&zone, &state](auto const& entry)
38 {
Matthew Barth9e741ed2017-06-02 16:29:09 -050039 return zone.template getPropertyValue<T>(
Matthew Barth17d1fe22017-05-11 15:00:36 -050040 entry.first,
Matthew Barthcec5ab72017-06-02 15:20:56 -050041 std::get<intfPos>(entry.second),
Matthew Barth17d1fe22017-05-11 15:00:36 -050042 std::get<propPos>(entry.second)) == state;
43 });
Matthew Barth861d77c2017-05-22 14:18:25 -050044 // Update group's fan control active allowed based on action results
45 zone.setActiveAllow(&group, !(numAtState >= count));
Matthew Barth17d1fe22017-05-11 15:00:36 -050046 if (numAtState >= count)
47 {
48 zone.setSpeed(speed);
49 }
50 };
51}
52
53} // namespace action
54} // namespace control
55} // namespace fan
56} // namespace phosphor