event: rework gpiod_line_event_wait_bulk()
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 10 Jan 2017 10:37:40 +0000 (11:37 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 10 Jan 2017 10:37:40 +0000 (11:37 +0100)
Instead of storing the index of the line - store the line handle
itself as the third parameter.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
core.c
gpiod.h

diff --git a/core.c b/core.c
index fa89110a833781b013048013b88c247c46744aa2..c898c73d7326976cbbc6845ae05242fcd7ea3ac8 100644 (file)
--- a/core.c
+++ b/core.c
@@ -652,10 +652,10 @@ static bool line_bulk_is_event_configured(struct gpiod_line_bulk *line_bulk)
 
 int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
                               const struct timespec *timeout,
-                              unsigned int *index)
+                              struct gpiod_line **line)
 {
        struct pollfd fds[GPIOD_REQUEST_MAX_LINES];
-       struct gpiod_line *line;
+       struct gpiod_line *linetmp;
        unsigned int i;
        int status;
 
@@ -667,9 +667,9 @@ int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
        memset(fds, 0, sizeof(fds));
 
        for (i = 0; i < bulk->num_lines; i++) {
-               line = bulk->lines[i];
+               linetmp = bulk->lines[i];
 
-               fds[i].fd = line->event.fd;
+               fds[i].fd = linetmp->event.fd;
                fds[i].events = POLLIN | POLLPRI;
        }
 
@@ -682,8 +682,8 @@ int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
        }
 
        for (i = 0; !fds[i].revents; i++);
-       if (index)
-               *index = i;
+       if (line)
+               *line = bulk->lines[i];
 
        return 1;
 }
diff --git a/gpiod.h b/gpiod.h
index 21082833dc05244c9b5bf8dba004bf6ba5c4f679..d5245caf251c23aa78134fda68d8397036d8a85c 100644 (file)
--- a/gpiod.h
+++ b/gpiod.h
@@ -533,15 +533,14 @@ int gpiod_line_event_wait(struct gpiod_line *line,
  * @brief Wait for the first event on a set of lines.
  * @param bulk Set of GPIO lines to monitor.
  * @param timeout Wait time limit.
- * @param index The position of the line on which an event occured is stored
- *              in this variable. Can be NULL, in which case the index will
- *              not be stored.
+ * @param line The handle of the line on which an event occurs is stored
+ *             in this variable. Can be NULL.
  * @return 0 if wait timed out, -1 if an error occurred, 1 if an event
  *         occurred.
  */
 int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk,
                               const struct timespec *timeout,
-                              unsigned int *index) GPIOD_API;
+                              struct gpiod_line **line) GPIOD_API;
 
 /**
  * @brief Read the last event from the GPIO line.