Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <gpiod.h> |
| 4 | |
| 5 | #include <boost/asio/io_service.hpp> |
| 6 | #include <boost/asio/posix/stream_descriptor.hpp> |
| 7 | |
| 8 | namespace attn |
| 9 | { |
| 10 | |
| 11 | /** |
| 12 | * @brief Responsible for monitoring attention GPIO state change |
| 13 | */ |
| 14 | class AttnMonitor |
| 15 | { |
| 16 | public: |
| 17 | AttnMonitor() = delete; |
| 18 | ~AttnMonitor() = default; |
| 19 | |
| 20 | /** @brief Constructs AttnMonitor object. |
| 21 | * |
| 22 | * The AttnMonitor constructor will create a new object and start |
| 23 | * the objects associated GPIO listener. |
| 24 | * |
| 25 | * @param line GPIO line handle |
| 26 | * @param config configuration of line |
| 27 | * @param io io service |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 28 | * @param i_breakpoints true = breakpoint special attn handling enabled |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 29 | */ |
| 30 | AttnMonitor(gpiod_line* line, gpiod_line_request_config& config, |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 31 | boost::asio::io_service& io, bool i_breakpoints) : |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 32 | iv_gpioLine(line), |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 33 | iv_gpioConfig(config), iv_gpioEventDescriptor(io), |
| 34 | iv_breakpoints(i_breakpoints) |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 35 | { |
| 36 | |
| 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 | |
| 62 | private: // class methods |
| 63 | /** @brief schedule a gpio event handler */ |
| 64 | void scheduleGPIOEvent(); |
| 65 | |
| 66 | /** @brief handle the GPIO event */ |
| 67 | void handleGPIOEvent(); |
| 68 | |
| 69 | /** @brief register for a gpio event */ |
| 70 | void requestGPIOEvent(); |
Ben Tyner | 970fd4f | 2020-02-19 13:46:42 -0600 | [diff] [blame] | 71 | |
| 72 | /** @brief enable breakpoint special attn handling */ |
| 73 | bool iv_breakpoints; |
Ben Tyner | 73ac368 | 2020-01-09 10:46:47 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace attn |