control: Construct events' groups
For each event, using the available groups, construct the groups
configured for the event. Groups with the same profiles configured as an
event can be used and events with no profiles configured, can also use
groups with no profiles configured.
*Note: Profiles are ways to keep specific configuration entries from
being used under specified details given within the `profiles.json`
configuration.
Change-Id: I47ce125ebb68e7075efc1c095d525bc9c96630e7
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/event.cpp b/control/json/event.cpp
index 94f860c..d19c9c1 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -22,6 +22,9 @@
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
+#include <optional>
+#include <tuple>
+
namespace phosphor::fan::control::json
{
@@ -83,12 +86,61 @@
for (const auto& group : jsonObj["groups"])
{
if (!group.contains("name") || !group.contains("interface") ||
- !group.contains("property"))
+ !group.contains("property") || !group["property"].contains("name"))
{
log<level::ERR>("Missing required event group attributes",
entry("JSON=%s", group.dump().c_str()));
throw std::runtime_error("Missing required event group attributes");
}
+
+ // Get the group memebers' data type
+ std::optional<std::string> type = std::nullopt;
+ if (group["property"].contains("type"))
+ {
+ type = group["property"]["type"].get<std::string>();
+ }
+
+ // Get the group memebers' expected value
+ std::optional<PropertyVariantType> value = std::nullopt;
+ if (group["property"].contains("value"))
+ {
+ value = getJsonValue(group["property"]["value"]);
+ }
+
+ // Groups with the same profiles as the event can be used
+ configKey key =
+ std::make_pair(group["name"].get<std::string>(), _profiles);
+ auto grpEntry = _availGrps.find(key);
+ if (grpEntry != _availGrps.end())
+ {
+ eGroup grp;
+ for (const auto& member : grpEntry->second->getMembers())
+ {
+ grp.emplace_back(std::make_tuple(
+ member, group["interface"].get<std::string>(),
+ group["property"]["name"].get<std::string>(), type, value));
+ }
+ _groups.emplace_back(grp);
+ }
+ else
+ {
+ // Groups with no profiles specified can be used in any event
+ key = std::make_pair(group["name"].get<std::string>(),
+ std::vector<std::string>{});
+ grpEntry = _availGrps.find(key);
+ if (grpEntry != _availGrps.end())
+ {
+ eGroup grp;
+ for (const auto& member : grpEntry->second->getMembers())
+ {
+ grp.emplace_back(std::make_tuple(
+ member, group["interface"].get<std::string>(),
+ group["property"]["name"].get<std::string>(), type,
+ value));
+ }
+ _groups.emplace_back(grp);
+ }
+ }
}
}