Marshalling to dbus dict

Sanel Zukan sanelz at gmail.com
Thu Mar 6 08:21:40 PST 2008


Hi to all,

I'm working on dbus c++ binding for EDE (Edbus) and seems that I got 
stucked with the complex types, especially with the dict. To better describe 
the problem, I will start from the beginning.

The basic type (please, do not confuse it with dbus "basic type") for
Edbus is EdbusData. It is a variant-like class that mimicks all known
dbus types, including a complex ones (variant, struct, dict and array).

I recently added EdbusDict; it is a map-like container with key/value 
pairs (each is EdbusData type) and it follows dbus specs: it will accept
keys as "dbus basic types" and container will not allow duplicate keys in it.
So, from container side, things are ok. But when comes to the part when
is needed to fill DBusMessage with container content, some things are
unclear for me (follows bellow).

I checked how this is done in libdbus-qt3 (0.8) and this is what I was able
to find about marshalling a dict (or map in libdbus-qt3) container:

  // 'it' message iterator is created

  dict_signature = '{' + key type + value type + '}'

  // init 'sub' iterator

  dbus_message_iter_open_container(it, DBUS_TYPE_ARRAY, 
              dict_signature, sub)

  for(iterate_over_my_container) {
      DBusMessageIter item_iterator;
      dbus_message_iter_open_container(sub, DBUS_TYPE_DICT_ENTRY, 
              0, item_iterator)

      // appending via main iterator
      dbus_message_iter_append_basic(it, key type, key);

      // appending via item_iterator
      dbus_message_iter_append_basic(item_iterator, value type, value);

      dbus_message_iter_close_container(sub, item_iterator);
   }

   dbus_message_iter_close_container(...)

Huh... hoping you will get a clue. Is this the only way dict can be
represented (because for me it is a bit messy and really don't know what
is going on) or there exists simpler solution :)?

At first, I thought dict containers will have a signature 
'a{key type val type}' and data would be in form "key val key val", but
it seems this is not the case. It would be nice if someone provides a
real example of dict (or map) container signature and how data is
represented. That would, probably, explain me things a lot :)

Thanks advanced,
-- 
Sanel Zukan
http://equinox-project.org


More information about the dbus mailing list