Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -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 <string> |
| 17 | #include "utility.hpp" |
| 18 | |
| 19 | namespace phosphor |
| 20 | { |
| 21 | namespace fan |
| 22 | { |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 23 | namespace util |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 24 | { |
| 25 | |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 26 | using namespace std::string_literals; |
| 27 | |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame^] | 28 | using namespace phosphor::logging; |
| 29 | using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: |
| 30 | Error::InternalFailure; |
| 31 | |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 32 | //TODO Should get these from phosphor-objmgr config.h |
| 33 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 34 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 35 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 36 | |
| 37 | //TODO Should get these from phosphor-inventory-manager config.h |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 38 | const auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"s; |
| 39 | const auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"s; |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 40 | |
| 41 | std::string getInvService(sdbusplus::bus::bus& bus) |
| 42 | { |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 43 | return getService(INVENTORY_PATH, INVENTORY_INTF, bus); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | std::string getService(const std::string& path, |
| 48 | const std::string& interface, |
| 49 | sdbusplus::bus::bus& bus) |
| 50 | { |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 51 | auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, |
| 52 | MAPPER_PATH, |
| 53 | MAPPER_INTERFACE, |
| 54 | "GetObject"); |
| 55 | |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 56 | mapperCall.append(path); |
| 57 | mapperCall.append(std::vector<std::string>({interface})); |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 58 | |
| 59 | auto mapperResponseMsg = bus.call(mapperCall); |
| 60 | if (mapperResponseMsg.is_method_error()) |
| 61 | { |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame^] | 62 | log<level::ERR>("Error in mapper call to get service name", |
| 63 | entry("PATH=%s", path.c_str()), |
| 64 | entry("INTERFACE=%s", interface.c_str())); |
| 65 | elog<InternalFailure>(); |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 66 | } |
| 67 | |
Matt Spinler | 5cfdf94 | 2017-04-10 14:25:47 -0500 | [diff] [blame] | 68 | |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 69 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 70 | mapperResponseMsg.read(mapperResponse); |
| 71 | |
| 72 | if (mapperResponse.empty()) |
| 73 | { |
Dinesh Chinari | 618027a | 2017-06-26 23:26:50 -0500 | [diff] [blame^] | 74 | log<level::ERR>( |
| 75 | "Error in mapper response for getting service name", |
| 76 | entry("PATH=%s", path.c_str()), |
| 77 | entry("INTERFACE=%s", interface.c_str())); |
| 78 | elog<InternalFailure>(); |
Brandon Wyman | 5914f65 | 2017-03-16 18:17:07 -0500 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return mapperResponse.begin()->first; |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | } |
| 86 | } |