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