Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 1 | #include "common_utility.hpp" |
| 2 | |
| 3 | #include "const.hpp" |
| 4 | |
| 5 | #include <iostream> |
| 6 | #include <phosphor-logging/log.hpp> |
| 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace vpd |
| 11 | { |
| 12 | namespace common |
| 13 | { |
| 14 | namespace utility |
| 15 | { |
| 16 | using namespace constants; |
| 17 | using namespace inventory; |
| 18 | using namespace phosphor::logging; |
| 19 | |
| 20 | std::string getService(sdbusplus::bus::bus& bus, const std::string& path, |
| 21 | const std::string& interface) |
| 22 | { |
| 23 | auto mapper = bus.new_method_call(mapperDestination, mapperObjectPath, |
| 24 | mapperInterface, "GetObject"); |
| 25 | mapper.append(path, std::vector<std::string>({interface})); |
| 26 | |
| 27 | std::map<std::string, std::vector<std::string>> response; |
| 28 | try |
| 29 | { |
| 30 | auto reply = bus.call(mapper); |
| 31 | reply.read(response); |
| 32 | } |
| 33 | catch (const sdbusplus::exception::SdBusError& e) |
| 34 | { |
| 35 | log<level::ERR>("D-Bus call exception", |
| 36 | entry("OBJPATH=%s", mapperObjectPath), |
| 37 | entry("INTERFACE=%s", mapperInterface), |
| 38 | entry("EXCEPTION=%s", e.what())); |
| 39 | |
| 40 | throw std::runtime_error("Service name is not found"); |
| 41 | } |
| 42 | |
| 43 | if (response.empty()) |
| 44 | { |
| 45 | throw std::runtime_error("Service name response is empty"); |
| 46 | } |
| 47 | |
| 48 | return response.begin()->first; |
| 49 | } |
| 50 | |
| 51 | void callPIM(ObjectMap&& objects) |
| 52 | { |
| 53 | try |
| 54 | { |
| 55 | auto bus = sdbusplus::bus::new_default(); |
| 56 | auto service = getService(bus, pimPath, pimIntf); |
| 57 | auto pimMsg = |
| 58 | bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify"); |
| 59 | pimMsg.append(std::move(objects)); |
| 60 | auto result = bus.call(pimMsg); |
| 61 | if (result.is_method_error()) |
| 62 | { |
| 63 | std::cerr << "PIM Notify() failed\n"; |
| 64 | } |
| 65 | } |
| 66 | catch (const std::runtime_error& e) |
| 67 | { |
| 68 | log<level::ERR>(e.what()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | } // namespace utility |
| 73 | } // namespace common |
| 74 | } // namespace vpd |
| 75 | } // namespace openpower |