From 0297ef69af3c1005edd0c1eea2dc38c0b6e64dad Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Sat, 14 Sep 2019 15:18:20 +0200 Subject: [PATCH] bindings: cxx: provide line::update() The C++ bindings are missing the functionality provided by the core C library's gpiod_line_update(). Extend the line class with the update() method that allows to re-read the line information from the kernel. Signed-off-by: Bartosz Golaszewski --- bindings/cxx/gpiod.hpp | 5 +++++ bindings/cxx/line.cpp | 11 +++++++++++ bindings/cxx/tests/tests-line.cpp | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index cf4489b..13b4d5b 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -395,6 +395,11 @@ public: */ GPIOD_API const chip& get_chip(void) const; + /** + * @brief Re-read the line info from the kernel. + */ + GPIOD_API void update(void) const; + /** * @brief Reset the state of this object. * diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index 4ccbd15..b698960 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -194,6 +194,17 @@ const chip& line::get_chip(void) const return this->_m_chip; } +void line::update(void) const +{ + this->throw_if_null(); + + int ret = ::gpiod_line_update(this->_m_line); + + if (ret < 0) + throw ::std::system_error(errno, ::std::system_category(), + "unable to update the line info"); +} + void line::reset(void) { this->_m_line = nullptr; diff --git a/bindings/cxx/tests/tests-line.cpp b/bindings/cxx/tests/tests-line.cpp index b008c30..3ba2fc2 100644 --- a/bindings/cxx/tests/tests-line.cpp +++ b/bindings/cxx/tests/tests-line.cpp @@ -89,6 +89,11 @@ TEST_CASE("Line information can be correctly retrieved", "[line]") REQUIRE(line.is_open_drain()); REQUIRE_FALSE(line.is_open_source()); } + + SECTION("update line info") + { + REQUIRE_NOTHROW(line.update()); + } } TEST_CASE("Line bulk object works correctly", "[line][bulk]") -- 2.30.2