blob: b860551bdca8f6575258587b18c04ccc853bce95 [file] [log] [blame]
Jagpal Singh Gill15dde862024-10-16 09:42:54 -07001#pragma once
2
3#include <gpiod.hpp>
4#include <sdbusplus/async.hpp>
5
6#include <functional>
7#include <memory>
8#include <string>
9
10namespace gpio
11{
12
13class GPIOInterface
14{
15 public:
16 using Callback_t = std::function<sdbusplus::async::task<>(bool)>;
17
18 GPIOInterface() = delete;
19
20 GPIOInterface(sdbusplus::async::context& ctx,
21 const std::string& consumerName, const std::string& pinName,
22 bool activeLow, Callback_t updateStateCallback);
23
24 /** @brief Start the GPIO Interface */
25 auto start() -> sdbusplus::async::task<>;
26
27 private:
28 /** @brief Read the gpio state asynchronously */
29 auto readGPIOAsync() -> sdbusplus::async::task<>;
30
31 /** @brief Read the gpio state asynchronously based on gpio event */
32 auto readGPIOAsyncEvent() -> sdbusplus::async::task<>;
33
34 sdbusplus::async::context& ctx;
35 const std::string& pinName;
36 Callback_t updateStateCallback;
37 gpiod::line line;
38 /** File descriptor based async event handler */
39 std::unique_ptr<sdbusplus::async::fdio> fdioInstance;
40};
41
42} // namespace gpio