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 | { |
| 17 | return [tConf = std::move(tConf), |
| 18 | actions = std::move(actions)](control::Zone& zone, |
| 19 | const Group& group) |
| 20 | { |
| 21 | try |
| 22 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 23 | auto it = zone.getTimerEvents().find(__func__); |
| 24 | if (it != zone.getTimerEvents().end()) |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 25 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 26 | auto& timers = it->second; |
| 27 | auto timerIter = zone.findTimer(group, actions, timers); |
Matthew Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 28 | if (timerIter == timers.end()) |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 29 | { |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 30 | // No timer exists yet for action, add timer |
| 31 | zone.addTimer(__func__, group, actions, tConf); |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 32 | } |
Matthew Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 33 | else if (timerIter != timers.end()) |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 34 | { |
| 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 Barth | e7d5389 | 2018-12-12 10:59:57 -0600 | [diff] [blame] | 43 | else |
Matthew Barth | d7b716a | 2018-11-16 13:37:57 -0600 | [diff] [blame] | 44 | { |
| 45 | // No timer exists yet for event, add timer |
| 46 | zone.addTimer(__func__, group, actions, tConf); |
Matthew Barth | 2a646c5 | 2017-10-05 17:04:11 -0500 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | catch (const std::out_of_range& oore) |
| 50 | { |
| 51 | // Group not found, no timers set |
| 52 | } |
| 53 | }; |
| 54 | } |
| 55 | |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 56 | void default_floor_on_missing_owner(Zone& zone, const Group& group) |
| 57 | { |
Matthew Barth | 480787c | 2017-11-06 11:00:00 -0600 | [diff] [blame] | 58 | // Set/update the services of the group |
| 59 | zone.setServices(&group); |
Matthew Barth | 98726c4 | 2017-10-17 10:35:20 -0500 | [diff] [blame] | 60 | 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 Barth | 0decd1b | 2017-10-24 15:58:17 -0500 | [diff] [blame] | 76 | Action set_speed_on_missing_owner(uint64_t speed) |
| 77 | { |
| 78 | return [speed](control::Zone& zone, const Group& group) |
| 79 | { |
Matthew Barth | 480787c | 2017-11-06 11:00:00 -0600 | [diff] [blame] | 80 | // Set/update the services of the group |
| 81 | zone.setServices(&group); |
Matthew Barth | 0decd1b | 2017-10-24 15:58:17 -0500 | [diff] [blame] | 82 | 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 Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 99 | void 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 Barth | 146b739 | 2018-03-08 16:17:58 -0600 | [diff] [blame] | 111 | std::get<pathPos>(entry), |
| 112 | std::get<intfPos>(entry), |
| 113 | std::get<propPos>(entry)); |
Matthew Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 114 | 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 Barth | b280bfa | 2017-09-15 09:56:50 -0500 | [diff] [blame] | 125 | } // namespace action |
| 126 | } // namespace control |
| 127 | } // namespace fan |
| 128 | } // namespace phosphor |