1 #include "utils.hpp"
2 
3 namespace phosphor
4 {
5 namespace time
6 {
7 
8 namespace // anonymous
9 {
10 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
11 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
12 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
13 } // namespace
14 
15 namespace utils
16 {
17 
18 std::string getService(sdbusplus::bus_t& bus, const char* path,
19                        const char* interface)
20 {
21     auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
22                                       MAPPER_INTERFACE, "GetObject");
23 
24     mapper.append(path, std::vector<std::string>({interface}));
25     try
26     {
27         auto mapperResponseMsg = bus.call(mapper);
28 
29         std::vector<std::pair<std::string, std::vector<std::string>>>
30             mapperResponse;
31         mapperResponseMsg.read(mapperResponse);
32         if (mapperResponse.empty())
33         {
34             lg2::error("Error reading mapper response");
35             throw std::runtime_error("Error reading mapper response");
36         }
37 
38         return mapperResponse[0].first;
39     }
40     catch (const sdbusplus::exception_t& ex)
41     {
42         lg2::error(
43             "Mapper call failed: path:{PATH}, interface:{INTF}, error:{ERROR}",
44             "PATH", path, "INTF", interface, "ERROR", ex);
45         throw std::runtime_error("Mapper call failed");
46     }
47 }
48 
49 Mode strToMode(const std::string& mode)
50 {
51     return ModeSetting::convertMethodFromString(mode);
52 }
53 
54 std::string modeToStr(Mode mode)
55 {
56     return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(
57         mode);
58 }
59 
60 } // namespace utils
61 } // namespace time
62 } // namespace phosphor
63