Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export an object on a custom dbus using Python?

Tags:

python

dbus

I want to provide dbus methods and signals on a custom bus (i.e. not SessionBus or SystemBus). If I start a test copy of the dbus-daemon from the command line, as described in dbus-daemon man page, like so:

dbus-daemon --session --print-address

then this returns for example the address:

unix:abstract=/tmp/dbus-vthAiAw4am,guid=60da6b6ef244a0dbdb9710a800002218

I can use this address in d-feet to "Connect to Other Bus", and there is nothing there. Now, I would like to claim a name on that bus and export objects to provide dbus methods and signals using Python. I have tried reading the code behind dbus.service.BusName where I would normally pass in the Session or System bus, but I simply get lost. Anyone know how to do this (if even possible)?

like image 367
JoGr Avatar asked Aug 27 '26 06:08

JoGr


1 Answers

Looking at the source code for d-feet was of course an easier way to find the answer than browsing the entire dbus-python lib. An address like the one in the question could be used when claiming a bus name, by passing in a dbus.bus.BusConnection object with the address as argument, like so:

bus_name = dbus.service.BusName('my.testbus.test', 
    dbus.bus.BusConnection('unix:abstract=/tmp/dbus-vthAiAw4am'))

I can then export methods and emit signals on this bus.

like image 110
JoGr Avatar answered Aug 29 '26 20:08

JoGr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!