libgpiod  2.1.2
chip.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_CHIP_HPP__
9 #define __LIBGPIOD_CXX_CHIP_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 <filesystem>
19 #include <memory>
20 
21 #include "line.hpp"
22 
23 namespace gpiod {
24 
25 class chip_info;
26 class info_event;
27 class line_config;
28 class line_info;
29 class line_request;
30 class request_builder;
31 class request_config;
32 
41 class chip final
42 {
43 public:
44 
50  explicit chip(const ::std::filesystem::path& path);
51 
56  chip(chip&& other) noexcept;
57 
58  ~chip();
59 
60  chip& operator=(const chip& other) = delete;
61 
67  chip& operator=(chip&& other) noexcept;
68 
76  explicit operator bool() const noexcept;
77 
83  void close();
84 
89  ::std::filesystem::path path() const;
90 
95  chip_info get_info() const;
96 
103  line_info get_line_info(line::offset offset) const;
104 
111  line_info watch_line_info(line::offset offset) const;
112 
117  void unwatch_line_info(line::offset offset) const;
118 
123  int fd() const;
124 
135  bool wait_info_event(const ::std::chrono::nanoseconds& timeout) const;
136 
141  info_event read_info_event() const;
142 
149  int get_line_offset_from_name(const ::std::string& name) const;
150 
156 
157 private:
158 
159  struct impl;
160 
161  ::std::shared_ptr<impl> _m_priv;
162 
163  chip(const chip& other);
164 
165  friend request_builder;
166 };
167 
174 ::std::ostream& operator<<(::std::ostream& out, const chip& chip);
175 
180 } /* namespace gpiod */
181 
182 #endif /* __LIBGPIOD_CXX_CHIP_HPP__ */
Represents an immutable snapshot of GPIO chip information.
Definition: chip-info.hpp:30
line_info get_line_info(line::offset offset) const
Retrieve the current snapshot of line information for a single line.
line_info watch_line_info(line::offset offset) const
Wrapper around gpiod::chip::get_line_info that retrieves the line info and starts watching the line f...
info_event read_info_event() const
Read a single line status change event from this chip.
void unwatch_line_info(line::offset offset) const
Stop watching the line at given offset for info events.
request_builder prepare_request()
Create a request_builder associated with this chip.
Intermediate object storing the configuration for a line request.
int get_line_offset_from_name(const ::std::string &name) const
Map a GPIO line's name to its offset within the chip.
Immutable object containing data about a single line info event.
Definition: info-event.hpp:34
chip_info get_info() const
Get information about the chip.
Represents a GPIO chip.
Definition: chip.hpp:41
Contains an immutable snapshot of the line's state at the time when the object of this class was inst...
Definition: line-info.hpp:34
void close()
Close the GPIO chip device file and free associated resources.
::std::filesystem::path path() const
Get the filesystem path that was used to open this GPIO chip.
Wrapper around unsigned int for representing line offsets.
Definition: line.hpp:34
int fd() const
Get the file descriptor associated with this chip.
bool wait_info_event(const ::std::chrono::nanoseconds &timeout) const
Wait for line status events on any of the watched lines exposed by this chip.
chip(const ::std::filesystem::path &path)
Instantiates a new chip object by opening the device file indicated by the path argument.