Add gpio-presence-sensor

This is to implement the gpio based hw inventory design [1].

There is a new meson option 'gpio-presence' to enable/disable the
daemon.

Summary of the functionality:

- fetch configuration from EM, according to the configuration interface
- the D-Bus interface is
  xyz.openbmc_project.Configuration.GPIODeviceDetect
- the configuration represents devices for which presence can be
  detected based on gpio values.
- watch gpios for changes
- add/remove the xyz.openbmc_project.Inventory.Source.DevicePresence
  interface on the object path based on gpio values.

References:
[1] https://github.com/openbmc/docs/blob/master/designs/inventory/gpio-based-hardware-inventory.md
[2] https://www.kernel.org/doc/html/latest/admin-guide/gpio/gpio-sim.html

Tested: using linux gpio-sim facility, see below

1. create a fake gpio via [2]
2. configure gpio-presence-sensor as per [1]
3. run the gpio-presence-sensor
4. change the value of the gpio previously configured
5. there should be log output (at debug level)
6. the dbus interfaces exposed should appear/disappear as per [1]

Change-Id: I4cf039b583247581aa5c6c6c59e7fc41ced0bb85
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/gpio-presence/device_presence.hpp b/src/gpio-presence/device_presence.hpp
new file mode 100644
index 0000000..cf1a283
--- /dev/null
+++ b/src/gpio-presence/device_presence.hpp
@@ -0,0 +1,62 @@
+/*
+ * SPDX-FileCopyrightText: Copyright (c) 2022-2024. All rights
+ * reserved. SPDX-License-Identifier: Apache-2.0
+ */
+#pragma once
+
+#include <xyz/openbmc_project/Inventory/Source/DevicePresence/aserver.hpp>
+
+#include <string>
+
+namespace gpio_presence
+{
+
+enum GPIO_POLARITY
+{
+    ACTIVE_HIGH,
+    ACTIVE_LOW,
+};
+
+class DevicePresence;
+
+using DevicePresenceInterface =
+    sdbusplus::aserver::xyz::openbmc_project::inventory::source::DevicePresence<
+        DevicePresence>;
+
+class DevicePresence
+{
+  public:
+    DevicePresence(sdbusplus::async::context& ctx,
+                   const std::vector<std::string>& gpioNames,
+                   const std::vector<uint64_t>& gpioValues,
+                   const std::string& deviceName,
+                   const std::unordered_map<std::string, bool>& gpioState);
+
+    auto updateGPIOPresence(const std::string& gpioLine) -> void;
+
+    // @returns the object path of the 'detected' interface
+    auto getObjPath() const -> sdbusplus::message::object_path;
+
+    // computed from the state of the configured gpios
+    auto isPresent() -> bool;
+
+    // name of the device to detect, e.g. 'cable0'
+    // (taken from EM config)
+    const std::string deviceName;
+
+    // maps the name of the gpio to its polarity
+    std::map<std::string, GPIO_POLARITY> gpioPolarity;
+
+  private:
+    // reference to the map in presence manager
+    const std::unordered_map<std::string, bool>& gpioState;
+
+    sdbusplus::async::context& ctx;
+
+    auto updateDbusInterfaces() -> void;
+
+    // property added when the hw is detected
+    std::unique_ptr<DevicePresenceInterface> detectedIface = nullptr;
+};
+
+} // namespace gpio_presence