Pelagicore / gdbus-codegen-glibmm

Code generator for C++ D-Bus stubs and proxies using Giomm/Glibmm
GNU Lesser General Public License v2.1
23 stars 25 forks source link

Support file descriptor with Gio::UnixFDList #95

Open WooJungMo opened 4 years ago

WooJungMo commented 4 years ago

gdbus-codegen supports file descriptors as the following anntation and GUnixFDList.

<annotation name = "org.gtk.GDBus.C.UnixFD" value = "true" />

It would be nice if gdbus-codegen-glibmm also supports file descriptors with the same annotation and Gio::UnixFDList.

I'm using glibmm's low API because the generator doesn't support it right now, so the code is unnatural.

mardy commented 4 years ago

In case someone wants to contribute a patch, the main file that will have to be modified is dbustypes.py.

I don't understand, though, why an annotation is needed. The file descriptors have their own signature (h), so it would be nice to know why the annotation is needed too.

WooJungMo commented 4 years ago

I also wonder why gdbus supports file descriptors with annotation and GUnixFDList, not the dbustype 'h'.

In my opinion, glib(gdbus) supports multiple OS platforms, unlike libdbus. So it seems to separate what is supported on UNIX platforms such as FD passing.

martin-ejdestig commented 4 years ago

I am not sure why the annotation was originally added (https://gitlab.gnome.org/GNOME/glib/commit/c404dbed11bc8bf4212d15719ef3a87ebf76efff in GLib does not say), but behavior in gdbus-codegen changed recently to generate GUnixFDList for h if --glib-min-version 2.64 is passed. See https://gitlab.gnome.org/GNOME/glib/commit/e3f80b925405359ed70530f5a478d0e70ed78a4d and discussion in https://gitlab.gnome.org/GNOME/glib/issues/1726 .

I do not see why an annotation would be needed for gdbus-codegen-glibmm (nor in gdbus-codegen) but perhaps I am missing something.

martin-ejdestig commented 4 years ago

In my opinion, glib(gdbus) supports multiple OS platforms, unlike libdbus. So it seems to separate what is supported on UNIX platforms such as FD passing.

That h is a UNIX file descriptor is in the D-Bus specification though. Platform does not matter.

WooJungMo commented 4 years ago

Thank you for the detailed explanation.

martin-ejdestig commented 4 years ago

One gets all fd:s in a single GUnixFdList though, it seems like... in same order as arguments and have to map index in that list to argument... ??? Am I missing something? If not, I wonder why they have designed the Glib API like this. Seems to be better handled in Qt where they map directly to QDBusUnixFileDescriptor.

WooJungMo commented 4 years ago

Before the commit(https://gitlab.gnome.org/GNOME/glib/commit/e3f80b925405359ed70530f5a478d0e70ed78a4d ) was applied, GUnixFDList was not related to arguments.

I haven't tried the latest glib version yet, so I'm not sure how 'h' works with GUnixFDList. However, this is a very interesting topic.

I am wondering what will be the index of the GUnixFDList and the index of the 'h' arguments, assuming the method below.

`

  <arg name="greeting_locale" direction="in" type="s"/>
  <arg name="response" direction="out" type="h"/>
  <arg name="response_locale" direction="out" type="s"/>
</method>

` https://github.com/GNOME/glib/blob/mainline/gio/tests/test-codegen.xml#L484

`

if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_64

static gboolean handle_no_annotation (FooiGenFDPassing object, GDBusMethodInvocation invocation, GUnixFDList fd_list, GVariant arg_greeting, const gchar *arg_greeting_locale) { foo_igen_fdpassing_complete_no_annotation (object, invocation, fd_list, arg_greeting, arg_greeting_locale); return TRUE; } ` https://github.com/GNOME/glib/blob/mainline/gio/tests/gdbus-test-codegen.c#L2653