blob: b9f2ccdf5bc1786ec8a07cd3399fb01ee487821f [file] [log] [blame]
Alexander Hansen8c4b1d92024-11-04 14:06:24 +01001/*
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
11namespace gpio_presence
12{
13
14enum GPIO_POLARITY
15{
16 ACTIVE_HIGH,
17 ACTIVE_LOW,
18};
19
20class DevicePresence;
21
22using DevicePresenceInterface =
23 sdbusplus::aserver::xyz::openbmc_project::inventory::source::DevicePresence<
24 DevicePresence>;
25
26class 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,
Alexander Hansen92d79812025-08-22 14:34:22 +020033 const std::unordered_map<std::string, bool>& gpioState,
34 const std::vector<std::string>& parentInvCompatible);
Alexander Hansen8c4b1d92024-11-04 14:06:24 +010035
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
Alexander Hansen92d79812025-08-22 14:34:22 +020057 const std::vector<std::string> parentInventoryCompatible;
58
Alexander Hansen8c4b1d92024-11-04 14:06:24 +010059 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