control: Create config key check function
Move the configuration/profile check to include groups into events to a
function that can be used by other configurations that also need to do
this check. Update the check to include a fan within a zone to use this
function.
Change-Id: I71259ce0fcd61917a5d7a5bb9ac2d1906130389e
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index ca94d9a..b5e986d 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -109,43 +109,11 @@
value = getJsonValue(group["property"]["value"]);
}
- configKey key =
+ configKey eventProfile =
std::make_pair(group["name"].get<std::string>(), _profiles);
- auto grpEntry =
- std::find_if(groups.begin(), groups.end(), [&key](const auto& grp) {
- if (grp.first.first != key.first)
- {
- return false;
- }
- // Groups with no profiles specified can be used in any event
- if (grp.first.second.empty())
- {
- return true;
- }
- else
- {
- // Groups with profiles must have one match in the event's
- // profiles(and they must be an active profile) to be used
- // in the event
- return std::any_of(
- grp.first.second.begin(), grp.first.second.end(),
- [&key](const auto& grpProfile) {
- return std::any_of(
- key.second.begin(), key.second.end(),
- [&grpProfile](const auto& eventProfile) {
- if (grpProfile != eventProfile)
- {
- return false;
- }
- auto activeProfs =
- Manager::getActiveProfiles();
- return std::find(activeProfs.begin(),
- activeProfs.end(),
- grpProfile) !=
- activeProfs.end();
- });
- });
- }
+ auto grpEntry = std::find_if(
+ groups.begin(), groups.end(), [&eventProfile](const auto& grp) {
+ return Manager::inConfig(grp.first, eventProfile);
});
if (grpEntry != groups.end())
{