control: Make setting groups public and static

There could be a need for actions to determine a list of groups to use,
so make setting the groups available for actions to use. For example,
the timer_based_actions action could have groups configured on the list
of actions that it runs when its timer expires. These groups need to be
checked against the active profiles and set on the list of actions.

Change-Id: I5b00f16af12bd15e56a65cb3a82a294860ab6d8d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index f63e38a..02f2ed5 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -45,7 +45,7 @@
     // Event groups are optional
     if (jsonObj.contains("groups"))
     {
-        setGroups(jsonObj, _groups);
+        setGroups(jsonObj, _profiles, _groups);
     }
     // Event actions are optional
     if (jsonObj.contains("actions"))
@@ -104,32 +104,36 @@
     }
 }
 
-void Event::setGroups(const json& jsonObj, std::vector<Group>& groups)
+void Event::setGroups(const json& jsonObj,
+                      const std::vector<std::string>& profiles,
+                      std::vector<Group>& groups)
 {
-    auto& availGroups = getAvailGroups();
-    for (const auto& jsonGrp : jsonObj["groups"])
+    if (jsonObj.contains("groups"))
     {
-        if (!jsonGrp.contains("name"))
+        auto& availGroups = getAvailGroups();
+        for (const auto& jsonGrp : jsonObj["groups"])
         {
-            auto msg = fmt::format(
-                "Missing required group name attribute in event {}", getName());
-            log<level::ERR>(msg.c_str(),
-                            entry("JSON=%s", jsonGrp.dump().c_str()));
-            throw std::runtime_error(msg.c_str());
-        }
+            if (!jsonGrp.contains("name"))
+            {
+                auto msg = fmt::format("Missing required group name attribute");
+                log<level::ERR>(msg.c_str(),
+                                entry("JSON=%s", jsonGrp.dump().c_str()));
+                throw std::runtime_error(msg.c_str());
+            }
 
-        configKey eventProfile =
-            std::make_pair(jsonGrp["name"].get<std::string>(), _profiles);
-        auto grpEntry =
-            std::find_if(availGroups.begin(), availGroups.end(),
-                         [&eventProfile](const auto& grp) {
-                             return Manager::inConfig(grp.first, eventProfile);
-                         });
-        if (grpEntry != availGroups.end())
-        {
-            auto group = Group(*grpEntry->second);
-            configGroup(group, jsonGrp);
-            groups.emplace_back(group);
+            configKey eventProfile =
+                std::make_pair(jsonGrp["name"].get<std::string>(), profiles);
+            auto grpEntry = std::find_if(availGroups.begin(), availGroups.end(),
+                                         [&eventProfile](const auto& grp) {
+                                             return Manager::inConfig(
+                                                 grp.first, eventProfile);
+                                         });
+            if (grpEntry != availGroups.end())
+            {
+                auto group = Group(*grpEntry->second);
+                configGroup(group, jsonGrp);
+                groups.emplace_back(group);
+            }
         }
     }
 }
@@ -148,10 +152,7 @@
         // Append action specific groups to the list of event groups for each
         // action in the event
         auto actionGroups = _groups;
-        if (jsonAct.contains("groups"))
-        {
-            setGroups(jsonAct, actionGroups);
-        }
+        setGroups(jsonAct, _profiles, actionGroups);
         if (actionGroups.empty())
         {
             log<level::DEBUG>(
diff --git a/control/json/event.hpp b/control/json/event.hpp
index 80e2f95..0e71f79 100644
--- a/control/json/event.hpp
+++ b/control/json/event.hpp
@@ -78,6 +78,29 @@
      */
     void enable();
 
+    /**
+     * @brief Parse group parameters and configure a group object
+     *
+     * @param[in] group - Group object to get configured
+     * @param[in] jsonObj - JSON object for the group
+     *
+     * Configures a given group from a set of JSON configuration attributes
+     */
+    static void configGroup(Group& group, const json& jsonObj);
+
+    /**
+     * @brief Parse and set the event's groups(OPTIONAL)
+     *
+     * @param[in] jsonObj - JSON object for the event
+     * @param[in] profiles - List of profiles to validate groups against
+     * @param[out] groups - List of groups to be configured
+     *
+     * Sets the list of groups associated with the event
+     */
+    static void setGroups(const json& jsonObj,
+                          const std::vector<std::string>& profiles,
+                          std::vector<Group>& groups);
+
   private:
     /* The sdbusplus bus object */
     sdbusplus::bus::bus& _bus;
@@ -105,26 +128,6 @@
     static auto& getAvailGroups() __attribute__((pure));
 
     /**
-     * @brief Parse group parameters and configure a group object
-     *
-     * @param[in] group - Group object to get configured
-     * @param[in] jsonObj - JSON object for the group
-     *
-     * Configures a given group from a set of JSON configuration attributes
-     */
-    void configGroup(Group& group, const json& jsonObj);
-
-    /**
-     * @brief Parse and set the event's groups(OPTIONAL)
-     *
-     * @param[in] jsonObj - JSON object for the event
-     * @param[out] groups - List of groups to be configured
-     *
-     * Sets the list of groups associated with the event
-     */
-    void setGroups(const json& jsonObj, std::vector<Group>& groups);
-
-    /**
      * @brief Parse and set the event's actions(OPTIONAL)
      *
      * @param[in] jsonObj - JSON object for the event