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