blob: 230773091cc2b7791ab8d2168181bd91d7f12169 [file] [log] [blame]
Matthew Barth1b4de262018-03-06 13:03:16 -06001#include "triggers.hpp"
2
3namespace phosphor
4{
5namespace fan
6{
7namespace control
8{
9namespace trigger
10{
11
12using namespace phosphor::fan;
13
14Trigger 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
Matthew Barth016bd242018-03-07 16:06:06 -060026Trigger 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
Matthew Barth1b4de262018-03-06 13:03:16 -060080} // namespace trigger
81} // namespace control
82} // namespace fan
83} // namespace phosphor