control: CountStateTarget action use unique identifier
Each instance of the CountStateTarget action needs to use a unique
identifier when setting a zone's active fan control allowed state. This
ensures that when more than one event is configured with the
CountStateTarget action against the same group, their active fan control
allowed states wont conflict.
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: Ie515119c697f6f1819beb26aa9d2b16ed171b571
diff --git a/control/json/actions/count_state_target.cpp b/control/json/actions/count_state_target.cpp
index 911134e..9f2ba5e 100644
--- a/control/json/actions/count_state_target.cpp
+++ b/control/json/actions/count_state_target.cpp
@@ -29,6 +29,9 @@
using json = nlohmann::json;
+// Instance id for setting the unique id of each instance of this action
+size_t CountStateTarget::instanceId = 0;
+
CountStateTarget::CountStateTarget(const json& jsonObj,
const std::vector<Group>& groups) :
ActionBase(jsonObj, groups)
@@ -36,6 +39,8 @@
setCount(jsonObj);
setState(jsonObj);
setTarget(jsonObj);
+
+ _id = instanceId++;
}
void CountStateTarget::run(Zone& zone)
@@ -43,7 +48,7 @@
size_t numAtState = 0;
for (const auto& group : _groups)
{
- for (auto& member : group.getMembers())
+ for (const auto& member : group.getMembers())
{
try
{
@@ -63,9 +68,15 @@
break;
}
}
- // Update group's fan control active allowed based on action results
- zone.setActiveAllow(group.getName(), !(numAtState >= _count));
+ if (numAtState >= _count)
+ {
+ break;
+ }
}
+
+ // Update zone's active fan control allowed based on action results
+ zone.setActiveAllow(ActionBase::getName() + std::to_string(_id),
+ !(numAtState >= _count));
}
void CountStateTarget::setCount(const json& jsonObj)
diff --git a/control/json/actions/count_state_target.hpp b/control/json/actions/count_state_target.hpp
index 2e7d6ec..b1b4eb9 100644
--- a/control/json/actions/count_state_target.hpp
+++ b/control/json/actions/count_state_target.hpp
@@ -70,6 +70,10 @@
*/
void run(Zone& zone) override;
+ protected:
+ /* Instance id for each instance of this action */
+ static size_t instanceId;
+
private:
/* Number of group members */
size_t _count;
@@ -80,6 +84,9 @@
/* Target for this action */
uint64_t _target;
+ /* Unique id of this action */
+ size_t _id;
+
/**
* @brief Parse and set the count
*