blob: 5231d7e3b0fbf72807050b84cd06f3f0cab1c769 [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
28 */
29 AttnMonitor(gpiod_line* line, gpiod_line_request_config& config,
30 boost::asio::io_service& io) :
31 iv_gpioLine(line),
32 iv_gpioConfig(config), iv_gpioEventDescriptor(io)
33 {
34
35 requestGPIOEvent(); // registers the event handler
36 }
37
38 // delete copy constructor
39 AttnMonitor(const AttnMonitor&) = delete;
40
41 // delete assignment operator
42 AttnMonitor& operator=(const AttnMonitor&) = delete;
43
44 // delere move copy consructor
45 AttnMonitor(AttnMonitor&&) = delete;
46
47 // delete move assignment operator
48 AttnMonitor& operator=(AttnMonitor&&) = delete;
49
50 private: // instance variables
51 /** @brief gpiod handle to gpio line */
52 gpiod_line* iv_gpioLine;
53
54 /** @brief gpiod line config data */
55 gpiod_line_request_config iv_gpioConfig;
56
57 /** @brief GPIO event descriptor */
58 boost::asio::posix::stream_descriptor iv_gpioEventDescriptor;
59
60 private: // class methods
61 /** @brief schedule a gpio event handler */
62 void scheduleGPIOEvent();
63
64 /** @brief handle the GPIO event */
65 void handleGPIOEvent();
66
67 /** @brief register for a gpio event */
68 void requestGPIOEvent();
69};
70
71} // namespace attn