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> |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 6 | #include <boost/asio/io_service.hpp> |
| 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: |
| 18 | AttnMonitor() = delete; |
| 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, |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 32 | boost::asio::io_service& io, Config* i_attnConfig) : |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 33 | iv_gpioLine(line), |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 34 | iv_gpioConfig(config), iv_gpioEventDescriptor(io), |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 35 | iv_config(i_attnConfig) |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 36 | { |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 37 | requestGPIOEvent(); // registers the event handler |
| 38 | } |
| 39 | |
| 40 | // delete copy constructor |
| 41 | AttnMonitor(const AttnMonitor&) = delete; |
| 42 | |
| 43 | // delete assignment operator |
| 44 | AttnMonitor& operator=(const AttnMonitor&) = delete; |
| 45 | |
| 46 | // delere move copy consructor |
| 47 | AttnMonitor(AttnMonitor&&) = delete; |
| 48 | |
| 49 | // delete move assignment operator |
| 50 | AttnMonitor& operator=(AttnMonitor&&) = delete; |
| 51 | |
| 52 | private: // instance variables |
| 53 | /** @brief gpiod handle to gpio line */ |
| 54 | gpiod_line* iv_gpioLine; |
| 55 | |
| 56 | /** @brief gpiod line config data */ |
| 57 | gpiod_line_request_config iv_gpioConfig; |
| 58 | |
| 59 | /** @brief GPIO event descriptor */ |
| 60 | boost::asio::posix::stream_descriptor iv_gpioEventDescriptor; |
| 61 | |
Ben Tyner | 3fb52e5 | 2020-03-31 10:10:07 -0500 | [diff] [blame] | 62 | /** @brief attention handler configuration object pointer */ |
| 63 | Config* iv_config; |
| 64 | |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 65 | private: // class methods |
| 66 | /** @brief schedule a gpio event handler */ |
| 67 | void scheduleGPIOEvent(); |
| 68 | |
| 69 | /** @brief handle the GPIO event */ |
| 70 | void handleGPIOEvent(); |
| 71 | |
| 72 | /** @brief register for a gpio event */ |
| 73 | void requestGPIOEvent(); |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace attn |