nintyfan nintyfan - 5 months ago 33
C Question

libdbus reading array type result

I have to read org.freedesktop.NetworkManager.GetDevices

My program calls the method and receives result correctly.

The problem is how to support array of string/paths type?
How get length of the array and how to obtain single element,

Answer Source

For array of not fixed size elements(such as strings), we must call dbus_message_iter_recurse(&args, &string);, giving pointer to main iterator as args and pointer for new iterator as second argument.

To obtain element, we call dus_message_iter_get_basic(&string, &paths);, where paths is pointer to character array.

The whole code looks like below:

if (!dbus_message_iter_init(msg, &args))
  fprintf(stderr, "Message has no arguments!\n");

  do {
    dbus_message_iter_recurse(&args, &string);
    do {

      dbus_message_iter_get_basic(&string, &paths);
    while (dbus_message_iter_next(&string));
  } while (dbus_message_iter_next(&args));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download