diff options
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/include/utils/pcie_util.hpp | 76 | ||||
-rw-r--r-- | redfish-core/lib/pcie.hpp | 40 | ||||
-rw-r--r-- | redfish-core/lib/systems.hpp | 4 |
3 files changed, 78 insertions, 42 deletions
diff --git a/redfish-core/include/utils/pcie_util.hpp b/redfish-core/include/utils/pcie_util.hpp new file mode 100644 index 0000000000..51423b435f --- /dev/null +++ b/redfish-core/include/utils/pcie_util.hpp @@ -0,0 +1,76 @@ +#pragma once + +#include "async_resp.hpp" +#include "dbus_utility.hpp" +#include "error_messages.hpp" +#include "http/utility.hpp" + +#include <boost/system/error_code.hpp> +#include <boost/url/format.hpp> +#include <nlohmann/json.hpp> + +#include <array> +#include <memory> +#include <string> +#include <string_view> + +namespace redfish +{ +namespace pcie_util +{ + +/** + * @brief Populate the PCIe Device list from a GetSubTreePaths search of + * inventory + * + * @param[i,o] aResp Async response object + * @param[i] Name Key to store the list of PCIe devices in aResp + * + * @return void + */ + +inline void + getPCIeDeviceList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::string& name) +{ + static constexpr std::array<std::string_view, 1> pcieDeviceInterface = { + "xyz.openbmc_project.Inventory.Item.PCIeDevice"}; + + dbus::utility::getSubTreePaths( + "/xyz/openbmc_project/inventory", 0, pcieDeviceInterface, + [asyncResp, name](const boost::system::error_code& ec, + const dbus::utility::MapperGetSubTreePathsResponse& + pcieDevicePaths) { + if (ec) + { + BMCWEB_LOG_DEBUG << "no PCIe device paths found ec: " + << ec.message(); + // Not an error, system just doesn't have PCIe info + return; + } + nlohmann::json& pcieDeviceList = asyncResp->res.jsonValue[name]; + pcieDeviceList = nlohmann::json::array(); + for (const std::string& pcieDevicePath : pcieDevicePaths) + { + size_t devStart = pcieDevicePath.rfind('/'); + if (devStart == std::string::npos) + { + continue; + } + + std::string devName = pcieDevicePath.substr(devStart + 1); + if (devName.empty()) + { + continue; + } + nlohmann::json::object_t pcieDevice; + pcieDevice["@odata.id"] = boost::urls::format( + "/redfish/v1/Systems/system/PCIeDevices/{}", devName); + pcieDeviceList.emplace_back(std::move(pcieDevice)); + } + asyncResp->res.jsonValue[name + "@odata.count"] = pcieDeviceList.size(); + }); +} + +} // namespace pcie_util +} // namespace redfish diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index 93b15c3abe..f98d6c8797 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -96,46 +96,6 @@ static inline void getValidPCIeDevicePath( }); } -static inline void - getPCIeDeviceList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& name) -{ - dbus::utility::getSubTreePaths( - inventoryPath, 0, pcieDeviceInterface, - [asyncResp, name](const boost::system::error_code& ec, - const dbus::utility::MapperGetSubTreePathsResponse& - pcieDevicePaths) { - if (ec) - { - BMCWEB_LOG_DEBUG << "no PCIe device paths found ec: " - << ec.message(); - // Not an error, system just doesn't have PCIe info - return; - } - nlohmann::json& pcieDeviceList = asyncResp->res.jsonValue[name]; - pcieDeviceList = nlohmann::json::array(); - for (const std::string& pcieDevicePath : pcieDevicePaths) - { - size_t devStart = pcieDevicePath.rfind('/'); - if (devStart == std::string::npos) - { - continue; - } - - std::string devName = pcieDevicePath.substr(devStart + 1); - if (devName.empty()) - { - continue; - } - nlohmann::json::object_t pcieDevice; - pcieDevice["@odata.id"] = boost::urls::format( - "/redfish/v1/Systems/system/PCIeDevices/{}", devName); - pcieDeviceList.emplace_back(std::move(pcieDevice)); - } - asyncResp->res.jsonValue[name + "@odata.count"] = pcieDeviceList.size(); - }); -} - static inline void handlePCIeDeviceCollectionGet( crow::App& app, const crow::Request& req, const std::shared_ptr<bmcweb::AsyncResp>& aResp, diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 573bf881db..19444b29c1 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -23,12 +23,12 @@ #include "health.hpp" #include "hypervisor_system.hpp" #include "led.hpp" -#include "pcie.hpp" #include "query.hpp" #include "redfish_util.hpp" #include "registries/privilege_registry.hpp" #include "utils/dbus_utils.hpp" #include "utils/json_utils.hpp" +#include "utils/pcie_util.hpp" #include "utils/sw_utils.hpp" #include "utils/time_utils.hpp" @@ -3182,7 +3182,7 @@ inline void requestRoutesSystems(App& app) getBootProperties(asyncResp); getBootProgress(asyncResp); getBootProgressLastStateTime(asyncResp); - getPCIeDeviceList(asyncResp, "PCIeDevices"); + pcie_util::getPCIeDeviceList(asyncResp, "PCIeDevices"); getHostWatchdogTimer(asyncResp); getPowerRestorePolicy(asyncResp); getAutomaticRetryPolicy(asyncResp); |