altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
187 stars 59 forks source link

export multiple interfaces from a ServiceInterface #71

Open acrisci opened 3 years ago

acrisci commented 3 years ago

Right now it's not possible to define methods on a single class that map to different interfaces. An example of how this is useful is how a ServiceInterface also implements the standard DBus interfaces such as the properties interface. Right now that's all done by the library.

One solution might be to add a member to the annotations to specify an interface name.

@method(interface_name='org.iface1')
def method1(self):
    pass

@method(interface_name='org.iface2')
def method2(self):
    pass

And a similar member for signals and properties. We can make that optional and take the constructor param as the default interface_name for backwards compatibility.

Another possibility to investigate is to use the python class inheritance system. However, in this case, it would require a class decorator to specify the interface name. Something like this (although this definitely would need some thought):

@DBusInterface(interface_name='org.iface1')
class Iface1(ServiceInterface):
    # ...
    pass

@DBusInterface(interface_name='org.iface2')
class Iface2(ServiceInterface):
    # ...
    pass

class Iface3(Iface1, Iface2):
    # ...
    pass