dbus-python: use home-made object as argument

Alban Crequy alban.crequy at collabora.co.uk
Fri Jul 17 10:20:54 PDT 2009


Le Tue, 14 Jul 2009 17:45:47 +0800,
Zhang Sen <zh.jesse at gmail.com> a écrit :

> Hi,
> 
> Can I use a custom object as the argument of dbus call, in python?
> Something like,

It is not possible to send arbitrary objects on D-Bus. dbus-python needs
to know how to serialize and unserialize your message on the D-Bus
socket. The list of possible argument of a dbus call are in the grid
on this webpage:

http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures

It seems you want to send 3 unsigned integers. The signature can be
"uuu" (not "a(uuu)", that's an array of a structure containing 3
unsigned integers).

You can then do:
proxy = bus.get_object(...)
c = Container(1, 2, 3)
proxy.foo(c.GetA(), c.GetB(), c.GetC())  
if you implement the getters.

There is no high-level python-dbus to send python objects. When you
send the content of your container in this D-Bus message, the recipient
receives it but does not get automatically updates when the sender
updates the values of your container. It is up to you to design a D-Bus
interface for that if it is what you want.

A common pattern is to have an object Container on the bus and have
getters and a D-Bus signal to signal the changes.

For the record, the dbus-python tutorial is here:
http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html

Regards,
Alban



More information about the dbus mailing list