-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutils.cpp
80 lines (66 loc) · 2.11 KB
/
utils.cpp
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
#include "utils.hpp"
namespace phosphor
{
namespace time
{
namespace // anonymous
{
constexpr auto mapperBusname = "xyz.openbmc_project.ObjectMapper";
constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
} // namespace
namespace utils
{
PHOSPHOR_LOG2_USING;
std::string getService(sdbusplus::bus_t& bus, const char* path,
const char* interface)
{
auto mapper = bus.new_method_call(mapperBusname, mapperPath,
mapperInterface, "GetObject");
mapper.append(path, std::vector<std::string>({interface}));
try
{
auto mapperResponseMsg = bus.call(mapper);
std::vector<std::pair<std::string, std::vector<std::string>>>
mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
error("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
return mapperResponse[0].first;
}
catch (const sdbusplus::exception_t& ex)
{
error(
"Mapper call failed: path:{PATH}, interface:{INTF}, error:{ERROR}",
"PATH", path, "INTF", interface, "ERROR", ex);
throw std::runtime_error("Mapper call failed");
}
}
MapperResponse getSubTree(sdbusplus::bus_t& bus, const std::string& root,
const Interfaces& interfaces, int32_t depth)
{
auto mapperCall = bus.new_method_call(mapperBusname, mapperPath,
mapperInterface, "GetSubTree");
mapperCall.append(root);
mapperCall.append(depth);
mapperCall.append(interfaces);
auto response = bus.call(mapperCall);
MapperResponse result;
response.read(result);
return result;
}
Mode strToMode(const std::string& mode)
{
return ModeSetting::convertMethodFromString(mode);
}
std::string modeToStr(Mode mode)
{
return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(
mode);
}
} // namespace utils
} // namespace time
} // namespace phosphor