#pragma once #include "dbus_singleton.hpp" #include "error_messages.hpp" #include #include #include #include #include #include #include namespace redfish { namespace location_util { /** * @brief Fill out location info of a resource by requesting data from the * given D-Bus object. * * @param[in] interface Location type interface. * * @return location if interface is supported Connector, otherwise, return * std::nullopt. */ inline std::optional getLocationType(const std::string& interface) { if (interface == "xyz.openbmc_project.Inventory.Connector.Embedded") { return "Embedded"; } if (interface == "xyz.openbmc_project.Inventory.Connector.Slot") { return "Slot"; } return std::nullopt; } inline void afterGetLocationCode( const std::shared_ptr& asyncResp, const nlohmann::json::json_pointer& location, const boost::system::error_code& ec, const std::string& property) { if (ec) { if (ec.value() != EBADR) { BMCWEB_LOG_ERROR("DBUS response error for Location"); messages::internalError(asyncResp->res); return; } BMCWEB_LOG_WARNING("DBUS response error for Location with EBADR error"); return; } asyncResp->res.jsonValue[location]["PartLocation"]["ServiceLabel"] = property; } /** * @brief Fill out location code of a resource by requesting data from the * given D-Bus object. * * @param[in,out] asyncResp Async HTTP response. * @param[in] service D-Bus service to query. * @param[in] objPath D-Bus object to query. * @param[in] location Json path of where to find the location * property. */ inline void getLocationCode(const std::shared_ptr& asyncResp, const std::string& service, const std::string& objPath, const nlohmann::json::json_pointer& location) { sdbusplus::asio::getProperty( *crow::connections::systemBus, service, objPath, "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", std::bind_front(afterGetLocationCode, asyncResp, location)); } } // namespace location_util } // namespace redfish