blob: 97f4f34816a3963968e7e304a118414939c4485e [file] [log] [blame]
Matthew Barthb280bfa2017-09-15 09:56:50 -05001#include "actions.hpp"
2
3namespace phosphor
4{
5namespace fan
6{
7namespace control
8{
9namespace action
10{
11
12using namespace phosphor::fan;
13
William A. Kennington III122b8432018-10-30 18:39:21 -070014Action call_actions_based_on_timer(TimerConf&& tConf,
15 std::vector<Action>&& actions)
Matthew Barth2a646c52017-10-05 17:04:11 -050016{
17 return [tConf = std::move(tConf),
18 actions = std::move(actions)](control::Zone& zone,
19 const Group& group)
20 {
21 try
22 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060023 auto it = zone.getTimerEvents().find(__func__);
24 if (it != zone.getTimerEvents().end())
Matthew Barth2a646c52017-10-05 17:04:11 -050025 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060026 auto& timers = it->second;
27 auto timerIter = zone.findTimer(group, actions, timers);
Matthew Barthe7d53892018-12-12 10:59:57 -060028 if (timerIter == timers.end())
Matthew Barth2a646c52017-10-05 17:04:11 -050029 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060030 // No timer exists yet for action, add timer
31 zone.addTimer(__func__, group, actions, tConf);
Matthew Barth2a646c52017-10-05 17:04:11 -050032 }
Matthew Barthe7d53892018-12-12 10:59:57 -060033 else if (timerIter != timers.end())
Matthew Barthd7b716a2018-11-16 13:37:57 -060034 {
35 // Remove any timer for this group
36 timers.erase(timerIter);
37 if (timers.empty())
38 {
39 zone.getTimerEvents().erase(it);
40 }
41 }
42 }
Matthew Barthe7d53892018-12-12 10:59:57 -060043 else
Matthew Barthd7b716a2018-11-16 13:37:57 -060044 {
45 // No timer exists yet for event, add timer
46 zone.addTimer(__func__, group, actions, tConf);
Matthew Barth2a646c52017-10-05 17:04:11 -050047 }
48 }
49 catch (const std::out_of_range& oore)
50 {
51 // Group not found, no timers set
52 }
53 };
54}
55
Matthew Barth98726c42017-10-17 10:35:20 -050056void default_floor_on_missing_owner(Zone& zone, const Group& group)
57{
Matthew Barth480787c2017-11-06 11:00:00 -060058 // Set/update the services of the group
59 zone.setServices(&group);
Matthew Barth98726c42017-10-17 10:35:20 -050060 auto services = zone.getGroupServices(&group);
61 auto defFloor = std::any_of(
62 services.begin(),
63 services.end(),
64 [](const auto& s)
65 {
66 return !std::get<hasOwnerPos>(s);
67 });
68 if (defFloor)
69 {
70 zone.setFloor(zone.getDefFloor());
71 }
72 // Update fan control floor change allowed
73 zone.setFloorChangeAllow(&group, !defFloor);
74}
75
Matthew Barth0decd1b2017-10-24 15:58:17 -050076Action set_speed_on_missing_owner(uint64_t speed)
77{
78 return [speed](control::Zone& zone, const Group& group)
79 {
Matthew Barth480787c2017-11-06 11:00:00 -060080 // Set/update the services of the group
81 zone.setServices(&group);
Matthew Barth0decd1b2017-10-24 15:58:17 -050082 auto services = zone.getGroupServices(&group);
83 auto missingOwner = std::any_of(
84 services.begin(),
85 services.end(),
86 [](const auto& s)
87 {
88 return !std::get<hasOwnerPos>(s);
89 });
90 if (missingOwner)
91 {
92 zone.setSpeed(speed);
93 }
94 // Update group's fan control active allowed based on action results
95 zone.setActiveAllow(&group, !missingOwner);
96 };
97}
98
Matthew Barthb280bfa2017-09-15 09:56:50 -050099void set_request_speed_base_with_max(control::Zone& zone,
100 const Group& group)
101{
102 int64_t base = 0;
103 std::for_each(
104 group.begin(),
105 group.end(),
106 [&zone, &base](auto const& entry)
107 {
108 try
109 {
110 auto value = zone.template getPropertyValue<int64_t>(
Matthew Barth146b7392018-03-08 16:17:58 -0600111 std::get<pathPos>(entry),
112 std::get<intfPos>(entry),
113 std::get<propPos>(entry));
Matthew Barthb280bfa2017-09-15 09:56:50 -0500114 base = std::max(base, value);
115 }
116 catch (const std::out_of_range& oore)
117 {
118 // Property value not found, base request speed unchanged
119 }
120 });
121 // A request speed base of 0 defaults to the current target speed
122 zone.setRequestSpeedBase(base);
123}
124
Matthew Barthb280bfa2017-09-15 09:56:50 -0500125} // namespace action
126} // namespace control
127} // namespace fan
128} // namespace phosphor