Move getResourceList to Util class
Allows a future commit to separate memory and process
functionality.
Tested: Top commit tested.
Change-Id: Icd3d26c054adf0477c938a7795a42b102cc05098
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
new file mode 100644
index 0000000..31d5da1
--- /dev/null
+++ b/redfish-core/include/utils/collection.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <boost/container/flat_map.hpp>
+
+#include <string>
+#include <vector>
+
+namespace redfish
+{
+namespace collection_util
+{
+
+inline void getResourceList(std::shared_ptr<AsyncResp> aResp,
+ const std::string& subclass,
+ const std::vector<const char*>& collectionName)
+{
+ BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources.";
+ crow::connections::systemBus->async_method_call(
+ [subclass, aResp{std::move(aResp)}](
+ const boost::system::error_code ec,
+ const boost::container::flat_map<
+ std::string, boost::container::flat_map<
+ std::string, std::vector<std::string>>>&
+ subtree) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error";
+ messages::internalError(aResp->res);
+ return;
+ }
+ nlohmann::json& members = aResp->res.jsonValue["Members"];
+ members = nlohmann::json::array();
+
+ for (const auto& object : subtree)
+ {
+ auto iter = object.first.rfind("/");
+ if ((iter != std::string::npos) && (iter < object.first.size()))
+ {
+ members.push_back(
+ {{"@odata.id", "/redfish/v1/Systems/system/" +
+ subclass + "/" +
+ object.first.substr(iter + 1)}});
+ }
+ }
+ aResp->res.jsonValue["Members@odata.count"] = members.size();
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetSubTree",
+ "/xyz/openbmc_project/inventory", 0, collectionName);
+}
+
+} // namespace collection_util
+} // namespace redfish