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