bindings: cxx: provide methods for releasing requested lines
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 19 Feb 2018 10:01:01 +0000 (11:01 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 19 Feb 2018 10:01:01 +0000 (11:01 +0100)
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 <bartekgola@gmail.com>
bindings/cxx/gpiod.hpp
bindings/cxx/line.cpp
bindings/cxx/line_bulk.cpp

index 5710d36bd74da563aa89660d82817de7abd18171..efa15f2da3decd349ff83fcfef09d9f3fc8f43d5 100644 (file)
@@ -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<int> default_vals = std::vector<int>()) 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
index 6603ef772b90a4b068def03b02fde738be912534..05f77fc0697bb06de153883c916f510cd450438a 100644 (file)
@@ -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();
index 106c30713a28c1cdb59788e91c3ba296855967fe..3ce8d94c3b1377dd549b6d660b00c0fa43a0bd16 100644 (file)
@@ -129,6 +129,17 @@ void line_bulk::request(const line_request& config, const std::vector<int> 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<int> line_bulk::get_values(void) const
 {
        this->throw_if_empty();