1 #include "common_utility.hpp"
2 
3 #include "const.hpp"
4 
5 #include <phosphor-logging/log.hpp>
6 
7 #include <iostream>
8 
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 
21 std::string getService(sdbusplus::bus_t& bus, const std::string& path,
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     }
34     catch (const sdbusplus::exception_t& e)
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);
58         auto pimMsg = bus.new_method_call(service.c_str(), pimPath, pimIntf,
59                                           "Notify");
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
76 } // namespace openpower
77