[patch] gobject sender and pid

Ross Burton ross at burtonini.com
Mon Mar 13 14:20:25 PST 2006

On Mon, 2006-03-13 at 15:15 -0500, David Zeuthen wrote:
> On Mon, 2006-03-13 at 08:26 +0000, Ross Burton wrote:
> > On Mon, 2006-03-13 at 00:03 -0500, David Zeuthen wrote:
> > > Attached is a patch that enables the method handler on a GObject to
> > > figure out who the sender is. I'm not sure this is the best way to do
> > > this but I thought I'd send the patch anyway. I'd like to see this fixed
> > > as I really need to know the sender. Without this patch the glib
> > > bindings are not very useful for system bus stuff since you more often
> > > than not needs to know who you are talking to. 
> > 
> > If you server-side methods are async, then you can call:
> > 
> > gchar* dbus_g_method_get_sender (DBusGMethodInvocation *context);
> Oh, do I just have to put some magic in my hand-written XML or how is
> this supposed to work? Please don't tell me that I have to write it by
> hand; it's so nice with the auto-generated glue.

Just add the Async annotation to your method:

    <method name="getBookView">
      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_AddressBook_Book_getBookView"/>
      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
      <arg name="listener" type="o" direction="in"/>
      <arg name="query" type="s" direction="in"/>
      <arg name="fields" type="as" direction="in"/>
      <arg name="max_results" type="u" direction="in"/>
      <arg name="view" type="o" direction="out"/>

Then your code looks a little like this:

static void
impl_AddressBook_Book_getBookView (EDataBook *book, const char *listener_path, const char *search, const char **fields, const guint max_results, DBusGMethodInvocation *context)
  const char* sender = dbus_g_method_get_sender (context);
  dbus_g_method_return (context, ...);  /* or actually do this async, in an idle handler or thread */

> The docs are a bit sparse so if anyone got a pointer, please tell me.

I thought I had expanded the annotations section, but obviously not
enough. :)

Ross Burton                                 mail: ross at burtonini.com
                                          jabber: ross at burtonini.com
                                     www: http://www.burtonini.com./
 PGP Fingerprint: 1A21 F5B0 D8D0 CFE3 81D4 E25A 2D09 E447 D0B4 33DF

More information about the dbus mailing list