Request for pointers/hints for processing container arguments ...

Mike Gorse mgorse at novell.com
Tue Jun 21 11:42:20 PDT 2011


Hi Rony,

Basically you can use dbus_message_iter_open_container and 
dbus_message_iter_close_container to write structs/dicts/arrays and 
dbus_message_iter_recurse to read them.  Dictionaries have a 
DBUS_TYPE_DICT (which wants a type that should look something like {ss}) 
containing entries (which want a type of NULL).  To write a struct, you 
can use something like

dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL, 
&iter_struct);
// use dbus_message_iter_append_basic on iter_struct to write your data
dbus_message_iter_close_container (&iter, &iter_struct);

where "iter" is a DBusMessageIter that you've initialized.  For a 
dictionary with strings for the key and value, you'd have something like

dbus_message_iter_open_container (&iter, DBUS_TYPE_DICT< 
"{ss}", &iter_dict);
while (more_entries_to_write) {
   dbus_message_iter_open_container (&iter_dict, DBUS_TYPE_DICT_ENTRY, 
NULL, &iter_dict_entry);
   dbus_message_iter_append_basic (&iter_dict_entry, 
DBUS_TYPE_STRING, &key);
   dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, 
&val);
   dbus_message_iter_close_container (&iter_dict, &iter_dict_entry);
}
dbus_message_iter_close_container (&iter, &iter_dict);

Arrays can be handled similarly and want a type argument (ie, "i" for 
integers), but they can also be handled with the functions you mentioned. 
Variants are similar and also want the type to be specified when opening 
the container.

Also, these functions have return values to return errors if they run out 
of memory.

Hth,
-Mike

On Tue, 21 Jun 2011, rony wrote:

> Hi there,
>
> my name is Rony and I have started to write a language binding for a
> scripting language named ooRexx (http://www.ooRexx.org). Hence, despite
> all well-meant warnings, I have to delve into the C bindings in order to
> successfully create the binding (starting out for Linux, but aiming also
> on porting later to MacOSX and Windows).
>
> In the process of doing so I have studied the specs, tutorials and
> Matthew Johnsons's *great tutorail* (however, the link on
> <http://www.freedesktop.org/wiki/Software/dbus> to his tutorial at
> <http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html> is dead,
> but I managed to get a version on his web site), which has helped me a lot.
>
> Currently I am involved in writng the code for processing the ooRexx
> arguments for DBus which now work for all simple types (using
> dbus_message_iter_append_basic(...)).
>
> The next step is to deal with the container types variant, arrays,
> structs and dicts. While studying the specification and the methods in
> DBusMessage (like dbus_message_iter_get_array_len(*iter) or
> dbus_message_iter_get_fixed_array(*iter, void *value, int *n_elements),
> but also dbus_message_iter_append_fixed_array(*iter, int element_type,
> const void *value, int n_elements) etc.) it is the case that I still am
> not able to understand how exactly these types have to be processed.
>
> Any little program/snippet or pseudo code would help me a lot and hence
> turning to this list of experts to ask for help!
>
> If you have pointers to any plain C code (glib's binding won't help me
> unfortunately) or would be kind enough to simply sketch in scarce
> pseudocode how to create those container values for message arguments, I
> would *really* appreciate it a lot!
>
> TIA,
>
> ---rony
>
> P.S.: If anyone has anything comparable to Matthew Johnson's tutorial,
> but demoing how to process container values, that would be a boon!
>
>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
>


More information about the dbus mailing list