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, 17 const Group& group, 18 const std::vector<Action>& actions) 19 { 20 zone.addTimer(group, 21 actions, 22 tConf); 23 }; 24 } 25 26 Trigger signal(const std::string& match, Handler&& handler) 27 { 28 return [match = std::move(match), 29 handler = std::move(handler)](control::Zone& zone, 30 const Group& group, 31 const std::vector<Action>& actions) 32 { 33 // Setup signal matches of the property for event 34 std::unique_ptr<EventData> eventData = 35 std::make_unique<EventData>( 36 group, 37 match, 38 handler, 39 actions 40 ); 41 std::unique_ptr<sdbusplus::server::match::match> mPtr = nullptr; 42 if (!match.empty()) 43 { 44 // Subscribe to signal match 45 mPtr = std::make_unique<sdbusplus::server::match::match>( 46 zone.getBus(), 47 match.c_str(), 48 std::bind(std::mem_fn(&Zone::handleEvent), 49 &zone, 50 std::placeholders::_1, 51 eventData.get()) 52 ); 53 } 54 else 55 { 56 // When match is empty, handle if zone object member 57 // Set event data for each host group member 58 for (auto& entry : group) 59 { 60 if (entry.first == zone.getPath()) 61 { 62 auto ifaces = zone.getIfaces(); 63 // Group member interface in list owned by zone 64 if (std::find(ifaces.begin(), ifaces.end(), 65 std::get<intfPos>(entry.second)) != ifaces.end()) 66 { 67 // Store path,interface,property as a managed object 68 zone.setObjectData(entry.first, 69 std::get<intfPos>(entry.second), 70 std::get<propPos>(entry.second), 71 eventData.get()); 72 } 73 } 74 } 75 } 76 zone.addSignal(std::move(eventData), std::move(mPtr)); 77 }; 78 } 79 80 } // namespace trigger 81 } // namespace control 82 } // namespace fan 83 } // namespace phosphor 84