1 /** 2 * Copyright © 2020 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 17 #include "presence_service.hpp" 18 19 #include "types.hpp" 20 #include "utility.hpp" 21 22 namespace phosphor::power::regulators 23 { 24 25 bool DBusPresenceService::isPresent(const std::string& inventoryPath) 26 { 27 bool present{false}; 28 29 // Try to find cached presence value 30 auto it = cache.find(inventoryPath); 31 if (it != cache.end()) 32 { 33 present = it->second; 34 } 35 else 36 { 37 // Get presence from D-Bus interface/property 38 util::getProperty(INVENTORY_IFACE, PRESENT_PROP, inventoryPath, 39 INVENTORY_MGR_IFACE, bus, present); 40 41 // Cache presence value 42 cache[inventoryPath] = present; 43 } 44 45 return present; 46 } 47 48 } // namespace phosphor::power::regulators 49