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