mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
GDBus: Add support for D-Bus type 'h' (ie. G_VARIANT_TYPE_HANDLE)
This allows sending and receiving D-Bus messages with instances of the 'h' D-Bus type. Unlike libdbus-1's dbus_message_iter_get_basic() method, g_variant_get_handle() does not return a duplicated unix file descriptor (that must be closed with close(2)) - instead, it returns an index that can be used to get/dup the file descriptor from a GUnixFDList object that can be obtained from the GDBusMessage object. Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
parent
66388120d2
commit
2be167f57c
@ -1006,6 +1006,19 @@ parse_value_from_blob (GMemoryInputStream *mis,
|
||||
g_free (v);
|
||||
}
|
||||
}
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
|
||||
{
|
||||
if (!ensure_input_padding (mis, 4, &local_error))
|
||||
goto fail;
|
||||
if (!just_align)
|
||||
{
|
||||
gint32 v;
|
||||
v = g_data_input_stream_read_int32 (dis, NULL, &local_error);
|
||||
if (local_error != NULL)
|
||||
goto fail;
|
||||
ret = g_variant_new_handle (v);
|
||||
}
|
||||
}
|
||||
else if (g_variant_type_is_array (type))
|
||||
{
|
||||
guint32 array_len;
|
||||
@ -1701,6 +1714,15 @@ append_value_to_blob (GVariant *value,
|
||||
g_data_output_stream_put_byte (dos, '\0', NULL, NULL);
|
||||
}
|
||||
}
|
||||
else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE))
|
||||
{
|
||||
padding_added = ensure_output_padding (mos, dos, 4);
|
||||
if (value != NULL)
|
||||
{
|
||||
gint32 v = g_variant_get_handle (value);
|
||||
g_data_output_stream_put_int32 (dos, v, NULL, NULL);
|
||||
}
|
||||
}
|
||||
else if (g_variant_type_is_array (type))
|
||||
{
|
||||
GVariant *item;
|
||||
|
@ -405,6 +405,18 @@ dbus_1_message_append (GString *s,
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef DBUS_TYPE_UNIX_FD
|
||||
case DBUS_TYPE_UNIX_FD:
|
||||
{
|
||||
/* unfortunately there's currently no way to get just the
|
||||
* protocol value, since dbus_message_iter_get_basic() wants
|
||||
* to be 'helpful' and dup the fd for the user...
|
||||
*/
|
||||
g_string_append (s, "unix-fd: (not extracted)\n");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case DBUS_TYPE_VARIANT:
|
||||
g_string_append_printf (s, "variant:\n");
|
||||
dbus_message_iter_recurse (iter, &sub);
|
||||
@ -672,6 +684,22 @@ message_serialize_complex (void)
|
||||
" string: `cwd'\n"
|
||||
" variant:\n"
|
||||
" string: `/home/davidz/Hacking/glib/gio/tests'\n");
|
||||
|
||||
#ifdef DBUS_TYPE_UNIX_FD
|
||||
value = g_variant_parse (G_VARIANT_TYPE ("(hah)"),
|
||||
"(42, [43, 44])",
|
||||
NULL, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (value != NULL);
|
||||
/* about (not extracted), see comment in DBUS_TYPE_UNIX_FD case in
|
||||
* dbus_1_message_append() above.
|
||||
*/
|
||||
check_serialization (value,
|
||||
"value 0: unix-fd: (not extracted)\n"
|
||||
"value 1: array:\n"
|
||||
" unix-fd: (not extracted)\n"
|
||||
" unix-fd: (not extracted)\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user