blob: 251857b799c8e9cc917249f2b0a77c7b91a3e35e [file] [log] [blame]
Ben Tyner73ac3682020-01-09 10:46:47 -06001#pragma once
2
3#include <gpiod.h>
4
5#include <boost/asio/io_service.hpp>
6#include <boost/asio/posix/stream_descriptor.hpp>
7
8namespace attn
9{
10
11/**
12 * @brief Responsible for monitoring attention GPIO state change
13 */
14class 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 Tyner970fd4f2020-02-19 13:46:42 -060028 * @param i_breakpoints true = breakpoint special attn handling enabled
Ben Tyner73ac3682020-01-09 10:46:47 -060029 */
30 AttnMonitor(gpiod_line* line, gpiod_line_request_config& config,
Ben Tyner970fd4f2020-02-19 13:46:42 -060031 boost::asio::io_service& io, bool i_breakpoints) :
Ben Tyner73ac3682020-01-09 10:46:47 -060032 iv_gpioLine(line),
Ben Tyner970fd4f2020-02-19 13:46:42 -060033 iv_gpioConfig(config), iv_gpioEventDescriptor(io),
34 iv_breakpoints(i_breakpoints)
Ben Tyner73ac3682020-01-09 10:46:47 -060035 {
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 Tyner970fd4f2020-02-19 13:46:42 -060071
72 /** @brief enable breakpoint special attn handling */
73 bool iv_breakpoints;
Ben Tyner73ac3682020-01-09 10:46:47 -060074};
75
76} // namespace attn