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
diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp
index 3823089..9351f6a 100644
--- a/redfish-core/lib/cpudimm.hpp
+++ b/redfish-core/lib/cpudimm.hpp
@@ -20,6 +20,7 @@
#include <boost/container/flat_map.hpp>
#include <boost/format.hpp>
#include <node.hpp>
+#include <utils/collection.hpp>
#include <utils/json_utils.hpp>
namespace redfish
@@ -29,46 +30,6 @@
std::string,
boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>;
-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);
-}
-
inline void
getCpuDataByInterface(const std::shared_ptr<AsyncResp>& aResp,
const InterfacesProperties& cpuInterfacesProperties)
@@ -1219,9 +1180,10 @@
res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Processors/";
auto asyncResp = std::make_shared<AsyncResp>(res);
- getResourceList(asyncResp, "Processors",
- {"xyz.openbmc_project.Inventory.Item.Cpu",
- "xyz.openbmc_project.Inventory.Item.Accelerator"});
+ collection_util::getResourceList(
+ asyncResp, "Processors",
+ {"xyz.openbmc_project.Inventory.Item.Cpu",
+ "xyz.openbmc_project.Inventory.Item.Accelerator"});
}
};
@@ -1302,8 +1264,8 @@
res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Memory";
auto asyncResp = std::make_shared<AsyncResp>(res);
- getResourceList(asyncResp, "Memory",
- {"xyz.openbmc_project.Inventory.Item.Dimm"});
+ collection_util::getResourceList(
+ asyncResp, "Memory", {"xyz.openbmc_project.Inventory.Item.Dimm"});
}
};