[libgpiod][PATCH 4/6] treewide: remove is_requested() and is_free()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>

This removes another two functions from the C API as well as their
bindings that don't make much sense (since the user should know if
they have requested the line or not).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>
---
 bindings/cxx/gpiod.hpp                 |  6 -----
 bindings/cxx/line.cpp                  |  8 ------
 bindings/cxx/tests/tests-line.cpp      |  9 -------
 bindings/python/gpiodmodule.c          | 23 ----------------
 bindings/python/tests/gpiod_py_test.py | 20 --------------
 include/gpiod.h                        | 15 -----------
 lib/core.c                             | 37 +++++---------------------
 7 files changed, 7 insertions(+), 111 deletions(-)

diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp
index 3a043a1..189a133 100644
--- a/bindings/cxx/gpiod.hpp
+++ b/bindings/cxx/gpiod.hpp
@@ -342,12 +342,6 @@ public:
 	 */
 	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.
-	 */
-	GPIOD_API bool is_requested(void) const;
-
 	/**
 	 * @brief Read the line value.
 	 * @return Current value (0 or 1).
diff --git a/bindings/cxx/line.cpp b/bindings/cxx/line.cpp
index 1d114ac..058f7ce 100644
--- a/bindings/cxx/line.cpp
+++ b/bindings/cxx/line.cpp
@@ -127,14 +127,6 @@ void line::release(void) const
 	bulk.release();
 }
 
-bool line::is_requested(void) const
-{
-	this->throw_if_null();
-	line::chip_guard lock_chip(*this);
-
-	return ::gpiod_line_is_requested(this->_m_line);
-}
-
 /*
  * REVISIT: Check the performance of get/set_value & event_wait compared to
  * the C API. Creating a line_bulk object involves a memory allocation every
diff --git a/bindings/cxx/tests/tests-line.cpp b/bindings/cxx/tests/tests-line.cpp
index 648012a..17fdd89 100644
--- a/bindings/cxx/tests/tests-line.cpp
+++ b/bindings/cxx/tests/tests-line.cpp
@@ -27,7 +27,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_INPUT);
 		REQUIRE_FALSE(line.is_active_low());
 		REQUIRE(line.consumer().empty());
-		REQUIRE_FALSE(line.is_requested());
 		REQUIRE_FALSE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_PUSH_PULL);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_UNKNOWN);
@@ -45,7 +44,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE_FALSE(line.is_active_low());
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_PUSH_PULL);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_UNKNOWN);
@@ -65,7 +63,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE(line.is_active_low());
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_OPEN_DRAIN);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_UNKNOWN);
@@ -84,7 +81,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE_FALSE(line.is_active_low());
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_OPEN_SOURCE);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_UNKNOWN);
@@ -103,7 +99,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE_FALSE(line.is_active_low());
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_PUSH_PULL);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_DISABLED);
@@ -122,7 +117,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE_FALSE(line.is_active_low());;
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_PUSH_PULL);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_DOWN);
@@ -141,7 +135,6 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
 		REQUIRE(line.name() == "gpio-mockup-A-4");
 		REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
 		REQUIRE_FALSE(line.is_active_low());
-		REQUIRE(line.is_requested());
 		REQUIRE(line.is_used());
 		REQUIRE(line.drive() == ::gpiod::line::DRIVE_PUSH_PULL);
 		REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_UP);
@@ -383,12 +376,10 @@ TEST_CASE("Exported line can be released", "[line]")
 
 	line.request(config);
 
-	REQUIRE(line.is_requested());
 	REQUIRE(line.get_value() == 0);
 
 	line.release();
 
-	REQUIRE_FALSE(line.is_requested());
 	REQUIRE_THROWS_AS(line.get_value(), ::std::system_error);
 }
 
diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
index e54c3ad..12a6867 100644
--- a/bindings/python/gpiodmodule.c
+++ b/bindings/python/gpiodmodule.c
@@ -501,23 +501,6 @@ static PyObject *gpiod_Line_request(gpiod_LineObject *self,
 	return ret;
 }
 
-PyDoc_STRVAR(gpiod_Line_is_requested_doc,
-"is_requested() -> boolean\n"
-"\n"
-"Check if this user has ownership of this line.");
-
-static PyObject *gpiod_Line_is_requested(gpiod_LineObject *self,
-					 PyObject *Py_UNUSED(ignored))
-{
-	if (gpiod_ChipIsClosed(self->owner))
-		return NULL;
-
-	if (gpiod_line_is_requested(self->line))
-		Py_RETURN_TRUE;
-
-	Py_RETURN_FALSE;
-}
-
 PyDoc_STRVAR(gpiod_Line_get_value_doc,
 "get_value() -> integer\n"
 "\n"
@@ -983,12 +966,6 @@ static PyMethodDef gpiod_Line_methods[] = {
 		.ml_flags = METH_VARARGS | METH_KEYWORDS,
 		.ml_doc = gpiod_Line_request_doc,
 	},
-	{
-		.ml_name = "is_requested",
-		.ml_meth = (PyCFunction)gpiod_Line_is_requested,
-		.ml_flags = METH_NOARGS,
-		.ml_doc = gpiod_Line_is_requested_doc,
-	},
 	{
 		.ml_name = "get_value",
 		.ml_meth = (PyCFunction)gpiod_Line_get_value,
diff --git a/bindings/python/tests/gpiod_py_test.py b/bindings/python/tests/gpiod_py_test.py
index b7c30de..d448776 100755
--- a/bindings/python/tests/gpiod_py_test.py
+++ b/bindings/python/tests/gpiod_py_test.py
@@ -204,7 +204,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), None)
             self.assertFalse(line.is_used())
-            self.assertFalse(line.is_requested())
 
     def test_exported_line(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
@@ -218,7 +217,6 @@ class LineInfo(MockupTestCase):
             self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
 
     def test_exported_line_with_flags(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
@@ -234,7 +232,6 @@ class LineInfo(MockupTestCase):
             self.assertTrue(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_DRAIN)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_UNKNOWN)
 
@@ -251,7 +248,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_DRAIN)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_UNKNOWN)
 
@@ -268,7 +264,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_OPEN_SOURCE)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_UNKNOWN)
 
@@ -285,7 +280,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_PUSH_PULL)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_DISABLED)
 
@@ -302,7 +296,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_PUSH_PULL)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_DOWN)
 
@@ -319,7 +312,6 @@ class LineInfo(MockupTestCase):
             self.assertFalse(line.is_active_low())
             self.assertEqual(line.consumer(), default_consumer)
             self.assertTrue(line.is_used())
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.drive(), gpiod.Line.DRIVE_PUSH_PULL)
             self.assertEqual(line.bias(), gpiod.Line.BIAS_PULL_UP)
 
@@ -605,16 +597,6 @@ class LineRequestBehavior(MockupTestCase):
 
     chip_sizes = ( 8, )
 
-    def test_line_export_release(self):
-        with gpiod.Chip(mockup.chip_path(0)) as chip:
-            line = chip.get_line(3)
-            line.request(consumer=default_consumer,
-                         type=gpiod.LINE_REQ_DIR_IN)
-            self.assertTrue(line.is_requested())
-            self.assertEqual(line.get_value(), 0)
-            line.release()
-            self.assertFalse(line.is_requested())
-
     def test_line_request_twice_two_calls(self):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
             line = chip.get_line(3)
@@ -647,10 +629,8 @@ class LineRequestBehavior(MockupTestCase):
         with gpiod.Chip(mockup.chip_path(0)) as chip:
             line = chip.get_line(2)
             line.request(default_consumer)
-            self.assertTrue(line.is_requested())
             self.assertEqual(line.direction(), gpiod.Line.DIRECTION_INPUT)
             line.release()
-            self.assertFalse(line.is_requested())
 
 #
 # Iterator test cases
diff --git a/include/gpiod.h b/include/gpiod.h
index 71abb2a..a5e09e2 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -700,21 +700,6 @@ void gpiod_line_release(struct gpiod_line *line) GPIOD_API;
  */
 void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API;
 
-/**
- * @brief Check if the calling user has ownership of this line.
- * @param line GPIO line object.
- * @return True if given line was requested, false otherwise.
- */
-bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API;
-
-/**
- * @brief Check if the calling user has neither requested ownership of this
- *        line nor configured any event notifications.
- * @param line GPIO line object.
- * @return True if given line is free, false otherwise.
- */
-bool gpiod_line_is_free(struct gpiod_line *line) GPIOD_API;
-
 /**
  * @}
  *
diff --git a/lib/core.c b/lib/core.c
index bab438f..8e3d8a7 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -561,13 +561,19 @@ int gpiod_line_update(struct gpiod_line *line)
 	return 0;
 }
 
+static bool line_is_requested(struct gpiod_line *line)
+{
+	return (line->state == LINE_REQUESTED_VALUES ||
+		line->state == LINE_REQUESTED_EVENTS);
+}
+
 static bool line_bulk_all_requested(struct gpiod_line_bulk *bulk)
 {
 	struct gpiod_line *line;
 	unsigned int idx;
 
 	line_bulk_foreach_line(bulk, line, idx) {
-		if (!gpiod_line_is_requested(line)) {
+		if (!line_is_requested(line)) {
 			errno = EPERM;
 			return false;
 		}
@@ -591,21 +597,6 @@ static bool line_bulk_all_requested_values(struct gpiod_line_bulk *bulk)
 	return true;
 }
 
-static bool line_bulk_all_free(struct gpiod_line_bulk *bulk)
-{
-	struct gpiod_line *line;
-	unsigned int idx;
-
-	line_bulk_foreach_line(bulk, line, idx) {
-		if (!gpiod_line_is_free(line)) {
-			errno = EBUSY;
-			return false;
-		}
-	}
-
-	return true;
-}
-
 static bool line_request_direction_is_valid(int direction)
 {
 	if ((direction == GPIOD_LINE_REQUEST_DIRECTION_AS_IS) ||
@@ -872,9 +863,6 @@ int gpiod_line_request_bulk(struct gpiod_line_bulk *bulk,
 			    const struct gpiod_line_request_config *config,
 			    const int *vals)
 {
-	if (!line_bulk_all_free(bulk))
-		return -1;
-
 	if (line_request_is_direction(config->request_type))
 		return line_request_values(bulk, config, vals);
 	else if (line_request_is_events(config->request_type))
@@ -904,17 +892,6 @@ void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk)
 	}
 }
 
-bool gpiod_line_is_requested(struct gpiod_line *line)
-{
-	return (line->state == LINE_REQUESTED_VALUES ||
-		line->state == LINE_REQUESTED_EVENTS);
-}
-
-bool gpiod_line_is_free(struct gpiod_line *line)
-{
-	return line->state == LINE_FREE;
-}
-
 int gpiod_line_get_value(struct gpiod_line *line)
 {
 	struct gpiod_line_bulk bulk = BULK_SINGLE_LINE_INIT(line);
-- 
2.30.1




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux