blob: 41a6e5f7f4119419b0fd02b1f7ca29d0e90cd578 [file] [log] [blame]
Brad Bishopfa51da72017-01-19 11:06:51 -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 */
16#include "events.hpp"
17#include <sdbusplus/bus.hpp>
18
19namespace phosphor
20{
21namespace inventory
22{
23namespace manager
24{
25namespace filters
26{
27namespace details
28{
29namespace property_condition
30{
31
32bool PropertyConditionBase::operator()(
33 sdbusplus::bus::bus& bus,
34 sdbusplus::message::message&,
35 Manager&) const
36{
37 std::string host;
38
39 if (_service)
40 {
41 host.assign(_service);
42 }
43 else
44 {
45 auto mapperCall = bus.new_method_call(
46 "xyz.openbmc_project.ObjectMapper",
47 "/xyz/openbmc_project/ObjectMapper",
48 "xyz.openbmc_project.ObjectMapper",
49 "GetObject");
50 mapperCall.append(_path);
51 mapperCall.append(std::vector<std::string>({_iface}));
52
53 auto mapperResponseMsg = bus.call(mapperCall);
54 if (mapperResponseMsg.is_method_error())
55 {
56 return false;
57 }
58
59 std::map<std::string, std::vector<std::string>> mapperResponse;
60 mapperResponseMsg.read(mapperResponse);
61
62 if (mapperResponse.begin() == mapperResponse.end())
63 {
64 return false;
65 }
66
67 host = mapperResponse.begin()->first;
68
69 if (host == bus.get_unique_name())
70 {
71 // TODO I can't call myself here.
72 return false;
73 }
74 }
75 auto hostCall = bus.new_method_call(
76 host.c_str(),
77 _path.c_str(),
78 "org.freedesktop.DBus.Properties",
79 "Get");
80 hostCall.append(_iface);
81 hostCall.append(_property);
82
83 auto hostResponseMsg = bus.call(hostCall);
84 if (hostResponseMsg.is_method_error())
85 {
86 return false;
87 }
88
89 return eval(hostResponseMsg);
90}
91
92} // namespace property_condition
93} // namespace details
94} // namespace filters
95} // namespace manager
96} // namespace inventory
97} // namespace phosphor
98
99// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4