returning properties

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Oct 21 04:43:56 PDT 2011


On Fri, 21 Oct 2011 at 13:10:38 +0200, Rony G. Flatscher wrote:
> On 21.10.2011 12:00, Simon McVittie wrote:
> > In GDBus this will get wrapped in the "fake struct" that's used to encode
> > multiple returns
>
> So is this done for GDBus users on the receiving side transparently?
> (What would be the purpose of this behaviour?)

D-Bus methods can have multiple "out" parameters, so every generic
client-side D-Bus binding has to deal with the possibility of multiple "out"
parameters from a method, somehow. If you're using a generic API like
g_dbus_connection_call(), the binding doesn't necessarily even know how
many "out" parameters there are going to be (and some people even write D-Bus
APIs where the number of "out" parameters is variable, although that's
a bad idea).

GDBus does this by always, consistently, returning a GVariant tuple that
doesn't directly correspond to a struct in the D-Bus message, but rather is
part of GDBus' C calling convention. Each of the tuple's 0 or more members
directly corresponds to a top-level "out" parameter of the D-Bus message.

dbus-glib has a different approach - it returns a boolean for success/failure
(which doesn't directly correspond to a boolean in the D-Bus message either),
and uses C "out" arguments (whose type is a pointer to the type you
wanted) for all of the 0-or-more return values.

dbus-python tries to guess what was meant to happen based on the number of
things returned: if there are no "out" parameters it returns None, if there's
exactly one "out" parameter it returns it, if there are two or more it returns
a tuple. So, it's like GDBus, but with odd special cases for 0 and 1 return
values. If the method doesn't return the same number of things you thought
it would, your Python code will probably crash with a TypeError. (Welcome to
Python...)

> Or with other words: if not using GDBus, but using the "raw" D-Bus level
> calls, would non-GDBus clients get the variant value (in the example of
> type string) without the "fake struct" from a GDBus server?

Yes, they would get a variant, returned in whatever way their binding
likes to return things. The underlying D-Bus messages are the same.

(Similarly, a GDBus client will always, consistently, get the extra top-level
struct, regardless of what language/binding the service is using.)

    S


More information about the dbus mailing list