blob: cf1a283040a0bffe9c69ed0c74ffc072452dab5a [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,
33 const std::unordered_map<std::string, bool>& gpioState);
34
35 auto updateGPIOPresence(const std::string& gpioLine) -> void;
36
37 // @returns the object path of the 'detected' interface
38 auto getObjPath() const -> sdbusplus::message::object_path;
39
40 // computed from the state of the configured gpios
41 auto isPresent() -> bool;
42
43 // name of the device to detect, e.g. 'cable0'
44 // (taken from EM config)
45 const std::string deviceName;
46
47 // maps the name of the gpio to its polarity
48 std::map<std::string, GPIO_POLARITY> gpioPolarity;
49
50 private:
51 // reference to the map in presence manager
52 const std::unordered_map<std::string, bool>& gpioState;
53
54 sdbusplus::async::context& ctx;
55
56 auto updateDbusInterfaces() -> void;
57
58 // property added when the hw is detected
59 std::unique_ptr<DevicePresenceInterface> detectedIface = nullptr;
60};
61
62} // namespace gpio_presence