presence: Extract fan object data
Extract the fan name and path for each entry within the JSON
configuration and store within a list of fan objects to be used when
constructing the fan presence policies.
Tested:
Fan objects created with a "name" and "path"
Missing "name" or "path" throws exception
Change-Id: I16c17b87576d68addaf69e72311681b46f83b49e
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/json_config.cpp b/presence/json_config.cpp
index 4a9d493..bd8a7f7 100644
--- a/presence/json_config.cpp
+++ b/presence/json_config.cpp
@@ -61,6 +61,8 @@
entry("JSON_FILE=%s", jsonFile.c_str()));
throw std::runtime_error("Unable to open JSON config file");
}
+
+ process(jsonConf);
}
const policies& JsonConfig::get()
@@ -68,6 +70,23 @@
return _policies;
}
+void JsonConfig::process(const json& jsonConf)
+{
+ for (auto& member : jsonConf)
+ {
+ if (!member.contains("name") || !member.contains("path"))
+ {
+ log<level::ERR>(
+ "Missing required fan presence properties",
+ entry("REQUIRED_PROPERTIES=%s", "{name, path}"));
+ throw std::runtime_error(
+ "Missing required fan presence properties");
+ }
+ // Create a fan object
+ _fans.emplace_back(std::make_tuple(member["name"], member["path"]));
+ }
+}
+
} // namespace presence
} // namespace fan
} // namespace phosphor