control: Actions use list of groups set on base object

Remove the reference to a group given when running an action and instead
have each action iterate over the list of groups configured/set on the
base action object. The group configured/set on the base action object
is the only set of groups that the action should use based on its
configuration in an event.

Change-Id: Ia298d270e782ad729b5a29f9cdfe9b6c9ea4bc45
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/actions/net_target_increase.cpp b/control/json/actions/net_target_increase.cpp
index 2240121..4387a4c 100644
--- a/control/json/actions/net_target_increase.cpp
+++ b/control/json/actions/net_target_increase.cpp
@@ -42,81 +42,87 @@
     setDelta(jsonObj);
 }
 
-void NetTargetIncrease::run(Zone& zone, const Group& group)
+void NetTargetIncrease::run(Zone& zone)
 {
     auto netDelta = zone.getIncDelta();
-    const auto& members = group.getMembers();
-    std::for_each(
-        members.begin(), members.end(),
-        [this, &zone, &group, &netDelta](const auto& member) {
-            try
-            {
-                auto value = Manager::getObjValueVariant(
-                    member, group.getInterface(), group.getProperty());
-                if (std::holds_alternative<int64_t>(value) ||
-                    std::holds_alternative<double>(value))
+    for (const auto& group : _groups)
+    {
+        const auto& members = group.getMembers();
+        std::for_each(
+            members.begin(), members.end(),
+            [this, &zone, &group, &netDelta](const auto& member) {
+                try
                 {
-                    // Where a group of int/doubles are greater than or equal
-                    // to the state(some value) provided, request an increase
-                    // of the configured delta times the difference between
-                    // the group member's value and configured state value.
-                    if (value >= _state)
+                    auto value = Manager::getObjValueVariant(
+                        member, group.getInterface(), group.getProperty());
+                    if (std::holds_alternative<int64_t>(value) ||
+                        std::holds_alternative<double>(value))
                     {
-                        uint64_t incDelta = 0;
-                        if (auto dblPtr = std::get_if<double>(&value))
+                        // Where a group of int/doubles are greater than or
+                        // equal to the state(some value) provided, request an
+                        // increase of the configured delta times the difference
+                        // between the group member's value and configured state
+                        // value.
+                        if (value >= _state)
                         {
-                            incDelta = static_cast<uint64_t>(
-                                (*dblPtr - std::get<double>(_state)) * _delta);
+                            uint64_t incDelta = 0;
+                            if (auto dblPtr = std::get_if<double>(&value))
+                            {
+                                incDelta = static_cast<uint64_t>(
+                                    (*dblPtr - std::get<double>(_state)) *
+                                    _delta);
+                            }
+                            else
+                            {
+                                // Increase by at least a single delta
+                                // to attempt bringing under provided 'state'
+                                auto deltaFactor =
+                                    std::max((std::get<int64_t>(value) -
+                                              std::get<int64_t>(_state)),
+                                             1ll);
+                                incDelta =
+                                    static_cast<uint64_t>(deltaFactor * _delta);
+                            }
+                            netDelta = std::max(netDelta, incDelta);
                         }
-                        else
+                    }
+                    else if (std::holds_alternative<bool>(value))
+                    {
+                        // Where a group of booleans equal the state(`true` or
+                        // `false`) provided, request an increase of the
+                        // configured delta
+                        if (_state == value)
                         {
-                            // Increase by at least a single delta
-                            // to attempt bringing under provided 'state'
-                            auto deltaFactor =
-                                std::max((std::get<int64_t>(value) -
-                                          std::get<int64_t>(_state)),
-                                         1ll);
-                            incDelta =
-                                static_cast<uint64_t>(deltaFactor * _delta);
+                            netDelta = std::max(netDelta, _delta);
                         }
-                        netDelta = std::max(netDelta, incDelta);
                     }
-                }
-                else if (std::holds_alternative<bool>(value))
-                {
-                    // Where a group of booleans equal the state(`true` or
-                    // `false`) provided, request an increase of the configured
-                    // delta
-                    if (_state == value)
+                    else if (std::holds_alternative<std::string>(value))
                     {
-                        netDelta = std::max(netDelta, _delta);
+                        // Where a group of strings equal the state(some string)
+                        // provided, request an increase of the configured delta
+                        if (_state == value)
+                        {
+                            netDelta = std::max(netDelta, _delta);
+                        }
                     }
-                }
-                else if (std::holds_alternative<std::string>(value))
-                {
-                    // Where a group of strings equal the state(some string)
-                    // provided, request an increase of the configured delta
-                    if (_state == value)
+                    else
                     {
-                        netDelta = std::max(netDelta, _delta);
+                        // Unsupported group member type for this action
+                        log<level::ERR>(
+                            fmt::format(
+                                "Action {}: Unsupported group member type "
+                                "given. [object = {} : {} : {}]",
+                                ActionBase::getName(), member,
+                                group.getInterface(), group.getProperty())
+                                .c_str());
                     }
                 }
-                else
+                catch (const std::out_of_range& oore)
                 {
-                    // Unsupported group member type for this action
-                    log<level::ERR>(
-                        fmt::format("Action {}: Unsupported group member type "
-                                    "given. [object = {} : {} : {}]",
-                                    ActionBase::getName(), member,
-                                    group.getInterface(), group.getProperty())
-                            .c_str());
+                    // Property value not found, netDelta unchanged
                 }
-            }
-            catch (const std::out_of_range& oore)
-            {
-                // Property value not found, netDelta unchanged
-            }
-        });
+            });
+    }
     // Request increase to target
     zone.requestIncrease(netDelta);
 }