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

Ali Abdallah aliov at xfce.org
Fri Aug 28 09:41:00 PDT 2009


Till Wimmer wrote:
> 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:
> <node>
>  <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"/>
>    </method>
>  </interface>
> </node>
>
> How do i rewrite the skypeapi_dbusobj_invoke function with 
> dbus_g_method_return at the end?
Now the function will look like

gboolean skypeapi_dbusobj_invoke(SkypeAPIDBusObj *obj, const char 
*message, char **ret, DBusGMethodInvocation *context) {

  /* code */

  return TRUE;
}

and later you can call dbus_g_method_return (content, str_ret);

>
> Thanks,
> Till
Cheers.
Ali


More information about the dbus mailing list