1*c1f4798dSBrad Bishop /** 2*c1f4798dSBrad Bishop * Copyright © 2017 IBM Corporation 3*c1f4798dSBrad Bishop * 4*c1f4798dSBrad Bishop * Licensed under the Apache License, Version 2.0 (the "License"); 5*c1f4798dSBrad Bishop * you may not use this file except in compliance with the License. 6*c1f4798dSBrad Bishop * You may obtain a copy of the License at 7*c1f4798dSBrad Bishop * 8*c1f4798dSBrad Bishop * http://www.apache.org/licenses/LICENSE-2.0 9*c1f4798dSBrad Bishop * 10*c1f4798dSBrad Bishop * Unless required by applicable law or agreed to in writing, software 11*c1f4798dSBrad Bishop * distributed under the License is distributed on an "AS IS" BASIS, 12*c1f4798dSBrad Bishop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*c1f4798dSBrad Bishop * See the License for the specific language governing permissions and 14*c1f4798dSBrad Bishop * limitations under the License. 15*c1f4798dSBrad Bishop */ 16*c1f4798dSBrad Bishop #include "functor.hpp" 17*c1f4798dSBrad Bishop #include <sdbusplus/bus.hpp> 18*c1f4798dSBrad Bishop 19*c1f4798dSBrad Bishop namespace phosphor 20*c1f4798dSBrad Bishop { 21*c1f4798dSBrad Bishop namespace inventory 22*c1f4798dSBrad Bishop { 23*c1f4798dSBrad Bishop namespace manager 24*c1f4798dSBrad Bishop { 25*c1f4798dSBrad Bishop namespace functor 26*c1f4798dSBrad Bishop { 27*c1f4798dSBrad Bishop 28*c1f4798dSBrad Bishop bool PropertyConditionBase::operator()( 29*c1f4798dSBrad Bishop sdbusplus::bus::bus& bus, 30*c1f4798dSBrad Bishop sdbusplus::message::message&, 31*c1f4798dSBrad Bishop Manager&) const 32*c1f4798dSBrad Bishop { 33*c1f4798dSBrad Bishop std::string host; 34*c1f4798dSBrad Bishop 35*c1f4798dSBrad Bishop if (_service) 36*c1f4798dSBrad Bishop { 37*c1f4798dSBrad Bishop host.assign(_service); 38*c1f4798dSBrad Bishop } 39*c1f4798dSBrad Bishop else 40*c1f4798dSBrad Bishop { 41*c1f4798dSBrad Bishop auto mapperCall = bus.new_method_call( 42*c1f4798dSBrad Bishop "xyz.openbmc_project.ObjectMapper", 43*c1f4798dSBrad Bishop "/xyz/openbmc_project/ObjectMapper", 44*c1f4798dSBrad Bishop "xyz.openbmc_project.ObjectMapper", 45*c1f4798dSBrad Bishop "GetObject"); 46*c1f4798dSBrad Bishop mapperCall.append(_path); 47*c1f4798dSBrad Bishop mapperCall.append(std::vector<std::string>({_iface})); 48*c1f4798dSBrad Bishop 49*c1f4798dSBrad Bishop auto mapperResponseMsg = bus.call(mapperCall); 50*c1f4798dSBrad Bishop if (mapperResponseMsg.is_method_error()) 51*c1f4798dSBrad Bishop { 52*c1f4798dSBrad Bishop return false; 53*c1f4798dSBrad Bishop } 54*c1f4798dSBrad Bishop 55*c1f4798dSBrad Bishop std::map<std::string, std::vector<std::string>> mapperResponse; 56*c1f4798dSBrad Bishop mapperResponseMsg.read(mapperResponse); 57*c1f4798dSBrad Bishop 58*c1f4798dSBrad Bishop if (mapperResponse.begin() == mapperResponse.end()) 59*c1f4798dSBrad Bishop { 60*c1f4798dSBrad Bishop return false; 61*c1f4798dSBrad Bishop } 62*c1f4798dSBrad Bishop 63*c1f4798dSBrad Bishop host = mapperResponse.begin()->first; 64*c1f4798dSBrad Bishop 65*c1f4798dSBrad Bishop if (host == bus.get_unique_name()) 66*c1f4798dSBrad Bishop { 67*c1f4798dSBrad Bishop // TODO I can't call myself here. 68*c1f4798dSBrad Bishop return false; 69*c1f4798dSBrad Bishop } 70*c1f4798dSBrad Bishop } 71*c1f4798dSBrad Bishop auto hostCall = bus.new_method_call( 72*c1f4798dSBrad Bishop host.c_str(), 73*c1f4798dSBrad Bishop _path.c_str(), 74*c1f4798dSBrad Bishop "org.freedesktop.DBus.Properties", 75*c1f4798dSBrad Bishop "Get"); 76*c1f4798dSBrad Bishop hostCall.append(_iface); 77*c1f4798dSBrad Bishop hostCall.append(_property); 78*c1f4798dSBrad Bishop 79*c1f4798dSBrad Bishop auto hostResponseMsg = bus.call(hostCall); 80*c1f4798dSBrad Bishop if (hostResponseMsg.is_method_error()) 81*c1f4798dSBrad Bishop { 82*c1f4798dSBrad Bishop return false; 83*c1f4798dSBrad Bishop } 84*c1f4798dSBrad Bishop 85*c1f4798dSBrad Bishop return eval(hostResponseMsg); 86*c1f4798dSBrad Bishop } 87*c1f4798dSBrad Bishop 88*c1f4798dSBrad Bishop } // namespace functor 89*c1f4798dSBrad Bishop } // namespace manager 90*c1f4798dSBrad Bishop } // namespace inventory 91*c1f4798dSBrad Bishop } // namespace phosphor 92*c1f4798dSBrad Bishop 93*c1f4798dSBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 94