control: Create parameter trigger
Create a new event trigger that will run actions when a parameter is
either added, removed, or changed.
When the trigger is enabled it is added to the Manager class since that
is where parameters are stored, and then the Manager watches for
parameter changes and runs actions as needed.
The JSON config would look like:
{
"class": "parameter",
"parameter": "pcie_floor_index"
}
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I8ff281d49ac780e8ff38f3e8ed02ab95395f1fd3
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 5bfa07c..0acf706 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -59,6 +59,7 @@
std::map<std::string, std::map<std::string, PropertyVariantType>>>
Manager::_objects;
std::unordered_map<std::string, PropertyVariantType> Manager::_parameters;
+std::unordered_map<std::string, TriggerActions> Manager::_parameterTriggers;
const std::string Manager::dumpFile = "/tmp/fan_control_dump.json";
@@ -665,7 +666,7 @@
*this))
{
// Perform the actions in the handler package
- auto& actions = std::get<SignalActions>(pkg);
+ auto& actions = std::get<TriggerActions>(pkg);
std::for_each(actions.begin(), actions.end(), [](auto& action) {
if (action.get())
{
@@ -711,4 +712,36 @@
}
}
+void Manager::addParameterTrigger(
+ const std::string& name, std::vector<std::unique_ptr<ActionBase>>& actions)
+{
+ auto it = _parameterTriggers.find(name);
+ if (it != _parameterTriggers.end())
+ {
+ std::for_each(actions.begin(), actions.end(),
+ [&actList = it->second](auto& action) {
+ actList.emplace_back(std::ref(action));
+ });
+ }
+ else
+ {
+ TriggerActions triggerActions;
+ std::for_each(actions.begin(), actions.end(),
+ [&triggerActions](auto& action) {
+ triggerActions.emplace_back(std::ref(action));
+ });
+ _parameterTriggers[name] = std::move(triggerActions);
+ }
+}
+
+void Manager::runParameterActions(const std::string& name)
+{
+ auto it = _parameterTriggers.find(name);
+ if (it != _parameterTriggers.end())
+ {
+ std::for_each(it->second.begin(), it->second.end(),
+ [](auto& action) { action.get()->run(); });
+ }
+}
+
} // namespace phosphor::fan::control::json