1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#pragma once
#include "dbus_singleton.hpp"
#include "error_messages.hpp"
#include <async_resp.hpp>
#include <boost/system/error_code.hpp>
#include <sdbusplus/asio/property.hpp>
#include <functional>
#include <memory>
#include <optional>
#include <string>
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<std::string> 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<bmcweb::AsyncResp>& 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<bmcweb::AsyncResp>& asyncResp,
const std::string& service,
const std::string& objPath,
const nlohmann::json::json_pointer& location)
{
sdbusplus::asio::getProperty<std::string>(
*crow::connections::systemBus, service, objPath,
"xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
std::bind_front(afterGetLocationCode, asyncResp, location));
}
} // namespace location_util
} // namespace redfish
|