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 | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 27 | bool PropertyConditionBase::operator()( |
| 28 | sdbusplus::bus::bus& bus, |
| 29 | sdbusplus::message::message&, |
Brad Bishop | d0f48ad | 2017-01-30 08:52:26 -0500 | [diff] [blame] | 30 | Manager& mgr) const |
| 31 | { |
| 32 | std::string path(_path); |
| 33 | return (*this)(path, bus, mgr); |
| 34 | } |
| 35 | |
| 36 | bool PropertyConditionBase::operator()( |
| 37 | const std::string& path, |
| 38 | sdbusplus::bus::bus& bus, |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 39 | Manager&) const |
| 40 | { |
| 41 | std::string host; |
| 42 | |
| 43 | if (_service) |
| 44 | { |
| 45 | host.assign(_service); |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | auto mapperCall = bus.new_method_call( |
| 50 | "xyz.openbmc_project.ObjectMapper", |
Leonel Gonzalez | 82aa223 | 2017-03-16 13:47:55 -0500 | [diff] [blame] | 51 | "/xyz/openbmc_project/object_mapper", |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 52 | "xyz.openbmc_project.ObjectMapper", |
| 53 | "GetObject"); |
Brad Bishop | d0f48ad | 2017-01-30 08:52:26 -0500 | [diff] [blame] | 54 | mapperCall.append(path); |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 55 | mapperCall.append(std::vector<std::string>({_iface})); |
| 56 | |
| 57 | auto mapperResponseMsg = bus.call(mapperCall); |
| 58 | if (mapperResponseMsg.is_method_error()) |
| 59 | { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 64 | mapperResponseMsg.read(mapperResponse); |
| 65 | |
Patrick Williams | 8ed114b | 2017-03-09 15:28:43 -0600 | [diff] [blame] | 66 | if (mapperResponse.empty()) |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 67 | { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | host = mapperResponse.begin()->first; |
| 72 | |
| 73 | if (host == bus.get_unique_name()) |
| 74 | { |
| 75 | // TODO I can't call myself here. |
| 76 | return false; |
| 77 | } |
| 78 | } |
| 79 | auto hostCall = bus.new_method_call( |
| 80 | host.c_str(), |
Brad Bishop | d0f48ad | 2017-01-30 08:52:26 -0500 | [diff] [blame] | 81 | path.c_str(), |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 82 | "org.freedesktop.DBus.Properties", |
| 83 | "Get"); |
| 84 | hostCall.append(_iface); |
| 85 | hostCall.append(_property); |
| 86 | |
| 87 | auto hostResponseMsg = bus.call(hostCall); |
| 88 | if (hostResponseMsg.is_method_error()) |
| 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | return eval(hostResponseMsg); |
| 94 | } |
| 95 | |
Brad Bishop | c1f4798 | 2017-02-09 01:27:38 -0500 | [diff] [blame] | 96 | } // namespace functor |
Brad Bishop | fa51da7 | 2017-01-19 11:06:51 -0500 | [diff] [blame] | 97 | } // namespace manager |
| 98 | } // namespace inventory |
| 99 | } // namespace phosphor |
| 100 | |
| 101 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |