LEW21 / pydbus

Pythonic DBus library
GNU Lesser General Public License v2.1
331 stars 75 forks source link

How to use two buses with different adresses ? #21

Closed predrag-viceic closed 8 years ago

predrag-viceic commented 8 years ago

Hello,

I need to connect to the session bus to retrieve some kde signals, and then I want to call methods on objects on another bus with another address (omxplayer).

Is this possible from the same python process ?

try:
  addressfile="/tmp/omxplayerdbus.dev"
  pidfile="/tmp/omxplayerdbus.dev.pid"

  with open (addressfile, "r") as myfile:
    address=myfile.readlines()[0]

  with open (pidfile, "r") as myfile:
    pid=myfile.readlines()[0]

  print address
  print pid
  os.environ['DBUS_SESSION_BUS_ADDRESS']=address

  omxbus = SessionBus()
  omxplayer = omxbus.get('org.mpris.MediaPlayer2.omxplayer', '/org/mpris/MediaPlayer2')
except Exception as e:
  print "No omxplayer dbus: "+str(e)

doesn't work..

LEW21 commented 8 years ago

I think that GDBus automatically shares the default connection between all Bus objects - as described in g_bus_get_sync

I guess you can create another true connection with g_dbus_connection_new_for_address_sync (Gio.DBusConnection.new_for_address_sync) - and then give it to the Bus object:

from gi.repository import Gio

bus = SessionBus()
bus.con = Gio.DBusConnection.new_for_address_sync(address, None, None, None, None)

Still, to solve it cleanly I'll need to add an official support for connecting to a given address.

predrag-viceic commented 8 years ago

Hello !

Thanks for your reply and for your library, it comes in handy when dealing with D-BUS !

With the following code I receive this error: g-io-error-quark: The connection is closed (18)

from gi.repository import Gio
omxbus = SessionBus()
omxbus.con = Gio.DBusConnection.new_for_address_sync(address, Gio.DBusConnectionFlags.AUTHENTICATION_CLIENT, None, None)

print(omxbus.con.get_guid())

omxplayer = omxbus.get('org.mpris.MediaPlayer2.omxplayer', '/org/mpris/MediaPlayer2')

As I understand, you are using reflection to call Gio (Gnome) APIs. Could it be that here is some incompatibility between KDE and Gnome when dealing with the connections out of the main session bus scope?

I can see the omx intefaces etc with qdbusviewer if I modify the DBUS_SESSION_BUS_ADDRESS before launching it.

LEW21 commented 8 years ago

Fixed in https://github.com/LEW21/pydbus/commit/f17ead4b08bcba39c647fd5250b5f65c679c6af7