I currently try to communicate with dbus and have a function, that will return array of struct(string, uint32, string, string, object path)
. I have the result stored in a GVariant
and printing this GVariant
shows that there are correct result values in there.
More descriptive: I try to get the result of Systemd's Logind Managers ListSessions
.
The output of print is:
[('2', uint32 1000, 'nidhoegger', 'seat0', objectpath
'/org/freedesktop/login1/session/_32'), ('6', 1001, 'test', 'seat0',
'/org/freedesktop/login1/session/_36'), ('c2', 111, 'lightdm',
'seat0', '/org/freedesktop/login1/session/c2')]
What I am trying right now is getting each array element in a loop using:
for (uint32_t i = 0; i < ::g_variant_n_children(v); ++i)
{
GVariant *child = ::g_variant_get_child_value(v, i);
}
When printing the child I get:
<('2', uint32 1000, 'nidhoegger', 'seat0', objectpath '/org/freedesktop/login1/session/_32')>
So far so good. Now I am trying to get the single items using g_variant_get
this way:
gchar *id = NULL;
uint32_t uid = 0;
gchar *user = NULL;
gchar *seat = NULL;
gchar *session_path = NULL;
::g_variant_get(v, "(susso)", &id, &uid, &user, &seat, &session_path);
But it only gives me this assertion:
(process:12712): GLib-CRITICAL **: the GVariant format string '(susso)' has a type of '(susso)' but the given value has a type of 'v'
(process:12712): GLib-CRITICAL **: g_variant_get_va: assertion 'valid_format_string (format_string, !endptr, value)' failed
If this is relevant: I generated the code to communicate with gdbus-codegen
and the function to obtain the value has this signature:
gboolean login1_manager_call_list_sessions_sync (
Login1Manager *proxy,
GVariant **out_unnamed_arg0,
GCancellable *cancellable,
GError **error);
What am I doing wrong? Why is it returning "v" as value?