#pragma once #include #include #include namespace redfish { namespace collection_util { /** * @brief Populate the collection "Members" from a GetSubTree search of * inventory * * @param[i,o] aResp Async response object * @param[i] collectionPath Redfish collection path which is used for the * Members Redfish Path * @param[i] interfaces List of interfaces to constrain the GetSubTree search * * @return void */ inline void getCollectionMembers(std::shared_ptr aResp, const std::string& collectionPath, const std::vector& interfaces) { BMCWEB_LOG_DEBUG << "Get collection members for: " << collectionPath; crow::connections::systemBus->async_method_call( [collectionPath, 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>>& 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", collectionPath + "/" + 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, interfaces); } } // namespace collection_util } // namespace redfish