Python Dbus: how to export an interface property

All python dbus docs have information on how to export objects, interfaces, signals, but there is nothing how to export interface properties.

Any ideas how to do this?

+4
source share
2 answers

It is definitely possible to implement D-Bus properties in Python! D-Bus properties are just methods on a specific interface, namely org.freedesktop.DBus.Properties . The interface is defined in the D-Bus specification ; you can implement it in your class, just like you implement any other D-Bus interface:

 # Untested, just off the top of my head import dbus MY_INTERFACE = 'com.example.Foo' class Foo(dbus.service.object): # … @dbus.service.method(interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v') def Get(self, interface_name, property_name): return self.GetAll(interface_name)[property_name] @dbus.service.method(interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}') def GetAll(self, interface_name): if interface_name == MY_INTERFACE: return { 'Blah': self.blah, # … } else: raise dbus.exceptions.DBusException( 'com.example.UnknownInterface', 'The Foo object does not implement the %s interface' % interface_name) @dbus.service.method(interface=dbus.PROPERTIES_IFACE, in_signature='ssv'): def Set(self, interface_name, property_name, new_value): # validate the property name and value, update internal state… self.PropertiesChanged(interface_name, { property_name: new_value }, []) @dbus.service.signal(interface=dbus.PROPERTIES_IFACE, signature='sa{sv}as') def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties): pass 

dbus-python should simplify the implementation of properties, but currently it is very easy to maintain at best.

If someone decided to plunge into the water and helped fix such things, they would be very welcome. Even adding an extended version of this template to the documentation would be a start, as this is a fairly frequently asked question. If you are interested, patches can be sent to the D-Bus mailing list or attached to errors filed against dbus-python in the FreeDesktop bug tracker .

+11
source

This example does not work, I think, because:

'' "Available properties and their writeability can be determined by calling org.freedesktop.DBus.Introspectable.Introspect, see the section" org.freedesktop.DBus.Introspectable. '' ''

and the property is missing in the introspection data:

I am using dbus-python-1.1.1

+2
source

All Articles