blob: f4d2574edbb6d2d8ee26c263ccf9247b7daf60f3 [file] [log] [blame]
Matthew Barthe6af2332017-04-12 13:37:29 -05001#include "functor.hpp"
2#include <sdbusplus/bus.hpp>
3#include <sdbusplus/message.hpp>
4
5namespace phosphor
6{
7namespace dbus
8{
9namespace monitoring
10{
11
12bool PropertyConditionBase::operator()(sdbusplus::bus::bus& bus,
13 sdbusplus::message::message&,
14 Monitor& mon) const
15{
16 std::string host;
17
18 if (_service)
19 {
20 host.assign(_service);
21 }
22 else
23 {
24 auto mapperCall = bus.new_method_call(
25 "xyz.openbmc_project.ObjectMapper",
26 "/xyz/openbmc_project/object_mapper",
27 "xyz.openbmc_project.ObjectMapper",
28 "GetObject");
29 mapperCall.append(_path);
30 mapperCall.append(std::vector<std::string>({_iface}));
31 auto mapperResponseMsg = bus.call(mapperCall);
32 if (mapperResponseMsg.is_method_error())
33 {
34 return false;
35 }
36
37 std::map<std::string, std::vector<std::string>> mapperResponse;
38 mapperResponseMsg.read(mapperResponse);
39 if (mapperResponse.empty())
40 {
41 return false;
42 }
43
44 host = mapperResponse.begin()->first;
45 }
46 auto hostCall = bus.new_method_call(host.c_str(),
47 _path.c_str(),
48 "org.freedesktop.DBus.Properties",
49 "Get");
50 hostCall.append(_iface);
51 hostCall.append(_property);
52 auto hostResponseMsg = bus.call(hostCall);
53 if (hostResponseMsg.is_method_error())
54 {
55 return false;
56 }
57
58 return eval(hostResponseMsg);
59}
60
61} // namespace monitoring
62} // namespace dbus
63} // namespace phosphor