How to get the name of the caller of a method in glib-dbus

Till Wimmer g4-lisz at
Fri Aug 28 06:54:48 PDT 2009

Ali Abdallah schrieb:
> Till Wimmer wrote:
>> Hello,
>> i wrote a daemon which exposes a method ("invoke") to the bus:
>>   dbus_g_object_type_install_info(...)
>>   dbus_g_connection_register_g_object(...)
>> This works fine.
>> Now i'd like to find the unique connection name of the client who 
>> calls the exposed method.
> <method name="YourMethod">
> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
>  <arg....... >
> </method>
> Then the exposed method in your GObject can be like:
> method_name (YourObject, args, DBusGMethodInvocation *context)
> And from the context you get
> dbus_g_method_get_sender (context); /* The unique name */
> Don't forget to return something with dbus_g_method_return at the end.
> Hope this is what you want.
> Cheers,
> Ali.
Hi Ali,

thanks four your help!

The DBusGMethodInvocation * argument was the missing link because my 
method looked like this before:

gboolean skypeapi_dbusobj_invoke(SkypeAPIDBusObj *obj, const char 
*message, char **ret, GError **error) {

   g_assert(obj != NULL);
   obj->str_ret = [ some code here to get the response ];
   *ret = obj->str_ret;

   return TRUE;

Now i changed the methods XML to:
  <interface name="com.Skype.API">
    <!-- Method definition -->
    <!-- char *Invoke(char *message) -->
    <method name="Invoke">
      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
      <arg type="s" name="message" direction="in"/>
      <arg type="s" name="str_ret" direction="out"/>

How do i rewrite the skypeapi_dbusobj_invoke function with 
dbus_g_method_return at the end?


More information about the dbus mailing list