n00b: signals with an extensible message

Schmottlach, Glenn glenn.schmottlach at harman.com
Tue Feb 16 05:38:44 PST 2010


Another alternative is to encode your payload using XML or (preferably) JSON on top of D-Bus. You'd be sending strings and relying on the receiver to decode the XML and/or JSON. This is similar to what WebOS does. Since JSON is self-descriptive, you can use the decoding libraries to pull out those fields you know about or test for the presence of fields you're not sure of. There is obviously an overhead impact and D-Bus essentially becomes a transport/routing mechanism at that point. Of course your D-Bus signals are not longer 'standard' signals but require an additional (JSON/XML) decoding library to make sense of the signal data.


-----Original Message-----
From: dbus-bounces at lists.freedesktop.org [mailto:dbus-bounces at lists.freedesktop.org] On Behalf Of Thiago Macieira
Sent: Tuesday, February 16, 2010 2:22 AM
To: dbus at lists.freedesktop.org
Subject: Re: n00b: signals with an extensible message

Em Terça-feira 16. Fevereiro 2010, às 03.04.23, Tim Hockin escreveu:
> Hey there,
> 
> I'm finally getting around to adding dbus support to some tools, and
> I'm not sure how to do the payload.
> 
> What I have is a data structure.  It has about 10 fields (all numeric,
> a mix of sizes and signedness) right now, but I know it will grow in
> the future (new fields, not modifying or removing old ones).  I want
> to send signals which carry the equivalent of this data structure.
> What I don't know is how to do this safely through DBUS.
> 
> What happens if the server is newer and has more fields than the
> client knows about?
> 
> What happens if the server is older and has less fields than the
> client knows about?
> 
> Is there a canonical answer to this?

Yes: it's not safe to do what you want.

If you change the structure (adding or removing elements), the signal will 
change its signature, so the lookup & connection mechanism will probably fail.

If you have a variable-sized argument, I recommend you consider using a hash 
or array (av or a{sv}).

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358


More information about the dbus mailing list