diff mbox series

[libgpiod,RFC,1/6] treewide: rename chip property accessors

Message ID 20210410145157.30718-2-brgl@bgdev.pl
State New
Headers show
Series first draft of libgpiod v2.0 API | expand

Commit Message

Bartosz Golaszewski April 10, 2021, 2:51 p.m. UTC
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 mbox series

Patch

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");