Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <gpiod.h> |
| 4 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 5 | #include <attn/attn_config.hpp> |
Ed Tanous | 0577c01 | 2023-03-01 11:18:36 -0800 | [diff] [blame] | 6 | #include <boost/asio/io_context.hpp> |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 7 | #include <boost/asio/posix/stream_descriptor.hpp> |
| 8 | |
| 9 | namespace attn |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @brief Responsible for monitoring attention GPIO state change |
| 14 | */ |
| 15 | class AttnMonitor |
| 16 | { |
| 17 | public: |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 18 | AttnMonitor() = delete; |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 19 | ~AttnMonitor() = default; |
| 20 | |
| 21 | /** @brief Constructs AttnMonitor object. |
| 22 | * |
| 23 | * The AttnMonitor constructor will create a new object and start |
| 24 | * the objects associated GPIO listener. |
| 25 | * |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 26 | * @param line GPIO line handle |
| 27 | * @param config configuration of line |
| 28 | * @param io io service |
| 29 | * @param i_attnConfig poiner to attention handler configuration object |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 30 | */ |
| 31 | AttnMonitor(gpiod_line* line, gpiod_line_request_config& config, |
Ed Tanous | 0577c01 | 2023-03-01 11:18:36 -0800 | [diff] [blame] | 32 | boost::asio::io_context& io, Config* i_attnConfig) : |
Patrick Williams | a0c724d | 2024-08-16 15:21:54 -0400 | [diff] [blame^] | 33 | iv_gpioLine(line), iv_gpioConfig(config), iv_gpioEventDescriptor(io), |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 34 | iv_config(i_attnConfig) |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 35 | { |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 36 | requestGPIOEvent(); // registers the event handler |
| 37 | } |
| 38 | |
| 39 | // delete copy constructor |
| 40 | AttnMonitor(const AttnMonitor&) = delete; |
| 41 | |
| 42 | // delete assignment operator |
| 43 | AttnMonitor& operator=(const AttnMonitor&) = delete; |
| 44 | |
| 45 | // delere move copy consructor |
| 46 | AttnMonitor(AttnMonitor&&) = delete; |
| 47 | |
| 48 | // delete move assignment operator |
| 49 | AttnMonitor& operator=(AttnMonitor&&) = delete; |
| 50 | |
| 51 | private: // instance variables |
| 52 | /** @brief gpiod handle to gpio line */ |
| 53 | gpiod_line* iv_gpioLine; |
| 54 | |
| 55 | /** @brief gpiod line config data */ |
| 56 | gpiod_line_request_config iv_gpioConfig; |
| 57 | |
| 58 | /** @brief GPIO event descriptor */ |
| 59 | boost::asio::posix::stream_descriptor iv_gpioEventDescriptor; |
| 60 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 61 | /** @brief attention handler configuration object pointer */ |
| 62 | Config* iv_config; |
| 63 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 64 | private: // class methods |
| 65 | /** @brief schedule a gpio event handler */ |
| 66 | void scheduleGPIOEvent(); |
| 67 | |
| 68 | /** @brief handle the GPIO event */ |
| 69 | void handleGPIOEvent(); |
| 70 | |
| 71 | /** @brief register for a gpio event */ |
| 72 | void requestGPIOEvent(); |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace attn |