libgpiod  2.1.3
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 
37 class line_request final
38 {
39 public:
40 
41  line_request(const line_request& other) = delete;
42 
47  line_request(line_request&& other) noexcept;
48 
49  ~line_request();
50 
51  line_request& operator=(const line_request& other) = delete;
52 
58  line_request& operator=(line_request&& other) noexcept;
59 
68  explicit operator bool() const noexcept;
69 
76  void release();
77 
82  ::std::string chip_name() const;
83 
88  ::std::size_t num_lines() const;
89 
94  line::offsets offsets() const;
95 
101  line::value get_value(line::offset offset);
102 
109  line::values get_values(const line::offsets& offsets);
110 
116 
126  void get_values(const line::offsets& offsets, line::values& values);
127 
134  void get_values(line::values& values);
135 
142  line_request& set_value(line::offset offset, line::value value);
143 
150 
158  line_request& set_values(const line::offsets& offsets, const line::values& values);
159 
167 
174 
180  int fd() const;
181 
192  bool wait_edge_events(const ::std::chrono::nanoseconds& timeout) const;
193 
200  ::std::size_t read_edge_events(edge_event_buffer& buffer);
201 
209  ::std::size_t read_edge_events(edge_event_buffer& buffer, ::std::size_t max_events);
210 
211 private:
212 
213  line_request();
214 
215  struct impl;
216 
217  ::std::unique_ptr<impl> _m_priv;
218 
219  friend request_builder;
220 };
221 
228 ::std::ostream& operator<<(::std::ostream& out, const line_request& request);
229 
234 } /* namespace gpiod */
235 
236 #endif /* __LIBGPIOD_CXX_LINE_REQUEST_HPP__ */
Object into which edge events are read for better performance.
Contains a set of line config options used in line requests and reconfiguration.
Definition: line-config.hpp:34
Stores the context of a set of requested GPIO lines.
line_request & operator=(line_request &&other) noexcept
Move assignment operator.
void release()
Release the GPIO chip and free all associated resources.
line_request(line_request &&other) noexcept
Move constructor.
::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_request & set_values(const line::value_mappings &values)
Set the values of a subset of requested lines.
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.
::std::string chip_name() const
Get the name of the chip this request was made on.
line::values get_values()
Get the values of all requested lines.
int fd() const
Get the file descriptor number associated with this line request.
::std::size_t num_lines() const
Get the number of requested lines.
line::value get_value(line::offset offset)
Get the value of a single requested line.
line_request & set_value(line::offset offset, line::value value)
Set the value of a single requested line.
line_request & reconfigure_lines(const line_config &config)
Apply new config options to requested lines.
Intermediate object storing the configuration for a line request.
::std::vector< value_mapping > value_mappings
Vector of offset->value mappings.
Definition: line.hpp:184
::std::vector< value > values
Vector of line values.
Definition: line.hpp:173
value
Logical line states.
Definition: line.hpp:87