bindings: cxx: provide chip::get_all_lines()
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 22 Feb 2018 20:31:56 +0000 (21:31 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 22 Feb 2018 20:31:56 +0000 (21:31 +0100)
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 <bartekgola@gmail.com>
bindings/cxx/chip.cpp
bindings/cxx/examples/gpio_cxx_tests.cpp
bindings/cxx/gpiod.hpp

index 5c626a98e5615eb36a8f564ace474a21196d8f2f..c0204989021df296c8e979654c9fe53bf5b97296 100644 (file)
@@ -153,6 +153,16 @@ line_bulk chip::get_lines(const ::std::vector<unsigned int>& 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;
index 7b12f957cb4304c4bff42612b71bb4534c8afd6b..a7d041881b605d0cc1801c27001f6fdd0848f315 100644 (file)
@@ -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 **)
index da1e83b134cbaadc244e62ad5057d91f1bdbcd47..ff46f264a95423413390526155289540af128fdc 100644 (file)
@@ -141,6 +141,12 @@ public:
         */
        GPIOD_API line_bulk get_lines(const ::std::vector<unsigned int>& 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.