control: Add interfacesAdded signal support
Subscribe to and handle interfacesAdded signals to trigger event
actions.
Change-Id: I9d42a4341cb2880cf839b626786c569bdbf19a7c
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/triggers/signal.cpp b/control/json/triggers/signal.cpp
index b5e1e6a..375ec0f 100644
--- a/control/json/triggers/signal.cpp
+++ b/control/json/triggers/signal.cpp
@@ -117,6 +117,32 @@
}
}
+void interfacesAdded(Manager* mgr, const std::string& eventName,
+ std::unique_ptr<ActionBase>& action)
+{
+ // Groups are optional, but a signal triggered event with no groups
+ // will do nothing since signals require a group
+ for (const auto& group : action->getGroups())
+ {
+ for (const auto& member : group.getMembers())
+ {
+ // Setup interfaces added signal handler on the group member
+ const auto match = rules::interfacesAdded(member);
+ SignalPkg signalPkg = {Handlers::interfacesAdded,
+ SignalObject(std::cref(member),
+ std::cref(group.getInterface()),
+ std::cref(group.getProperty())),
+ SignalActions({action})};
+ auto isSameSig = [&intf = group.getInterface()](SignalPkg& pkg) {
+ auto& obj = std::get<SignalObject>(pkg);
+ return intf == std::get<Intf>(obj);
+ };
+
+ subscribe(match, std::move(signalPkg), isSameSig, mgr);
+ }
+ }
+}
+
void triggerSignal(const json& jsonObj, const std::string& eventName,
Manager* mgr,
std::vector<std::unique_ptr<ActionBase>>& actions)