Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 1 | #include "utils.hpp" |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 2 | |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 3 | #include <iostream> |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 4 | #include <phosphor-logging/log.hpp> |
| 5 | #include <sdbusplus/server.hpp> |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace vpd |
| 10 | { |
| 11 | |
| 12 | namespace inventory |
| 13 | { |
| 14 | |
| 15 | auto getPIMService() |
| 16 | { |
| 17 | auto bus = sdbusplus::bus::new_default(); |
| 18 | auto mapper = |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 19 | bus.new_method_call("xyz.openbmc_project.ObjectMapper", |
| 20 | "/xyz/openbmc_project/object_mapper", |
| 21 | "xyz.openbmc_project.ObjectMapper", "GetObject"); |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 22 | |
| 23 | mapper.append(pimPath); |
| 24 | mapper.append(std::vector<std::string>({pimIntf})); |
| 25 | |
| 26 | auto result = bus.call(mapper); |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 27 | if (result.is_method_error()) |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 28 | { |
| 29 | throw std::runtime_error("ObjectMapper GetObject failed"); |
| 30 | } |
| 31 | |
| 32 | std::map<std::string, std::vector<std::string>> response; |
| 33 | result.read(response); |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 34 | if (response.empty()) |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 35 | { |
| 36 | throw std::runtime_error("ObjectMapper GetObject bad response"); |
| 37 | } |
| 38 | |
| 39 | return response.begin()->first; |
| 40 | } |
| 41 | |
| 42 | void callPIM(ObjectMap&& objects) |
| 43 | { |
| 44 | std::string service; |
| 45 | |
| 46 | try |
| 47 | { |
| 48 | service = getPIMService(); |
| 49 | auto bus = sdbusplus::bus::new_default(); |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 50 | auto pimMsg = |
| 51 | bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify"); |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 52 | pimMsg.append(std::move(objects)); |
| 53 | auto result = bus.call(pimMsg); |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 54 | if (result.is_method_error()) |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 55 | { |
| 56 | std::cerr << "PIM Notify() failed\n"; |
| 57 | } |
| 58 | } |
| 59 | catch (const std::runtime_error& e) |
| 60 | { |
| 61 | using namespace phosphor::logging; |
| 62 | log<level::ERR>(e.what()); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } // namespace inventory |
| 67 | |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 68 | } // namespace vpd |
| 69 | } // namespace openpower |