qemu-gpiodev/libgpiod.git
6 years agobindings: python: examples: close chip objects where needed
Bartosz Golaszewski [Fri, 27 Jul 2018 11:52:18 +0000 (13:52 +0200)]
bindings: python: examples: close chip objects where needed

Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: add a comment about libtool version to configure.ac
Bartosz Golaszewski [Thu, 26 Jul 2018 11:09:34 +0000 (13:09 +0200)]
build: add a comment about libtool version to configure.ac

The libtool version only applies to the core C library, not to tools
or python bindings. C++ bindings have a separate libtool version.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotools: tweak the displayed version format
Bartosz Golaszewski [Tue, 24 Jul 2018 13:09:35 +0000 (15:09 +0200)]
tools: tweak the displayed version format

Prepend the version string with a 'v' to stay consistent with git
tags we're using.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix tp_dealloc callbacks in all objects
Bartosz Golaszewski [Tue, 24 Jul 2018 12:12:18 +0000 (14:12 +0200)]
bindings: python: fix tp_dealloc callbacks in all objects

We have a significant memory leak in the current implementation as we
don't call PyObject_Del() as the last action in tp_dealloc callbacks.

From tp_dealloc's documentation:

---
The destructor function should free all references which the instance
owns, free all memory buffers owned by the instance (using the freeing
function corresponding to the allocation function used to allocate the
buffer), and finally (as its last action) call the type’s tp_free
function.
---

PyObject_Del() will internally call the tp_free callback of the type.
Add a call to it as the last action in every destructor.

Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: don't force python to use the system allocator
Bartosz Golaszewski [Sun, 22 Jul 2018 19:26:47 +0000 (21:26 +0200)]
bindings: python: don't force python to use the system allocator

When allocating raw memory let python decide which allocator to use.
Convert all calls to PyMem_Raw*() to PyMem_*().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: examples: new test case
Bartosz Golaszewski [Sun, 22 Jul 2018 18:12:40 +0000 (20:12 +0200)]
bindings: python: examples: new test case

Add a test case for incorrect number of default values in line
requests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: don't call gpiod_LineBulk_init() directly
Bartosz Golaszewski [Sun, 22 Jul 2018 13:23:59 +0000 (15:23 +0200)]
bindings: python: don't call gpiod_LineBulk_init() directly

We can instantiate an object of a type by "calling" it's type structure
using PyObject_CallObject(). It will internally call the constructor so
use it to shrink the code.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: add test cases for default values in line requests
Bartosz Golaszewski [Fri, 20 Jul 2018 08:27:53 +0000 (10:27 +0200)]
bindings: python: add test cases for default values in line requests

Add two new tests verifying the default_vals argument in line requests
for single and multiple lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix the default_vals argument in line requests
Bartosz Golaszewski [Fri, 20 Jul 2018 08:13:59 +0000 (10:13 +0200)]
bindings: python: fix the default_vals argument in line requests

We're assigning the wrong local variable in PyArg_ParseTupleAndKeywords()
which results in not honoring the default_vals argument. Fix the
LineBulk.request() implementation.

Fixes: 96c524c4951c ("bindings: implement python bindings")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: examples: remove unnecessary import
Bartosz Golaszewski [Fri, 13 Jul 2018 17:47:37 +0000 (19:47 +0200)]
bindings: python: examples: remove unnecessary import

We no longer need sys in gpiod_tests.py. Remove it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: move gpiod_ChipIsClosed() to the top of gpiodmodule.c
Bartosz Golaszewski [Fri, 13 Jul 2018 16:34:50 +0000 (18:34 +0200)]
bindings: python: move gpiod_ChipIsClosed() to the top of gpiodmodule.c

Unlike the other two helpers that are still declared at the top of the
source file - this routine doesn't need to know any gpiod-specific type
so move it up and remove the prototype.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: examples: don't use sys.argv[0] as consumer string
Bartosz Golaszewski [Fri, 13 Jul 2018 14:00:23 +0000 (16:00 +0200)]
bindings: python: examples: don't use sys.argv[0] as consumer string

Strings with slashes trigger a warning in the kernel in
fs/proc/generic.c. Use a hardcoded consumer string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: call gpiod_LineBulk_init() directly
Bartosz Golaszewski [Fri, 13 Jul 2018 13:57:25 +0000 (15:57 +0200)]
bindings: python: call gpiod_LineBulk_init() directly

Using the .tp_init callback is more complicated and unnecessary. Call
gpiod_LineBulk_init() directly from gpiod_ListToLineBulk().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: provide a helper for calling methods with python args
Bartosz Golaszewski [Fri, 13 Jul 2018 13:07:47 +0000 (15:07 +0200)]
bindings: python: provide a helper for calling methods with python args

Wrap the calls to PyObject_GetAttrString() and PyObject_Call() in
a single helper that allows to call a python method and pass it the
args and kwds tuples directly as received from the interpreter.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix a memory corruption
Bartosz Golaszewski [Fri, 13 Jul 2018 09:21:31 +0000 (11:21 +0200)]
bindings: python: fix a memory corruption

PyList_GetItem() returns a borrowed reference so we need to increase
the reference count on the returned object before DECREF'ing the list
object itself

This fixes random 'free(): invalid pointer' errors.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix a memory leak in error path
Bartosz Golaszewski [Fri, 13 Jul 2018 08:10:34 +0000 (10:10 +0200)]
bindings: python: fix a memory leak in error path

We need to decref the iter object in Line.set_values() if the
conversion from python to C unsigned integer fails.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix a warning
Bartosz Golaszewski [Wed, 6 Jun 2018 15:01:44 +0000 (17:01 +0200)]
bindings: python: fix a warning

On some architectures we get a 'comparison between signed and unsigned
integer' warning when building python bindings. Fix it by changing the
type of the variable used for offset to unsigned int.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: add a test case for line_event's __repr__
Bartosz Golaszewski [Wed, 6 Jun 2018 10:49:00 +0000 (12:49 +0200)]
bindings: python: add a test case for line_event's __repr__

Check if an event's representation string is generated correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: avoid calling object method callbacks directly
Bartosz Golaszewski [Wed, 6 Jun 2018 10:26:23 +0000 (12:26 +0200)]
bindings: python: avoid calling object method callbacks directly

Where it's impossible to use PyObject_CallMethod() (e.g. when we want
to pass args and kwargs unchanged to the method being called), use
a combination of PyObject_GetAttrString() and PyObject_Call().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: use PyObject_CallMethod() where possible
Bartosz Golaszewski [Wed, 6 Jun 2018 10:15:54 +0000 (12:15 +0200)]
bindings: python: use PyObject_CallMethod() where possible

Avoid directly calling method callbacks. Use the routine provided by
Python API instead where possible.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agolibgpiod: start v1.2 development cycle
Bartosz Golaszewski [Wed, 6 Jun 2018 09:25:06 +0000 (11:25 +0200)]
libgpiod: start v1.2 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agolibgpiod v1.1
Bartosz Golaszewski [Wed, 16 May 2018 13:28:39 +0000 (15:28 +0200)]
libgpiod v1.1

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoNEWS: updates for v1.1
Bartosz Golaszewski [Wed, 16 May 2018 12:30:36 +0000 (14:30 +0200)]
NEWS: updates for v1.1

Add release notes for libgpiod v1.1.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: set the ABI version to 1.0.0
Bartosz Golaszewski [Wed, 16 May 2018 12:14:12 +0000 (14:14 +0200)]
bindings: cxx: set the ABI version to 1.0.0

The C++ bindings ABI that will be released in v1.1 is considered
stable. Set it to 1.0.0 for the release.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: add support for controlled execution
Bartosz Golaszewski [Wed, 16 May 2018 10:18:40 +0000 (12:18 +0200)]
bindings: python: add support for controlled execution

Provide __enter__ and __exit__ callbacks for Chip so that it can be
used with the 'with' statement.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: provide better resource control
Bartosz Golaszewski [Wed, 16 May 2018 09:53:18 +0000 (11:53 +0200)]
bindings: python: provide better resource control

So far we rely on cpython's reference counting for closing the GPIO
chips and freeing the underlying resources. This is however wrong.
Python doesn't guarantee anything regarding the lifetime of an object.

Provide a method for closing the underlying chip handle and add
relevant checks to all methods using the resources associated with
a GPIO chip, so that we raise an error should the user use a chip
after closing it.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: provide gpiod.version_string()
Bartosz Golaszewski [Wed, 16 May 2018 08:36:28 +0000 (10:36 +0200)]
bindings: python: provide gpiod.version_string()

Implement a python wrapper around gpiod_version_string().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agodoc: tweak the comment for gpiod_version_string()
Bartosz Golaszewski [Wed, 16 May 2018 08:11:57 +0000 (10:11 +0200)]
doc: tweak the comment for gpiod_version_string()

Make it clear that this function returns the API version as we now have
separate API and ABI versions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: test case for line flags
Bartosz Golaszewski [Tue, 15 May 2018 16:35:16 +0000 (18:35 +0200)]
bindings: python: test case for line flags

Add a new test case verifying that line flags work as expected.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: provide Line.is_requested()
Bartosz Golaszewski [Tue, 15 May 2018 16:33:47 +0000 (18:33 +0200)]
bindings: python: provide Line.is_requested()

Add a python wrapper around gpiod_line_is_requested().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: improve readability in test cases
Bartosz Golaszewski [Tue, 15 May 2018 16:12:20 +0000 (18:12 +0200)]
bindings: python: improve readability in test cases

Mostly just add new lines for improved readability.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: new test cases/examples
Bartosz Golaszewski [Tue, 15 May 2018 12:51:00 +0000 (14:51 +0200)]
bindings: python: new test cases/examples

Add more test cases/code examples for python bindings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: provide Chip.get_all_lines()
Bartosz Golaszewski [Tue, 15 May 2018 10:04:25 +0000 (12:04 +0200)]
bindings: python: provide Chip.get_all_lines()

Add a method for retrieving all GPIO lines exposed by a chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: improve readability
Bartosz Golaszewski [Tue, 15 May 2018 09:50:16 +0000 (11:50 +0200)]
bindings: python: improve readability

Order the arguments in a reverse christmas tree shape in
gpiod_Chip_find_lines();

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: code shrink
Bartosz Golaszewski [Tue, 15 May 2018 09:49:16 +0000 (11:49 +0200)]
bindings: python: code shrink

Provide a helper for converting a list of lines into a LineBulk object
in a single call.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: implement Chip.find_lines()
Bartosz Golaszewski [Tue, 15 May 2018 09:41:52 +0000 (11:41 +0200)]
bindings: python: implement Chip.find_lines()

Provide a method for looking up multiple lines by name at once.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: extend tests
Bartosz Golaszewski [Wed, 9 May 2018 20:01:47 +0000 (22:01 +0200)]
bindings: python: extend tests

Add more test cases/examples, implement some helper functions, tweak
the output messages, mention the need for a dummy chip in the system
in the module's pydoc string.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: change the return value of gpiod_LineBulk_event_wait()
Bartosz Golaszewski [Mon, 14 May 2018 09:20:23 +0000 (11:20 +0200)]
bindings: python: change the return value of gpiod_LineBulk_event_wait()

gpiod_Line_event_wait() works differently than its LineBulk
counterpart. While the latter returns either a list of lines or False,
the former returns True if an event occurred on this line or False
otherwise.

False is not a good counterpart for an actual object, so instead return
None if no events occurred on any of the monitored lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix a memory leak in gpiod_Line_event_wait()
Bartosz Golaszewski [Mon, 14 May 2018 09:18:18 +0000 (11:18 +0200)]
bindings: python: fix a memory leak in gpiod_Line_event_wait()

We don't return the object returned from gpiod_LineBulk_event_wait()
back to the interpreter. We need to collect it before returning True.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: fix the return value of line_bulk::find_lines()
Bartosz Golaszewski [Sun, 13 May 2018 21:34:38 +0000 (23:34 +0200)]
bindings: cxx: fix the return value of line_bulk::find_lines()

We should return an invalid line_bulk object if we failed to look up at
least one line from the provided list of names.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: fix a memory leak in Line.set_value()
Bartosz Golaszewski [Sun, 13 May 2018 21:25:06 +0000 (23:25 +0200)]
bindings: python: fix a memory leak in Line.set_value()

We're not collecting the bulk object we're creating in this method. Add
Py_DECREF() where needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agohelpers: provide gpiod_chip_find_lines()
Bartosz Golaszewski [Sun, 13 May 2018 11:56:49 +0000 (13:56 +0200)]
helpers: provide gpiod_chip_find_lines()

Implement a new helper that allows to look-up multiple GPIO lines by
their names. Include a set of test cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: return None if line can't be found by name
Bartosz Golaszewski [Sat, 12 May 2018 12:48:58 +0000 (14:48 +0200)]
bindings: python: return None if line can't be found by name

For both find_line() variants (Chip's method and global function)
return None if the internal call to the C find_line function fails
with ENOENT. This is not an error so don't raise an exception.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: decref the chip object in gpiod_Module_find_line()
Bartosz Golaszewski [Sat, 12 May 2018 12:30:44 +0000 (14:30 +0200)]
bindings: python: decref the chip object in gpiod_Module_find_line()

When returning back to the interpreter from gpiod_Module_find_line(),
there's only one chip object reference holder, but we set the refcount
to 2 (as if the chip object existed separately in the interpreter).

Fix it by decreasing the chip's refcount by one before returning the
line object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: add test cases for iterators
Bartosz Golaszewski [Wed, 9 May 2018 20:23:14 +0000 (22:23 +0200)]
bindings: cxx: add test cases for iterators

Add simple tests for chip and line iterators.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: new test cases
Bartosz Golaszewski [Wed, 2 May 2018 10:19:39 +0000 (12:19 +0200)]
bindings: cxx: new test cases

Implement more test cases for C++ bindings and extend the existing
ones.

While we're at it: use auto where applicable and log to stderr instead
of stdout.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: add a comment about the need for a dummy chip to run tests
Bartosz Golaszewski [Wed, 9 May 2018 12:05:20 +0000 (14:05 +0200)]
bindings: cxx: add a comment about the need for a dummy chip to run tests

In order to run the C++ tests/examples, we need at least one dummy chip
to be present in the system. It also needs to be the first GPIO chip.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: initialize the line_request flags before using them
Bartosz Golaszewski [Wed, 9 May 2018 11:19:30 +0000 (13:19 +0200)]
bindings: cxx: initialize the line_request flags before using them

We store the flag values in the request flags mapping before
initializing them so flags don't get translated correctly in
line_bulk::request(). Fix it by moving the flag definitions above the
mapping initialization.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: export static members of gpiod::line_request
Bartosz Golaszewski [Tue, 8 May 2018 20:55:02 +0000 (22:55 +0200)]
bindings: cxx: export static members of gpiod::line_request

The static flags definitions of gpiod::line_request are not exported.
Add the missing GPIOD_API attributes.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: cxx: fix SPDX license identifiers in examples
Bartosz Golaszewski [Mon, 7 May 2018 20:15:51 +0000 (22:15 +0200)]
bindings: cxx: fix SPDX license identifiers in examples

The source files in bindings/cxx/examples still use C-style comments
for SPDX license identifiers. Use C++-style comments for consistency
with all other source files in the repository.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: python: release the GIL during blocking I/O operations
Bartosz Golaszewski [Sat, 21 Apr 2018 13:37:19 +0000 (15:37 +0200)]
bindings: python: release the GIL during blocking I/O operations

We should release the python global interpreter lock when performing
blocking operations and reacquire it again when we're done. Use the
relevant APIs provided by libpython.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoREADME: add info about building from release tarballs
Bartosz Golaszewski [Sat, 21 Apr 2018 13:31:30 +0000 (15:31 +0200)]
README: add info about building from release tarballs

There's no need to use autogen.sh if building from release tarballs as
the configure script is already provided. Only git builds need
autoreconf.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agoREADME: add info about high-level bindings
Bartosz Golaszewski [Sat, 21 Apr 2018 13:29:33 +0000 (15:29 +0200)]
README: add info about high-level bindings

Briefly describe C++ and python bindings.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: fix cross-compilation of python bindings
Bartosz Golaszewski [Fri, 20 Apr 2018 09:54:51 +0000 (11:54 +0200)]
build: fix cross-compilation of python bindings

AX_PYTHON_DEVEL macro from the autoconf-archive collection doesn't work
when we're trying to cross-compile python bindings in environments such
as buildroot or yocto. It can't properly detect the location of python
headers.

Let's use AM_PATH_PYTHON to detect the python3 interpreter and then
either take the PYTHON_CPPFLAGS and PYTHON_LIBS variables from the
environment (so that cross-compiling build systems can pass their
custom locations to autotools) or try to detect them ourselves using
the python3-config tool.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: check for unexpanded macros in configure.ac
Bartosz Golaszewski [Wed, 18 Apr 2018 15:44:52 +0000 (17:44 +0200)]
build: check for unexpanded macros in configure.ac

We're now using m4 macros from the autoconf-archive collection. The
user may be missing this package so check for unexpanded AX_* macros
and bail-out if any are found.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobindings: implement python bindings
Bartosz Golaszewski [Mon, 19 Feb 2018 11:52:38 +0000 (12:52 +0100)]
bindings: implement python bindings

Create a C extension module wrapping the functionality of libgpiod
in a set of Python classes.

Add code examples including simplified reimplementations of gpio-tools
in Python.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agocore: events: correctly handle POLLNVAL in gpiod_line_event_wait()
Bartosz Golaszewski [Sat, 14 Apr 2018 20:20:53 +0000 (22:20 +0200)]
core: events: correctly handle POLLNVAL in gpiod_line_event_wait()

The only error that can be indicated by ppoll() in the revents field
of struct pollfd when polling a line events file descriptor is
POLLNVAL. It can happen if the user calls close() on said descriptor
after retrieving it with gpiod_line_event_get_fd().

Currently we would act as if there's a line event to read. Make
gpiod_line_event_wait() and its bulk variant return -1 and set errno
to EINVAL in this case.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agotools: fix the copyright notice
Bartosz Golaszewski [Thu, 12 Apr 2018 15:15:44 +0000 (17:15 +0200)]
tools: fix the copyright notice

The copyright notice displayed together with the package version using
the --version argument got accidentally modified by commit 0704bcdbbf56
("all: update the copyright notice") and is now incorrect. Fix it.

Fixes: 0704bcdbbf56 ("all: update the copyright notice")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agobuild: tweak the message emitted after building tests
Bartosz Golaszewski [Thu, 12 Apr 2018 12:51:09 +0000 (14:51 +0200)]
build: tweak the message emitted after building tests

The kernel version displayed in the message has not been updated the
last time we bumped the kernel version required for running tests.

We don't need to print this version here - the test suite will bail-out
anyway if the kernel is too old. Drop it from the message.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
6 years agocore: use reference counting for line file descriptors
Bartosz Golaszewski [Thu, 12 Apr 2018 10:28:18 +0000 (12:28 +0200)]
core: use reference counting for line file descriptors

In v0.x series we were using a separate, refcounted structure for
storing the file descriptor returned by the linehandle request ioctl().
We also had a separate mechanism for event file descriptors. This was
quite complicated and was replaced by a simpler structure in v1.x
series.

It turned out however that we're now calling close() on already closed
descriptors when releasing a set of simultaneously requested lines.

In order to fix that we need to go back to having a refcounted file
descriptor handle. This time we're using the same structure for storing
both values and events file descriptors (even though there can't be
more than one line per descriptor requested for events) for simplicity.

This patch also adds a test case that verifies the reference counting
works as expected.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolicense: use C++-style comments for SPDX headers in source files
Bartosz Golaszewski [Wed, 4 Apr 2018 11:19:05 +0000 (13:19 +0200)]
license: use C++-style comments for SPDX headers in source files

Follow the linux kernel licensing style and only use C-style comments
in C headers.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: gpioinfo: expect default direction to be input
Bartosz Golaszewski [Tue, 3 Apr 2018 08:05:29 +0000 (10:05 +0200)]
tests: gpioinfo: expect default direction to be input

Starting with linux v4.16 the direction of gpio-mockup lines is input
by default as is the case for all real gpio drivers.

Modify the expected strings in test cases for gpioinfo and make v4.16
the minimum kernel version to run libgpiod tests.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobuild: use separate versioning schemes for API & ABI
Bartosz Golaszewski [Tue, 13 Mar 2018 17:14:48 +0000 (18:14 +0100)]
build: use separate versioning schemes for API & ABI

Commit 783ff2e3c707 ("API: start certain enums from 1") broke the ABI
compatibility (while keeping the source compatibility). We need to
indicate that to the users by changing the SONAME string. Up until now
the SONAME would correspond with the major release number. We now need
to have a separate versioning schemes for API and ABI.

Keep using the same MAJOR.MINOR.RELEASE scheme for the API, but switch
to using the libtool versioning - CURRENT.REVISION.AGE - for ABI. Start
the ABI version from 2.0.0 to indicate that it changed since 1.0.0.

Define a separate ABI version for the C++ bindings, but start with 0.0.0
since it was not a part of any release yet.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobuild: user SPDX license identifier
Bartosz Golaszewski [Sun, 4 Mar 2018 11:12:56 +0000 (12:12 +0100)]
build: user SPDX license identifier

Use the SPDX license identifier for LGPLv2.1 or later in the remaining
build and helper files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: use SPDX license identifier
Bartosz Golaszewski [Sun, 4 Mar 2018 11:09:27 +0000 (12:09 +0100)]
bindings: cxx: use SPDX license identifier

Use the SPDX license identifier for LGPLv2.1 or later in C++ bindings
directory.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoinclude: use SPDX license identifier
Bartosz Golaszewski [Sun, 4 Mar 2018 09:50:11 +0000 (10:50 +0100)]
include: use SPDX license identifier

Use the SPDX license identifier for LGPLv2.1 or later in the public
API header and the corresponding Makefile.am.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: use SPDX license identifier
Bartosz Golaszewski [Sun, 4 Mar 2018 09:37:34 +0000 (10:37 +0100)]
core: use SPDX license identifier

Use the SPDX license identifier for LGPLv2.1 or later in core source
files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: use SPDX license identifier
Bartosz Golaszewski [Sun, 4 Mar 2018 09:32:25 +0000 (10:32 +0100)]
tests: use SPDX license identifier

Use the SPDX license identifier for LGPLv2.1 or later in source files
of the testing framework.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: rename the C++ tests executable
Bartosz Golaszewski [Tue, 27 Feb 2018 12:48:08 +0000 (13:48 +0100)]
bindings: cxx: rename the C++ tests executable

Include the project's prefix in the executable name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: rename line_bulk::add() to line_bulk::append()
Bartosz Golaszewski [Tue, 27 Feb 2018 12:41:46 +0000 (13:41 +0100)]
bindings: cxx: rename line_bulk::add() to line_bulk::append()

This routine adds the line at the end of the internal list of lines.
Rename it to append() in case we ever want to introduce prepend().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: don't check the chip's label and name for empty strings
Bartosz Golaszewski [Sun, 25 Feb 2018 13:18:56 +0000 (14:18 +0100)]
bindings: cxx: don't check the chip's label and name for empty strings

The core library guarantees that a GPIO chip will have a name and
a label. No need to check if the returned strings are empty.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: provide chip::get_all_lines()
Bartosz Golaszewski [Thu, 22 Feb 2018 20:31:56 +0000 (21:31 +0100)]
bindings: cxx: provide chip::get_all_lines()

This is a C++ method for getting all lines exposed by a GPIO chip. It
corresponds with the helper function recently added to the C API.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: add a new cleanup macro
Bartosz Golaszewski [Thu, 22 Feb 2018 20:21:56 +0000 (21:21 +0100)]
tests: add a new cleanup macro

The most commonly used cleanup attribute is the one used for automatic
closing of GPIO chips. For brevity: hide the long TEST_CLEANUP(...)
invocation behind a shorter TEST_CLEANUP_CHIP macro.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoAPI: provide new line accessors
Bartosz Golaszewski [Thu, 22 Feb 2018 20:15:43 +0000 (21:15 +0100)]
API: provide new line accessors

Add two new public functions that allow to retrieve multiple lines from
GPIO chips at once. Include test cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: rename line and chip iterator classes
Bartosz Golaszewski [Wed, 21 Feb 2018 12:39:25 +0000 (13:39 +0100)]
bindings: cxx: rename line and chip iterator classes

Use a shorter name for code brevity. Change chip_iterator to chip_iter
and line_iterator to line_iter.

Rename the helper functions as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: add pkg-config support
Bartosz Golaszewski [Wed, 21 Feb 2018 08:38:28 +0000 (09:38 +0100)]
bindings: cxx: add pkg-config support

This will allow to use PKG_CHECK_MODULES() for C++ bindings as well.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotools: move function attributes to the header file
Clemens Gruber [Tue, 20 Feb 2018 16:57:32 +0000 (17:57 +0100)]
tools: move function attributes to the header file

The attributes must be located next to function declarations in the
header file. Otherwise, the NORETURN attribute seems to have no effect
and GCC emits several Wimplicit-fallthrough warnings when compiling
libgpiod. This patch fixes those warnings.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: allow empty default values in line_bulk::request()
Bartosz Golaszewski [Mon, 19 Feb 2018 10:43:36 +0000 (11:43 +0100)]
bindings: cxx: allow empty default values in line_bulk::request()

The core library now supports NULL default values in output requests.

Update the C++ bindings and the relevant example.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: allow NULL default_vals for output requests
Bartosz Golaszewski [Mon, 19 Feb 2018 10:32:41 +0000 (11:32 +0100)]
core: allow NULL default_vals for output requests

Explicitly allow default_vals to be NULL for output requests, in which
case the actual default values passed to the kernel are set to 0.

Add a test case that verifies that this works correctly.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: use gpiod_line_bulk_foreach_line_off() in line_request_values()
Bartosz Golaszewski [Mon, 19 Feb 2018 10:12:32 +0000 (11:12 +0100)]
core: use gpiod_line_bulk_foreach_line_off() in line_request_values()

Use the provided helper macro instead of a manual for loop.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: new example
Bartosz Golaszewski [Mon, 19 Feb 2018 10:02:48 +0000 (11:02 +0100)]
bindings: cxx: new example

Add a test case to C++ examples demonstrating the manipulation of
several lines held by a line_bulk object.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: provide methods for releasing requested lines
Bartosz Golaszewski [Mon, 19 Feb 2018 10:01:01 +0000 (11:01 +0100)]
bindings: cxx: provide methods for releasing requested lines

Add release methods to line and line_bulk classes. This allows to
release requested lines without having to destroy the owning objects.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: require default values for output requests
Bartosz Golaszewski [Mon, 19 Feb 2018 09:51:17 +0000 (10:51 +0100)]
bindings: cxx: require default values for output requests

Require users to provide default values to line_bulk::request() when
direction is output.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: cxx: constify default_vals in line_bulk::request()
Bartosz Golaszewski [Mon, 19 Feb 2018 09:40:35 +0000 (10:40 +0100)]
bindings: cxx: constify default_vals in line_bulk::request()

The default values should be passed by const reference similarly to
how it's done in line_bulk::set_values().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoAPI: start certain enums from 1
Bartosz Golaszewski [Mon, 19 Feb 2018 09:06:07 +0000 (10:06 +0100)]
API: start certain enums from 1

For enums describing direction & active state, event types etc. use 1
as the first value as it's easier to debug when all valid values are
different than in a zero-initialized data structure.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobindings: implement C++ bindings
Bartosz Golaszewski [Wed, 25 Oct 2017 19:11:37 +0000 (21:11 +0200)]
bindings: implement C++ bindings

Wrap the C API in a set of C++ classes which allow to use all libgpiod
functionalities in an object-oriented manner.

Include simplified reimplementations of gpio-tools and a set of
tests/examples showing how to use the C++ interface.

The C++ API is fully documented in doxygen.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agotests: event: new test case
Bartosz Golaszewski [Mon, 12 Feb 2018 10:55:49 +0000 (11:55 +0100)]
tests: event: new test case

Verify that the active-low flag is respected when reading line values
from lines configured for events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agodist: include Doxyfile in the release tarball
Bartosz Golaszewski [Thu, 8 Feb 2018 17:25:58 +0000 (18:25 +0100)]
dist: include Doxyfile in the release tarball

Doxyfile was missing from release tarballs. Include it.

Reported-by: SZ Lin <sz.lin@moxa.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod: start v1.1 development cycle
Bartosz Golaszewski [Wed, 7 Feb 2018 15:38:26 +0000 (16:38 +0100)]
libgpiod: start v1.1 development cycle

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agolibgpiod v1.0
Bartosz Golaszewski [Wed, 7 Feb 2018 13:56:03 +0000 (14:56 +0100)]
libgpiod v1.0

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoNEWS: updates for v1.0
Bartosz Golaszewski [Wed, 7 Feb 2018 10:11:46 +0000 (11:11 +0100)]
NEWS: updates for v1.0

Add release notes for v1.0.

Also: the master branch doesn't contain the tags for bugfix releases so
documenting them in this branche's NEWS makes no sense.

Fold all the info about bugfix releases into the next minor release and
only keep major and minor releases in NEWS on the master branch. Bugfix
releases will only be documented in their respective minor branches
from now on.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agocore: constify *values in gpiod_line_set_value_bulk()
Bartosz Golaszewski [Sat, 3 Feb 2018 15:06:47 +0000 (16:06 +0100)]
core: constify *values in gpiod_line_set_value_bulk()

The values in the array passed as argument to this routine are never
modified.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agodoc: improve the doxygen description of default_val(s)
Bartosz Golaszewski [Mon, 29 Jan 2018 16:10:54 +0000 (17:10 +0100)]
doc: improve the doxygen description of default_val(s)

Users report being confused by the name 'default_val(s)' for function
parameters. Because it's in line with the kernel uAPI, we'll leave it
like this, but let's improve the documentation a bit by stating
explicitly that this parameter represents the initial values for
requested GPIO lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agodoc: consistently break lines in @param's descriptions
Bartosz Golaszewski [Fri, 26 Jan 2018 10:02:37 +0000 (11:02 +0100)]
doc: consistently break lines in @param's descriptions

When breaking the line in doxygen's @param descriptions, start the
next one after the param's name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agodoc: explicitly state that the ctxless event poll callback can be NULL
Bartosz Golaszewski [Fri, 26 Jan 2018 09:58:18 +0000 (10:58 +0100)]
doc: explicitly state that the ctxless event poll callback can be NULL

This is mentioned later in the text, but state it in the argument's
description too.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agodoc: clarify that the high-level set value callback is optional
Bartosz Golaszewski [Fri, 26 Jan 2018 09:53:23 +0000 (10:53 +0100)]
doc: clarify that the high-level set value callback is optional

Users have reported it as confusing so make it clear.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agoAPI: use gpiod_ctxless_ as prefix for the high-level API
Bartosz Golaszewski [Wed, 24 Jan 2018 11:36:14 +0000 (12:36 +0100)]
API: use gpiod_ctxless_ as prefix for the high-level API

As suggested by Linus Walleij: the word 'simple' is generally
subjective and the high-level routines provided by libgpiod are not
necessarily simple, but rather contextless, as they don't require any
resource managemend. Use 'gpiod_ctxless_' as prefix for all high-level
symbols.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogitignore: add libgpiod.pc
Bartosz Golaszewski [Wed, 24 Jan 2018 11:19:03 +0000 (12:19 +0100)]
gitignore: add libgpiod.pc

Add the automatically generated libgpiod.pc to .gitignore.

Fixes: 819e2f5ee3e6 ("build: add pkg-config support")
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agobuild: add pkg-config support
Clemens Gruber [Mon, 22 Jan 2018 16:12:12 +0000 (17:12 +0100)]
build: add pkg-config support

Create a libgpiod.pc file for pkg-config. Allows to use
PKG_CHECK_MODULES([gpiod], [libgpiod >= 1.0],,) in other
autoconf-based projects.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
7 years agogpiomon: initialize the active low variable
Clemens Gruber [Mon, 22 Jan 2018 16:12:13 +0000 (17:12 +0100)]
gpiomon: initialize the active low variable

The variable active_low is not initialized, so the value is undefined
and if the -l argument is not passed, the undefined value remains. Fix
it by initializing it to false.

Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>