Export the Bluez device's object path

Rather than proxying all metadata (name, address, ...) add a reference to the
bluez device instead.

Fixes #60
pull/61/head
Peter Hutterer 2018-02-01 09:40:33 +10:00
parent 9cecc1b535
commit 31e1f2ad3b
4 changed files with 40 additions and 16 deletions

View File

@ -143,12 +143,8 @@ org.freedesktop.tuhi1.Device
Interface to a device known by tuhi. Each object in Manager.Devices
implements this interface.
Property: Name (s)
Human-readable name of the device.
Read-only
Property: Address (s)
Bluetooth address of the device.
Property: BlueZDevice (o)
Object path to the org.bluez.Device1 device that is this device.
Read-only
Property: Dimensions (uu)

View File

@ -67,6 +67,8 @@ ORG_FREEDESKTOP_TUHI1_MANAGER = 'org.freedesktop.tuhi1.Manager'
ORG_FREEDESKTOP_TUHI1_DEVICE = 'org.freedesktop.tuhi1.Device'
ROOT_PATH = '/org/freedesktop/tuhi1'
ORG_BLUEZ_DEVICE1 = 'org.bluez.Device1'
# remove ':' from the completer delimiters of readline so we can match on
# device addresses
completer_delims = readline.get_completer_delims()
@ -92,7 +94,7 @@ class _DBusObject(GObject.Object):
self.objpath = objpath
try:
self.proxy = Gio.DBusProxy.new_sync(_DBusObject._connection,
self.proxy = Gio.DBusProxy.new_sync(self._connection,
Gio.DBusProxyFlags.NONE, None,
name, objpath, interface, None)
except GLib.Error as e:
@ -133,6 +135,30 @@ class _DBusObject(GObject.Object):
return p
class _DBusSystemObject(_DBusObject):
'''
Same as the _DBusObject, but connects to the system bus instead
'''
def __init__(self, name, interface, objpath):
self._connect_to_system()
super().__init__(name, interface, objpath)
def _connect_to_system(self):
try:
self._connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
except GLib.Error as e:
if (e.domain == 'g-io-error-quark' and
e.code == Gio.IOErrorEnum.DBUS_ERROR):
raise DBusError(e.message)
else:
raise e
class BlueZDevice(_DBusSystemObject):
def __init__(self, objpath):
super().__init__('org.bluez', ORG_BLUEZ_DEVICE1, objpath)
class TuhiKeteDevice(_DBusObject):
def __init__(self, manager, objpath):
_DBusObject.__init__(self, TUHI_DBUS_NAME,
@ -140,6 +166,7 @@ class TuhiKeteDevice(_DBusObject):
objpath)
self.manager = manager
self.is_pairing = False
self._bluez_device = BlueZDevice(self.property('BlueZDevice'))
@classmethod
def is_device_address(cls, string):
@ -149,11 +176,11 @@ class TuhiKeteDevice(_DBusObject):
@GObject.Property
def address(self):
return self.property('Address')
return self._bluez_device.property('Address')
@GObject.Property
def name(self):
return self.property('Name')
return self._bluez_device.property('Name')
@GObject.Property
def listening(self):

View File

@ -86,6 +86,10 @@ class TuhiDevice(GObject.Object):
def address(self):
return self._bluez_device.address
@GObject.Property
def bluez_device(self):
return self._bluez_device
@GObject.Property
def dbus_device(self):
return self._tuhi_dbus_device

View File

@ -47,8 +47,7 @@ INTROSPECTION_XML = '''
</interface>
<interface name='org.freedesktop.tuhi1.Device'>
<property type='s' name='Name' access='read'/>
<property type='s' name='Address' access='read'/>
<property type='o' name='BlueZDevice' access='read'/>
<property type='uu' name='Dimensions' access='read'/>
<property type='b' name='Listening' access='read'>
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
@ -144,8 +143,8 @@ class TuhiDBusDevice(_TuhiDBus):
objpath = f'{BASE_PATH}/{objpath}'
_TuhiDBus.__init__(self, connection, objpath, INTF_DEVICE)
self.bluez_device_objpath = device.bluez_device.objpath
self.name = device.name
self.btaddr = device.address
self.width, self.height = 0, 0
self.drawings = {}
self.paired = device.paired
@ -240,10 +239,8 @@ class TuhiDBusDevice(_TuhiDBus):
if interface != INTF_DEVICE:
return None
if propname == 'Name':
return GLib.Variant.new_string(self.name)
elif propname == 'Address':
return GLib.Variant.new_string(self.btaddr)
if propname == 'BlueZDevice':
return GLib.Variant.new_object_path(self.bluez_device_objpath)
elif propname == 'Dimensions':
w = GLib.Variant.new_uint32(self.width)
h = GLib.Variant.new_uint32(self.height)