From: Bartosz Golaszewski Date: Mon, 19 Feb 2018 10:01:01 +0000 (+0100) Subject: bindings: cxx: provide methods for releasing requested lines X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=10a156752be0b938a0808ad144371774d88574a5;p=qemu-gpiodev%2Flibgpiod.git bindings: cxx: provide methods for releasing requested lines Add release methods to line and line_bulk classes. This allows to release requested lines without having to destroy the owning objects. Signed-off-by: Bartosz Golaszewski --- diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index 5710d36..efa15f2 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -345,6 +345,11 @@ public: */ GPIOD_API void request(const line_request& config, int default_val = 0) const; + /** + * @brief Release the line if it was previously requested. + */ + GPIOD_API void release(void) const; + /** * @brief Check if this user has ownership of this line. * @return True if the user has ownership of this line, false otherwise. @@ -592,6 +597,11 @@ public: GPIOD_API void request(const line_request& config, const std::vector default_vals = std::vector()) const; + /** + * @brief Release all lines held by this object. + */ + GPIOD_API void release(void) const; + /** * @brief Read values from all lines held by this object. * @return Vector containing line values the order of which corresponds diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp index 6603ef7..05f77fc 100644 --- a/bindings/cxx/line.cpp +++ b/bindings/cxx/line.cpp @@ -102,6 +102,15 @@ void line::request(const line_request& config, int default_val) const bulk.request(config, { default_val }); } +void line::release(void) const +{ + this->throw_if_null(); + + line_bulk bulk({ *this }); + + bulk.release(); +} + bool line::is_requested(void) const { this->throw_if_null(); diff --git a/bindings/cxx/line_bulk.cpp b/bindings/cxx/line_bulk.cpp index 106c307..3ce8d94 100644 --- a/bindings/cxx/line_bulk.cpp +++ b/bindings/cxx/line_bulk.cpp @@ -129,6 +129,17 @@ void line_bulk::request(const line_request& config, const std::vector defau "error requesting GPIO lines"); } +void line_bulk::release(void) const +{ + this->throw_if_empty(); + + ::gpiod_line_bulk bulk; + + this->to_line_bulk(::std::addressof(bulk)); + + ::gpiod_line_release_bulk(::std::addressof(bulk)); +} + ::std::vector line_bulk::get_values(void) const { this->throw_if_empty();