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