Using dbus.service.signal decorator

Simon McVittie smcv at collabora.com
Fri Jun 16 20:45:22 UTC 2017


On Fri, 16 Jun 2017 at 19:54:29 +0200, Bogdan Lotko wrote:
> variant   struct {
>      string "myString"
>      array [
>         variant       struct {
>              int32          1
>              int32          1
>              int32          1
>         }
>      ]
>  }
> so what I really need to send is a variant. 'v'.

Then your signature is just v, yes. A variant in a signature means that
you can't say in advance what the data type is going to be, and different
senders might be putting different content in it.

The outer variant seems a really strange API - how can anyone know what
your signal means if they don't even know what data types it will contain? -
but presumably you have your reasons. Variants are normally only used
if your design contains a deliberate extension point (like the popular
a{sv} type, a dict {string => anything}) or if your design is very generic
(like org.freedesktop.DBus.Properties and org.freedesktop.DBus.ObjectManager,
which are really more like building blocks for other people's designs
than anything else).

The inner array of variants also seems like a strange design - I'm having
a hard time thinking of any reason why that would be necessary, given
that the outer variant means you can already send whatever types you want,
and in particular you can equally well send a simpler representation of
the same content.

Perhaps if you describe the real-world problem you are solving (and in
particular what other types you expect the variants to contain in cases other
than your example), someone can suggest a less complicated way to solve that?

> Probably the only possible solution is
...
>   arr = dbus.Array( [], signature='(iii)' )
>   s1 = dbus.Struct( (1,1,1), signature='(iii)', variant_level=1 )
>   arr.append(s1)
>   e.mySignal( ('myString', arr) )

Yes, when you're using a variant the type essentially ends up part of the
value, so you have to be very explicit about what type you want.
I don't *think* you need the explicitly-typed dbus.Array - you could
probably get away with using an ordinary Python list, [] - but explicit
is better than implicit.

Using variant_level >= 1 when building a message, as here, is usually a sign
that you are doing something odd and unusual. But at least you aren't using
variant_level >= 2, which is a crazy thing to do and only exists for
completeness :-)

    S


More information about the dbus mailing list