bindings: cxx: implement C++ bindings for libgpiod v2.0
v6 cover bindings: cxx: implement C++ bindings for libgpiod v2.0
This rewrites the C++ bindings for libgpiod in order to work with v2.0 version of the C API. The C++ standard use is C++17 which is well supported in GCC. The documentation covers the entire API so for details please refer to it, the tests and example programs.
I suggested by Kent, I've also split the big patch into several subpatches which are not bisectable but make the review easier.
I'm Cc'ing people who've worked on the C++ bindings over time too in this iteration.
I didn't address all the issues Kent raised in his las review. For the gpiomon example it's because I sent a separate patch fixing the non-blocking behavior of the request file descriptor first.
For the potential edge_event iterator - I simply don't understand how it would work or if it would be needed at all since the code using the buffer and iterating over it is already quite brief.
We can sort that out once we have most of the code in master.
Bartosz Golaszewski (5):
bindings: cxx: remove old code
bindings: cxx: add v2 headers
bindings: cxx: add v2 tests
bindings: cxx: add examples
bindings: cxx: add implementation
Doxyfile.in | 4 +- bindings/cxx/Makefile.am | 23 +- bindings/cxx/chip-info.cpp | 74 ++ bindings/cxx/chip.cpp | 213 +++-- bindings/cxx/edge-event-buffer.cpp | 115 +++ bindings/cxx/edge-event.cpp | 135 +++ bindings/cxx/examples/Makefile.am | 16 +- bindings/cxx/examples/gpiodetectcxx.cpp | 10 +- bindings/cxx/examples/gpiofindcxx.cpp | 4 +- bindings/cxx/examples/gpiogetcxx.cpp | 19 +- bindings/cxx/examples/gpioinfocxx.cpp | 64 +- bindings/cxx/examples/gpiomoncxx.cpp | 53 +- bindings/cxx/examples/gpiosetcxx.cpp | 33 +- bindings/cxx/exception.cpp | 119 +++ bindings/cxx/gpiod.hpp | 944 +------------------- bindings/cxx/gpiodcxx/Makefile.am | 18 + bindings/cxx/gpiodcxx/chip-info.hpp | 105 +++ bindings/cxx/gpiodcxx/chip.hpp | 179 ++++ bindings/cxx/gpiodcxx/edge-event-buffer.hpp | 129 +++ bindings/cxx/gpiodcxx/edge-event.hpp | 137 +++ bindings/cxx/gpiodcxx/exception.hpp | 158 ++++ bindings/cxx/gpiodcxx/info-event.hpp | 123 +++ bindings/cxx/gpiodcxx/line-config.hpp | 564 ++++++++++++ bindings/cxx/gpiodcxx/line-info.hpp | 176 ++++ bindings/cxx/gpiodcxx/line-request.hpp | 221 +++++ bindings/cxx/gpiodcxx/line.hpp | 274 ++++++ bindings/cxx/gpiodcxx/misc.hpp | 44 + bindings/cxx/gpiodcxx/request-config.hpp | 163 ++++ bindings/cxx/gpiodcxx/timestamp.hpp | 122 +++ bindings/cxx/info-event.cpp | 102 +++ bindings/cxx/internal.cpp | 28 + bindings/cxx/internal.hpp | 208 ++++- bindings/cxx/iter.cpp | 60 -- bindings/cxx/line-config.cpp | 685 ++++++++++++++ bindings/cxx/line-info.cpp | 189 ++++ bindings/cxx/line-request.cpp | 225 +++++ bindings/cxx/line.cpp | 331 ++----- bindings/cxx/line_bulk.cpp | 366 -------- bindings/cxx/misc.cpp | 20 + bindings/cxx/request-config.cpp | 174 ++++ bindings/cxx/tests/Makefile.am | 28 +- bindings/cxx/tests/check-kernel.cpp | 48 + bindings/cxx/tests/gpio-mockup.cpp | 153 ---- bindings/cxx/tests/gpio-mockup.hpp | 94 -- bindings/cxx/tests/gpiod-cxx-test.cpp | 55 -- bindings/cxx/tests/gpiosim.cpp | 258 ++++++ bindings/cxx/tests/gpiosim.hpp | 69 ++ bindings/cxx/tests/helpers.cpp | 37 + bindings/cxx/tests/helpers.hpp | 62 ++ bindings/cxx/tests/tests-chip-info.cpp | 109 +++ bindings/cxx/tests/tests-chip.cpp | 218 +++-- bindings/cxx/tests/tests-edge-event.cpp | 417 +++++++++ bindings/cxx/tests/tests-event.cpp | 280 ------ bindings/cxx/tests/tests-info-event.cpp | 198 ++++ bindings/cxx/tests/tests-iter.cpp | 21 - bindings/cxx/tests/tests-line-config.cpp | 270 ++++++ bindings/cxx/tests/tests-line-info.cpp | 156 ++++ bindings/cxx/tests/tests-line-request.cpp | 490 ++++++++++ bindings/cxx/tests/tests-line.cpp | 494 ++-------- bindings/cxx/tests/tests-misc.cpp | 78 ++ bindings/cxx/tests/tests-request-config.cpp | 155 ++++ configure.ac | 1 + 62 files changed, 7406 insertions(+), 2912 deletions(-) create mode 100644 bindings/cxx/chip-info.cpp create mode 100644 bindings/cxx/edge-event-buffer.cpp create mode 100644 bindings/cxx/edge-event.cpp create mode 100644 bindings/cxx/exception.cpp create mode 100644 bindings/cxx/gpiodcxx/Makefile.am create mode 100644 bindings/cxx/gpiodcxx/chip-info.hpp create mode 100644 bindings/cxx/gpiodcxx/chip.hpp create mode 100644 bindings/cxx/gpiodcxx/edge-event-buffer.hpp create mode 100644 bindings/cxx/gpiodcxx/edge-event.hpp create mode 100644 bindings/cxx/gpiodcxx/exception.hpp create mode 100644 bindings/cxx/gpiodcxx/info-event.hpp create mode 100644 bindings/cxx/gpiodcxx/line-config.hpp create mode 100644 bindings/cxx/gpiodcxx/line-info.hpp create mode 100644 bindings/cxx/gpiodcxx/line-request.hpp create mode 100644 bindings/cxx/gpiodcxx/line.hpp create mode 100644 bindings/cxx/gpiodcxx/misc.hpp create mode 100644 bindings/cxx/gpiodcxx/request-config.hpp create mode 100644 bindings/cxx/gpiodcxx/timestamp.hpp create mode 100644 bindings/cxx/info-event.cpp create mode 100644 bindings/cxx/internal.cpp delete mode 100644 bindings/cxx/iter.cpp create mode 100644 bindings/cxx/line-config.cpp create mode 100644 bindings/cxx/line-info.cpp create mode 100644 bindings/cxx/line-request.cpp delete mode 100644 bindings/cxx/line_bulk.cpp create mode 100644 bindings/cxx/misc.cpp create mode 100644 bindings/cxx/request-config.cpp create mode 100644 bindings/cxx/tests/check-kernel.cpp delete mode 100644 bindings/cxx/tests/gpio-mockup.cpp delete mode 100644 bindings/cxx/tests/gpio-mockup.hpp delete mode 100644 bindings/cxx/tests/gpiod-cxx-test.cpp create mode 100644 bindings/cxx/tests/gpiosim.cpp create mode 100644 bindings/cxx/tests/gpiosim.hpp create mode 100644 bindings/cxx/tests/helpers.cpp create mode 100644 bindings/cxx/tests/helpers.hpp create mode 100644 bindings/cxx/tests/tests-chip-info.cpp create mode 100644 bindings/cxx/tests/tests-edge-event.cpp delete mode 100644 bindings/cxx/tests/tests-event.cpp create mode 100644 bindings/cxx/tests/tests-info-event.cpp delete mode 100644 bindings/cxx/tests/tests-iter.cpp create mode 100644 bindings/cxx/tests/tests-line-config.cpp create mode 100644 bindings/cxx/tests/tests-line-info.cpp create mode 100644 bindings/cxx/tests/tests-line-request.cpp create mode 100644 bindings/cxx/tests/tests-misc.cpp create mode 100644 bindings/cxx/tests/tests-request-config.cpp
Signature · 1 line
2.32.0
PATCH v6 1/5 bindings: cxx: remove old code
For easier review, let's first remove the entire sub-tree containing the old C++ bindings.
--- bindings/cxx/Makefile.am | 28 - bindings/cxx/chip.cpp | 157 ---- bindings/cxx/examples/.gitignore | 9 - bindings/cxx/examples/Makefile.am | 26 - bindings/cxx/examples/gpiodetectcxx.cpp | 30 - bindings/cxx/examples/gpiofindcxx.cpp | 32 - bindings/cxx/examples/gpiogetcxx.cpp | 39 - bindings/cxx/examples/gpioinfocxx.cpp | 51 -- bindings/cxx/examples/gpiomoncxx.cpp | 65 -- bindings/cxx/examples/gpiosetcxx.cpp | 48 -- bindings/cxx/gpiod.hpp | 940 --------------------- bindings/cxx/internal.hpp | 9 - bindings/cxx/iter.cpp | 60 -- bindings/cxx/libgpiodcxx.pc.in | 14 - bindings/cxx/line.cpp | 321 ------- bindings/cxx/line_bulk.cpp | 366 -------- bindings/cxx/tests/.gitignore | 4 - bindings/cxx/tests/Makefile.am | 21 - bindings/cxx/tests/gpio-mockup.cpp | 153 ---- bindings/cxx/tests/gpio-mockup.hpp | 94 --- bindings/cxx/tests/gpiod-cxx-test-main.cpp | 5 - bindings/cxx/tests/gpiod-cxx-test.cpp | 55 -- bindings/cxx/tests/tests-chip.cpp | 173 ---- bindings/cxx/tests/tests-event.cpp | 280 ------ bindings/cxx/tests/tests-iter.cpp | 21 - bindings/cxx/tests/tests-line.cpp | 467 ---------- 26 files changed, 3468 deletions(-) delete mode 100644 bindings/cxx/Makefile.am delete mode 100644 bindings/cxx/chip.cpp delete mode 100644 bindings/cxx/examples/.gitignore delete mode 100644 bindings/cxx/examples/Makefile.am delete mode 100644 bindings/cxx/examples/gpiodetectcxx.cpp delete mode 100644 bindings/cxx/examples/gpiofindcxx.cpp delete mode 100644 bindings/cxx/examples/gpiogetcxx.cpp delete mode 100644 bindings/cxx/examples/gpioinfocxx.cpp delete mode 100644 bindings/cxx/examples/gpiomoncxx.cpp delete mode 100644 bindings/cxx/examples/gpiosetcxx.cpp delete mode 100644 bindings/cxx/gpiod.hpp delete mode 100644 bindings/cxx/internal.hpp delete mode 100644 bindings/cxx/iter.cpp delete mode 100644 bindings/cxx/libgpiodcxx.pc.in delete mode 100644 bindings/cxx/line.cpp delete mode 100644 bindings/cxx/line_bulk.cpp delete mode 100644 bindings/cxx/tests/.gitignore delete mode 100644 bindings/cxx/tests/Makefile.am delete mode 100644 bindings/cxx/tests/gpio-mockup.cpp delete mode 100644 bindings/cxx/tests/gpio-mockup.hpp delete mode 100644 bindings/cxx/tests/gpiod-cxx-test-main.cpp delete mode 100644 bindings/cxx/tests/gpiod-cxx-test.cpp delete mode 100644 bindings/cxx/tests/tests-chip.cpp delete mode 100644 bindings/cxx/tests/tests-event.cpp delete mode 100644 bindings/cxx/tests/tests-iter.cpp delete mode 100644 bindings/cxx/tests/tests-line.cpp
bindings/cxx/Makefile.am deleted +0 -28
@@ -1,28 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -lib_LTLIBRARIES = libgpiodcxx.la -libgpiodcxx_la_SOURCES = chip.cpp internal.h iter.cpp line.cpp line_bulk.cpp -libgpiodcxx_la_CPPFLAGS = -Wall -Wextra -g -std=gnu++11 -libgpiodcxx_la_CPPFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/ -libgpiodcxx_la_LDFLAGS = -version-info $(subst .,:,$(ABI_CXX_VERSION)) -libgpiodcxx_la_LDFLAGS += -lgpiod -L$(top_builddir)/lib - -include_HEADERS = gpiod.hpp - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libgpiodcxx.pc - -SUBDIRS = . - -if WITH_TESTS - -SUBDIRS += tests - -endif - -if WITH_EXAMPLES - -SUBDIRS += examples - -endif
bindings/cxx/chip.cpp deleted +0 -157
157 lines not on this page · raw message
bindings/cxx/examples/.gitignore deleted +0 -9
@@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -gpiodetectcxx -gpiofindcxx -gpiogetcxx -gpioinfocxx -gpiomoncxx -gpiosetcxx
bindings/cxx/examples/Makefile.am deleted +0 -26
@@ -1,26 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -AM_CPPFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include -AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++17 -AM_LDFLAGS = -lgpiodcxx -L$(top_builddir)/bindings/cxx/ -lstdc++fs - -noinst_PROGRAMS = \ - gpiodetectcxx \ - gpiofindcxx \ - gpiogetcxx \ - gpioinfocxx \ - gpiomoncxx \ - gpiosetcxx - -gpiodetectcxx_SOURCES = gpiodetectcxx.cpp - -gpiofindcxx_SOURCES = gpiofindcxx.cpp - -gpiogetcxx_SOURCES = gpiogetcxx.cpp - -gpioinfocxx_SOURCES = gpioinfocxx.cpp - -gpiomoncxx_SOURCES = gpiomoncxx.cpp - -gpiosetcxx_SOURCES = gpiosetcxx.cpp
bindings/cxx/examples/gpiodetectcxx.cpp deleted +0 -30
@@ -1,30 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -/* C++ reimplementation of the gpiodetect tool. */ - -#include <gpiod.hpp> - -#include <cstdlib> -#include <filesystem> -#include <iostream> - -int main(int argc, char **argv) -{ - if (argc != 1) { - ::std::cerr << "usage: " << argv[0] << ::std::endl; - return EXIT_FAILURE; - } - - for (const auto& entry: ::std::filesystem::directory_iterator("/dev/")) { - if (::gpiod::is_gpiochip_device(entry.path())) { - ::gpiod::chip chip(entry.path()); - - ::std::cout << chip.name() << " [" - << chip.label() << "] (" - << chip.num_lines() << " lines)" << ::std::endl; - } - } - - return EXIT_SUCCESS; -}
bindings/cxx/examples/gpiofindcxx.cpp deleted +0 -32
@@ -1,32 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -/* C++ reimplementation of the gpiofind tool. */ - -#include <gpiod.hpp> - -#include <cstdlib> -#include <filesystem> -#include <iostream> - -int main(int argc, char **argv) -{ - if (argc != 2) { - ::std::cerr << "usage: " << argv[0] << " <line name>" << ::std::endl; - return EXIT_FAILURE; - } - - for (const auto& entry: ::std::filesystem::directory_iterator("/dev/")) { - if (::gpiod::is_gpiochip_device(entry.path())) { - ::gpiod::chip chip(entry.path()); - - auto offset = chip.find_line(argv[1]); - if (offset >= 0) { - ::std::cout << chip.name() << " " << offset << ::std::endl; - return EXIT_SUCCESS; - } - } - } - - return EXIT_FAILURE; -}
bindings/cxx/examples/gpiogetcxx.cpp deleted +0 -39
@@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -/* Simplified C++ reimplementation of the gpioget tool. */ - -#include <gpiod.hpp> - -#include <cstdlib> -#include <iostream> - -int main(int argc, char **argv) -{ - if (argc < 3) { - ::std::cerr << "usage: " << argv[0] << " <chip> <line_offset0> ..." << ::std::endl; - return EXIT_FAILURE; - } - - ::std::vector<unsigned int> offsets; - - for (int i = 2; i < argc; i++) - offsets.push_back(::std::stoul(argv[i])); - - ::gpiod::chip chip(argv[1]); - auto lines = chip.get_lines(offsets); - - lines.request({ - argv[0], - ::gpiod::line_request::DIRECTION_INPUT, - 0 - }); - - auto vals = lines.get_values(); - - for (auto& it: vals) - ::std::cout << it << ' '; - ::std::cout << ::std::endl; - - return EXIT_SUCCESS; -}
bindings/cxx/examples/gpioinfocxx.cpp deleted +0 -51
51 lines not on this page · raw message
bindings/cxx/examples/gpiomoncxx.cpp deleted +0 -65
65 lines not on this page · raw message
bindings/cxx/examples/gpiosetcxx.cpp deleted +0 -48
48 lines not on this page · raw message
bindings/cxx/gpiod.hpp deleted +0 -940
940 lines not on this page · raw message
bindings/cxx/internal.hpp deleted +0 -9
@@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: LGPL-3.0-or-later */ -/* SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <[email protected]> */ - -#ifndef __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__ -#define __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__ - -#define GPIOD_CXX_API __attribute__((visibility("default"))) - -#endif /* __LIBGPIOD_GPIOD_CXX_INTERNAL_HPP__ */
bindings/cxx/iter.cpp deleted +0 -60
60 lines not on this page · raw message
bindings/cxx/libgpiodcxx.pc.in deleted +0 -14
@@ -1,14 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libgpiodcxx -Description: C++ bindings for libgpiod -URL: @PACKAGE_URL@ -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lgpiodcxx -Cflags: -I${includedir}
bindings/cxx/line.cpp deleted +0 -321
321 lines not on this page · raw message
bindings/cxx/line_bulk.cpp deleted +0 -366
366 lines not on this page · raw message
bindings/cxx/tests/.gitignore deleted +0 -4
@@ -1,4 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -gpiod-cxx-test
bindings/cxx/tests/Makefile.am deleted +0 -21
@@ -1,21 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-or-later -# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -AM_CPPFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include -AM_CPPFLAGS += -I$(top_srcdir)/tests/mockup/ -AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++11 $(CATCH2_CFLAGS) -AM_LDFLAGS = -lgpiodcxx -L$(top_builddir)/bindings/cxx/ -AM_LDFLAGS += -lgpiomockup -L$(top_builddir)/tests/mockup/ -AM_LDFLAGS += -pthread - -bin_PROGRAMS = gpiod-cxx-test - -gpiod_cxx_test_SOURCES = \ - gpiod-cxx-test-main.cpp \ - gpiod-cxx-test.cpp \ - gpio-mockup.cpp \ - gpio-mockup.hpp \ - tests-chip.cpp \ - tests-event.cpp \ - tests-iter.cpp \ - tests-line.cpp
bindings/cxx/tests/gpio-mockup.cpp deleted +0 -153
153 lines not on this page · raw message
bindings/cxx/tests/gpio-mockup.hpp deleted +0 -94
94 lines not on this page · raw message
bindings/cxx/tests/gpiod-cxx-test-main.cpp deleted +0 -5
@@ -1,5 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -#define CATCH_CONFIG_MAIN -#include <catch2/catch.hpp>
bindings/cxx/tests/gpiod-cxx-test.cpp deleted +0 -55
55 lines not on this page · raw message
bindings/cxx/tests/tests-chip.cpp deleted +0 -173
173 lines not on this page · raw message
bindings/cxx/tests/tests-event.cpp deleted +0 -280
280 lines not on this page · raw message
bindings/cxx/tests/tests-iter.cpp deleted +0 -21
@@ -1,21 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> - -#include <catch2/catch.hpp> -#include <gpiod.hpp> - -#include "gpio-mockup.hpp" - -using ::gpiod::test::mockup; - -TEST_CASE("Line iterator works", "[iter][line]") -{ - mockup::probe_guard mockup_chips({ 4 }); - ::gpiod::chip chip(mockup::instance().chip_path(0)); - unsigned int count = 0; - - for (auto& it: ::gpiod::line_iter(chip)) - REQUIRE(it.offset() == count++); - - REQUIRE(count == chip.num_lines());
Lines of this file are not shown. View the raw message.
bindings/cxx/tests/tests-line.cpp deleted +0 -467
467 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.32.0
Part of the diff is not shown here. View the raw message.
PATCH v6 2/5 bindings: cxx: add v2 headers
In reply to Bartosz GolaszewskiThis adds the headers for the v2 C++ bindings.
--- Doxyfile.in | 4 +- bindings/cxx/gpiodcxx/Makefile.am | 18 + bindings/cxx/gpiodcxx/chip-info.hpp | 105 ++++ bindings/cxx/gpiodcxx/chip.hpp | 179 +++++++ bindings/cxx/gpiodcxx/edge-event-buffer.hpp | 129 +++++ bindings/cxx/gpiodcxx/edge-event.hpp | 137 +++++ bindings/cxx/gpiodcxx/exception.hpp | 158 ++++++ bindings/cxx/gpiodcxx/info-event.hpp | 123 +++++ bindings/cxx/gpiodcxx/line-config.hpp | 564 ++++++++++++++++++++ bindings/cxx/gpiodcxx/line-info.hpp | 176 ++++++ bindings/cxx/gpiodcxx/line-request.hpp | 221 ++++++++ bindings/cxx/gpiodcxx/line.hpp | 274 ++++++++++ bindings/cxx/gpiodcxx/misc.hpp | 44 ++ bindings/cxx/gpiodcxx/request-config.hpp | 163 ++++++ bindings/cxx/gpiodcxx/timestamp.hpp | 122 +++++ configure.ac | 1 + 16 files changed, 2417 insertions(+), 1 deletion(-) create mode 100644 bindings/cxx/gpiodcxx/Makefile.am create mode 100644 bindings/cxx/gpiodcxx/chip-info.hpp create mode 100644 bindings/cxx/gpiodcxx/chip.hpp create mode 100644 bindings/cxx/gpiodcxx/edge-event-buffer.hpp create mode 100644 bindings/cxx/gpiodcxx/edge-event.hpp create mode 100644 bindings/cxx/gpiodcxx/exception.hpp create mode 100644 bindings/cxx/gpiodcxx/info-event.hpp create mode 100644 bindings/cxx/gpiodcxx/line-config.hpp create mode 100644 bindings/cxx/gpiodcxx/line-info.hpp create mode 100644 bindings/cxx/gpiodcxx/line-request.hpp create mode 100644 bindings/cxx/gpiodcxx/line.hpp create mode 100644 bindings/cxx/gpiodcxx/misc.hpp create mode 100644 bindings/cxx/gpiodcxx/request-config.hpp create mode 100644 bindings/cxx/gpiodcxx/timestamp.hpp
Doxyfile.in +3 -1
@@ -44,7 +44,9 @@ WARNINGS = YES WARN_IF_UNDOCUMENTED = YES WARN_FORMAT = WARN_LOGFILE = -INPUT = @top_srcdir@/include/gpiod.h @top_srcdir@/bindings/cxx/gpiod.hpp +INPUT = @top_srcdir@/include/gpiod.h \ + @top_srcdir@/bindings/cxx/gpiod.hpp \ + @top_srcdir@/bindings/cxx/gpiodcxx/ SOURCE_BROWSER = YES INLINE_SOURCES = NO REFERENCED_BY_RELATION = YES
bindings/cxx/gpiodcxx/Makefile.am new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <[email protected]> + +otherincludedir = $(includedir)/gpiodcxx +otherinclude_HEADERS = \ + chip.hpp \ + chip-info.hpp \ + edge-event-buffer.hpp \ + edge-event.hpp \ + exception.hpp \ + info-event.hpp \ + line.hpp \ + line-config.hpp \ + line-info.hpp \ + line-request.hpp \ + misc.hpp \ + request-config.hpp \ + timestamp.hpp
bindings/cxx/gpiodcxx/chip-info.hpp new file +105 -0
105 lines not on this page · raw message
bindings/cxx/gpiodcxx/chip.hpp new file +179 -0
179 lines not on this page · raw message
bindings/cxx/gpiodcxx/edge-event-buffer.hpp new file +129 -0
129 lines not on this page · raw message
bindings/cxx/gpiodcxx/edge-event.hpp new file +137 -0
137 lines not on this page · raw message
bindings/cxx/gpiodcxx/exception.hpp new file +158 -0
158 lines not on this page · raw message
bindings/cxx/gpiodcxx/info-event.hpp new file +123 -0
123 lines not on this page · raw message
bindings/cxx/gpiodcxx/line-config.hpp new file +564 -0
564 lines not on this page · raw message
bindings/cxx/gpiodcxx/line-info.hpp new file +176 -0
176 lines not on this page · raw message
bindings/cxx/gpiodcxx/line-request.hpp new file +221 -0
221 lines not on this page · raw message
bindings/cxx/gpiodcxx/line.hpp new file +274 -0
274 lines not on this page · raw message
bindings/cxx/gpiodcxx/misc.hpp new file +44 -0
44 lines not on this page · raw message
bindings/cxx/gpiodcxx/request-config.hpp new file +163 -0
163 lines not on this page · raw message
bindings/cxx/gpiodcxx/timestamp.hpp new file +122 -0
122 lines not on this page · raw message
configure.ac +1 -0
@@ -239,6 +239,7 @@ AC_CONFIG_FILES([Makefile bindings/cxx/libgpiodcxx.pc bindings/Makefile bindings/cxx/Makefile + bindings/cxx/gpiodcxx/Makefile bindings/cxx/examples/Makefile bindings/cxx/tests/Makefile bindings/python/Makefile
Signature · 1 line
2.32.0
Re: [libgpiod v2][PATCH v6 2/5] bindings: cxx: add v2 headers
Quoted 4 lines · Bartosz Golaszewski
This adds the headers for the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>
I'm pasting below the review I got from my work colleague Bernhard Rosenkränzer (Cc'ed):
Bart
---
Looks good to me, one minor nit: I presume bindings/cxx/gpiod.hpp Is supposed to be #include-d by users of the library. The definition of GPIOD_CXX_API in the file causes the symbol to be re-exported by anything including the header. Usually the way to achieve what you want there is
AM_CPPFLAGS += -DBUILDING_GPIOD=1
in Makefile.am, and the definition of GPIOD_CXX_API changed to
#ifdef BUILDING_GPIOD
#define GPIOD_CXX_API __attribute__((visibility("default"))) #else
#define GPIOD_CXX_API __attribute__((visibility("hidden"))) #endif
Also, in Makefile.am you probably want to change libgpiodcxx_la_CPPFLAGS to libgpiodcxx_la_CXXFLAGS -- CPPFLAGS is for C/C++ PreProcessor flags, CXXFLAGS is for the C++ compiler
Doesn't make much of a difference currently because at least with clang and gcc the preprocessor isn't called separately, but you never know what kind of insanity a future automake version will bring
You might also want to change the various methods taking (void) [none] as parameters to just taking () -- (void) is a C-ism, not needed for C++ (and you never know if at some point the standard will actually disallow it)
Also, I'm not sure if it's intentional that some classes (class chip etc.) aren't marked GPIOD_CXX_API
line-config.hpp uses using override = ::std::pair<line::offset, property>; -- override is a reserved word (to be used by something inheriting a class to indicate the method being defined overrides a base class method -- optional, what it actually does is cause a compile time error if parameters mismatch or there's some other reason why it doesn't overload something), so using it in this context might break with some compilers
Minor nit: some parameters could add more const-ness (e.g. void clear_drive_override(*const* line::offset offset) noexcept;)
In theory, this could help a compiler optimize something out, but in practice I don't know any compiler that would actually generate better code from that
PATCH v6 3/5 bindings: cxx: add v2 tests
In reply to Bartosz GolaszewskiThis adds the tests for the v2 C++ bindings.
--- bindings/cxx/tests/.gitignore | 4 + bindings/cxx/tests/Makefile.am | 31 ++ bindings/cxx/tests/check-kernel.cpp | 48 ++ bindings/cxx/tests/gpiod-cxx-test-main.cpp | 5 + bindings/cxx/tests/gpiosim.cpp | 258 +++++++++++ bindings/cxx/tests/gpiosim.hpp | 69 +++ bindings/cxx/tests/helpers.cpp | 37 ++ bindings/cxx/tests/helpers.hpp | 62 +++ bindings/cxx/tests/tests-chip-info.cpp | 109 +++++ bindings/cxx/tests/tests-chip.cpp | 171 +++++++ bindings/cxx/tests/tests-edge-event.cpp | 417 +++++++++++++++++ bindings/cxx/tests/tests-info-event.cpp | 198 ++++++++ bindings/cxx/tests/tests-line-config.cpp | 270 +++++++++++ bindings/cxx/tests/tests-line-info.cpp | 156 +++++++ bindings/cxx/tests/tests-line-request.cpp | 490 ++++++++++++++++++++ bindings/cxx/tests/tests-line.cpp | 137 ++++++ bindings/cxx/tests/tests-misc.cpp | 78 ++++ bindings/cxx/tests/tests-request-config.cpp | 155 +++++++ 18 files changed, 2695 insertions(+) create mode 100644 bindings/cxx/tests/.gitignore create mode 100644 bindings/cxx/tests/Makefile.am create mode 100644 bindings/cxx/tests/check-kernel.cpp create mode 100644 bindings/cxx/tests/gpiod-cxx-test-main.cpp create mode 100644 bindings/cxx/tests/gpiosim.cpp create mode 100644 bindings/cxx/tests/gpiosim.hpp create mode 100644 bindings/cxx/tests/helpers.cpp create mode 100644 bindings/cxx/tests/helpers.hpp create mode 100644 bindings/cxx/tests/tests-chip-info.cpp create mode 100644 bindings/cxx/tests/tests-chip.cpp create mode 100644 bindings/cxx/tests/tests-edge-event.cpp create mode 100644 bindings/cxx/tests/tests-info-event.cpp create mode 100644 bindings/cxx/tests/tests-line-config.cpp create mode 100644 bindings/cxx/tests/tests-line-info.cpp create mode 100644 bindings/cxx/tests/tests-line-request.cpp create mode 100644 bindings/cxx/tests/tests-line.cpp create mode 100644 bindings/cxx/tests/tests-misc.cpp create mode 100644 bindings/cxx/tests/tests-request-config.cpp
bindings/cxx/tests/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +gpiod-cxx-test
bindings/cxx/tests/Makefile.am new file +31 -0
@@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +AM_CPPFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include +AM_CPPFLAGS += -I$(top_srcdir)/tests/gpiosim/ +AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++17 $(CATCH2_CFLAGS) +AM_CPPFLAGS += $(PROFILING_CFLAGS) +AM_LDFLAGS = -lgpiodcxx -L$(top_builddir)/bindings/cxx/ +AM_LDFLAGS += -lgpiosim -L$(top_builddir)/tests/gpiosim/ +AM_LDFLAGS += $(PROFILING_LDFLAGS) +AM_LDFLAGS += -pthread + +bin_PROGRAMS = gpiod-cxx-test + +gpiod_cxx_test_SOURCES = \ + check-kernel.cpp \ + gpiod-cxx-test-main.cpp \ + gpiosim.cpp \ + gpiosim.hpp \ + helpers.cpp \ + helpers.hpp \ + tests-chip.cpp \ + tests-chip-info.cpp \ + tests-edge-event.cpp \ + tests-line.cpp \ + tests-line-config.cpp \ + tests-line-info.cpp \ + tests-line-request.cpp \ + tests-info-event.cpp \ + tests-misc.cpp \ + tests-request-config.cpp
bindings/cxx/tests/check-kernel.cpp new file +48 -0
48 lines not on this page · raw message
bindings/cxx/tests/gpiod-cxx-test-main.cpp new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp>
bindings/cxx/tests/gpiosim.cpp new file +258 -0
258 lines not on this page · raw message
bindings/cxx/tests/gpiosim.hpp new file +69 -0
69 lines not on this page · raw message
bindings/cxx/tests/helpers.cpp new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> + +#include "helpers.hpp" + +system_error_matcher::system_error_matcher(int expected_errno) + : _m_cond(::std::system_category().default_error_condition(expected_errno)) +{ + +} + +::std::string system_error_matcher::describe(void) const +{ + return "matches: errno " + ::std::to_string(this->_m_cond.value()); +} + +bool system_error_matcher::match(const ::std::system_error& error) const +{ + return error.code().value() == this->_m_cond.value(); +} + +regex_matcher::regex_matcher(const ::std::string& pattern) + : _m_pattern(pattern), + _m_repr("matches: regex \"" + pattern + "\"") +{ + +} + +::std::string regex_matcher::describe(void) const +{ + return this->_m_repr; +} + +bool regex_matcher::match(const ::std::string& str) const +{ + return ::std::regex_match(str, this->_m_pattern); +}
bindings/cxx/tests/helpers.hpp new file +62 -0
62 lines not on this page · raw message
bindings/cxx/tests/tests-chip-info.cpp new file +109 -0
109 lines not on this page · raw message
bindings/cxx/tests/tests-chip.cpp new file +171 -0
171 lines not on this page · raw message
bindings/cxx/tests/tests-edge-event.cpp new file +417 -0
417 lines not on this page · raw message
bindings/cxx/tests/tests-info-event.cpp new file +198 -0
198 lines not on this page · raw message
bindings/cxx/tests/tests-line-config.cpp new file +270 -0
270 lines not on this page · raw message
bindings/cxx/tests/tests-line-info.cpp new file +156 -0
156 lines not on this page · raw message
bindings/cxx/tests/tests-line-request.cpp new file +490 -0
490 lines not on this page · raw message
bindings/cxx/tests/tests-line.cpp new file +137 -0
137 lines not on this page · raw message
bindings/cxx/tests/tests-misc.cpp new file +78 -0
78 lines not on this page · raw message
bindings/cxx/tests/tests-request-config.cpp new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH v6 4/5 bindings: cxx: add examples
In reply to Bartosz GolaszewskiThis adds a couple example tools written using the new bindings.
--- bindings/cxx/examples/.gitignore | 9 +++ bindings/cxx/examples/Makefile.am | 26 +++++++++ bindings/cxx/examples/gpiodetectcxx.cpp | 30 ++++++++++ bindings/cxx/examples/gpiofindcxx.cpp | 32 +++++++++++ bindings/cxx/examples/gpiogetcxx.cpp | 38 +++++++++++++ bindings/cxx/examples/gpioinfocxx.cpp | 61 ++++++++++++++++++++ bindings/cxx/examples/gpiomoncxx.cpp | 74 +++++++++++++++++++++++++ bindings/cxx/examples/gpiosetcxx.cpp | 57 +++++++++++++++++++ 8 files changed, 327 insertions(+) create mode 100644 bindings/cxx/examples/.gitignore create mode 100644 bindings/cxx/examples/Makefile.am create mode 100644 bindings/cxx/examples/gpiodetectcxx.cpp create mode 100644 bindings/cxx/examples/gpiofindcxx.cpp create mode 100644 bindings/cxx/examples/gpiogetcxx.cpp create mode 100644 bindings/cxx/examples/gpioinfocxx.cpp create mode 100644 bindings/cxx/examples/gpiomoncxx.cpp create mode 100644 bindings/cxx/examples/gpiosetcxx.cpp
bindings/cxx/examples/.gitignore new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +gpiodetectcxx +gpiofindcxx +gpiogetcxx +gpioinfocxx +gpiomoncxx +gpiosetcxx
bindings/cxx/examples/Makefile.am new file +26 -0
@@ -0,0 +1,26 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +AM_CPPFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include +AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++17 +AM_LDFLAGS = -lgpiodcxx -L$(top_builddir)/bindings/cxx/ + +noinst_PROGRAMS = \ + gpiodetectcxx \ + gpiofindcxx \ + gpiogetcxx \ + gpioinfocxx \ + gpiomoncxx \ + gpiosetcxx + +gpiodetectcxx_SOURCES = gpiodetectcxx.cpp + +gpiofindcxx_SOURCES = gpiofindcxx.cpp + +gpiogetcxx_SOURCES = gpiogetcxx.cpp + +gpioinfocxx_SOURCES = gpioinfocxx.cpp + +gpiomoncxx_SOURCES = gpiomoncxx.cpp + +gpiosetcxx_SOURCES = gpiosetcxx.cpp
bindings/cxx/examples/gpiodetectcxx.cpp new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +/* C++ reimplementation of the gpiodetect tool. */ + +#include <cstdlib> +#include <filesystem> +#include <gpiod.hpp> +#include <iostream> + +int main(int argc, char **argv) +{ + if (argc != 1) { + ::std::cerr << "usage: " << argv[0] << ::std::endl; + return EXIT_FAILURE; + } + + for (const auto& entry: ::std::filesystem::directory_iterator("/dev/")) { + if (::gpiod::is_gpiochip_device(entry.path())) { + ::gpiod::chip chip(entry.path()); + auto info = chip.get_info(); + + ::std::cout << info.name() << " [" << + info.label() << "] (" << + info.num_lines() << " lines)" << ::std::endl; + } + } + + return EXIT_SUCCESS; +}
bindings/cxx/examples/gpiofindcxx.cpp new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +/* C++ reimplementation of the gpiofind tool. */ + +#include <gpiod.hpp> + +#include <cstdlib> +#include <filesystem> +#include <iostream> + +int main(int argc, char **argv) +{ + if (argc != 2) { + ::std::cerr << "usage: " << argv[0] << " <line name>" << ::std::endl; + return EXIT_FAILURE; + } + + for (const auto& entry: ::std::filesystem::directory_iterator("/dev/")) { + if (::gpiod::is_gpiochip_device(entry.path())) { + ::gpiod::chip chip(entry.path()); + + auto offset = chip.get_line_offset_from_name(argv[1]); + if (offset >= 0) { + ::std::cout << chip.get_info().name() << " " << offset << ::std::endl; + return EXIT_SUCCESS; + } + } + } + + return EXIT_FAILURE; +}
bindings/cxx/examples/gpiogetcxx.cpp new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +/* Simplified C++ reimplementation of the gpioget tool. */ + +#include <gpiod.hpp> + +#include <cstdlib> +#include <iostream> + +int main(int argc, char **argv) +{ + if (argc < 3) { + ::std::cerr << "usage: " << argv[0] << " <chip> <line_offset0> ..." << ::std::endl; + return EXIT_FAILURE; + } + + ::gpiod::line::offsets offsets; + + for (int i = 2; i < argc; i++) + offsets.push_back(::std::stoul(argv[i])); + + ::gpiod::chip chip(argv[1]); + auto request = chip.request_lines( + ::gpiod::request_config({ + { ::gpiod::request_config::property::OFFSETS, offsets }, + { ::gpiod::request_config::property::CONSUMER, "gpiogetcxx" } + }), + ::gpiod::line_config()); + + auto vals = request.get_values(); + + for (auto& it: vals) + ::std::cout << (it == ::gpiod::line::value::ACTIVE ? "1" : "0") << ' '; + ::std::cout << ::std::endl; + + return EXIT_SUCCESS; +}
bindings/cxx/examples/gpioinfocxx.cpp new file +61 -0
61 lines not on this page · raw message
bindings/cxx/examples/gpiomoncxx.cpp new file +74 -0
74 lines not on this page · raw message
bindings/cxx/examples/gpiosetcxx.cpp new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH v6 5/5 bindings: cxx: add implementation
In reply to Bartosz GolaszewskiThis contains the actual implementation of the v2 C++ bindings.
--- bindings/cxx/Makefile.am | 45 ++ bindings/cxx/chip-info.cpp | 74 ++++ bindings/cxx/chip.cpp | 218 +++++++++ bindings/cxx/edge-event-buffer.cpp | 115 +++++ bindings/cxx/edge-event.cpp | 135 ++++++ bindings/cxx/exception.cpp | 119 +++++ bindings/cxx/gpiod.hpp | 46 ++ bindings/cxx/info-event.cpp | 102 +++++ bindings/cxx/internal.cpp | 28 ++ bindings/cxx/internal.hpp | 207 +++++++++ bindings/cxx/libgpiodcxx.pc.in | 14 + bindings/cxx/line-config.cpp | 685 +++++++++++++++++++++++++++++ bindings/cxx/line-info.cpp | 189 ++++++++ bindings/cxx/line-request.cpp | 225 ++++++++++ bindings/cxx/line.cpp | 128 ++++++ bindings/cxx/misc.cpp | 20 + bindings/cxx/request-config.cpp | 174 ++++++++ 17 files changed, 2524 insertions(+) create mode 100644 bindings/cxx/Makefile.am create mode 100644 bindings/cxx/chip-info.cpp create mode 100644 bindings/cxx/chip.cpp create mode 100644 bindings/cxx/edge-event-buffer.cpp create mode 100644 bindings/cxx/edge-event.cpp create mode 100644 bindings/cxx/exception.cpp create mode 100644 bindings/cxx/gpiod.hpp create mode 100644 bindings/cxx/info-event.cpp create mode 100644 bindings/cxx/internal.cpp create mode 100644 bindings/cxx/internal.hpp create mode 100644 bindings/cxx/libgpiodcxx.pc.in create mode 100644 bindings/cxx/line-config.cpp create mode 100644 bindings/cxx/line-info.cpp create mode 100644 bindings/cxx/line-request.cpp create mode 100644 bindings/cxx/line.cpp create mode 100644 bindings/cxx/misc.cpp create mode 100644 bindings/cxx/request-config.cpp
bindings/cxx/Makefile.am new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +lib_LTLIBRARIES = libgpiodcxx.la +libgpiodcxx_la_SOURCES = \ + chip.cpp \ + chip-info.cpp \ + edge-event-buffer.cpp \ + edge-event.cpp \ + exception.cpp \ + info-event.cpp \ + internal.cpp \ + internal.hpp \ + line.cpp \ + line-config.cpp \ + line-info.cpp \ + line-request.cpp \ + misc.cpp \ + request-config.cpp + +libgpiodcxx_la_CPPFLAGS = -Wall -Wextra -g -std=gnu++17 +libgpiodcxx_la_CPPFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/ +libgpiodcxx_la_CPPFLAGS += $(PROFILING_CFLAGS) +libgpiodcxx_la_LDFLAGS = -version-info $(subst .,:,$(ABI_CXX_VERSION)) +libgpiodcxx_la_LDFLAGS += -lgpiod -L$(top_builddir)/lib +libgpiodcxx_la_LDFLAGS += $(PROFILING_LDFLAGS) + +include_HEADERS = gpiod.hpp + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libgpiodcxx.pc + +SUBDIRS = gpiodcxx . + +if WITH_TESTS + +SUBDIRS += tests + +endif + +if WITH_EXAMPLES + +SUBDIRS += examples + +endif
bindings/cxx/chip-info.cpp new file +74 -0
74 lines not on this page · raw message
bindings/cxx/chip.cpp new file +218 -0
218 lines not on this page · raw message
bindings/cxx/edge-event-buffer.cpp new file +115 -0
115 lines not on this page · raw message
bindings/cxx/edge-event.cpp new file +135 -0
135 lines not on this page · raw message
bindings/cxx/exception.cpp new file +119 -0
119 lines not on this page · raw message
bindings/cxx/gpiod.hpp new file +46 -0
46 lines not on this page · raw message
bindings/cxx/info-event.cpp new file +102 -0
102 lines not on this page · raw message
bindings/cxx/internal.cpp new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> + +#include <map> +#include <stdexcept> +#include <system_error> + +#include "internal.hpp" + +namespace gpiod { + +void throw_from_errno(const ::std::string& what) +{ + switch (errno) { + case EINVAL: + throw ::std::invalid_argument(what); + case E2BIG: + throw ::std::length_error(what); + case ENOMEM: + throw ::std::bad_alloc(); + case EDOM: + throw ::std::domain_error(what); + default: + throw ::std::system_error(errno, ::std::system_category(), what); + } +} + +} /* namespace gpiod */
bindings/cxx/internal.hpp new file +207 -0
207 lines not on this page · raw message
bindings/cxx/libgpiodcxx.pc.in new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# SPDX-FileCopyrightText: 2017-2021 Bartosz Golaszewski <[email protected]> + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libgpiodcxx +Description: C++ bindings for libgpiod +URL: @PACKAGE_URL@ +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lgpiodcxx +Cflags: -I${includedir}
bindings/cxx/line-config.cpp new file +685 -0
685 lines not on this page · raw message
bindings/cxx/line-info.cpp new file +189 -0
189 lines not on this page · raw message
bindings/cxx/line-request.cpp new file +225 -0
225 lines not on this page · raw message
bindings/cxx/line.cpp new file +128 -0
128 lines not on this page · raw message
bindings/cxx/misc.cpp new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> + +#include "internal.hpp" + +namespace gpiod { + +GPIOD_CXX_API bool is_gpiochip_device(const ::std::filesystem::path& path) +{ + return ::gpiod_is_gpiochip_device(path.c_str()); +} + +GPIOD_CXX_API const ::std::string& version_string(void) +{ + static const ::std::string version(::gpiod_version_string()); + + return version; +} + +} /* namespace gpiod */
bindings/cxx/request-config.cpp new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [libgpiod v2][PATCH v6 5/5] bindings: cxx: add implementation
Quoted 3 lines · Bartosz Golaszewski
This contains the actual implementation of the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>
[snip]
Quoted 14 lines
bindings/cxx/line-request.cpp new file +14
-0+ +GPIOD_CXX_API ::std::size_t line_request::num_lines(void) const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_num_lines(this->_m_priv->request.get()); +} + +GPIOD_CXX_API line::offsets line_request::offsets(void) const +{ + this->_m_priv->throw_if_released(); + + ::std::vector<unsigned int> buf(this->num_lines()); + line::offsets offsets(this->num_lines());
bindings/cxx/line-request.cpp line 87
Quoted 10 lines
bindings/cxx/line-request.cpp new file +10
-0+ + ::gpiod_line_request_get_offsets(this->_m_priv->request.get(), buf.data()); + + auto num_lines = this->num_lines(); + for (unsigned int i = 0; i < num_lines; i++) + offsets[i] = buf[i]; + + return offsets; +} +
My previous comment was "Cache num_lines locally rather than calling num_lines() several times."
You cached it in the wrong place - it should be first thing in the function, so you only call it once, not three times.
And the throw_if_released() is still "redundant as this->num_lines() also does it", and it is the first thing called here - after the throw_if_released().
And I would've made this patch 3/5, not 5/5.
But I'm fine with this set going in either way - in fact give its size I'd rather see minor tweaks applied later than go through another round of review.
For the series:
I really would also like to see some feedback from C++ developers that will actually be using it, as they have a bigger stake in it than I do. But that is up to them.
Cheers,
Kent.
Re: [libgpiod v2][PATCH v6 5/5] bindings: cxx: add implementation
Quoted 36 lines · Kent Gibson
Quoted 3 lines · Bartosz Golaszewski
This contains the actual implementation of the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>[snip]
Quoted 14 lines
bindings/cxx/line-request.cpp new file +14
-0+ +GPIOD_CXX_API ::std::size_t line_request::num_lines(void) const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_num_lines(this->_m_priv->request.get()); +} + +GPIOD_CXX_API line::offsets line_request::offsets(void) const +{ + this->_m_priv->throw_if_released(); + + ::std::vector<unsigned int> buf(this->num_lines()); + line::offsets offsets(this->num_lines());bindings/cxx/line-request.cpp line 87
Quoted 10 lines
bindings/cxx/line-request.cpp new file +10
-0+ + ::gpiod_line_request_get_offsets(this->_m_priv->request.get(), buf.data()); + + auto num_lines = this->num_lines(); + for (unsigned int i = 0; i < num_lines; i++) + offsets[i] = buf[i]; + + return offsets; +} +My previous comment was "Cache
num_lineslocally rather than callingnum_lines()several times."
Quoted 3 lines
You cached it in the wrong place - it should be first thing in the function, so you only call it once, not three times.
I fixed it when applying.
Quoted 4 lines
And the
throw_if_released()is still "redundant asthis->num_lines()also does it", and it is the first thing called here - after thethrow_if_released().
I think it's still worth having it here because at least the code makes it clear, we need to have a valid request here. It's not like it's a hot path where this additional function call would matter IMO.
Quoted 9 lines
And I would've made this patch 3/5, not 5/5.
But I'm fine with this set going in either way - in fact give its size I'd rather see minor tweaks applied later than go through another round of review.
For the series:
Reviewed-by Kent Gibson <[email protected]>
Thanks I applied it for now as it is, let's get it into master with the Python bindings and then polish it some more there.
Quoted 5 lines
I really would also like to see some feedback from C++ developers that will actually be using it, as they have a bigger stake in it than I do. But that is up to them.
Indeed, any idea where to post that to get some free code reviews from C++ devs? :)
Bart
Re: [libgpiod v2][PATCH v6 5/5] bindings: cxx: add implementation
Quoted 43 lines · Bartosz Golaszewski
Quoted 36 lines · Kent Gibson
Quoted 3 lines · Bartosz Golaszewski
This contains the actual implementation of the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>[snip]
Quoted 14 lines
bindings/cxx/line-request.cpp new file +14
-0+ +GPIOD_CXX_API ::std::size_t line_request::num_lines(void) const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_num_lines(this->_m_priv->request.get()); +} + +GPIOD_CXX_API line::offsets line_request::offsets(void) const +{ + this->_m_priv->throw_if_released(); + + ::std::vector<unsigned int> buf(this->num_lines()); + line::offsets offsets(this->num_lines());bindings/cxx/line-request.cpp line 87
Quoted 10 lines
bindings/cxx/line-request.cpp new file +10
-0+ + ::gpiod_line_request_get_offsets(this->_m_priv->request.get(), buf.data()); + + auto num_lines = this->num_lines(); + for (unsigned int i = 0; i < num_lines; i++) + offsets[i] = buf[i]; + + return offsets; +} +My previous comment was "Cache
num_lineslocally rather than callingnum_lines()several times."Quoted 3 lines
You cached it in the wrong place - it should be first thing in the function, so you only call it once, not three times.
I fixed it when applying.
Quoted 9 lines
Quoted 4 lines
And the
throw_if_released()is still "redundant asthis->num_lines()also does it", and it is the first thing called here - after thethrow_if_released().I think it's still worth having it here because at least the code makes it clear, we need to have a valid request here. It's not like it's a hot path where this additional function call would matter IMO.
So add a comment?
Pointless work is pointless work, hot path or not.
Quoted 14 lines
Quoted 9 lines
And I would've made this patch 3/5, not 5/5.
But I'm fine with this set going in either way - in fact give its size I'd rather see minor tweaks applied later than go through another round of review.
For the series:
Reviewed-by Kent Gibson <[email protected]>Thanks I applied it for now as it is, let's get it into master with the Python bindings and then polish it some more there.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I really would also like to see some feedback from C++ developers that will actually be using it, as they have a bigger stake in it than I do. But that is up to them.
Indeed, any idea where to post that to get some free code reviews from C++ devs? :)
That does raise the issue of whether libgpiod should have a forum other than this mailing list.
I was hoping to at least nudge the others on the CC list ¯\_(ツ)_/¯. If no one is sufficiently interested to bother reviewing, or even acking, the C++ bindings, perhaps deprecate them instead ;-)?
Cheers,
Kent.
Re: [libgpiod v2][PATCH v6 5/5] bindings: cxx: add implementation
Quoted 81 lines · Kent Gibson
Quoted 43 lines · Bartosz Golaszewski
Quoted 36 lines · Kent Gibson
Quoted 3 lines · Bartosz Golaszewski
This contains the actual implementation of the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>[snip]
Quoted 14 lines
bindings/cxx/line-request.cpp new file +14
-0+ +GPIOD_CXX_API ::std::size_t line_request::num_lines(void) const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_num_lines(this->_m_priv->request.get()); +} + +GPIOD_CXX_API line::offsets line_request::offsets(void) const +{ + this->_m_priv->throw_if_released(); + + ::std::vector<unsigned int> buf(this->num_lines()); + line::offsets offsets(this->num_lines());bindings/cxx/line-request.cpp line 87
Quoted 10 lines
bindings/cxx/line-request.cpp new file +10
-0+ + ::gpiod_line_request_get_offsets(this->_m_priv->request.get(), buf.data()); + + auto num_lines = this->num_lines(); + for (unsigned int i = 0; i < num_lines; i++) + offsets[i] = buf[i]; + + return offsets; +} +My previous comment was "Cache
num_lineslocally rather than callingnum_lines()several times."Quoted 3 lines
You cached it in the wrong place - it should be first thing in the function, so you only call it once, not three times.
I fixed it when applying.
Quoted 9 lines
Quoted 4 lines
And the
throw_if_released()is still "redundant asthis->num_lines()also does it", and it is the first thing called here - after thethrow_if_released().I think it's still worth having it here because at least the code makes it clear, we need to have a valid request here. It's not like it's a hot path where this additional function call would matter IMO.
So add a comment?
Pointless work is pointless work, hot path or not.Quoted 14 lines
Quoted 9 lines
And I would've made this patch 3/5, not 5/5.
But I'm fine with this set going in either way - in fact give its size I'd rather see minor tweaks applied later than go through another round of review.
For the series:
Reviewed-by Kent Gibson <[email protected]>Thanks I applied it for now as it is, let's get it into master with the Python bindings and then polish it some more there.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I really would also like to see some feedback from C++ developers that will actually be using it, as they have a bigger stake in it than I do. But that is up to them.
Indeed, any idea where to post that to get some free code reviews from C++ devs? :)
Quoted 7 lines
That does raise the issue of whether libgpiod should have a forum other than this mailing list.
I was hoping to at least nudge the others on the CC list ¯\_(ツ)_/¯. If no one is sufficiently interested to bother reviewing, or even acking, the C++ bindings, perhaps deprecate them instead ;-)?
Well, I've received enough emails over the years with questions about C++ bindings to assume they are being used (although Python bindings seem to be preferred indeed). I think it's just a significant amount of work to go through 10000 LOC just for fun, hence the lack of reviews. :)
Anyway, I'm pretty happy with how they turned out and I intend to keep them. Hopefully nothing is too broken to require an incompatible fix. I'll try to find some reviewers outside the list in the meantime.
Bart
Re: [libgpiod v2][PATCH v6 5/5] bindings: cxx: add implementation
Quoted 90 lines · Bartosz Golaszewski
Quoted 81 lines · Kent Gibson
Quoted 43 lines · Bartosz Golaszewski
Quoted 36 lines · Kent Gibson
Quoted 3 lines · Bartosz Golaszewski
This contains the actual implementation of the v2 C++ bindings.
Signed-off-by Bartosz Golaszewski <[email protected]>[snip]
Quoted 14 lines
bindings/cxx/line-request.cpp new file +14
-0+ +GPIOD_CXX_API ::std::size_t line_request::num_lines(void) const +{ + this->_m_priv->throw_if_released(); + + return ::gpiod_line_request_get_num_lines(this->_m_priv->request.get()); +} + +GPIOD_CXX_API line::offsets line_request::offsets(void) const +{ + this->_m_priv->throw_if_released(); + + ::std::vector<unsigned int> buf(this->num_lines()); + line::offsets offsets(this->num_lines());bindings/cxx/line-request.cpp line 87
Quoted 10 lines
bindings/cxx/line-request.cpp new file +10
-0+ + ::gpiod_line_request_get_offsets(this->_m_priv->request.get(), buf.data()); + + auto num_lines = this->num_lines(); + for (unsigned int i = 0; i < num_lines; i++) + offsets[i] = buf[i]; + + return offsets; +} +My previous comment was "Cache
num_lineslocally rather than callingnum_lines()several times."Quoted 3 lines
You cached it in the wrong place - it should be first thing in the function, so you only call it once, not three times.
I fixed it when applying.
Quoted 9 lines
Quoted 4 lines
And the
throw_if_released()is still "redundant asthis->num_lines()also does it", and it is the first thing called here - after thethrow_if_released().I think it's still worth having it here because at least the code makes it clear, we need to have a valid request here. It's not like it's a hot path where this additional function call would matter IMO.
So add a comment?
Pointless work is pointless work, hot path or not.Quoted 14 lines
Quoted 9 lines
And I would've made this patch 3/5, not 5/5.
But I'm fine with this set going in either way - in fact give its size I'd rather see minor tweaks applied later than go through another round of review.
For the series:
Reviewed-by Kent Gibson <[email protected]>Thanks I applied it for now as it is, let's get it into master with the Python bindings and then polish it some more there.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I really would also like to see some feedback from C++ developers that will actually be using it, as they have a bigger stake in it than I do. But that is up to them.
Indeed, any idea where to post that to get some free code reviews from C++ devs? :)
Quoted 7 lines
That does raise the issue of whether libgpiod should have a forum other than this mailing list.
I was hoping to at least nudge the others on the CC list ¯\_(ツ)_/¯. If no one is sufficiently interested to bother reviewing, or even acking, the C++ bindings, perhaps deprecate them instead ;-)?
Quoted 5 lines
Well, I've received enough emails over the years with questions about C++ bindings to assume they are being used (although Python bindings seem to be preferred indeed). I think it's just a significant amount of work to go through 10000 LOC just for fun, hence the lack of reviews. :)
That was why I asked to have the original patch split.
An end user/lite review could just cover the headers and examples, and optionally the tools as additional examples, and say "yeah that makes sense", or "why the hell did you do it that way?" and not have to concern themselves with the impl or tests.
Quoted 5 lines
Anyway, I'm pretty happy with how they turned out and I intend to keep them. Hopefully nothing is too broken to require an incompatible fix. I'll try to find some reviewers outside the list in the meantime.
Btw, by "deprecate" I didn't mean throw them away, just delay merging them into master until you get some user feedback.
And even then it was in jest. Mostly.
Cheers,
Kent.