blob: 7b703168c8ce0918f89787a71d54882c9d816fed [file] [log] [blame]
Ben Tyner73ac3682020-01-09 10:46:47 -06001#pragma once
2
3#include <gpiod.h>
4
Ben Tyner3fb52e52020-03-31 10:10:07 -05005#include <attn/attn_config.hpp>
Ben Tyner73ac3682020-01-09 10:46:47 -06006#include <boost/asio/io_service.hpp>
7#include <boost/asio/posix/stream_descriptor.hpp>
8
9namespace attn
10{
11
12/**
13 * @brief Responsible for monitoring attention GPIO state change
14 */
15class 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 Tyner3fb52e52020-03-31 10:10:07 -050026 * @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 Tyner73ac3682020-01-09 10:46:47 -060030 */
31 AttnMonitor(gpiod_line* line, gpiod_line_request_config& config,
Ben Tyner3fb52e52020-03-31 10:10:07 -050032 boost::asio::io_service& io, Config* i_attnConfig) :
Ben Tyner73ac3682020-01-09 10:46:47 -060033 iv_gpioLine(line),
Ben Tyner970fd4f2020-02-19 13:46:42 -060034 iv_gpioConfig(config), iv_gpioEventDescriptor(io),
Ben Tyner3fb52e52020-03-31 10:10:07 -050035 iv_config(i_attnConfig)
Ben Tyner73ac3682020-01-09 10:46:47 -060036 {
37
38 requestGPIOEvent(); // registers the event handler
39 }
40
41 // delete copy constructor
42 AttnMonitor(const AttnMonitor&) = delete;
43
44 // delete assignment operator
45 AttnMonitor& operator=(const AttnMonitor&) = delete;
46
47 // delere move copy consructor
48 AttnMonitor(AttnMonitor&&) = delete;
49
50 // delete move assignment operator
51 AttnMonitor& operator=(AttnMonitor&&) = delete;
52
53 private: // instance variables
54 /** @brief gpiod handle to gpio line */
55 gpiod_line* iv_gpioLine;
56
57 /** @brief gpiod line config data */
58 gpiod_line_request_config iv_gpioConfig;
59
60 /** @brief GPIO event descriptor */
61 boost::asio::posix::stream_descriptor iv_gpioEventDescriptor;
62
Ben Tyner3fb52e52020-03-31 10:10:07 -050063 /** @brief attention handler configuration object pointer */
64 Config* iv_config;
65
Ben Tyner73ac3682020-01-09 10:46:47 -060066 private: // class methods
67 /** @brief schedule a gpio event handler */
68 void scheduleGPIOEvent();
69
70 /** @brief handle the GPIO event */
71 void handleGPIOEvent();
72
73 /** @brief register for a gpio event */
74 void requestGPIOEvent();
Ben Tyner73ac3682020-01-09 10:46:47 -060075};
76
77} // namespace attn