libgpiod
Loading...
Searching...
No Matches
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
23namespace gpiod {
24
25class chip_info;
26class info_event;
27class line_config;
28class line_info;
29class line_request;
30class request_builder;
31class request_config;
32
36class chip final
37{
38public:
39
45 explicit chip(const ::std::filesystem::path& path);
46
51 chip(chip&& other) noexcept;
52
54
55 chip& operator=(const chip& other) = delete;
56
62 chip& operator=(chip&& other) noexcept;
63
71 explicit operator bool() const noexcept;
72
78 void close();
79
84 ::std::filesystem::path path() const;
85
91
98 line_info get_line_info(line::offset offset) const;
99
106 line_info watch_line_info(line::offset offset) const;
107
112 void unwatch_line_info(line::offset offset) const;
113
118 int fd() const;
119
130 bool wait_info_event(const ::std::chrono::nanoseconds& timeout) const;
131
137
144 int get_line_offset_from_name(const ::std::string& name) const;
145
151
152private:
153
154 struct impl;
155
156 ::std::shared_ptr<impl> _m_priv;
157
158 chip(const chip& other);
159
160 friend request_builder;
161};
162
169::std::ostream& operator<<(::std::ostream& out, const chip& chip);
170
171} /* namespace gpiod */
172
173#endif /* __LIBGPIOD_CXX_CHIP_HPP__ */
Represents an immutable snapshot of GPIO chip information.
Definition chip-info.hpp:26
Represents a GPIO chip.
Definition chip.hpp:37
chip & operator=(chip &&other) noexcept
Move assignment operator.
chip & operator=(const chip &other)=delete
chip_info get_info() const
Get information about the chip.
void close()
Close the GPIO chip device file and free associated resources.
void unwatch_line_info(line::offset offset) const
Stop watching the line at given offset for info events.
info_event read_info_event() const
Read a single line status change event from this chip.
request_builder prepare_request()
Create a request_builder associated with this chip.
int fd() const
Get the file descriptor associated with this chip.
chip(chip &&other) noexcept
Move constructor.
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...
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.
int get_line_offset_from_name(const ::std::string &name) const
Map a GPIO line's name to its offset within the chip.
chip(const ::std::filesystem::path &path)
Instantiates a new chip object by opening the device file indicated by the path argument.
line_info get_line_info(line::offset offset) const
Retrieve the current snapshot of line information for a single line.
::std::filesystem::path path() const
Get the filesystem path that was used to open this GPIO chip.
Immutable object containing data about a single line info event.
Definition info-event.hpp:30
Contains an immutable snapshot of the line's state at the time when the object of this class was inst...
Definition line-info.hpp:30
Intermediate object storing the configuration for a line request.
Definition request-builder.hpp:29
Definition chip-info.hpp:18