blob: 1a40ce8d3553a2c68100a6fb9774bf0ad8bf8215 [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{
Matthew Barth3e1bb272020-05-26 11:09:21 -050017 return [tConf = std::move(tConf), actions = std::move(actions)](
18 control::Zone& zone, const Group& group) {
Matthew Barth2a646c52017-10-05 17:04:11 -050019 try
20 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060021 auto it = zone.getTimerEvents().find(__func__);
22 if (it != zone.getTimerEvents().end())
Matthew Barth2a646c52017-10-05 17:04:11 -050023 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060024 auto& timers = it->second;
25 auto timerIter = zone.findTimer(group, actions, timers);
Matthew Barthe7d53892018-12-12 10:59:57 -060026 if (timerIter == timers.end())
Matthew Barth2a646c52017-10-05 17:04:11 -050027 {
Matthew Barthd7b716a2018-11-16 13:37:57 -060028 // No timer exists yet for action, add timer
29 zone.addTimer(__func__, group, actions, tConf);
Matthew Barth2a646c52017-10-05 17:04:11 -050030 }
Matthew Barthe7d53892018-12-12 10:59:57 -060031 else if (timerIter != timers.end())
Matthew Barthd7b716a2018-11-16 13:37:57 -060032 {
33 // Remove any timer for this group
34 timers.erase(timerIter);
35 if (timers.empty())
36 {
37 zone.getTimerEvents().erase(it);
38 }
39 }
40 }
Matthew Barthe7d53892018-12-12 10:59:57 -060041 else
Matthew Barthd7b716a2018-11-16 13:37:57 -060042 {
43 // No timer exists yet for event, add timer
44 zone.addTimer(__func__, group, actions, tConf);
Matthew Barth2a646c52017-10-05 17:04:11 -050045 }
46 }
47 catch (const std::out_of_range& oore)
48 {
49 // Group not found, no timers set
50 }
51 };
52}
53
Matthew Barth98726c42017-10-17 10:35:20 -050054void default_floor_on_missing_owner(Zone& zone, const Group& group)
55{
Matthew Barth480787c2017-11-06 11:00:00 -060056 // Set/update the services of the group
57 zone.setServices(&group);
Matthew Barth98726c42017-10-17 10:35:20 -050058 auto services = zone.getGroupServices(&group);
Matthew Barth3e1bb272020-05-26 11:09:21 -050059 auto defFloor =
60 std::any_of(services.begin(), services.end(),
61 [](const auto& s) { return !std::get<hasOwnerPos>(s); });
Matthew Barth98726c42017-10-17 10:35:20 -050062 if (defFloor)
63 {
64 zone.setFloor(zone.getDefFloor());
65 }
66 // Update fan control floor change allowed
67 zone.setFloorChangeAllow(&group, !defFloor);
68}
69
Matthew Barth0decd1b2017-10-24 15:58:17 -050070Action set_speed_on_missing_owner(uint64_t speed)
71{
Matthew Barth3e1bb272020-05-26 11:09:21 -050072 return [speed](control::Zone& zone, const Group& group) {
Matthew Barth480787c2017-11-06 11:00:00 -060073 // Set/update the services of the group
74 zone.setServices(&group);
Matthew Barth0decd1b2017-10-24 15:58:17 -050075 auto services = zone.getGroupServices(&group);
Patrick Williamsdfddd642024-08-16 15:21:51 -040076 auto missingOwner =
77 std::any_of(services.begin(), services.end(), [](const auto& s) {
78 return !std::get<hasOwnerPos>(s);
79 });
Matthew Barth0decd1b2017-10-24 15:58:17 -050080 if (missingOwner)
81 {
82 zone.setSpeed(speed);
83 }
84 // Update group's fan control active allowed based on action results
85 zone.setActiveAllow(&group, !missingOwner);
86 };
87}
88
Matthew Barth3e1bb272020-05-26 11:09:21 -050089void set_request_speed_base_with_max(control::Zone& zone, const Group& group)
Matthew Barthb280bfa2017-09-15 09:56:50 -050090{
91 int64_t base = 0;
Patrick Williamsdfddd642024-08-16 15:21:51 -040092 std::for_each(
93 group.begin(), group.end(), [&zone, &base](const auto& entry) {
94 try
95 {
96 auto value = zone.template getPropertyValue<int64_t>(
97 std::get<pathPos>(entry), std::get<intfPos>(entry),
98 std::get<propPos>(entry));
99 base = std::max(base, value);
100 }
101 catch (const std::out_of_range& oore)
102 {
103 // Property value not found, base request speed unchanged
104 }
105 });
Matthew Barthb280bfa2017-09-15 09:56:50 -0500106 // A request speed base of 0 defaults to the current target speed
107 zone.setRequestSpeedBase(base);
108}
109
Matthew Barthb280bfa2017-09-15 09:56:50 -0500110} // namespace action
111} // namespace control
112} // namespace fan
113} // namespace phosphor