sending pointlessly complex types over D-Bus with the Glib
bindings
John (J5) Palmieri
johnp at redhat.com
Wed Oct 26 13:00:40 PDT 2005
On Wed, 2005-10-26 at 13:20 +0100, Robert McQueen wrote:
> A wise man once said:
> Finally, it is possible users will want to write or invoke D-BUS
> methods which have arbitrarily complex type signatures not
> directly supported by these bindings. For this case, we have a
> <literal>DBusGValue</literal> which acts as a kind of special
> variant value which may be iterated over manually. The
> <literal>GType</literal> associated is
> <literal>DBUS_TYPE_G_VALUE</literal>.
>
> Unfortunately, he then went on to say:
> TODO insert usage of <literal>DBUS_TYPE_G_VALUE</literal> here.
I'm wondering if this patch was not applied as I can not find any
refrence to DBUS_TYPE_G_VALUE or DBusGValue anywhere in the code except
for a couple of comments: /* Later we need to return DBUS_TYPE_G_VALUE
*/ in dbus-signature.c.
> A foolish man said "how do I emit a signal with the prototype
> a{s(ua{sa{sv}})}?" and wondered if anyone could be kind enough to give
> some kind of example. :)
short answer is I think you can't. In the python tests I attach to the
glib server and have an echo method that takes a n and sends a v back.
Marshaling this {'1': (3, {'2': {'3': 100}})} which is basically an
instance of your signature does not work. The problem is that structs
(or GValueArrays in the glib bindings) are not actually types. When it
comes time to marshal (demarshaling works fine with this signature) as
soon as you hit the dictionary it starts getting the signatures from the
types. Since the GValueArray is not a specialized type but we need to
get a signature composed of the types of the values inside the struct we
lose at this point. This is because while iterating over special types
the code only iterates over the signatures of the types and not the
values which is stored by the type info foo. When you hit a GValueArray
there is no way to iterate over its value to get the types. Now a
signature of a{s{ua{sa{sv}}}} should work and even a{sv} where v is
(ua{sa{sv}}) might even work.
I tried to fix this but I don't know the inner workings of the type
system or if this is even possible to fix. My head exploded as I
thought of clever workarounds and then would hit an edge case where it
would not work. Colin seems to think creating a special type for structs
would fix this which is why I put out a plea in my blog for someone who
cares about the bindings to step up.
> Also, does anyone have a cunning idea about how one might
> marshal/unmarshal the 'g' (D-Bus signature) type in a meaningful way in
> the glib bindings? Is there some kind of GType or derivative that can
> always represent the type of what you want to be able to send or
> receive? Or is this getting overly meta? :)
I think you can just send over a registered GObject, though I think it
reconstructs it as a proxy on the other side. Of course this is just
from memory of a conversation I had with Colin. I see some
G_TYPE_OBJECT foo in dbus-gsignature.c.
--
John (J5) Palmieri <johnp at redhat.com>
More information about the dbus
mailing list