[systemd-devel] bus: suggestion for reading "trough" variants

Lennart Poettering lennart at poettering.net
Mon Apr 8 08:13:41 PDT 2013


On Mon, 08.04.13 16:22, Peeters Simon (peeters.simon at gmail.com) wrote:

> hey,
> 
> While experimenting a bit with the really nice api of libsystemd-bus
> (seriously, I love it), I came across an idea that would probably make
> using the library even easier.
> 
> The idea is to be able to read "trough" a variant using sd_bus_message_read()
> 
> f.ex you get a message with signature "sv" with the variant being
> supposed to be an other string (since it is a reply to a request
> requesting a string).
> 
> now one has to:
> 1. read the first string
> 2. enter the variant
> 3. read the second string
> 4. exit the variant
> 
> what I would like to be able to do is something like this:
> sd_bus_message_read(m, "sv+s", &first, &second);
> 
> which will error out if the variant does not contain a string.
> 
> of course the "+" can be decided to be something else, I also thought
> of using "[" and "]" around the inner signature, but the basic idea
> stays the same.
> 
> One of the biggest uses would probably be for reading properties,
> since org.freedesktop.DBus.Properties.Get() always returns a variant,
> but the reader knows which type it is supposed to be.
> 
> Anyways, thanks for the library (a welcome change from libdbus)

Thanks for having a look!

I certainly can see the usefulness of this, and I had similar ideas too
(for exmaple, I though about adding a special syntax to demarshal "as"
into one of those strv string lists of char** backed by malloc()), but I
always stepped back from that after much consideration since right now
we always use signature strings 1:1 from the actual
marshalling. I.e. what you pass as 'types' string is actually the exact
signature that appears in the message, in the exact same syntax the dbus
spec defines. Now, this syntax is hence kinda property of the D-Bus
specification. That shouldn't make it impossible to add extensions to it
(for example glib's GVariant did that), but it sounds to me as if we
should be very conservative about those extensions, and when we do them
for very strong reasons. And this probably also means that we should
not extend the syntax in ways that are relevant only in some app contexts
for the demarshalling process, but are irrelevant for the actual
marshalled data stream.

So, I see the usefulness, I am not totally against it, but if we do that
we should have strong reasons and be careful in not deluting the precise
definition of dbus signature strings with our own idea of parsing
formats...

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list