0
我目前尝试与dbus进行通信并且有函数,该函数将返回array of struct(string, uint32, string, string, object path)
。我将结果存储在GVariant
中,并打印此GVariant
表明其中存在正确的结果值。获取GVariant的内容
更具描述性:我尝试获取Systemd的Logind管理器ListSessions
的结果。
打印的输出是:
[('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')]
什么我想现在正确的使用越来越每个数组元素的循环:
for (uint32_t i = 0; i < ::g_variant_n_children(v); ++i)
{
GVariant *child = ::g_variant_get_child_value(v, i);
}
当打印的孩子,我得到:
<('2', uint32 1000, 'nidhoegger', 'seat0', objectpath '/org/freedesktop/login1/session/_32')>
到目前为止这么好。现在我试图让使用g_variant_get
这样的单品:
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);
但它只是给了我这个说法:
(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
如果这是相关的:我生成的代码与gdbus-codegen
进行沟通,获取该值的函数具有此签名:
gboolean login1_manager_call_list_sessions_sync (
Login1Manager *proxy,
GVariant **out_unnamed_arg0,
GCancellable *cancellable,
GError **error);
我在做什么错?为什么它返回“v”作为价值?