From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod][RFC 0/6] first draft of libgpiod v2.0 API
Date: Mon, 19 Apr 2021 09:17:46 +0800 [thread overview]
Message-ID: <20210419011746.GA4766@sol> (raw)
In-Reply-To: <CAMRc=Md8S=CayttjiEVw7f6LYUZzUO9EE-kv6iyUkDqi_5GE3w@mail.gmail.com>
On Sun, Apr 18, 2021 at 11:12:24PM +0200, Bartosz Golaszewski wrote:
> On Sun, Apr 18, 2021 at 5:48 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
[snip!]
> >
> > I forgot to add that wrt the config mutators, you need to allow
> > overriding of existing config, rather than returning an error on
> > conflict, so that you can change config for the set_config ioctl().
> > Hence the last-in-wins approach. And as a consequence the mutator is
> > always right and so needs no return code.
> >
>
> This sounds good in theory but how do we handle a situation that
> requires more than 10 attributes? Override the first one? The last
> one? What if the line offsets passed to the request config repeat
> themselves? I think some sanitization of input is in order.
>
Repeating of lines is equivalent to repeatedly setting a bit, so the
subsequent instances are ignored. In practice I don't even need to check
- if the user includes the line multiple times then it gets set multiple
times - to the same thing.
The case where a complex config can't be mapped to the uAPI, e.g. due to
too many attributes on too many lines, is handled at the time of the
request_lines() or set_config() itself when that mapping is performed.
Those will return an "overly complex config" error.
> Regarding offsets: I was thinking about how to approach referring to
> lines in configs and requests by offsets only (in order to hide the
> whole masking logic) and while for a request (for example: when
> setting/reading line) this is straightforward (as long as we make sure
> the offsets are never duplicated), the line config structure doesn't
> really know the concept of offsets. So when we set a config option for
> a specific line, we need to carry the offset information somehow in
> the structure until the request is actually made. How do you deal with
> this in your library? Did you expose any of the bitmap details in your
> API? Can we really avoid dealing with indexing of lines in a request?
>
In the request config I use a map of offset to line config to avoid
duplication. A config change that alters any existing setting just
overwrites the old.
The line config is similar to your struct gpiod_line_config.
The line config for a particular line is only created and added to the
map if there is a config change specific to that line.
Each attribute has a "not set" value, in which case the request-wide
default is used.
The request-wide default config is stored separately from the map.
And there is a function to reset a line config back to the default,
i.e. drop that line config from the map.
The request_lines() and set_config(), that accept the config, also have
the list of offsets available (provided to the request_lines() and
subsequently stored as part of the request struct for the set_config())
and so can map from offsets to indices to build the bitmap.
The bitmap and indices themselves are never exposed.
That is a high level description - the details are actually a little
different as the Go implementation uses functional options, so the
initial config settings become parameters to the request, and bundles
the config into the request object itself.
> > And you might want to add a copy() for config to allow the user to
> > easily create two slightly different configurations.
> >
> > > I was on the fence wrt reference counting but then realized that in
> > > C++ or Python we still need to provide a mechanism for unconditional
> > > closing of chips and releasing of requests. For the former it's
> > > because otherwise we'd need to make the object go out of scope
> > > manually (probably by storing it in another object that would be
> > > "closed" -> pointless abstraction) and in the latter case: Python
> > > doesn't even guarantee that the destructor will be called at any
> > > specific point.
> > >
> >
> > Hmmm, ok, I was assuming the C++ bindings would wrap the C objects in C++
> > objects, and the C++ destructor would release any associated resources.
> >
>
> Yes, but what if the user wants to close the chip or release the
> request without the underlying object going out of scope? I think we
> need to keep that possibility.
>
Then you also provide a close() method. They aren't mutually exclusive.
Cheers,
Kent.
next prev parent reply other threads:[~2021-04-19 1:17 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 ` [libgpiod][RFC 1/6] treewide: rename chip property accessors Bartosz Golaszewski
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 [this message]
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=20210419011746.GA4766@sol \
--to=warthog618@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
/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.