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