Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 3 | #include <phosphor-logging/elog.hpp> |
| 4 | #include <phosphor-logging/elog-errors.hpp> |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 6 | #include <xyz/openbmc_project/Common/error.hpp> |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 7 | |
| 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace time |
| 12 | { |
| 13 | |
| 14 | namespace // anonymous |
| 15 | { |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 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"; |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | namespace utils |
| 22 | { |
| 23 | |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 24 | using InvalidArgumentError = |
| 25 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 26 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 27 | using namespace phosphor::logging; |
| 28 | |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 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 | { |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 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({})); |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 51 | mapperResponseMsg.read(mapperResponse); |
| 52 | if (mapperResponse.empty()) |
| 53 | { |
Lei YU | 86d8041 | 2017-07-12 13:12:12 +0800 | [diff] [blame] | 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")); |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | return mapperResponse.begin()->first; |
| 62 | } |
| 63 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 64 | Mode strToMode(const std::string& mode) |
| 65 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 66 | return ModeSetting::convertMethodFromString(mode); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | Owner strToOwner(const std::string& owner) |
| 70 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 71 | return OwnerSetting::convertOwnersFromString(owner); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 74 | std::string modeToStr(Mode mode) |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 75 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 76 | return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(mode); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 77 | } |
| 78 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 79 | std::string ownerToStr(Owner owner) |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 80 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 81 | return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(owner); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | } // namespace utils |
| 85 | } // namespace time |
| 86 | } // namespace phosphor |