forked from openbmc/openpower-vpd-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
69 lines (57 loc) · 1.57 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "utils.hpp"
#include <iostream>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/server.hpp>
namespace openpower
{
namespace vpd
{
namespace inventory
{
auto getPIMService()
{
auto bus = sdbusplus::bus::new_default();
auto mapper =
bus.new_method_call("xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetObject");
mapper.append(pimPath);
mapper.append(std::vector<std::string>({pimIntf}));
auto result = bus.call(mapper);
if (result.is_method_error())
{
throw std::runtime_error("ObjectMapper GetObject failed");
}
std::map<std::string, std::vector<std::string>> response;
result.read(response);
if (response.empty())
{
throw std::runtime_error("ObjectMapper GetObject bad response");
}
return response.begin()->first;
}
void callPIM(ObjectMap&& objects)
{
std::string service;
try
{
service = getPIMService();
auto bus = sdbusplus::bus::new_default();
auto pimMsg =
bus.new_method_call(service.c_str(), pimPath, pimIntf, "Notify");
pimMsg.append(std::move(objects));
auto result = bus.call(pimMsg);
if (result.is_method_error())
{
std::cerr << "PIM Notify() failed\n";
}
}
catch (const std::runtime_error& e)
{
using namespace phosphor::logging;
log<level::ERR>(e.what());
}
}
} // namespace inventory
} // namespace vpd
} // namespace openpower