Matt Spinler | 974c916 | 2017-08-04 08:36:37 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "utility.hpp" |
| 17 | |
| 18 | namespace witherspoon |
| 19 | { |
| 20 | namespace power |
| 21 | { |
| 22 | namespace util |
| 23 | { |
| 24 | |
| 25 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 26 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 27 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 28 | |
| 29 | using namespace phosphor::logging; |
Matt Spinler | 48b4a43 | 2017-08-04 11:57:37 -0500 | [diff] [blame] | 30 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 31 | std::string getService(const std::string& path, const std::string& interface, |
Matt Spinler | 974c916 | 2017-08-04 08:36:37 -0500 | [diff] [blame] | 32 | sdbusplus::bus::bus& bus) |
| 33 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 34 | auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 35 | MAPPER_INTERFACE, "GetObject"); |
Matt Spinler | 974c916 | 2017-08-04 08:36:37 -0500 | [diff] [blame] | 36 | |
| 37 | method.append(path); |
| 38 | method.append(std::vector<std::string>({interface})); |
| 39 | |
| 40 | auto reply = bus.call(method); |
Matt Spinler | 974c916 | 2017-08-04 08:36:37 -0500 | [diff] [blame] | 41 | |
| 42 | std::map<std::string, std::vector<std::string>> response; |
| 43 | reply.read(response); |
| 44 | |
| 45 | if (response.empty()) |
| 46 | { |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 47 | log<level::ERR>("Error in mapper response for getting service name", |
| 48 | entry("PATH=%s", path.c_str()), |
| 49 | entry("INTERFACE=%s", interface.c_str())); |
Matt Spinler | 974c916 | 2017-08-04 08:36:37 -0500 | [diff] [blame] | 50 | return std::string{}; |
| 51 | } |
| 52 | |
| 53 | return response.begin()->first; |
| 54 | } |
| 55 | |
Matt Spinler | f0f02b9 | 2018-10-25 16:12:43 -0500 | [diff] [blame] | 56 | } // namespace util |
| 57 | } // namespace power |
| 58 | } // namespace witherspoon |