blob: 31d5da10096e95ad2f15736cb99c4ee7342470f7 [file] [log] [blame]
Gunnar Mills116bcc52020-10-14 15:23:42 -05001#pragma once
2
3#include <boost/container/flat_map.hpp>
4
5#include <string>
6#include <vector>
7
8namespace redfish
9{
10namespace collection_util
11{
12
13inline void getResourceList(std::shared_ptr<AsyncResp> aResp,
14 const std::string& subclass,
15 const std::vector<const char*>& collectionName)
16{
17 BMCWEB_LOG_DEBUG << "Get available system cpu/mem resources.";
18 crow::connections::systemBus->async_method_call(
19 [subclass, aResp{std::move(aResp)}](
20 const boost::system::error_code ec,
21 const boost::container::flat_map<
22 std::string, boost::container::flat_map<
23 std::string, std::vector<std::string>>>&
24 subtree) {
25 if (ec)
26 {
27 BMCWEB_LOG_DEBUG << "DBUS response error";
28 messages::internalError(aResp->res);
29 return;
30 }
31 nlohmann::json& members = aResp->res.jsonValue["Members"];
32 members = nlohmann::json::array();
33
34 for (const auto& object : subtree)
35 {
36 auto iter = object.first.rfind("/");
37 if ((iter != std::string::npos) && (iter < object.first.size()))
38 {
39 members.push_back(
40 {{"@odata.id", "/redfish/v1/Systems/system/" +
41 subclass + "/" +
42 object.first.substr(iter + 1)}});
43 }
44 }
45 aResp->res.jsonValue["Members@odata.count"] = members.size();
46 },
47 "xyz.openbmc_project.ObjectMapper",
48 "/xyz/openbmc_project/object_mapper",
49 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
50 "/xyz/openbmc_project/inventory", 0, collectionName);
51}
52
53} // namespace collection_util
54} // namespace redfish