blob: 57cba0a8865f9861e93564c7f8c8340b11ef3b54 [file] [log] [blame]
Deepak Kodihalli76794492017-02-16 23:48:18 -06001#include "utils.hpp"
2#include <sdbusplus/server.hpp>
Saqib Khan2ff29062017-02-20 15:53:16 -06003#include <phosphor-logging/log.hpp>
Deepak Kodihalli76794492017-02-16 23:48:18 -06004#include <iostream>
5
6namespace openpower
7{
8namespace vpd
9{
10
11namespace inventory
12{
13
14auto getPIMService()
15{
16 auto bus = sdbusplus::bus::new_default();
17 auto mapper =
18 bus.new_method_call(
Patrick Williams847d6492017-03-20 11:50:32 -050019 "xyz.openbmc_project.ObjectMapper",
Leonel Gonzalez86400872017-03-16 13:47:56 -050020 "/xyz/openbmc_project/object_mapper",
Patrick Williams847d6492017-03-20 11:50:32 -050021 "xyz.openbmc_project.ObjectMapper",
Deepak Kodihalli76794492017-02-16 23:48:18 -060022 "GetObject");
23
24 mapper.append(pimPath);
25 mapper.append(std::vector<std::string>({pimIntf}));
26
27 auto result = bus.call(mapper);
28 if(result.is_method_error())
29 {
30 throw std::runtime_error("ObjectMapper GetObject failed");
31 }
32
33 std::map<std::string, std::vector<std::string>> response;
34 result.read(response);
35 if(response.empty())
36 {
37 throw std::runtime_error("ObjectMapper GetObject bad response");
38 }
39
40 return response.begin()->first;
41}
42
43void callPIM(ObjectMap&& objects)
44{
45 std::string service;
46
47 try
48 {
49 service = getPIMService();
50 auto bus = sdbusplus::bus::new_default();
51 auto pimMsg = bus.new_method_call(
52 service.c_str(),
Deepak Kodihalli193b2282017-06-07 08:34:30 -050053 pimPath,
54 pimIntf,
Deepak Kodihalli76794492017-02-16 23:48:18 -060055 "Notify");
56 pimMsg.append(std::move(objects));
57 auto result = bus.call(pimMsg);
58 if(result.is_method_error())
59 {
60 std::cerr << "PIM Notify() failed\n";
61 }
62 }
63 catch (const std::runtime_error& e)
64 {
65 using namespace phosphor::logging;
66 log<level::ERR>(e.what());
67 }
68}
69
70} // namespace inventory
71
72} //namespace vpd
73} //namespace openpower