diff options
author | Bartosz Golaszewski <bartekgola@gmail.com> | 2017-11-04 22:39:36 +0100 |
---|---|---|
committer | Bartosz Golaszewski <bartekgola@gmail.com> | 2017-11-04 23:18:26 +0100 |
commit | 230868dcfadd24c8a1cbad7ee4a42127cd4fe127 (patch) | |
tree | cdc2b2ec2f9c19f60e0029ba0b4c2c7f4068137a /include | |
parent | f949d196dab8e7106fd437f9679f8fd5dbbacb82 (diff) | |
download | external_libgpiod-230868dcfadd24c8a1cbad7ee4a42127cd4fe127.tar.gz external_libgpiod-230868dcfadd24c8a1cbad7ee4a42127cd4fe127.tar.bz2 external_libgpiod-230868dcfadd24c8a1cbad7ee4a42127cd4fe127.zip |
iter: rework chip iterators
We can significantly simplify the chip iterators by performing all
actions that can yield an error in gpiod_chip_iter_new(). Instead of
opening each subsequent chip in gpiod_chip_iter_next(), open them all
in the new function and make next just return an active handle.
Fix relevant test cases and macros, remove related routines that are
no longer needed.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/gpiod.h | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/include/gpiod.h b/include/gpiod.h index 03c5b23..3276036 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -1153,8 +1153,9 @@ struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API; * @brief Create a new gpiochip iterator. * @return Pointer to a new chip iterator object or NULL if an error occurred. * - * Internally this routine scand the /dev/ directory for GPIO chip device - * files and stores their list in the iterator structure. + * Internally this routine scans the /dev/ directory for GPIO chip device + * files, opens them and stores their the handles until ::gpiod_chip_iter_free + * or ::gpiod_chip_iter_free_noclose is called. */ struct gpiod_chip_iter * gpiod_chip_iter_new(void) GPIOD_API; @@ -1181,9 +1182,7 @@ void gpiod_chip_iter_free_noclose(struct gpiod_chip_iter *iter) GPIOD_API; * @param iter The gpiochip iterator object. * @return Pointer to an open gpiochip handle or NULL if the next chip can't * be accessed. - * - * Internally this routine tries to open the next /dev/gpiochipX device file. - * If an error occurs or no more chips are present, the function returns NULL. + * @note The previous chip handle will be closed using ::gpiod_chip_iter_free. */ struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API; @@ -1212,11 +1211,11 @@ gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API; */ #define gpiod_foreach_chip(iter, chip) \ for ((chip) = gpiod_chip_iter_next(iter); \ - !gpiod_chip_iter_done(iter); \ + (chip); \ (chip) = gpiod_chip_iter_next(iter)) /** - * @brief Iterate over all gpiochip present in the system without closing them. + * @brief Iterate over all chips present in the system without closing them. * @param iter An initialized GPIO chip iterator. * @param chip Pointer to a GPIO chip handle. On each iteration the newly * opened chip handle is assigned to this argument. @@ -1227,38 +1226,10 @@ gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API; */ #define gpiod_foreach_chip_noclose(iter, chip) \ for ((chip) = gpiod_chip_iter_next_noclose(iter); \ - !gpiod_chip_iter_done(iter); \ + (chip); \ (chip) = gpiod_chip_iter_next_noclose(iter)) /** - * @brief Check if we're done iterating over gpiochips on this iterator. - * @param iter The gpiochip iterator object. - * @return True if we've iterated over all chips, false otherwise. - */ -bool gpiod_chip_iter_done(struct gpiod_chip_iter *iter) GPIOD_API; - -/** - * @brief Check if we've encountered an error condition while opening a - * gpiochip. - * @param iter The gpiochip iterator object. - * @return True if there was an error opening a gpiochip device file, - * false otherwise. - */ -bool gpiod_chip_iter_err(struct gpiod_chip_iter *iter) GPIOD_API; - -/** - * @brief Get the name of the gpiochip that we failed to access. - * @param iter The gpiochip iterator object. - * @return If ::gpiod_chip_iter_iserr returned true, this function returns a - * pointer to the name of the gpiochip that we failed to access. - * If there was no error this function returns NULL. - * @note This function will return NULL if the internal memory - * allocation fails. - */ -const char * -gpiod_chip_iter_failed_chip(struct gpiod_chip_iter *iter) GPIOD_API; - -/** * @brief Possible states of a line iterator. */ enum { |