Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 1 | /** |
| 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 Bishop | c1f4798 | 2017-02-09 01:27:38 -0500 | [diff] [blame] | 16 | #include "functor.hpp" |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 17 | #include <sdbusplus/bus.hpp> |
| 18 | |
| 19 | namespace phosphor |
| 20 | { |
| 21 | namespace inventory |
| 22 | { |
| 23 | namespace manager |
| 24 | { |
Brad Bishop | c1f4798 | 2017-02-09 01:27:38 -0500 | [diff] [blame] | 25 | namespace functor |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 26 | { |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 27 | bool PropertyConditionBase::operator()(sdbusplus::bus::bus& bus, |
| 28 | sdbusplus::message::message&, |
| 29 | Manager& mgr) const |
Brad Bishop | d0f48ad | 2017-01-30 08:52:26 -0500 | [diff] [blame] | 30 | { |
| 31 | std::string path(_path); |
| 32 | return (*this)(path, bus, mgr); |
| 33 | } |
| 34 | |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 35 | bool PropertyConditionBase::operator()(const std::string& path, |
| 36 | sdbusplus::bus::bus& bus, Manager&) const |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 37 | { |
| 38 | std::string host; |
| 39 | |
| 40 | if (_service) |
| 41 | { |
| 42 | host.assign(_service); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | auto mapperCall = bus.new_method_call( |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 47 | "xyz.openbmc_project.ObjectMapper", |
| 48 | "/xyz/openbmc_project/object_mapper", |
| 49 | "xyz.openbmc_project.ObjectMapper", "GetObject"); |
Brad Bishop | d0f48ad | 2017-01-30 08:52:26 -0500 | [diff] [blame] | 50 | mapperCall.append(path); |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 8ed114b | 2017-03-09 15:28:43 -0600 | [diff] [blame] | 62 | if (mapperResponse.empty()) |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 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( |
Brad Bishop | 615b2a8 | 2018-03-29 10:32:41 -0400 | [diff] [blame] | 76 | host.c_str(), path.c_str(), "org.freedesktop.DBus.Properties", "Get"); |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 77 | hostCall.append(_iface); |
| 78 | hostCall.append(_property); |
| 79 | |
| 80 | auto hostResponseMsg = bus.call(hostCall); |
| 81 | if (hostResponseMsg.is_method_error()) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | return eval(hostResponseMsg); |
| 87 | } |
| 88 | |
Brad Bishop | c1f4798 | 2017-02-09 01:27:38 -0500 | [diff] [blame] | 89 | } // namespace functor |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 90 | } // namespace manager |
| 91 | } // namespace inventory |
| 92 | } // namespace phosphor |
| 93 | |
| 94 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |