Matthew Barth | 1b4de26 | 2018-03-06 13:03:16 -0600 | [diff] [blame] | 1 | #include "triggers.hpp" |
| 2 | |
| 3 | namespace phosphor |
| 4 | { |
| 5 | namespace fan |
| 6 | { |
| 7 | namespace control |
| 8 | { |
| 9 | namespace trigger |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::fan; |
| 13 | |
| 14 | Trigger timer(TimerConf&& tConf) |
| 15 | { |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 16 | return |
| 17 | [tConf = std::move(tConf)](control::Zone& zone, const std::string& name, |
| 18 | const Group& group, |
| 19 | const std::vector<Action>& actions) { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 20 | zone.addTimer(name, group, actions, tConf); |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 21 | }; |
Matthew Barth | 1b4de26 | 2018-03-06 13:03:16 -0600 | [diff] [blame] | 22 | } |
| 23 | |
Matthew Barth | 926df66 | 2018-10-09 09:51:12 -0500 | [diff] [blame] | 24 | Trigger signal(const std::string& match, SignalHandler&& handler) |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 25 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 26 | return [match = std::move(match), handler = std::move(handler)]( |
| 27 | control::Zone& zone, const std::string& name, const Group& group, |
| 28 | const std::vector<Action>& actions) { |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 29 | // Setup signal matches of the property for event |
| 30 | std::unique_ptr<EventData> eventData = |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 31 | std::make_unique<EventData>(group, match, handler, actions); |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 32 | std::unique_ptr<sdbusplus::bus::match_t> mPtr = nullptr; |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 33 | if (!match.empty()) |
| 34 | { |
| 35 | // Subscribe to signal match |
Patrick Williams | 3ea9ec2 | 2021-11-19 12:21:08 -0600 | [diff] [blame] | 36 | mPtr = std::make_unique<sdbusplus::bus::match_t>( |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 37 | zone.getBus(), match.c_str(), |
| 38 | std::bind(std::mem_fn(&Zone::handleEvent), &zone, |
| 39 | std::placeholders::_1, eventData.get())); |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 40 | } |
| 41 | else |
| 42 | { |
| 43 | // When match is empty, handle if zone object member |
| 44 | // Set event data for each host group member |
| 45 | for (auto& entry : group) |
| 46 | { |
Matthew Barth | 146b739 | 2018-03-08 16:17:58 -0600 | [diff] [blame] | 47 | if (std::get<pathPos>(entry) == zone.getPath()) |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 48 | { |
| 49 | auto ifaces = zone.getIfaces(); |
| 50 | // Group member interface in list owned by zone |
| 51 | if (std::find(ifaces.begin(), ifaces.end(), |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 52 | std::get<intfPos>(entry)) != ifaces.end()) |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 53 | { |
| 54 | // Store path,interface,property as a managed object |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 55 | zone.setObjectData( |
| 56 | std::get<pathPos>(entry), std::get<intfPos>(entry), |
| 57 | std::get<propPos>(entry), eventData.get()); |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
Matthew Barth | 79cb831 | 2018-11-14 15:20:31 -0600 | [diff] [blame] | 62 | zone.addSignal(name, std::move(eventData), std::move(mPtr)); |
Matthew Barth | 016bd24 | 2018-03-07 16:06:06 -0600 | [diff] [blame] | 63 | }; |
| 64 | } |
| 65 | |
Matthew Barth | 926df66 | 2018-10-09 09:51:12 -0500 | [diff] [blame] | 66 | Trigger init(MethodHandler&& handler) |
Matthew Barth | cd3bfbc | 2018-03-07 16:26:03 -0600 | [diff] [blame] | 67 | { |
Matthew Barth | 3e1bb27 | 2020-05-26 11:09:21 -0500 | [diff] [blame] | 68 | return [handler = std::move(handler)]( |
Mike Capps | b2e9a4f | 2022-06-13 10:15:42 -0400 | [diff] [blame] | 69 | control::Zone& zone, const std::string& /*name*/, |
| 70 | const Group& group, const std::vector<Action>& actions) { |
Matthew Barth | cd3bfbc | 2018-03-07 16:26:03 -0600 | [diff] [blame] | 71 | // A handler function is optional |
| 72 | if (handler) |
| 73 | { |
Matthew Barth | 926df66 | 2018-10-09 09:51:12 -0500 | [diff] [blame] | 74 | handler(zone, group); |
Matthew Barth | cd3bfbc | 2018-03-07 16:26:03 -0600 | [diff] [blame] | 75 | } |
Matthew Barth | 926df66 | 2018-10-09 09:51:12 -0500 | [diff] [blame] | 76 | |
Matthew Barth | cd3bfbc | 2018-03-07 16:26:03 -0600 | [diff] [blame] | 77 | // Run action functions for initial event state |
Patrick Williams | 61b7329 | 2023-05-10 07:50:12 -0500 | [diff] [blame] | 78 | std::for_each(actions.begin(), actions.end(), |
| 79 | [&zone, &group](auto const& action) { |
| 80 | action(zone, group); |
| 81 | }); |
Matthew Barth | cd3bfbc | 2018-03-07 16:26:03 -0600 | [diff] [blame] | 82 | }; |
| 83 | } |
| 84 | |
Matthew Barth | 1b4de26 | 2018-03-06 13:03:16 -0600 | [diff] [blame] | 85 | } // namespace trigger |
| 86 | } // namespace control |
| 87 | } // namespace fan |
| 88 | } // namespace phosphor |