From 67376bd706014617d2a399fb3b716e59ddc74ea9 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 22 Feb 2018 21:31:56 +0100 Subject: [PATCH] bindings: cxx: provide chip::get_all_lines() This is a C++ method for getting all lines exposed by a GPIO chip. It corresponds with the helper function recently added to the C API. Signed-off-by: Bartosz Golaszewski --- bindings/cxx/chip.cpp | 10 ++++++++++ bindings/cxx/examples/gpio_cxx_tests.cpp | 13 +++++++++++++ bindings/cxx/gpiod.hpp | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/bindings/cxx/chip.cpp b/bindings/cxx/chip.cpp index 5c626a9..c020498 100644 --- a/bindings/cxx/chip.cpp +++ b/bindings/cxx/chip.cpp @@ -153,6 +153,16 @@ line_bulk chip::get_lines(const ::std::vector& offsets) const return ::std::move(lines); } +line_bulk chip::get_all_lines(void) const +{ + line_bulk lines; + + for (unsigned int i = 0; i < this->num_lines(); i++) + lines.add(this->get_line(i)); + + return ::std::move(lines); +} + line_bulk chip::find_lines(const ::std::vector<::std::string>& names) const { line_bulk lines; diff --git a/bindings/cxx/examples/gpio_cxx_tests.cpp b/bindings/cxx/examples/gpio_cxx_tests.cpp index 7b12f95..a7d0418 100644 --- a/bindings/cxx/examples/gpio_cxx_tests.cpp +++ b/bindings/cxx/examples/gpio_cxx_tests.cpp @@ -183,6 +183,19 @@ void multiple_lines_test(void) } TEST_CASE(multiple_lines_test); +void get_all_lines(void) +{ + ::gpiod::chip chip("gpiochip0"); + + ::std::cout << "Getting all lines from a chip" << ::std::endl; + + auto lines = chip.get_all_lines(); + + for (auto& it: lines) + ::std::cout << "Offset: " << it.offset() << ::std::endl; +} +TEST_CASE(get_all_lines); + } /* namespace */ int main(int, char **) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index da1e83b..ff46f26 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -141,6 +141,12 @@ public: */ GPIOD_API line_bulk get_lines(const ::std::vector& offsets) const; + /** + * @brief Get all lines exposed by this chip. + * @return All lines exposed by this chip held by a line_bulk object. + */ + GPIOD_API line_bulk get_all_lines(void) const; + /** * @brief Get a set of lines exposed by this chip by their names. * @param names Vector of line names. -- 2.30.2