#include "utils.hpp" #include namespace phosphor { namespace time { namespace // anonymous { constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; } // namespace namespace utils { using namespace phosphor::logging; std::string getService(sdbusplus::bus::bus& bus, const char* path, const char* interface) { auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject"); mapper.append(path, std::vector({interface})); try { auto mapperResponseMsg = bus.call(mapper); std::vector>> mapperResponse; mapperResponseMsg.read(mapperResponse); if (mapperResponse.empty()) { log("Error reading mapper response"); throw std::runtime_error("Error reading mapper response"); } if (mapperResponse.size() < 1) { return ""; } return mapperResponse[0].first; } catch (const sdbusplus::exception::SdBusError& ex) { log("Mapper call failed", entry("METHOD=%d", "GetObject"), entry("PATH=%s", path), entry("INTERFACE=%s", interface)); throw std::runtime_error("Mapper call failed"); } } Mode strToMode(const std::string& mode) { return ModeSetting::convertMethodFromString(mode); } Owner strToOwner(const std::string& owner) { return OwnerSetting::convertOwnersFromString(owner); } std::string modeToStr(Mode mode) { return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage( mode); } std::string ownerToStr(Owner owner) { return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage( owner); } } // namespace utils } // namespace time } // namespace phosphor