1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 2022-2024. All rights 3 * reserved. SPDX-License-Identifier: Apache-2.0 4 */ 5 #pragma once 6 7 #include <xyz/openbmc_project/Inventory/Source/DevicePresence/aserver.hpp> 8 9 #include <string> 10 11 namespace gpio_presence 12 { 13 14 enum GPIO_POLARITY 15 { 16 ACTIVE_HIGH, 17 ACTIVE_LOW, 18 }; 19 20 class DevicePresence; 21 22 using DevicePresenceInterface = 23 sdbusplus::aserver::xyz::openbmc_project::inventory::source::DevicePresence< 24 DevicePresence>; 25 26 class DevicePresence 27 { 28 public: 29 DevicePresence(sdbusplus::async::context& ctx, 30 const std::vector<std::string>& gpioNames, 31 const std::vector<uint64_t>& gpioValues, 32 const std::string& deviceName, 33 const std::unordered_map<std::string, bool>& gpioState, 34 const std::vector<std::string>& parentInvCompatible); 35 36 auto updateGPIOPresence(const std::string& gpioLine) -> void; 37 38 // @returns the object path of the 'detected' interface 39 auto getObjPath() const -> sdbusplus::message::object_path; 40 41 // computed from the state of the configured gpios 42 auto isPresent() -> bool; 43 44 // name of the device to detect, e.g. 'cable0' 45 // (taken from EM config) 46 const std::string deviceName; 47 48 // maps the name of the gpio to its polarity 49 std::map<std::string, GPIO_POLARITY> gpioPolarity; 50 51 private: 52 // reference to the map in presence manager 53 const std::unordered_map<std::string, bool>& gpioState; 54 55 sdbusplus::async::context& ctx; 56 57 const std::vector<std::string> parentInventoryCompatible; 58 59 auto updateDbusInterfaces() -> void; 60 61 // property added when the hw is detected 62 std::unique_ptr<DevicePresenceInterface> detectedIface = nullptr; 63 }; 64 65 } // namespace gpio_presence 66