From: Bartosz Golaszewski Date: Tue, 17 Jan 2017 14:57:37 +0000 (+0100) Subject: core: allow to specify the consumer in the simple event loop X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6c0b5dd40d7c295865e1db8673b8abca0ccabbc3;p=qemu-gpiodev%2Flibgpiod.git core: allow to specify the consumer in the simple event loop Signed-off-by: Bartosz Golaszewski --- diff --git a/include/gpiod.h b/include/gpiod.h index f0b739c..3ef2a8a 100644 --- a/include/gpiod.h +++ b/include/gpiod.h @@ -233,6 +233,7 @@ typedef int (*gpiod_event_cb)(int, const struct timespec *, void *); /** * @brief Wait for events on a single GPIO line. + * @param consumer Name of the consumer. * @param device Name, path or number of the gpiochip. * @param offset GPIO line offset on the chip. * @param active_low The active state of this line - true if low. @@ -242,9 +243,10 @@ typedef int (*gpiod_event_cb)(int, const struct timespec *, void *); * @return 0 no errors were encountered, -1 if an error occured. * */ -int gpiod_simple_event_loop(const char *device, unsigned int offset, - bool active_low, struct timespec *timeout, - gpiod_event_cb callback, void *cbdata) GPIOD_API; +int gpiod_simple_event_loop(const char *consumer, const char *device, + unsigned int offset, bool active_low, + struct timespec *timeout, gpiod_event_cb callback, + void *cbdata) GPIOD_API; /** * @} diff --git a/src/lib/core.c b/src/lib/core.c index 3488d43..011ffa4 100644 --- a/src/lib/core.c +++ b/src/lib/core.c @@ -68,7 +68,6 @@ struct gpiod_chip_iter static const char dev_dir[] = "/dev/"; static const char cdev_prefix[] = "gpiochip"; -static const char libgpiod_consumer[] = "libgpiod"; /* * The longest error message in glibc is about 50 characters long so 64 should @@ -253,9 +252,10 @@ int gpiod_simple_set_value_multiple(const char *consumer, const char *device, return 0; } -int gpiod_simple_event_loop(const char *device, unsigned int offset, - bool active_low, struct timespec *timeout, - gpiod_event_cb callback, void *cbdata) +int gpiod_simple_event_loop(const char *consumer, const char *device, + unsigned int offset, bool active_low, + struct timespec *timeout, gpiod_event_cb callback, + void *cbdata) { struct gpiod_line_event event; struct gpiod_chip *chip; @@ -272,8 +272,7 @@ int gpiod_simple_event_loop(const char *device, unsigned int offset, return -1; } - status = gpiod_line_event_request_all(line, - libgpiod_consumer, active_low); + status = gpiod_line_event_request_all(line, consumer, active_low); if (status < 0) { gpiod_chip_close(chip); return -1; diff --git a/src/tools/gpiomon.c b/src/tools/gpiomon.c index 46cad7d..ff78b6d 100644 --- a/src/tools/gpiomon.c +++ b/src/tools/gpiomon.c @@ -121,7 +121,7 @@ int main(int argc, char **argv) signal(SIGINT, sighandler); signal(SIGTERM, sighandler); - status = gpiod_simple_event_loop(device, offset, active_low, + status = gpiod_simple_event_loop("gpiomon", device, offset, active_low, &timeout, event_callback, NULL); if (status < 0) die_perror("error waiting for events");