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::vector<std::pair<std::string, std::vector<std::string>>> 51 mapperResponse; 52 mapperResponseMsg.read(mapperResponse); 53 if (mapperResponse.empty()) 54 { 55 using namespace xyz::openbmc_project::Time::Internal; 56 elog<MethodErr>(MethodError::METHOD_NAME("GetObject"), 57 MethodError::PATH(path), 58 MethodError::INTERFACE(interface), 59 MethodError::MISC("Error reading mapper response")); 60 } 61 if (mapperResponse.size() < 1){ 62 return ""; 63 } 64 return mapperResponse[0].first; 65 } 66 67 Mode strToMode(const std::string& mode) 68 { 69 return ModeSetting::convertMethodFromString(mode); 70 } 71 72 Owner strToOwner(const std::string& owner) 73 { 74 return OwnerSetting::convertOwnersFromString(owner); 75 } 76 77 std::string modeToStr(Mode mode) 78 { 79 return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(mode); 80 } 81 82 std::string ownerToStr(Owner owner) 83 { 84 return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(owner); 85 } 86 87 } // namespace utils 88 } // namespace time 89 } // namespace phosphor 90