blob: 276f4063ad087624711d4bb75bce7118f159900b [file] [log] [blame]
Deepak Kodihalli76794492017-02-16 23:48:18 -06001#include "utils.hpp"
Patrick Venturec83c4dc2018-11-01 16:29:18 -07002
Deepak Kodihalli76794492017-02-16 23:48:18 -06003#include <iostream>
Patrick Venturec83c4dc2018-11-01 16:29:18 -07004#include <phosphor-logging/log.hpp>
5#include <sdbusplus/server.hpp>
Deepak Kodihalli76794492017-02-16 23:48:18 -06006
7namespace openpower
8{
9namespace vpd
10{
11
12namespace inventory
13{
14
15auto getPIMService()
16{
17 auto bus = sdbusplus::bus::new_default();
18 auto mapper =
Patrick Venturec83c4dc2018-11-01 16:29:18 -070019 bus.new_method_call("xyz.openbmc_project.ObjectMapper",
20 "/xyz/openbmc_project/object_mapper",
21 "xyz.openbmc_project.ObjectMapper", "GetObject");
Deepak Kodihalli76794492017-02-16 23:48:18 -060022
23 mapper.append(pimPath);
24 mapper.append(std::vector<std::string>({pimIntf}));
25
26 auto result = bus.call(mapper);
Patrick Venturec83c4dc2018-11-01 16:29:18 -070027 if (result.is_method_error())
Deepak Kodihalli76794492017-02-16 23:48:18 -060028 {
29 throw std::runtime_error("ObjectMapper GetObject failed");
30 }
31
32 std::map<std::string, std::vector<std::string>> response;
33 result.read(response);
Patrick Venturec83c4dc2018-11-01 16:29:18 -070034 if (response.empty())
Deepak Kodihalli76794492017-02-16 23:48:18 -060035 {
36 throw std::runtime_error("ObjectMapper GetObject bad response");
37 }
38
39 return response.begin()->first;
40}
41
42void callPIM(ObjectMap&& objects)
43{
44 std::string service;
45
46 try
47 {
48 service = getPIMService();
49 auto bus = sdbusplus::bus::new_default();
Patrick Venturec83c4dc2018-11-01 16:29:18 -070050 auto pimMsg =
51 bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
Deepak Kodihalli76794492017-02-16 23:48:18 -060052 pimMsg.append(std::move(objects));
53 auto result = bus.call(pimMsg);
Patrick Venturec83c4dc2018-11-01 16:29:18 -070054 if (result.is_method_error())
Deepak Kodihalli76794492017-02-16 23:48:18 -060055 {
56 std::cerr << "PIM Notify() failed\n";
57 }
58 }
59 catch (const std::runtime_error& e)
60 {
61 using namespace phosphor::logging;
62 log<level::ERR>(e.what());
63 }
64}
65
66} // namespace inventory
67
Patrick Venturec83c4dc2018-11-01 16:29:18 -070068} // namespace vpd
69} // namespace openpower