simple-api: improve the naming convention
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 27 Sep 2017 09:44:09 +0000 (11:44 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 27 Sep 2017 09:44:09 +0000 (11:44 +0200)
Discern between the callback arguments and return values by renaming
relevant defines.

Also: prefix all simple API defines with GPIOD_SIMPLE_.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
include/gpiod.h
src/lib/simple.c
src/tools/gpiomon.c
tests/tests-simple-api.c

index 749752aac8de167e80d488550280f6e049a71375..6853884b2af886b993ebab4512af9a83dbc1427d 100644 (file)
@@ -137,11 +137,11 @@ int gpiod_simple_set_value_multiple(const char *consumer, const char *device,
  * @brief Event types that can be passed to the simple event callback.
  */
 enum {
-       GPIOD_EVENT_CB_TIMEOUT,
+       GPIOD_SIMPLE_EVENT_CB_TIMEOUT,
        /**< Waiting for events timed out. */
-       GPIOD_EVENT_CB_RISING_EDGE,
+       GPIOD_SIMPLE_EVENT_CB_RISING_EDGE,
        /**< Rising edge event occured. */
-       GPIOD_EVENT_CB_FALLING_EDGE,
+       GPIOD_SIMPLE_EVENT_CB_FALLING_EDGE,
        /**< Falling edge event occured. */
 };
 
@@ -149,9 +149,9 @@ enum {
  * @brief Return status values that the simple event callback can return.
  */
 enum {
-       GPIOD_EVENT_CB_OK = 0,
+       GPIOD_SIMPLE_EVENT_CB_RET_OK = 0,
        /**< Continue processing events. */
-       GPIOD_EVENT_CB_STOP,
+       GPIOD_SIMPLE_EVENT_CB_RET_STOP,
        /**< Stop processing events. */
 };
 
@@ -169,13 +169,13 @@ typedef int (*gpiod_event_handle_cb)(int, unsigned int,
  * @brief Return status values that the simple event poll callback can return.
  */
 enum {
-       GPIOD_EVENT_POLL_ERR = -1,
+       GPIOD_SIMPLE_EVENT_POLL_RET_ERR = -1,
        /**< Polling error occurred (the polling function should set errno). */
-       GPIOD_EVENT_POLL_TIMEOUT = 0,
+       GPIOD_SIMPLE_EVENT_POLL_RET_TIMEOUT = 0,
        /**< Poll timed out. */
-       GPIOD_EVENT_POLL_EVENT = 1,
+       GPIOD_SIMPLE_EVENT_POLL_RET_EVENT = 1,
        /**< Line event occurred. */
-       GPIOD_EVENT_POLL_STOP = 2,
+       GPIOD_SIMPLE_EVENT_POLL_RET_STOP = 2,
        /**< The event loop should stop processing events. */
 };
 
index 186564641becd511a8a7f78d51edad36f8cb45fc..a1bb49b4a1c1d550d9861495e103cbc84009234d 100644 (file)
@@ -154,17 +154,17 @@ static int basic_event_poll(unsigned int num_lines, const int *fds,
        status = ppoll(poll_fds, num_lines, timeout, NULL);
        if (status < 0) {
                if (errno == EINTR)
-                       return GPIOD_EVENT_POLL_TIMEOUT;
+                       return GPIOD_SIMPLE_EVENT_POLL_RET_TIMEOUT;
                else
-                       return GPIOD_EVENT_POLL_ERR;
+                       return GPIOD_SIMPLE_EVENT_POLL_RET_ERR;
        } else if (status == 0) {
-               return GPIOD_EVENT_POLL_TIMEOUT;
+               return GPIOD_SIMPLE_EVENT_POLL_RET_TIMEOUT;
        }
 
        for (i = 0; !poll_fds[i].revents; i++);
        *event_offset = i;
 
-       return GPIOD_EVENT_POLL_EVENT;
+       return GPIOD_SIMPLE_EVENT_POLL_RET_EVENT;
 }
 
 int gpiod_simple_event_loop(const char *consumer, const char *device,
@@ -237,10 +237,10 @@ int gpiod_simple_event_loop_multiple(const char *consumer, const char *device,
                ret = poll_cb(num_lines, fds, &event_offset, timeout, data);
                if (ret < 0) {
                        goto out;
-               } else if (ret == GPIOD_EVENT_POLL_TIMEOUT) {
-                       evtype = GPIOD_EVENT_CB_TIMEOUT;
+               } else if (ret == GPIOD_SIMPLE_EVENT_POLL_RET_TIMEOUT) {
+                       evtype = GPIOD_SIMPLE_EVENT_CB_TIMEOUT;
                        line_offset = 0;
-               } else if (ret == GPIOD_EVENT_POLL_STOP) {
+               } else if (ret == GPIOD_SIMPLE_EVENT_POLL_RET_STOP) {
                        ret = 0;
                        goto out;
                } else {
@@ -250,14 +250,14 @@ int gpiod_simple_event_loop_multiple(const char *consumer, const char *device,
                                goto out;
 
                        evtype = event.event_type == GPIOD_EVENT_RISING_EDGE
-                                               ? GPIOD_EVENT_CB_RISING_EDGE
-                                               : GPIOD_EVENT_CB_FALLING_EDGE;
+                                       ? GPIOD_SIMPLE_EVENT_CB_RISING_EDGE
+                                       : GPIOD_SIMPLE_EVENT_CB_FALLING_EDGE;
 
                        line_offset = offsets[event_offset];
                }
 
                ret = event_cb(evtype, line_offset, &event.ts, data);
-               if (ret == GPIOD_EVENT_CB_STOP) {
+               if (ret == GPIOD_SIMPLE_EVENT_CB_RET_STOP) {
                        ret = 0;
                        goto out;
                }
index e46057c91975d1ea86dd451d1fb1db60ab085030..533d57870ad62780e8a3bac903c0299a538ff337 100644 (file)
@@ -95,7 +95,7 @@ static void event_print_custom(unsigned int offset,
                        printf("%u", offset);
                        break;
                case 'e':
-                       if (event_type == GPIOD_EVENT_CB_RISING_EDGE)
+                       if (event_type == GPIOD_SIMPLE_EVENT_CB_RISING_EDGE)
                                fputc('1', stdout);
                        else
                                fputc('0', stdout);
@@ -131,7 +131,7 @@ static void event_print_human_readable(unsigned int offset,
 {
        char *evname;
 
-       if (event_type == GPIOD_EVENT_CB_RISING_EDGE)
+       if (event_type == GPIOD_SIMPLE_EVENT_CB_RISING_EDGE)
                evname = " RISING EDGE";
        else
                evname = "FALLING EDGE";
@@ -161,14 +161,14 @@ static int poll_callback(unsigned int num_lines, const int *fds,
 
        ret = poll(pfds, num_lines + 1, ts);
        if (ret < 0)
-               return GPIOD_EVENT_POLL_ERR;
+               return GPIOD_SIMPLE_EVENT_POLL_RET_ERR;
        else if (ret == 0)
-               return GPIOD_EVENT_POLL_TIMEOUT;
+               return GPIOD_SIMPLE_EVENT_POLL_RET_TIMEOUT;
 
        for (i = 0; i < num_lines; i++) {
                if (pfds[i].revents) {
                        *event_offset = i;
-                       return GPIOD_EVENT_POLL_EVENT;
+                       return GPIOD_SIMPLE_EVENT_POLL_RET_EVENT;
                }
        }
 
@@ -178,7 +178,7 @@ static int poll_callback(unsigned int num_lines, const int *fds,
         */
        close(ctx->sigfd);
 
-       return GPIOD_EVENT_POLL_STOP;
+       return GPIOD_SIMPLE_EVENT_POLL_RET_STOP;
 }
 
 static int event_callback(int event_type, unsigned int line_offset,
@@ -187,9 +187,9 @@ static int event_callback(int event_type, unsigned int line_offset,
        struct mon_ctx *ctx = data;
 
        if (!ctx->silent) {
-               if ((event_type == GPIOD_EVENT_CB_RISING_EDGE
+               if ((event_type == GPIOD_SIMPLE_EVENT_CB_RISING_EDGE
                    && ctx->watch_rising)
-                   || (event_type == GPIOD_EVENT_CB_FALLING_EDGE
+                   || (event_type == GPIOD_SIMPLE_EVENT_CB_FALLING_EDGE
                    && ctx->watch_falling)) {
                        if (ctx->fmt)
                                event_print_custom(line_offset, timestamp,
@@ -203,9 +203,9 @@ static int event_callback(int event_type, unsigned int line_offset,
        ctx->events_done++;
 
        if (ctx->events_wanted && ctx->events_done >= ctx->events_wanted)
-               return GPIOD_EVENT_CB_STOP;
+               return GPIOD_SIMPLE_EVENT_CB_RET_STOP;
 
-       return GPIOD_EVENT_CB_OK;
+       return GPIOD_SIMPLE_EVENT_CB_RET_OK;
 }
 
 static int make_signalfd(void)
index 55dcb7100cbad13247dae29c0e9b875ec2f3838d..579cdd484f2d57a674778ec2216233466722da51 100644 (file)
@@ -133,14 +133,15 @@ static int simple_event_cb(int evtype, unsigned int offset,
 {
        struct simple_event_data *evdata = data;
 
-       if (evtype == GPIOD_EVENT_CB_RISING_EDGE)
+       if (evtype == GPIOD_SIMPLE_EVENT_CB_RISING_EDGE)
                evdata->got_rising_edge = true;
-       else if (evtype == GPIOD_EVENT_CB_FALLING_EDGE)
+       else if (evtype == GPIOD_SIMPLE_EVENT_CB_FALLING_EDGE)
                evdata->got_falling_edge = true;
 
        evdata->offset = offset;
 
-       return ++evdata->count == 2 ? GPIOD_EVENT_CB_STOP : GPIOD_EVENT_CB_OK;
+       return ++evdata->count == 2 ? GPIOD_SIMPLE_EVENT_CB_RET_STOP
+                                   : GPIOD_SIMPLE_EVENT_CB_RET_OK;
 }
 
 static void simple_event_loop(void)