simple-api: modify the order of arguments in get value routines
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 11 Oct 2017 15:53:32 +0000 (17:53 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 11 Oct 2017 15:53:32 +0000 (17:53 +0200)
Move the consumer string to the end of the argument list as the least
significant option.

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

index 04f89d94f5f69bac3dca1648022c782bd668a581..81713697f51cc894f68fa3b16545618d3c40e85b 100644 (file)
@@ -68,29 +68,29 @@ struct gpiod_chip_iter;
 
 /**
  * @brief Read current value from 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.
+ * @param consumer Name of the consumer.
  * @return 0 or 1 (GPIO value) if the operation succeeds, -1 on error.
  */
-int gpiod_simple_get_value(const char *consumer, const char *device,
-                          unsigned int offset, bool active_low) GPIOD_API;
+int gpiod_simple_get_value(const char *device, unsigned int offset,
+                          bool active_low, const char *consumer) GPIOD_API;
 
 /**
  * @brief Read current values from a set of GPIO lines.
- * @param consumer Name of the consumer.
  * @param device Name, path or number of the gpiochip.
  * @param offsets An array of offsets of lines whose values should be read.
  * @param values A buffer in which the values will be stored.
  * @param num_lines Number of lines, must be > 0.
  * @param active_low The active state of the lines - true if low.
+ * @param consumer Name of the consumer.
  * @return 0 if the operation succeeds, -1 on error.
  */
-int gpiod_simple_get_value_multiple(const char *consumer, const char *device,
+int gpiod_simple_get_value_multiple(const char *device,
                                    const unsigned int *offsets, int *values,
-                                   unsigned int num_lines,
-                                   bool active_low) GPIOD_API;
+                                   unsigned int num_lines, bool active_low,
+                                   const char *consumer) GPIOD_API;
 
 /**
  * @brief Simple set value callback signature.
index a71ea0015a9e8850b33e16e003e7b85fd972cc3a..8b3561b2f9485f7567edde632901ea7e20ed6abf 100644 (file)
 #include <errno.h>
 #include <poll.h>
 
-int gpiod_simple_get_value(const char *consumer, const char *device,
-                          unsigned int offset, bool active_low)
+int gpiod_simple_get_value(const char *device, unsigned int offset,
+                          bool active_low, const char *consumer)
 {
        int value, status;
 
-       status = gpiod_simple_get_value_multiple(consumer, device, &offset,
-                                                &value, 1, active_low);
+       status = gpiod_simple_get_value_multiple(device, &offset, &value,
+                                                1, active_low, consumer);
        if (status < 0)
                return status;
 
        return value;
 }
 
-int gpiod_simple_get_value_multiple(const char *consumer, const char *device,
+int gpiod_simple_get_value_multiple(const char *device,
                                    const unsigned int *offsets, int *values,
-                                   unsigned int num_lines, bool active_low)
+                                   unsigned int num_lines, bool active_low,
+                                   const char *consumer)
 {
        struct gpiod_line_bulk bulk;
        struct gpiod_chip *chip;
index fba161ca055f46ad94d5a9b95d8c173ae866d4e0..37fd7cce7f3bc36fe01d5ccf5bc5ce2641aabed3 100644 (file)
@@ -88,9 +88,9 @@ int main(int argc, char **argv)
                        die("invalid GPIO offset: %s", argv[i + 1]);
        }
 
-       status = gpiod_simple_get_value_multiple("gpioset", device,
-                                                offsets, values,
-                                                num_lines, active_low);
+       status = gpiod_simple_get_value_multiple(device, offsets, values,
+                                                num_lines, active_low,
+                                                "gpioget");
        if (status < 0)
                die_perror("error reading GPIO values");
 
index d265bf562ec84358a1646f15efeb61fe8c693840..3d10023f76bd3e16416d6e169efad42914b88ea3 100644 (file)
@@ -39,8 +39,8 @@ static void gpioset_set_lines_and_exit(void)
        offsets[6] = 6;
        offsets[7] = 7;
 
-       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2),
-                                            offsets, values, 8, false);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets,
+                                            values, 8, false, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 0);
@@ -80,8 +80,8 @@ static void gpioset_set_lines_and_exit_active_low(void)
        offsets[6] = 6;
        offsets[7] = 7;
 
-       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2),
-                                            offsets, values, 8, false);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets,
+                                            values, 8, false, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 1);
@@ -121,8 +121,8 @@ static void gpioset_set_lines_and_exit_explicit_mode(void)
        offsets[6] = 6;
        offsets[7] = 7;
 
-       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2),
-                                            offsets, values, 8, false);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets,
+                                            values, 8, false, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 0);
@@ -159,8 +159,8 @@ static void gpioset_set_some_lines_and_wait_for_enter(void)
        offsets[3] = 6;
        offsets[4] = 7;
 
-       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2),
-                                            offsets, values, 5, false);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(2), offsets,
+                                            values, 5, false, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 0);
@@ -198,10 +198,9 @@ static void gpioset_set_some_lines_and_wait_for_signal(void)
                offsets[3] = 6;
                offsets[4] = 7;
 
-               rv = gpiod_simple_get_value_multiple(TEST_CONSUMER,
-                                                    test_chip_name(2),
+               rv = gpiod_simple_get_value_multiple(test_chip_name(2),
                                                     offsets, values,
-                                                    5, false);
+                                                    5, false, TEST_CONSUMER);
                TEST_ASSERT_RET_OK(rv);
 
                TEST_ASSERT_EQ(values[0], 0);
@@ -235,8 +234,8 @@ static void gpioset_set_some_lines_and_wait_time(void)
        offsets[1] = 2;
        offsets[2] = 5;
 
-       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0),
-                                            offsets, values, 3, false);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets,
+                                            values, 3, false, TEST_CONSUMER);
        TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 1);
index bfbe6262bc3feb00f9b13830d09807a10a4522da..11d1a7455212e89e20aec618a412f7a8f626abce 100644 (file)
@@ -18,16 +18,16 @@ static void simple_set_get_value(void)
 {
        int ret;
 
-       ret = gpiod_simple_get_value(TEST_CONSUMER,
-                                    test_chip_name(0), 3, false);
+       ret = gpiod_simple_get_value(test_chip_name(0), 3,
+                                    false, TEST_CONSUMER);
        TEST_ASSERT_EQ(ret, 0);
 
        ret = gpiod_simple_set_value(TEST_CONSUMER, test_chip_name(0),
                                     3, 1, false, NULL, NULL);
        TEST_ASSERT_RET_OK(ret);
 
-       ret = gpiod_simple_get_value(TEST_CONSUMER,
-                                    test_chip_name(0), 3, false);
+       ret = gpiod_simple_get_value(test_chip_name(0), 3,
+                                    false, TEST_CONSUMER);
        TEST_ASSERT_EQ(ret, 1);
 }
 TEST_DEFINE(simple_set_get_value,
@@ -37,11 +37,11 @@ TEST_DEFINE(simple_set_get_value,
 static void simple_set_get_value_multiple(void)
 {
        unsigned int offsets[] = { 0, 1, 2, 3, 4, 5, 6, 12, 13, 15 };
-       int values[10], ret;
+       int values[10], rv;
 
-       ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0),
-                                             offsets, values, 10, false);
-       TEST_ASSERT_RET_OK(ret);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets,
+                                            values, 10, false, TEST_CONSUMER);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 0);
        TEST_ASSERT_EQ(values[1], 0);
@@ -65,14 +65,14 @@ static void simple_set_get_value_multiple(void)
        values[8] = 0;
        values[9] = 0;
 
-       ret = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(0),
+       rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(0),
                                              offsets, values, 10, false,
                                              NULL, NULL);
-       TEST_ASSERT_RET_OK(ret);
+       TEST_ASSERT_RET_OK(rv);
 
-       ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0),
-                                             offsets, values, 10, false);
-       TEST_ASSERT_RET_OK(ret);
+       rv = gpiod_simple_get_value_multiple(test_chip_name(0), offsets,
+                                            values, 10, false, TEST_CONSUMER);
+       TEST_ASSERT_RET_OK(rv);
 
        TEST_ASSERT_EQ(values[0], 1);
        TEST_ASSERT_EQ(values[1], 1);
@@ -94,10 +94,10 @@ static void simple_get_value_multiple_max_lines(void)
        unsigned int offsets[GPIOD_LINE_BULK_MAX_LINES + 1];
        int values[GPIOD_LINE_BULK_MAX_LINES + 1], ret;
 
-       ret = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(0),
-                                             offsets, values,
+       ret = gpiod_simple_get_value_multiple(test_chip_name(0), offsets,
+                                             values,
                                              GPIOD_LINE_BULK_MAX_LINES + 1,
-                                             false);
+                                             false, TEST_CONSUMER);
        TEST_ASSERT_NOTEQ(ret, 0);
        TEST_ASSERT_ERRNO_IS(EINVAL);
 }