libgpiod
line-request.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /* SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <brgl@bgdev.pl> */
3 
8 #ifndef __LIBGPIOD_CXX_LINE_REQUEST_HPP__
9 #define __LIBGPIOD_CXX_LINE_REQUEST_HPP__
10 
11 #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__)
12 #error "Only gpiod.hpp can be included directly."
13 #endif
14 
15 #include <chrono>
16 #include <cstddef>
17 #include <iostream>
18 #include <memory>
19 
20 #include "misc.hpp"
21 
22 namespace gpiod {
23 
24 class chip;
25 class edge_event;
26 class edge_event_buffer;
27 class line_config;
28 
32 class line_request final
33 {
34 public:
35 
36  line_request(const line_request& other) = delete;
37 
42  line_request(line_request&& other) noexcept;
43 
44  ~line_request();
45 
46  line_request& operator=(const line_request& other) = delete;
47 
53  line_request& operator=(line_request&& other) noexcept;
54 
63  explicit operator bool() const noexcept;
64 
71  void release();
72 
77  ::std::string chip_name() const;
78 
83  ::std::size_t num_lines() const;
84 
89  line::offsets offsets() const;
90 
97 
104  line::values get_values(const line::offsets& offsets);
105 
111 
121  void get_values(const line::offsets& offsets, line::values& values);
122 
129  void get_values(line::values& values);
130 
138 
145 
153  line_request& set_values(const line::offsets& offsets, const line::values& values);
154 
161  line_request& set_values(const line::values& values);
162 
169 
175  int fd() const;
176 
187  bool wait_edge_events(const ::std::chrono::nanoseconds& timeout) const;
188 
195  ::std::size_t read_edge_events(edge_event_buffer& buffer);
196 
204  ::std::size_t read_edge_events(edge_event_buffer& buffer, ::std::size_t max_events);
205 
206 private:
207 
208  line_request();
209 
210  struct impl;
211 
212  ::std::unique_ptr<impl> _m_priv;
213 
214  friend request_builder;
215 };
216 
223 ::std::ostream& operator<<(::std::ostream& out, const line_request& request);
224 
225 } /* namespace gpiod */
226 
227 #endif /* __LIBGPIOD_CXX_LINE_REQUEST_HPP__ */
Definition: chip-info.hpp:18
::std::size_t read_edge_events(edge_event_buffer &buffer)
Read a number of edge events from this request up to the maximum capacity of the buffer.
line::value get_value(line::offset offset)
Get the value of a single requested line.
::std::ostream & operator<<(::std::ostream &out, const chip_info &chip)
Stream insertion operator for GPIO chip objects.
line_request & reconfigure_lines(const line_config &config)
Apply new config options to requested lines.
line::values get_values()
Get the values of all requested lines.
::std::string chip_name() const
Get the name of the chip this request was made on.
line_request & operator=(const line_request &other)=delete
Stores the context of a set of requested GPIO lines.
Definition: line-request.hpp:32
::std::vector< value > values
Vector of line values.
Definition: line.hpp:168
Intermediate object storing the configuration for a line request.
Definition: request-builder.hpp:28
value
Logical line states.
Definition: line.hpp:81
Contains a set of line config options used in line requests and reconfiguration.
Definition: line-config.hpp:28
void release()
Release the requested lines and free all associated resources.
Object into which edge events are read for better performance.
Definition: edge-event-buffer.hpp:32
::std::vector< offset > offsets
Vector of line offsets.
Definition: line.hpp:163
bool wait_edge_events(const ::std::chrono::nanoseconds &timeout) const
Wait for edge events on any of the lines requested with edge detection enabled.
line::offsets offsets() const
Get the list of offsets of requested lines.
int fd() const
Get the file descriptor number associated with this line request.
Wrapper around unsigned int for representing line offsets.
Definition: line.hpp:29
line_request & set_values(const line::value_mappings &values)
Set the values of a subset of requested lines.
::std::vector< value_mapping > value_mappings
Vector of offset->value mappings. Each mapping is defined as a pair of an unsigned and signed integer...
Definition: line.hpp:179
line_request & set_value(line::offset offset, line::value value)
Set the value of a single requested line.
::std::size_t num_lines() const
Get the number of requested lines.