1ddd54428SLei YU #include "utils.hpp"
2ddd54428SLei YU
3ddd54428SLei YU namespace phosphor
4ddd54428SLei YU {
5ddd54428SLei YU namespace time
6ddd54428SLei YU {
7ddd54428SLei YU
8ddd54428SLei YU namespace // anonymous
9ddd54428SLei YU {
10*864e173eSPavithra Barithaya constexpr auto mapperBusname = "xyz.openbmc_project.ObjectMapper";
11*864e173eSPavithra Barithaya constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
12*864e173eSPavithra Barithaya constexpr auto mapperInterface = "xyz.openbmc_project.ObjectMapper";
13ab4cc6a5SGunnar Mills } // namespace
14ddd54428SLei YU
15ddd54428SLei YU namespace utils
16ddd54428SLei YU {
17ddd54428SLei YU
18dd42c7faSPavithra Barithaya PHOSPHOR_LOG2_USING;
19dd42c7faSPavithra Barithaya
getService(sdbusplus::bus_t & bus,const char * path,const char * interface)2038679266SPatrick Williams std::string getService(sdbusplus::bus_t& bus, const char* path,
21dd8e9e40SLei YU const char* interface)
22dd8e9e40SLei YU {
23*864e173eSPavithra Barithaya auto mapper = bus.new_method_call(mapperBusname, mapperPath,
24*864e173eSPavithra Barithaya mapperInterface, "GetObject");
25dd8e9e40SLei YU
26dd8e9e40SLei YU mapper.append(path, std::vector<std::string>({interface}));
2786c83f38SLei YU try
28dd8e9e40SLei YU {
2986c83f38SLei YU auto mapperResponseMsg = bus.call(mapper);
30dd8e9e40SLei YU
317aa715b2SEd Tanous std::vector<std::pair<std::string, std::vector<std::string>>>
327aa715b2SEd Tanous mapperResponse;
33dd8e9e40SLei YU mapperResponseMsg.read(mapperResponse);
34dd8e9e40SLei YU if (mapperResponse.empty())
35dd8e9e40SLei YU {
36dd42c7faSPavithra Barithaya error("Error reading mapper response");
3786c83f38SLei YU throw std::runtime_error("Error reading mapper response");
38dd8e9e40SLei YU }
39261525d1SGeorge Liu
407aa715b2SEd Tanous return mapperResponse[0].first;
41dd8e9e40SLei YU }
4238679266SPatrick Williams catch (const sdbusplus::exception_t& ex)
4386c83f38SLei YU {
44dd42c7faSPavithra Barithaya error(
45947b5346SGeorge Liu "Mapper call failed: path:{PATH}, interface:{INTF}, error:{ERROR}",
46947b5346SGeorge Liu "PATH", path, "INTF", interface, "ERROR", ex);
4786c83f38SLei YU throw std::runtime_error("Mapper call failed");
4886c83f38SLei YU }
4986c83f38SLei YU }
50dd8e9e40SLei YU
getSubTree(sdbusplus::bus_t & bus,const std::string & root,const Interfaces & interfaces,int32_t depth)51dc746c0bSGeorge Liu MapperResponse getSubTree(sdbusplus::bus_t& bus, const std::string& root,
52dc746c0bSGeorge Liu const Interfaces& interfaces, int32_t depth)
53dc746c0bSGeorge Liu {
54*864e173eSPavithra Barithaya auto mapperCall = bus.new_method_call(mapperBusname, mapperPath,
55*864e173eSPavithra Barithaya mapperInterface, "GetSubTree");
56dc746c0bSGeorge Liu mapperCall.append(root);
57dc746c0bSGeorge Liu mapperCall.append(depth);
58dc746c0bSGeorge Liu mapperCall.append(interfaces);
59dc746c0bSGeorge Liu
60dc746c0bSGeorge Liu auto response = bus.call(mapperCall);
61dc746c0bSGeorge Liu
62dc746c0bSGeorge Liu MapperResponse result;
63dc746c0bSGeorge Liu response.read(result);
64dc746c0bSGeorge Liu return result;
65dc746c0bSGeorge Liu }
66dc746c0bSGeorge Liu
strToMode(const std::string & mode)67ddd54428SLei YU Mode strToMode(const std::string& mode)
68ddd54428SLei YU {
69ad14354fSLei YU return ModeSetting::convertMethodFromString(mode);
70ddd54428SLei YU }
71ddd54428SLei YU
modeToStr(Mode mode)72ad14354fSLei YU std::string modeToStr(Mode mode)
73ddd54428SLei YU {
74ab4cc6a5SGunnar Mills return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(
75ab4cc6a5SGunnar Mills mode);
76ddd54428SLei YU }
77ddd54428SLei YU
78ddd54428SLei YU } // namespace utils
79ddd54428SLei YU } // namespace time
80ddd54428SLei YU } // namespace phosphor
81