From: Bartosz Golaszewski Date: Wed, 4 Jan 2017 21:44:41 +0000 (+0100) Subject: core: tweak line iterators X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=fc80fc18a8453bb1bd7528ed6f4f0371bba7bf14;p=qemu-gpiodev%2Flibgpiod.git core: tweak line iterators Some line iterator changes to keep them similar to chip iterators. Signed-off-by: Bartosz Golaszewski --- diff --git a/gpiod.h b/gpiod.h index 5792fbf..d223b1c 100644 --- a/gpiod.h +++ b/gpiod.h @@ -176,28 +176,31 @@ gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API; struct gpiod_line_iter { unsigned int offset; + struct gpiod_chip *chip; }; -#define GPIOD_LINE_ITER_INITIALIZER { 0 } +#define GPIOD_LINE_ITER_INITIALIZER(chip) { 0, (chip) } -static inline void gpiod_line_iter_init(struct gpiod_line_iter *iter) +static inline void gpiod_line_iter_init(struct gpiod_line_iter *iter, + struct gpiod_chip *chip) { iter->offset = 0; + iter->chip = chip; } static inline struct gpiod_line * -gpiod_chip_line_next(struct gpiod_chip *chip, struct gpiod_line_iter *iter) +gpiod_line_iter_next(struct gpiod_line_iter *iter) { - if (iter->offset >= gpiod_chip_num_lines(chip)) + if (iter->offset >= gpiod_chip_num_lines(iter->chip)) return NULL; - return gpiod_chip_get_line(chip, iter->offset++); + return gpiod_chip_get_line(iter->chip, iter->offset++); } -#define gpiod_chip_foreach_line(iter, chip, line) \ - for ((line) = gpiod_chip_line_next(chip, iter); \ +#define gpiod_foreach_line(iter, line) \ + for ((line) = gpiod_line_iter_next(iter); \ (line); \ - (line) = gpiod_chip_line_next(chip, iter)) + (line) = gpiod_line_iter_next(iter)) #ifdef __cplusplus } /* extern "C" */ diff --git a/gpioinfo.c b/gpioinfo.c index 327d34f..79a3b6a 100644 --- a/gpioinfo.c +++ b/gpioinfo.c @@ -59,8 +59,8 @@ int main(int argc, char **argv) printf("%s - %u lines:\n", gpiod_chip_name(chip), gpiod_chip_num_lines(chip)); - gpiod_line_iter_init(&iter); - gpiod_chip_foreach_line(&iter, chip, line) { + gpiod_line_iter_init(&iter, chip); + gpiod_foreach_line(&iter, line) { name = gpiod_line_name(line); consumer = gpiod_line_consumer(line); direction = gpiod_line_direction(line);