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