Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 1 | #include "utils.hpp" |
| 2 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 3 | namespace phosphor |
| 4 | { |
| 5 | namespace time |
| 6 | { |
| 7 | |
| 8 | namespace // anonymous |
| 9 | { |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 10 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 11 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 12 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 13 | } // namespace |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 14 | |
| 15 | namespace utils |
| 16 | { |
| 17 | |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 18 | std::string getService(sdbusplus::bus_t& bus, const char* path, |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 19 | const char* interface) |
| 20 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 21 | auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 22 | MAPPER_INTERFACE, "GetObject"); |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 23 | |
| 24 | mapper.append(path, std::vector<std::string>({interface})); |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 25 | try |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 26 | { |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 27 | auto mapperResponseMsg = bus.call(mapper); |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 28 | |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 29 | std::vector<std::pair<std::string, std::vector<std::string>>> |
| 30 | mapperResponse; |
| 31 | mapperResponseMsg.read(mapperResponse); |
| 32 | if (mapperResponse.empty()) |
| 33 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 34 | lg2::error("Error reading mapper response"); |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 35 | throw std::runtime_error("Error reading mapper response"); |
| 36 | } |
George Liu | 261525d | 2022-07-01 17:02:55 +0800 | [diff] [blame] | 37 | |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 38 | return mapperResponse[0].first; |
| 39 | } |
Patrick Williams | 3867926 | 2022-07-22 19:26:55 -0500 | [diff] [blame^] | 40 | catch (const sdbusplus::exception_t& ex) |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 41 | { |
George Liu | 947b534 | 2022-07-01 16:12:18 +0800 | [diff] [blame] | 42 | lg2::error( |
| 43 | "Mapper call failed: path:{PATH}, interface:{INTF}, error:{ERROR}", |
| 44 | "PATH", path, "INTF", interface, "ERROR", ex); |
Lei YU | 86c83f3 | 2018-07-13 15:14:56 +0800 | [diff] [blame] | 45 | throw std::runtime_error("Mapper call failed"); |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 46 | } |
Lei YU | dd8e9e4 | 2017-04-19 17:46:58 +0800 | [diff] [blame] | 47 | } |
| 48 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 49 | Mode strToMode(const std::string& mode) |
| 50 | { |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 51 | return ModeSetting::convertMethodFromString(mode); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 52 | } |
| 53 | |
Lei YU | ad14354 | 2017-07-25 14:27:07 +0800 | [diff] [blame] | 54 | std::string modeToStr(Mode mode) |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 55 | { |
Gunnar Mills | ab4cc6a | 2018-09-14 14:42:39 -0500 | [diff] [blame] | 56 | return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage( |
| 57 | mode); |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 58 | } |
| 59 | |
Lei YU | ddd5442 | 2017-04-18 16:38:44 +0800 | [diff] [blame] | 60 | } // namespace utils |
| 61 | } // namespace time |
| 62 | } // namespace phosphor |