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