event: rename event requests routines
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 10 Jul 2017 08:15:05 +0000 (10:15 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 10 Jul 2017 08:27:40 +0000 (10:27 +0200)
The event request functionality is now merged with the regular
requests. Change the naming pattern for event requests and move the
prototypes under the input and output requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/line.c
src/lib/simple.c
tests/tests-event.c

index 0ac9583de5bf569ec409643f90d0c5ad83b739fc..8fd521cfeb87b0d559ef9640b9e11a9033ab1e67 100644 (file)
@@ -425,6 +425,39 @@ int gpiod_line_request_input(struct gpiod_line *line,
 int gpiod_line_request_output(struct gpiod_line *line, const char *consumer,
                              bool active_low, int default_val) GPIOD_API;
 
+/**
+ * @brief Request rising edge event notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param active_low Active state of the line - true if low.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
+                                         const char *consumer,
+                                         bool active_low) GPIOD_API;
+
+/**
+ * @brief Request falling edge event notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param active_low Active state of the line - true if low.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
+                                          const char *consumer,
+                                          bool active_low) GPIOD_API;
+
+/**
+ * @brief Request all event type notifications on a single line.
+ * @param line GPIO line object.
+ * @param consumer Name of the consumer.
+ * @param active_low Active state of the line - true if low.
+ * @return 0 if the operation succeeds, -1 on failure.
+ */
+int gpiod_line_request_both_edges_events(struct gpiod_line *line,
+                                        const char *consumer,
+                                        bool active_low) GPIOD_API;
+
 /**
  * @brief Reserve a set of GPIO lines.
  * @param bulk Set of GPIO lines to reserve.
@@ -584,39 +617,6 @@ struct gpiod_line_event {
        /**< Type of the event that occurred. */
 };
 
-/**
- * @brief Request rising edge event notifications on a single line.
- * @param line GPIO line object.
- * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
- * @return 0 if the operation succeeds, -1 on failure.
- */
-int gpiod_line_event_request_rising(struct gpiod_line *line,
-                                   const char *consumer,
-                                   bool active_low) GPIOD_API;
-
-/**
- * @brief Request falling edge event notifications on a single line.
- * @param line GPIO line object.
- * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
- * @return 0 if the operation succeeds, -1 on failure.
- */
-int gpiod_line_event_request_falling(struct gpiod_line *line,
-                                    const char *consumer,
-                                    bool active_low) GPIOD_API;
-
-/**
- * @brief Request all event type notifications on a single line.
- * @param line GPIO line object.
- * @param consumer Name of the consumer.
- * @param active_low Active state of the line - true if low.
- * @return 0 if the operation succeeds, -1 on failure.
- */
-int gpiod_line_event_request_both(struct gpiod_line *line,
-                                 const char *consumer,
-                                 bool active_low) GPIOD_API;
-
 /**
  * @brief Wait for an event on a single line.
  * @param line GPIO line object.
index 4dde754517da5325bd458815672456b035d49452..b15502886085144911ee346210563ee91bdcaebe 100644 (file)
@@ -642,22 +642,24 @@ static int line_event_request_type(struct gpiod_line *line,
        return gpiod_line_request(line, &config, 0);
 }
 
-int gpiod_line_event_request_rising(struct gpiod_line *line,
-                                   const char *consumer, bool active_low)
+int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
+                                         const char *consumer,
+                                         bool active_low)
 {
        return line_event_request_type(line, consumer, active_low,
                                       GPIOD_REQUEST_EVENT_RISING_EDGE);
 }
 
-int gpiod_line_event_request_falling(struct gpiod_line *line,
-                                    const char *consumer, bool active_low)
+int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
+                                          const char *consumer,
+                                          bool active_low)
 {
        return line_event_request_type(line, consumer, active_low,
                                       GPIOD_REQUEST_EVENT_FALLING_EDGE);
 }
 
-int gpiod_line_event_request_both(struct gpiod_line *line,
-                                 const char *consumer, bool active_low)
+int gpiod_line_request_both_edges_events(struct gpiod_line *line,
+                                        const char *consumer, bool active_low)
 {
        return line_event_request_type(line, consumer, active_low,
                                       GPIOD_REQUEST_EVENT_BOTH_EDGES);
index f3ac1b99fba88e9fbf2ac761865d3611956c25d4..d6db02e7198db1e053fe4e389059ac4a1ef6d92d 100644 (file)
@@ -150,7 +150,7 @@ int gpiod_simple_event_loop(const char *consumer, const char *device,
                return -1;
        }
 
-       status = gpiod_line_event_request_both(line, consumer, active_low);
+       status = gpiod_line_request_both_edges_events(line, consumer, active_low);
        if (status < 0) {
                gpiod_chip_close(chip);
                return -1;
index 532b00e92d9d937f16224ca4046559db4de241dc..a00752fa9ab06d32249c12d67d9be8c3e599227f 100644 (file)
@@ -16,7 +16,7 @@ static void event_rising_edge_good(void)
        struct timespec ts = { 1, 0 };
        struct gpiod_line_event ev;
        struct gpiod_line *line;
-       int status;
+       int rv;
 
        chip = gpiod_chip_open(test_chip_path(0));
        TEST_ASSERT_NOT_NULL(chip);
@@ -24,16 +24,16 @@ static void event_rising_edge_good(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_RISING, 100);
 
-       status = gpiod_line_event_wait(line, &ts);
-       TEST_ASSERT_EQ(status, 1);
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 1);
 
-       status = gpiod_line_event_read(line, &ev);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_event_read(line, &ev);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE);
 }
@@ -47,7 +47,7 @@ static void event_falling_edge_good(void)
        struct timespec ts = { 1, 0 };
        struct gpiod_line_event ev;
        struct gpiod_line *line;
-       int status;
+       int rv;
 
        chip = gpiod_chip_open(test_chip_path(0));
        TEST_ASSERT_NOT_NULL(chip);
@@ -55,16 +55,17 @@ static void event_falling_edge_good(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_event_request_falling(line, TEST_CONSUMER, false);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_request_falling_edge_events(line,
+                                                   TEST_CONSUMER, false);
+       TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_FALLING, 100);
 
-       status = gpiod_line_event_wait(line, &ts);
-       TEST_ASSERT_EQ(status, 1);
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 1);
 
-       status = gpiod_line_event_read(line, &ev);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_event_read(line, &ev);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_FALLING_EDGE);
 }
@@ -77,7 +78,7 @@ static void event_rising_edge_ignore_falling(void)
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;
        struct timespec ts = { 0, 300 };
        struct gpiod_line *line;
-       int status;
+       int rv;
 
        chip = gpiod_chip_open(test_chip_path(0));
        TEST_ASSERT_NOT_NULL(chip);
@@ -85,13 +86,13 @@ static void event_rising_edge_ignore_falling(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_FALLING, 100);
 
-       status = gpiod_line_event_wait(line, &ts);
-       TEST_ASSERT_EQ(status, 0);
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 0);
 }
 TEST_DEFINE(event_rising_edge_ignore_falling,
            "events - request rising edge & ignore falling edge events",
@@ -103,7 +104,7 @@ static void event_rising_edge_active_low(void)
        struct timespec ts = { 1, 0 };
        struct gpiod_line_event ev;
        struct gpiod_line *line;
-       int status;
+       int rv;
 
        chip = gpiod_chip_open(test_chip_path(0));
        TEST_ASSERT_NOT_NULL(chip);
@@ -111,16 +112,16 @@ static void event_rising_edge_active_low(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_event_request_rising(line, TEST_CONSUMER, true);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, true);
+       TEST_ASSERT_RET_OK(rv);
 
        test_set_event(0, 7, TEST_EVENT_RISING, 100);
 
-       status = gpiod_line_event_wait(line, &ts);
-       TEST_ASSERT_EQ(status, 1);
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 1);
 
-       status = gpiod_line_event_read(line, &ev);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_event_read(line, &ev);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE);
 }
@@ -134,7 +135,7 @@ static void event_get_value(void)
        struct timespec ts = { 1, 0 };
        struct gpiod_line_event ev;
        struct gpiod_line *line;
-       int status;
+       int rv;
 
        chip = gpiod_chip_open(test_chip_path(0));
        TEST_ASSERT_NOT_NULL(chip);
@@ -142,24 +143,24 @@ static void event_get_value(void)
        line = gpiod_chip_get_line(chip, 7);
        TEST_ASSERT_NOT_NULL(line);
 
-       status = gpiod_line_event_request_rising(line, TEST_CONSUMER, false);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_request_rising_edge_events(line, TEST_CONSUMER, false);
+       TEST_ASSERT_RET_OK(rv);
 
-       status = gpiod_line_get_value(line);
-       TEST_ASSERT_EQ(status, 0);
+       rv = gpiod_line_get_value(line);
+       TEST_ASSERT_EQ(rv, 0);
 
        test_set_event(0, 7, TEST_EVENT_RISING, 100);
 
-       status = gpiod_line_event_wait(line, &ts);
-       TEST_ASSERT_EQ(status, 1);
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 1);
 
-       status = gpiod_line_event_read(line, &ev);
-       TEST_ASSERT_RET_OK(status);
+       rv = gpiod_line_event_read(line, &ev);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(ev.event_type, GPIOD_EVENT_RISING_EDGE);
 
-       status = gpiod_line_get_value(line);
-       TEST_ASSERT_EQ(status, 1);
+       rv = gpiod_line_get_value(line);
+       TEST_ASSERT_EQ(rv, 1);
 }
 TEST_DEFINE(event_get_value,
            "events - mixing events and gpiod_line_get_value()",