blob: 0497d0fbbfd2ee11db5c64b2b00270fcbb8e99ef [file] [log] [blame]
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05001#include "common_utility.hpp"
2
3#include "const.hpp"
4
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05005#include <phosphor-logging/log.hpp>
6
Patrick Williamsc78d8872023-05-10 07:50:56 -05007#include <iostream>
8
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05009namespace openpower
10{
11namespace vpd
12{
13namespace common
14{
15namespace utility
16{
17using namespace constants;
18using namespace inventory;
19using namespace phosphor::logging;
20
Patrick Williams2eb01762022-07-22 19:26:56 -050021std::string getService(sdbusplus::bus_t& bus, const std::string& path,
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050022 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 Williams2eb01762022-07-22 19:26:56 -050034 catch (const sdbusplus::exception_t& e)
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050035 {
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
52void callPIM(ObjectMap&& objects)
53{
54 try
55 {
56 auto bus = sdbusplus::bus::new_default();
57 auto service = getService(bus, pimPath, pimIntf);
Patrick Williams08dc31c2024-08-16 15:21:06 -040058 auto pimMsg =
59 bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -050060 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 Williamsc78d8872023-05-10 07:50:56 -050076} // namespace openpower