treewide: remove is_requested() and is_free()
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Sun, 21 Feb 2021 13:27:31 +0000 (14:27 +0100)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 18 Mar 2021 08:34:15 +0000 (09:34 +0100)
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@baylibre.com>
bindings/cxx/gpiod.hpp
bindings/cxx/line.cpp
bindings/cxx/tests/tests-line.cpp
bindings/python/gpiodmodule.c
bindings/python/tests/gpiod_py_test.py
include/gpiod.h
lib/core.c

index 3a043a15d178bec28f9c0861e11f4a454f1293d3..189a1330d04fecadc23e09a9c5651d8dcd6ffb3d 100644 (file)
@@ -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).
index 1d114acb846c045f4b90d02499e9887e1ec54f38..058f7ce0b8ff10565b6e2d420c1d13574409327d 100644 (file)
@@ -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
index 648012a10f8d055c728fbbef7db1227f6229b721..17fdd89cc89d56f5750125761a2d435d501f39a6 100644 (file)
@@ -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);
 }
 
index e54c3ad77090e7c8af38780a3ba63d7d82cb2fc7..12a6867dd06fed2722b1c1bcb2855d746f7a9016 100644 (file)
@@ -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,
index b7c30ded62fbb0ee6fd3ea1469e938ba05f6f0dc..d4487769e09e5d7058b438bac7703b7f7e002f33 100755 (executable)
@@ -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
index 71abb2a8244751f56b0738e741fd71d3840703cc..a5e09e2fcb6b6f181dd65998f83f7f0254c17886 100644 (file)
@@ -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;
-
 /**
  * @}
  *
index bab438f14f92b6da7e3fc3c3b88a3d6ca56cf1b3..8e3d8a72e17ed89dc3fc779839b6da6b209b76f0 100644 (file)
@@ -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);