blob: 72ff65ef9dbbae07685e98da0fdd28c6210da109 [file] [log] [blame]
Matthew Barthc5736432017-04-17 12:22:50 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matthew Barthe6af2332017-04-12 13:37:29 -050016#include "functor.hpp"
17#include <sdbusplus/bus.hpp>
18#include <sdbusplus/message.hpp>
19
20namespace phosphor
21{
22namespace dbus
23{
24namespace monitoring
25{
26
27bool PropertyConditionBase::operator()(sdbusplus::bus::bus& bus,
28 sdbusplus::message::message&,
29 Monitor& mon) const
30{
31 std::string host;
32
33 if (_service)
34 {
35 host.assign(_service);
36 }
37 else
38 {
39 auto mapperCall = bus.new_method_call(
40 "xyz.openbmc_project.ObjectMapper",
41 "/xyz/openbmc_project/object_mapper",
42 "xyz.openbmc_project.ObjectMapper",
43 "GetObject");
44 mapperCall.append(_path);
45 mapperCall.append(std::vector<std::string>({_iface}));
46 auto mapperResponseMsg = bus.call(mapperCall);
47 if (mapperResponseMsg.is_method_error())
48 {
49 return false;
50 }
51
52 std::map<std::string, std::vector<std::string>> mapperResponse;
53 mapperResponseMsg.read(mapperResponse);
54 if (mapperResponse.empty())
55 {
56 return false;
57 }
58
59 host = mapperResponse.begin()->first;
60 }
61 auto hostCall = bus.new_method_call(host.c_str(),
62 _path.c_str(),
63 "org.freedesktop.DBus.Properties",
64 "Get");
65 hostCall.append(_iface);
66 hostCall.append(_property);
67 auto hostResponseMsg = bus.call(hostCall);
68 if (hostResponseMsg.is_method_error())
69 {
70 return false;
71 }
72
73 return eval(hostResponseMsg);
74}
75
76} // namespace monitoring
77} // namespace dbus
78} // namespace phosphor