All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [libgpiod][RFC 1/6] treewide: rename chip property accessors
Date: Sat, 10 Apr 2021 16:51:52 +0200	[thread overview]
Message-ID: <20210410145157.30718-2-brgl@bgdev.pl> (raw)
In-Reply-To: <20210410145157.30718-1-brgl@bgdev.pl>

In v2 API all getters will be called using the following pattern:

    gpiod_<object>_get_<what>

Apply this to already existing getters for gpiod_chip.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 bindings/cxx/chip.cpp         |  6 +++---
 bindings/python/gpiodmodule.c | 14 +++++++-------
 include/gpiod.h               |  6 +++---
 lib/core.c                    |  6 +++---
 lib/helpers.c                 |  6 +++---
 tests/tests-chip.c            | 25 ++++++++++++++-----------
 tools/gpiodetect.c            |  6 +++---
 tools/gpiofind.c              |  2 +-
 tools/gpioinfo.c              |  4 ++--
 9 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/bindings/cxx/chip.cpp b/bindings/cxx/chip.cpp
index d5a9837..ee6ab6f 100644
--- a/bindings/cxx/chip.cpp
+++ b/bindings/cxx/chip.cpp
@@ -62,21 +62,21 @@ GPIOD_CXX_API ::std::string chip::name(void) const
 {
 	this->throw_if_noref();
 
-	return ::std::string(::gpiod_chip_name(this->_m_chip.get()));
+	return ::std::string(::gpiod_chip_get_name(this->_m_chip.get()));
 }
 
 GPIOD_CXX_API ::std::string chip::label(void) const
 {
 	this->throw_if_noref();
 
-	return ::std::string(::gpiod_chip_label(this->_m_chip.get()));
+	return ::std::string(::gpiod_chip_get_label(this->_m_chip.get()));
 }
 
 GPIOD_CXX_API unsigned int chip::num_lines(void) const
 {
 	this->throw_if_noref();
 
-	return ::gpiod_chip_num_lines(this->_m_chip.get());
+	return ::gpiod_chip_get_num_lines(this->_m_chip.get());
 }
 
 GPIOD_CXX_API line chip::get_line(unsigned int offset) const
diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c
index 8bfb4c4..ed039e4 100644
--- a/bindings/python/gpiodmodule.c
+++ b/bindings/python/gpiodmodule.c
@@ -1918,9 +1918,9 @@ static PyObject *gpiod_Chip_repr(gpiod_ChipObject *self)
 		return NULL;
 
 	return PyUnicode_FromFormat("'%s /%s/ %u lines'",
-				    gpiod_chip_name(self->chip),
-				    gpiod_chip_label(self->chip),
-				    gpiod_chip_num_lines(self->chip));
+				    gpiod_chip_get_name(self->chip),
+				    gpiod_chip_get_label(self->chip),
+				    gpiod_chip_get_num_lines(self->chip));
 }
 
 PyDoc_STRVAR(gpiod_Chip_close_doc,
@@ -1971,7 +1971,7 @@ static PyObject *gpiod_Chip_name(gpiod_ChipObject *self,
 	if (gpiod_ChipIsClosed(self))
 		return NULL;
 
-	return PyUnicode_FromFormat("%s", gpiod_chip_name(self->chip));
+	return PyUnicode_FromFormat("%s", gpiod_chip_get_name(self->chip));
 }
 
 PyDoc_STRVAR(gpiod_Chip_label_doc,
@@ -1985,7 +1985,7 @@ static PyObject *gpiod_Chip_label(gpiod_ChipObject *self,
 	if (gpiod_ChipIsClosed(self))
 		return NULL;
 
-	return PyUnicode_FromFormat("%s", gpiod_chip_label(self->chip));
+	return PyUnicode_FromFormat("%s", gpiod_chip_get_label(self->chip));
 }
 
 PyDoc_STRVAR(gpiod_Chip_num_lines_doc,
@@ -1999,7 +1999,7 @@ static PyObject *gpiod_Chip_num_lines(gpiod_ChipObject *self,
 	if (gpiod_ChipIsClosed(self))
 		return NULL;
 
-	return Py_BuildValue("I", gpiod_chip_num_lines(self->chip));
+	return Py_BuildValue("I", gpiod_chip_get_num_lines(self->chip));
 }
 
 static gpiod_LineObject *
@@ -2381,7 +2381,7 @@ static gpiod_LineObject *gpiod_LineIter_next(gpiod_LineIterObject *self)
 {
 	struct gpiod_line *line;
 
-	if (self->offset == gpiod_chip_num_lines(self->owner->chip))
+	if (self->offset == gpiod_chip_get_num_lines(self->owner->chip))
 		return NULL; /* Last element. */
 
 	line = gpiod_chip_get_line(self->owner->chip, self->offset++);
diff --git a/include/gpiod.h b/include/gpiod.h
index 5aea01f..a4ce01f 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -94,21 +94,21 @@ void gpiod_chip_unref(struct gpiod_chip *chip);
  * @param chip The GPIO chip object.
  * @return Pointer to a human-readable string containing the chip name.
  */
-const char *gpiod_chip_name(struct gpiod_chip *chip);
+const char *gpiod_chip_get_name(struct gpiod_chip *chip);
 
 /**
  * @brief Get the GPIO chip label as represented in the kernel.
  * @param chip The GPIO chip object.
  * @return Pointer to a human-readable string containing the chip label.
  */
-const char *gpiod_chip_label(struct gpiod_chip *chip);
+const char *gpiod_chip_get_label(struct gpiod_chip *chip);
 
 /**
  * @brief Get the number of GPIO lines exposed by this chip.
  * @param chip The GPIO chip object.
  * @return Number of GPIO lines.
  */
-unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip);
+unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip);
 
 /**
  * @brief Get the handle to the GPIO line at given offset.
diff --git a/lib/core.c b/lib/core.c
index 32c4238..2e7ee4b 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -335,17 +335,17 @@ GPIOD_API void gpiod_chip_unref(struct gpiod_chip *chip)
 	free(chip);
 }
 
-GPIOD_API const char *gpiod_chip_name(struct gpiod_chip *chip)
+GPIOD_API const char *gpiod_chip_get_name(struct gpiod_chip *chip)
 {
 	return chip->name;
 }
 
-GPIOD_API const char *gpiod_chip_label(struct gpiod_chip *chip)
+GPIOD_API const char *gpiod_chip_get_label(struct gpiod_chip *chip)
 {
 	return chip->label;
 }
 
-GPIOD_API unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip)
+GPIOD_API unsigned int gpiod_chip_get_num_lines(struct gpiod_chip *chip)
 {
 	return chip->num_lines;
 }
diff --git a/lib/helpers.c b/lib/helpers.c
index 9c4b28e..fb53518 100644
--- a/lib/helpers.c
+++ b/lib/helpers.c
@@ -45,11 +45,11 @@ gpiod_chip_get_all_lines(struct gpiod_chip *chip)
 	struct gpiod_line *line;
 	unsigned int offset;
 
-	bulk = gpiod_line_bulk_new(gpiod_chip_num_lines(chip));
+	bulk = gpiod_line_bulk_new(gpiod_chip_get_num_lines(chip));
 	if (!bulk)
 		return NULL;
 
-	for (offset = 0; offset < gpiod_chip_num_lines(chip); offset++) {
+	for (offset = 0; offset < gpiod_chip_get_num_lines(chip); offset++) {
 		line = gpiod_chip_get_line(chip, offset);
 		if (!line) {
 			gpiod_line_bulk_free(bulk);
@@ -68,7 +68,7 @@ GPIOD_API int gpiod_chip_find_line(struct gpiod_chip *chip, const char *name)
 	struct gpiod_line *line;
 	const char *tmp;
 
-	num_lines = gpiod_chip_num_lines(chip);
+	num_lines = gpiod_chip_get_num_lines(chip);
 
 	for (offset = 0; offset < num_lines; offset++) {
 		line = gpiod_chip_get_line(chip, offset);
diff --git a/tests/tests-chip.c b/tests/tests-chip.c
index a87dc9a..46fb8d2 100644
--- a/tests/tests-chip.c
+++ b/tests/tests-chip.c
@@ -63,9 +63,12 @@ GPIOD_TEST_CASE(get_name, 0, { 8, 8, 8})
 	g_assert_nonnull(chip2);
 	gpiod_test_return_if_failed();
 
-	g_assert_cmpstr(gpiod_chip_name(chip0), ==, gpiod_test_chip_name(0));
-	g_assert_cmpstr(gpiod_chip_name(chip1), ==, gpiod_test_chip_name(1));
-	g_assert_cmpstr(gpiod_chip_name(chip2), ==, gpiod_test_chip_name(2));
+	g_assert_cmpstr(gpiod_chip_get_name(chip0), ==,
+			gpiod_test_chip_name(0));
+	g_assert_cmpstr(gpiod_chip_get_name(chip1), ==,
+			gpiod_test_chip_name(1));
+	g_assert_cmpstr(gpiod_chip_get_name(chip2), ==,
+			gpiod_test_chip_name(2));
 }
 
 GPIOD_TEST_CASE(get_label, 0, { 8, 8, 8})
@@ -83,9 +86,9 @@ GPIOD_TEST_CASE(get_label, 0, { 8, 8, 8})
 	g_assert_nonnull(chip2);
 	gpiod_test_return_if_failed();
 
-	g_assert_cmpstr(gpiod_chip_label(chip0), ==, "gpio-mockup-A");
-	g_assert_cmpstr(gpiod_chip_label(chip1), ==, "gpio-mockup-B");
-	g_assert_cmpstr(gpiod_chip_label(chip2), ==, "gpio-mockup-C");
+	g_assert_cmpstr(gpiod_chip_get_label(chip0), ==, "gpio-mockup-A");
+	g_assert_cmpstr(gpiod_chip_get_label(chip1), ==, "gpio-mockup-B");
+	g_assert_cmpstr(gpiod_chip_get_label(chip2), ==, "gpio-mockup-C");
 }
 
 GPIOD_TEST_CASE(num_lines, 0, { 1, 4, 8, 16, 32 })
@@ -109,11 +112,11 @@ GPIOD_TEST_CASE(num_lines, 0, { 1, 4, 8, 16, 32 })
 	g_assert_nonnull(chip4);
 	gpiod_test_return_if_failed();
 
-	g_assert_cmpuint(gpiod_chip_num_lines(chip0), ==, 1);
-	g_assert_cmpuint(gpiod_chip_num_lines(chip1), ==, 4);
-	g_assert_cmpuint(gpiod_chip_num_lines(chip2), ==, 8);
-	g_assert_cmpuint(gpiod_chip_num_lines(chip3), ==, 16);
-	g_assert_cmpuint(gpiod_chip_num_lines(chip4), ==, 32);
+	g_assert_cmpuint(gpiod_chip_get_num_lines(chip0), ==, 1);
+	g_assert_cmpuint(gpiod_chip_get_num_lines(chip1), ==, 4);
+	g_assert_cmpuint(gpiod_chip_get_num_lines(chip2), ==, 8);
+	g_assert_cmpuint(gpiod_chip_get_num_lines(chip3), ==, 16);
+	g_assert_cmpuint(gpiod_chip_get_num_lines(chip4), ==, 32);
 }
 
 GPIOD_TEST_CASE(get_line, 0, { 16 })
diff --git a/tools/gpiodetect.c b/tools/gpiodetect.c
index 9f4c28c..10706e2 100644
--- a/tools/gpiodetect.c
+++ b/tools/gpiodetect.c
@@ -76,9 +76,9 @@ int main(int argc, char **argv)
 		}
 
 		printf("%s [%s] (%u lines)\n",
-		       gpiod_chip_name(chip),
-		       gpiod_chip_label(chip),
-		       gpiod_chip_num_lines(chip));
+		       gpiod_chip_get_name(chip),
+		       gpiod_chip_get_label(chip),
+		       gpiod_chip_get_num_lines(chip));
 
 		gpiod_chip_unref(chip);
 		free(entries[i]);
diff --git a/tools/gpiofind.c b/tools/gpiofind.c
index 83af76b..32b7852 100644
--- a/tools/gpiofind.c
+++ b/tools/gpiofind.c
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
 		offset = gpiod_chip_find_line(chip, argv[0]);
 		if (offset >= 0) {
 			printf("%s %u\n",
-			       gpiod_chip_name(chip), offset);
+			       gpiod_chip_get_name(chip), offset);
 			gpiod_chip_unref(chip);
 			return EXIT_SUCCESS;
 		}
diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c
index eba8c72..3d89111 100644
--- a/tools/gpioinfo.c
+++ b/tools/gpioinfo.c
@@ -130,9 +130,9 @@ static void list_lines(struct gpiod_chip *chip)
 	int direction;
 
 	printf("%s - %u lines:\n",
-	       gpiod_chip_name(chip), gpiod_chip_num_lines(chip));
+	       gpiod_chip_get_name(chip), gpiod_chip_get_num_lines(chip));
 
-	for (offset = 0; offset < gpiod_chip_num_lines(chip); offset++) {
+	for (offset = 0; offset < gpiod_chip_get_num_lines(chip); offset++) {
 		line = gpiod_chip_get_line(chip, offset);
 		if (!line)
 			die_perror("unable to retrieve the line object from chip");
-- 
2.30.1


  reply	other threads:[~2021-04-10 14:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-10 14:51 [libgpiod][RFC 0/6] first draft of libgpiod v2.0 API Bartosz Golaszewski
2021-04-10 14:51 ` Bartosz Golaszewski [this message]
2021-04-10 14:51 ` [libgpiod][RFC 2/6] core: add refcounting helpers Bartosz Golaszewski
2021-04-10 14:51 ` [libgpiod][RFC 3/6] core: implement line_info objects Bartosz Golaszewski
2021-04-10 14:51 ` [libgpiod][RFC 4/6] core: rework line events Bartosz Golaszewski
2021-04-10 14:51 ` [libgpiod][RFC 5/6] core: rework line requests Bartosz Golaszewski
2021-04-10 14:51 ` [libgpiod][RFC 6/6] core: implement line watch events Bartosz Golaszewski
2021-04-14 14:15 ` [libgpiod][RFC 0/6] first draft of libgpiod v2.0 API Kent Gibson
2021-04-16  9:36   ` Bartosz Golaszewski
2021-04-17  7:23     ` Kent Gibson
2021-04-17 11:31       ` Bartosz Golaszewski
2021-04-18  3:48         ` Kent Gibson
2021-04-18 21:12           ` Bartosz Golaszewski
2021-04-19  1:17             ` Kent Gibson
2021-04-21 20:04               ` Bartosz Golaszewski
2021-04-22  2:32                 ` Kent Gibson
2021-04-22  9:24                   ` Bartosz Golaszewski
2021-04-23  1:38                     ` Kent Gibson
2021-04-28  9:19                       ` Bartosz Golaszewski
2021-04-28 10:34                         ` Kent Gibson
2021-04-30 17:52                           ` Bartosz Golaszewski
2021-05-01  0:15                             ` Kent Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210410145157.30718-2-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.