aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-07-20 16:47:45 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-07-21 20:33:39 +0200
commit1787cee1b32930157eed22bd9bdff4be5be7aa01 (patch)
tree205e75388cf1942a4e813bbce5f5c025cf71c11f
parent856989c7705e131024816f6ba4d71a8177364fdb (diff)
downloadlibgpiod-1787cee1b32930157eed22bd9bdff4be5be7aa01.tar.gz
bindings: cxx: provide line_request::chip_name()
Provide a wrapper around gpiod_line_request_get_chip_name() for C++ bindings and update the tests. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
-rw-r--r--bindings/cxx/gpiodcxx/line-request.hpp6
-rw-r--r--bindings/cxx/line-request.cpp10
-rw-r--r--bindings/cxx/tests/tests-line-request.cpp6
3 files changed, 19 insertions, 3 deletions
diff --git a/bindings/cxx/gpiodcxx/line-request.hpp b/bindings/cxx/gpiodcxx/line-request.hpp
index c1e1520a..8c1b4743 100644
--- a/bindings/cxx/gpiodcxx/line-request.hpp
+++ b/bindings/cxx/gpiodcxx/line-request.hpp
@@ -76,6 +76,12 @@ public:
void release();
/**
+ * @brief Get the name of the chip this request was made on.
+ * @return Name to the GPIO chip.
+ */
+ ::std::string chip_name() const;
+
+ /**
* @brief Get the number of requested lines.
* @return Number of lines in this request.
*/
diff --git a/bindings/cxx/line-request.cpp b/bindings/cxx/line-request.cpp
index b0723c35..e8e0b96b 100644
--- a/bindings/cxx/line-request.cpp
+++ b/bindings/cxx/line-request.cpp
@@ -63,6 +63,13 @@ GPIOD_CXX_API void line_request::release()
this->_m_priv->request.reset();
}
+GPIOD_CXX_API ::std::string line_request::chip_name() const
+{
+ this->_m_priv->throw_if_released();
+
+ return ::gpiod_line_request_get_chip_name(this->_m_priv->request.get());
+}
+
GPIOD_CXX_API ::std::size_t line_request::num_lines() const
{
this->_m_priv->throw_if_released();
@@ -222,7 +229,8 @@ GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const line_request
if (!request)
out << "gpiod::line_request(released)";
else
- out << "gpiod::line_request(num_lines=" << request.num_lines() <<
+ out << "gpiod::line_request(chip=\"" << request.chip_name() <<
+ "\", num_lines=" << request.num_lines() <<
", line_offsets=" << request.offsets() <<
", fd=" << request.fd() <<
")";
diff --git a/bindings/cxx/tests/tests-line-request.cpp b/bindings/cxx/tests/tests-line-request.cpp
index d1a56ae5..9632ae0d 100644
--- a/bindings/cxx/tests/tests-line-request.cpp
+++ b/bindings/cxx/tests/tests-line-request.cpp
@@ -468,14 +468,16 @@ TEST_CASE("line_request stream insertion operator works", "[line-request]")
.set_num_lines(4)
.build();
- auto request = ::gpiod::chip(sim.dev_path())
+ auto chip = ::gpiod::chip(sim.dev_path());
+ auto request = chip
.prepare_request()
.add_line_settings({ 3, 1, 0, 2}, ::gpiod::line_settings())
.do_request();
::std::stringstream buf, expected;
- expected << "gpiod::line_request(num_lines=4, line_offsets=gpiod::offsets(3, 1, 0, 2), fd=" <<
+ expected << "gpiod::line_request(chip=\"" << sim.name() <<
+ "\", num_lines=4, line_offsets=gpiod::offsets(3, 1, 0, 2), fd=" <<
request.fd() << ")";
SECTION("active request")