control: Provide zones to the events

The event actions need the zone(s) to run the event's configured
action(s) against. The YAML based configs did not support configuring
which zone(s) to run any particular action within an event against.
A follow up commit will package the zone(s) an action should run against
and provide that directly to the action, eliminating the need to store
that for the trigger callbacks.

Change-Id: I1d0de02a61c9a906f932487231b46add92e8b1d5
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index 971c875..f02a590 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -36,9 +36,10 @@
 using namespace phosphor::logging;
 
 Event::Event(const json& jsonObj, sdbusplus::bus::bus& bus,
-             std::map<configKey, std::unique_ptr<Group>>& groups) :
+             std::map<configKey, std::unique_ptr<Group>>& groups,
+             std::map<configKey, std::unique_ptr<Zone>>& zones) :
     ConfigBase(jsonObj),
-    _bus(bus)
+    _bus(bus), _zones(zones)
 {
     // Event could have a precondition
     if (!jsonObj.contains("precondition"))
@@ -48,12 +49,12 @@
         {
             setGroups(jsonObj, groups);
         }
-        setTriggers(jsonObj);
         // Event actions are optional
         if (jsonObj.contains("actions"))
         {
-            setActions(jsonObj);
+            setActions(jsonObj, groups);
         }
+        setTriggers(jsonObj);
     }
     else
     {
@@ -137,17 +138,8 @@
     }
 }
 
-void Event::setTriggers(const json& jsonObj)
-{
-    if (!jsonObj.contains("triggers"))
-    {
-        log<level::ERR>("Missing required event triggers list",
-                        entry("JSON=%s", jsonObj.dump().c_str()));
-        throw std::runtime_error("Missing required event triggers list");
-    }
-}
-
-void Event::setActions(const json& jsonObj)
+void Event::setActions(const json& jsonObj,
+                       std::map<configKey, std::unique_ptr<Group>>& groups)
 {
     for (const auto& action : jsonObj["actions"])
     {
@@ -157,6 +149,10 @@
                             entry("JSON=%s", action.dump().c_str()));
             throw std::runtime_error("Missing required event action name");
         }
+        // TODO Append action specific groups to event groups list separate from
+        // each action in the event and pass reference of group to action
+        // TODO Consider supporting zones per action and pass a reference to the
+        // zone(s) the action should be run against
         auto actObj =
             ActionFactory::getAction(action["name"].get<std::string>(), action);
         if (actObj)
@@ -166,4 +162,14 @@
     }
 }
 
+void Event::setTriggers(const json& jsonObj)
+{
+    if (!jsonObj.contains("triggers"))
+    {
+        log<level::ERR>("Missing required event triggers list",
+                        entry("JSON=%s", jsonObj.dump().c_str()));
+        throw std::runtime_error("Missing required event triggers list");
+    }
+}
+
 } // namespace phosphor::fan::control::json