[glib] GDBus: Add support for D-Bus type 'h' (ie. G_VARIANT_TYPE_HANDLE)



commit 2be167f57c2b59d427aa54e2204bfaa906391b3e
Author: David Zeuthen <davidz redhat com>
Date:   Tue Jul 20 11:38:23 2010 -0400

    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>

 gio/gdbusmessage.c              |   22 ++++++++++++++++++++++
 gio/tests/gdbus-serialization.c |   28 ++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c
index 01d00a0..b435d6f 100644
--- a/gio/gdbusmessage.c
+++ b/gio/gdbusmessage.c
@@ -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;
diff --git a/gio/tests/gdbus-serialization.c b/gio/tests/gdbus-serialization.c
index a36dd8b..2cb80ce 100644
--- a/gio/tests/gdbus-serialization.c
+++ b/gio/tests/gdbus-serialization.c
@@ -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
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]