From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Jack Winch <sunt.un.morcov@gmail.com>,
Helmut Grohne <helmut.grohne@intenta.de>,
Ben Hutchings <ben.hutchings@essensium.com>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [libgpiod v2][PATCH v4 0/2] libgpiod v2: C++ bindings
Date: Thu, 4 Nov 2021 20:22:50 +0100 [thread overview]
Message-ID: <20211104192252.21883-1-brgl@bgdev.pl> (raw)
This series contains the implementation of the C++ bindings for libgpiod v2.
In general the C++ library follows the data structure model as defined by
the C library with one notable exception: objects that represent immutable
snapshots of kernel data (line_info and edge & info events) are copyable
(or rather shared behind the scenes using ::std::shared_ptr). The rest of
the classes delete their copy constructors and assignment operators and
are only move constructible and move assignable.
All classes follow the pimpl idiom - using either shared_ptr or unique_ptr -
and all implementations are hidden from the user for easier maintenance and
less ABI breakage in the future.
The edge_event class is a bit of a special case. While it looks the same
as other copyable objects to the user, the implementation uses a tiny bit of
polymorphism (although it never crosses the ABI boundary). This is done
to make it possible to use the edge_event_buffer without any memory
allocations like what the C API enables. The edge_event objects stored
in the buffer only contain a raw pointer to the C object stored in the
underlying C edge_event_buffer. The event is copied into a fully managed
object once the copy assignment operator is called.
I'm Cc'ing people who showed interest and helped me with C++ bindings
before for review.
v1 -> v2:
Kent: I addressed most points from your review. Some are unaddressed due to
personal preference (for instance: I still allow creating of empty line-request
objects as they may be reused in subsequent requests). I also kept the 'watch'
argument in get_line_info() as well as the boolean operators for chip and
request - although with (hopefully) better documentation.
v2 -> v3:
- use scoped class enums instead of regular integer ones
- rename getters to get_<property>() in order to avoid name conflicts with
the new enum types
v3 -> v4:
The bindings have been significantly rebuilt and the list of changes
is mostly likely too long put all here but in short:
- renamed and reworked the accessors
- added custom stream insertion operators and exceptions
- used scoped C++ enum and unifying their definitions across classes
- deconstified all mutators for logical consistency
- modified the implementation to work with the reworked C API
- many more small tweaks all over the place
Bartosz Golaszewski (2):
line-config: rework the interface some more
bindings: cxx: implement C++ bindings for libgpiod v2.0
Doxyfile.in | 4 +-
bindings/cxx/Makefile.am | 18 +-
bindings/cxx/chip.cpp | 214 +++--
bindings/cxx/edge-event-buffer.cpp | 118 +++
bindings/cxx/edge-event.cpp | 135 +++
bindings/cxx/examples/Makefile.am | 12 +-
bindings/cxx/examples/gpiodetectcxx.cpp | 9 +-
bindings/cxx/examples/gpiogetcxx.cpp | 12 +-
bindings/cxx/examples/gpioinfocxx.cpp | 62 +-
bindings/cxx/examples/gpiomoncxx.cpp | 39 +-
bindings/cxx/examples/gpiosetcxx.cpp | 19 +-
bindings/cxx/exception.cpp | 107 +++
bindings/cxx/gpiod.hpp | 946 +-------------------
bindings/cxx/gpiodcxx/Makefile.am | 16 +
bindings/cxx/gpiodcxx/chip.hpp | 197 ++++
bindings/cxx/gpiodcxx/edge-event-buffer.hpp | 122 +++
bindings/cxx/gpiodcxx/edge-event.hpp | 135 +++
bindings/cxx/gpiodcxx/exception.hpp | 149 +++
bindings/cxx/gpiodcxx/info-event.hpp | 115 +++
bindings/cxx/gpiodcxx/line-config.hpp | 445 +++++++++
bindings/cxx/gpiodcxx/line-info.hpp | 169 ++++
bindings/cxx/gpiodcxx/line-request.hpp | 214 +++++
bindings/cxx/gpiodcxx/line.hpp | 123 +++
bindings/cxx/gpiodcxx/misc.hpp | 44 +
bindings/cxx/gpiodcxx/request-config.hpp | 128 +++
bindings/cxx/info-event.cpp | 102 +++
bindings/cxx/internal.cpp | 91 ++
bindings/cxx/internal.hpp | 188 +++-
bindings/cxx/iter.cpp | 60 --
bindings/cxx/line-config.cpp | 589 ++++++++++++
bindings/cxx/line-info.cpp | 199 ++++
bindings/cxx/line-request.cpp | 200 +++++
bindings/cxx/line.cpp | 321 -------
bindings/cxx/line_bulk.cpp | 366 --------
bindings/cxx/misc.cpp | 20 +
bindings/cxx/request-config.cpp | 117 +++
configure.ac | 1 +
include/gpiod.h | 255 ++++--
lib/line-config.c | 295 ++++--
tools/gpioget.c | 6 +-
tools/gpiomon.c | 6 +-
tools/gpioset.c | 9 +-
42 files changed, 4380 insertions(+), 1997 deletions(-)
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.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/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.cpp
delete mode 100644 bindings/cxx/line_bulk.cpp
create mode 100644 bindings/cxx/misc.cpp
create mode 100644 bindings/cxx/request-config.cpp
--
2.30.1
next reply other threads:[~2021-11-04 19:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 19:22 Bartosz Golaszewski [this message]
2021-11-04 19:22 ` [libgpiod v2][PATCH v4 1/2] line-config: rework the interface some more Bartosz Golaszewski
2021-11-08 1:02 ` Kent Gibson
2021-11-10 13:15 ` Bartosz Golaszewski
2021-11-11 3:25 ` Kent Gibson
2021-11-04 19:22 ` [libgpiod v2][PATCH v4 2/2] bindings: cxx: implement C++ bindings for libgpiod v2.0 Bartosz Golaszewski
2021-11-08 1:04 ` Kent Gibson
2021-11-10 13:42 ` Bartosz Golaszewski
2021-11-11 3:25 ` Kent Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211104192252.21883-1-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ben.hutchings@essensium.com \
--cc=helmut.grohne@intenta.de \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=sunt.un.morcov@gmail.com \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).