Move signals to event triggers

Move the generation and initialization of signals to be included in the
available event triggers. The signal trigger consists of subscribing to
a given signal match where when the signal is received and handled, it
causes the event actions to be called.

Tested:
    All current event signals are still registered and received
    Speed changes occur based on temperature sensor change signals

Change-Id: Iab4ccabb50ad910d5d566bd8c1922109638bd760
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/triggers.cpp b/control/triggers.cpp
index 5314a95..2307730 100644
--- a/control/triggers.cpp
+++ b/control/triggers.cpp
@@ -23,6 +23,60 @@
     };
 }
 
+Trigger signal(const std::string& match, Handler&& handler)
+{
+    return [match = std::move(match),
+            handler = std::move(handler)](control::Zone& zone,
+                                          const Group& group,
+                                          const std::vector<Action>& actions)
+    {
+        // Setup signal matches of the property for event
+        std::unique_ptr<EventData> eventData =
+            std::make_unique<EventData>(
+                    group,
+                    match,
+                    handler,
+                    actions
+            );
+        std::unique_ptr<sdbusplus::server::match::match> mPtr = nullptr;
+        if (!match.empty())
+        {
+            // Subscribe to signal match
+            mPtr = std::make_unique<sdbusplus::server::match::match>(
+                    zone.getBus(),
+                    match.c_str(),
+                    std::bind(std::mem_fn(&Zone::handleEvent),
+                              &zone,
+                              std::placeholders::_1,
+                              eventData.get())
+            );
+        }
+        else
+        {
+            // When match is empty, handle if zone object member
+            // Set event data for each host group member
+            for (auto& entry : group)
+            {
+                if (entry.first == zone.getPath())
+                {
+                    auto ifaces = zone.getIfaces();
+                    // Group member interface in list owned by zone
+                    if (std::find(ifaces.begin(), ifaces.end(),
+                        std::get<intfPos>(entry.second)) != ifaces.end())
+                    {
+                        // Store path,interface,property as a managed object
+                        zone.setObjectData(entry.first,
+                                           std::get<intfPos>(entry.second),
+                                           std::get<propPos>(entry.second),
+                                           eventData.get());
+                    }
+                }
+            }
+        }
+        zone.addSignal(std::move(eventData), std::move(mPtr));
+    };
+}
+
 } // namespace trigger
 } // namespace control
 } // namespace fan