Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 1 | #include "preconditions.hpp" |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 2 | |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 3 | #include "zone.hpp" |
| 4 | |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
| 7 | #include <algorithm> |
| 8 | |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 9 | namespace phosphor |
| 10 | { |
| 11 | namespace fan |
| 12 | { |
| 13 | namespace control |
| 14 | { |
| 15 | namespace precondition |
| 16 | { |
| 17 | |
| 18 | using namespace phosphor::fan; |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 19 | using namespace phosphor::logging; |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 20 | |
| 21 | Action property_states_match(std::vector<PrecondGroup>&& pg, |
| 22 | std::vector<SetSpeedEvent>&& sse) |
| 23 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 24 | return [pg = std::move(pg), sse = std::move(sse)](auto& zone, auto& group) { |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 25 | // Compare given precondition entries |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 26 | auto precondState = std::all_of(pg.begin(), pg.end(), |
| 27 | [&zone](auto const& entry) { |
| 28 | try |
| 29 | { |
| 30 | return zone.getPropValueVariant(std::get<pcPathPos>(entry), |
| 31 | std::get<pcIntfPos>(entry), |
| 32 | std::get<pcPropPos>(entry)) == |
| 33 | std::get<pcValuePos>(entry); |
| 34 | } |
| 35 | catch (const std::out_of_range& oore) |
| 36 | { |
| 37 | // Default to property variants not equal when not found |
| 38 | return false; |
| 39 | } |
| 40 | }); |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 41 | |
| 42 | if (precondState) |
| 43 | { |
| 44 | log<level::DEBUG>( |
| 45 | "Preconditions passed, init the associated events", |
| 46 | entry("EVENT_COUNT=%u", sse.size())); |
| 47 | // Init the events when all the precondition(s) are true |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 48 | std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) { |
| 49 | zone.initEvent(entry); |
| 50 | }); |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 51 | } |
| 52 | else |
| 53 | { |
| 54 | log<level::DEBUG>( |
| 55 | "Preconditions not met for events, events removed if present", |
| 56 | entry("EVENT_COUNT=%u", sse.size())); |
| 57 | // Unsubscribe the events' signals when any precondition is false |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 58 | std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) { |
| 59 | zone.removeEvent(entry); |
| 60 | }); |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 61 | zone.setFullSpeed(); |
| 62 | } |
| 63 | // Update group's fan control active allowed |
| 64 | zone.setActiveAllow(&group, precondState); |
| 65 | }; |
| 66 | } |
| 67 | |
Matthew Barth | 36cfcec | 2018-12-14 10:18:53 -0600 | [diff] [blame] | 68 | Action services_missing_owner(std::vector<SetSpeedEvent>&& sse) |
| 69 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 70 | return [sse = std::move(sse)](auto& zone, auto& group) { |
Matthew Barth | 36cfcec | 2018-12-14 10:18:53 -0600 | [diff] [blame] | 71 | // Set/update the services of the group |
| 72 | zone.setServices(&group); |
| 73 | const auto& services = zone.getGroupServices(&group); |
Patrick Williams | 5e15c3b | 2023-10-20 11:18:11 -0500 | [diff] [blame] | 74 | auto precondState = std::any_of( |
| 75 | services.begin(), services.end(), |
| 76 | [](const auto& s) { return !std::get<hasOwnerPos>(s); }); |
Matthew Barth | 36cfcec | 2018-12-14 10:18:53 -0600 | [diff] [blame] | 77 | |
| 78 | if (precondState) |
| 79 | { |
| 80 | // Init the events when all the precondition(s) are true |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 81 | std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) { |
| 82 | zone.initEvent(entry); |
| 83 | }); |
Matthew Barth | 36cfcec | 2018-12-14 10:18:53 -0600 | [diff] [blame] | 84 | } |
| 85 | else |
| 86 | { |
| 87 | // Unsubscribe the events' signals when any precondition is false |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 88 | std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) { |
| 89 | zone.removeEvent(entry); |
| 90 | }); |
Matthew Barth | 36cfcec | 2018-12-14 10:18:53 -0600 | [diff] [blame] | 91 | } |
| 92 | }; |
| 93 | } |
| 94 | |
Matthew Barth | 03aff08 | 2018-12-12 15:20:22 -0600 | [diff] [blame] | 95 | } // namespace precondition |
| 96 | } // namespace control |
| 97 | } // namespace fan |
| 98 | } // namespace phosphor |