Matthew Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 1 | #include "actions.hpp" |
| 2 | |
| 3 | namespace phosphor |
| 4 | { |
| 5 | namespace fan |
| 6 | { |
| 7 | namespace control |
| 8 | { |
| 9 | namespace action |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::fan; |
| 13 | |
William A. Kennington III | 122b843 | 2018-10-30 18:39:21 -0700 | [diff] [blame] | 14 | Action call_actions_based_on_timer(TimerConf&& tConf, |
| 15 | std::vector<Action>&& actions) |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 16 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 17 | return [tConf = std::move(tConf), actions = std::move(actions)]( |
| 18 | control::Zone& zone, const Group& group) { |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 19 | try |
| 20 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 21 | auto it = zone.getTimerEvents().find(__func__); |
| 22 | if (it != zone.getTimerEvents().end()) |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 23 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 24 | auto& timers = it->second; |
| 25 | auto timerIter = zone.findTimer(group, actions, timers); |
Matthew Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 26 | if (timerIter == timers.end()) |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 27 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 28 | // No timer exists yet for action, add timer |
| 29 | zone.addTimer(__func__, group, actions, tConf); |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 30 | } |
Matthew Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 31 | else if (timerIter != timers.end()) |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 32 | { |
| 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 Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 41 | else |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 42 | { |
| 43 | // No timer exists yet for event, add timer |
| 44 | zone.addTimer(__func__, group, actions, tConf); |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | catch (const std::out_of_range& oore) |
| 48 | { |
| 49 | // Group not found, no timers set |
| 50 | } |
| 51 | }; |
| 52 | } |
| 53 | |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 54 | void default_floor_on_missing_owner(Zone& zone, const Group& group) |
| 55 | { |
Matthew Barth | 480787c | 2017-11-06 11:00:00 -0600 | [diff] [blame] | 56 | // Set/update the services of the group |
| 57 | zone.setServices(&group); |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 58 | auto services = zone.getGroupServices(&group); |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 59 | auto defFloor = |
| 60 | std::any_of(services.begin(), services.end(), |
| 61 | [](const auto& s) { return !std::get<hasOwnerPos>(s); }); |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 62 | if (defFloor) |
| 63 | { |
| 64 | zone.setFloor(zone.getDefFloor()); |
| 65 | } |
| 66 | // Update fan control floor change allowed |
| 67 | zone.setFloorChangeAllow(&group, !defFloor); |
| 68 | } |
| 69 | |
Matthew Barth | 0decd1b | 2017-10-24 15:58:17 -0500 | [diff] [blame] | 70 | Action set_speed_on_missing_owner(uint64_t speed) |
| 71 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 72 | return [speed](control::Zone& zone, const Group& group) { |
Matthew Barth | 480787c | 2017-11-06 11:00:00 -0600 | [diff] [blame] | 73 | // Set/update the services of the group |
| 74 | zone.setServices(&group); |
Matthew Barth | 0decd1b | 2017-10-24 15:58:17 -0500 | [diff] [blame] | 75 | auto services = zone.getGroupServices(&group); |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 76 | auto missingOwner = |
| 77 | std::any_of(services.begin(), services.end(), [](const auto& s) { |
| 78 | return !std::get<hasOwnerPos>(s); |
| 79 | }); |
Matthew Barth | 0decd1b | 2017-10-24 15:58:17 -0500 | [diff] [blame] | 80 | 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 Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 89 | void set_request_speed_base_with_max(control::Zone& zone, const Group& group) |
Matthew Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 90 | { |
| 91 | int64_t base = 0; |
Patrick Williams | dfddd64 | 2024-08-16 15:21:51 -0400 | [diff] [blame^] | 92 | 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 Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 106 | // A request speed base of 0 defaults to the current target speed |
| 107 | zone.setRequestSpeedBase(base); |
| 108 | } |
| 109 | |
Matthew Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 110 | } // namespace action |
| 111 | } // namespace control |
| 112 | } // namespace fan |
| 113 | } // namespace phosphor |