core: allow to specify the consumer in the simple event loop
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:57:37 +0000 (15:57 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 17 Jan 2017 14:57:37 +0000 (15:57 +0100)
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/core.c
src/tools/gpiomon.c

index f0b739c42d7712885e998d325f7a3579edac1bbb..3ef2a8ae403b655421f237b5e8e08719dbaf0753 100644 (file)
@@ -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;
 
 /**
  * @}
index 3488d4379a95f21c620635a8832c172d25331486..011ffa485d09dd6f59ba3aae45baa46c701c0847 100644 (file)
@@ -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;
index 46cad7d8fba557d8233bee805fb8981528261ffe..ff78b6d48a675d4c96940677bd3ee3d100b90abb 100644 (file)
@@ -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");