|
| 1 | + |
| 2 | +#pragma once |
| 3 | +#include "dbus_utility.hpp" |
| 4 | +#include "error_messages.hpp" |
| 5 | +#include "logging.hpp" |
| 6 | + |
| 7 | +#include <async_resp.hpp> |
| 8 | +#include <boost/system/error_code.hpp> |
| 9 | + |
| 10 | +#include <memory> |
| 11 | +#include <string> |
| 12 | + |
| 13 | +namespace redfish |
| 14 | +{ |
| 15 | +namespace name_util |
| 16 | +{ |
| 17 | + |
| 18 | +/** |
| 19 | + * @brief Populate the collection "Members" from a GetSubTreePaths search of |
| 20 | + * inventory |
| 21 | + * |
| 22 | + * @param[i,o] asyncResp Async response object |
| 23 | + * @param[i] path D-bus object path to find the pretty name |
| 24 | + * @param[i] services Service to exporting the D-bus object path |
| 25 | + * @param[i] namePath Json pointer to the name field to update. |
| 26 | + * |
| 27 | + * @return void |
| 28 | + */ |
| 29 | +inline void getPrettyName(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 30 | + const std::string& path, |
| 31 | + const std::string& serviceName, |
| 32 | + const nlohmann::json::json_pointer& namePath) |
| 33 | +{ |
| 34 | + BMCWEB_LOG_DEBUG("Get PrettyName for: {}", path); |
| 35 | + |
| 36 | + dbus::utility::getProperty<std::string>( |
| 37 | + serviceName, path, "xyz.openbmc_project.Inventory.Item", "PrettyName", |
| 38 | + [asyncResp, path, namePath](const boost::system::error_code& ec, |
| 39 | + const std::string& prettyName) { |
| 40 | + if (ec) |
| 41 | + { |
| 42 | + BMCWEB_LOG_DEBUG("DBUS response error : {}", ec.value()); |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + if (prettyName.empty()) |
| 47 | + { |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + BMCWEB_LOG_DEBUG("Pretty Name: {}", prettyName); |
| 52 | + |
| 53 | + asyncResp->res.jsonValue[namePath] = prettyName; |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * @brief Populate the collection "Members" from a GetSubTreePaths search of |
| 59 | + * inventory |
| 60 | + * |
| 61 | + * @param[i,o] asyncResp Async response object |
| 62 | + * @param[i] path D-bus object path to find the pretty name |
| 63 | + * @param[i] services List of services to exporting the D-bus object path |
| 64 | + * @param[i] namePath Json pointer to the name field to update. |
| 65 | + * |
| 66 | + * @return void |
| 67 | + */ |
| 68 | +inline void getPrettyName(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 69 | + const std::string& path, |
| 70 | + const dbus::utility::MapperServiceMap& services, |
| 71 | + const nlohmann::json::json_pointer& namePath) |
| 72 | +{ |
| 73 | + BMCWEB_LOG_DEBUG("Get PrettyName with MapperServiceMap for: {}", path); |
| 74 | + |
| 75 | + // Ensure we only got one service back |
| 76 | + if (services.size() != 1) |
| 77 | + { |
| 78 | + BMCWEB_LOG_ERROR("Invalid Service Size {}", services.size()); |
| 79 | + for (const auto& service : services) |
| 80 | + { |
| 81 | + BMCWEB_LOG_ERROR("Invalid Service Name: {}", service.first); |
| 82 | + } |
| 83 | + if (asyncResp) |
| 84 | + { |
| 85 | + messages::internalError(asyncResp->res); |
| 86 | + } |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + getPrettyName(asyncResp, path, services[0].first, namePath); |
| 91 | +} |
| 92 | + |
| 93 | +} // namespace name_util |
| 94 | +} // namespace redfish |
0 commit comments