control: Store/use trigger enable functions on events
Create and store trigger enablement functions on the events based on the
trigger's configuration so that they can be enabled separately from when
the event is created. This will allow actions that load events to be
able to be parsed and then enabled when the action determines that the
events should be enabled. It also supports the use of SIGHUP to reload
the event configuration since the events JSON configuration must
successfully be loaded before the newly created events can be enabled in
place of the currently enabled events.
Change-Id: I31871ee1691d5e6b26fe16cde2a829c426ad6504
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/triggers/signal.cpp b/control/json/triggers/signal.cpp
index 9e793f0..4869ee9 100644
--- a/control/json/triggers/signal.cpp
+++ b/control/json/triggers/signal.cpp
@@ -19,6 +19,7 @@
#include "action.hpp"
#include "group.hpp"
#include "handlers.hpp"
+#include "trigger_aliases.hpp"
#include <fmt/format.h>
@@ -214,9 +215,9 @@
}
}
-void triggerSignal(const json& jsonObj, const std::string& eventName,
- Manager* mgr,
- std::vector<std::unique_ptr<ActionBase>>& actions)
+enableTrigger triggerSignal(const json& jsonObj, const std::string& eventName,
+ Manager* mgr,
+ std::vector<std::unique_ptr<ActionBase>>& actions)
{
auto subscriber = signals.end();
if (jsonObj.contains("signal"))
@@ -241,11 +242,15 @@
throw std::runtime_error(msg.c_str());
}
- for (auto& action : actions)
- {
- // Call signal subscriber for each group in the action
- subscriber->second(mgr, eventName, action);
- }
+ return [subscriber = std::move(subscriber)](
+ const std::string& eventName, Manager* mgr,
+ std::vector<std::unique_ptr<ActionBase>>& actions) {
+ for (auto& action : actions)
+ {
+ // Call signal subscriber for each group in the action
+ subscriber->second(mgr, eventName, action);
+ }
+ };
}
} // namespace phosphor::fan::control::json::trigger::signal