Export the Bluez device's object path
Rather than proxying all metadata (name, address, ...) add a reference to the bluez device instead. Fixes #60
This commit is contained in:
parent
9cecc1b535
commit
31e1f2ad3b
|
@ -143,12 +143,8 @@ org.freedesktop.tuhi1.Device
|
||||||
Interface to a device known by tuhi. Each object in Manager.Devices
|
Interface to a device known by tuhi. Each object in Manager.Devices
|
||||||
implements this interface.
|
implements this interface.
|
||||||
|
|
||||||
Property: Name (s)
|
Property: BlueZDevice (o)
|
||||||
Human-readable name of the device.
|
Object path to the org.bluez.Device1 device that is this device.
|
||||||
Read-only
|
|
||||||
|
|
||||||
Property: Address (s)
|
|
||||||
Bluetooth address of the device.
|
|
||||||
Read-only
|
Read-only
|
||||||
|
|
||||||
Property: Dimensions (uu)
|
Property: Dimensions (uu)
|
||||||
|
|
|
@ -67,6 +67,8 @@ ORG_FREEDESKTOP_TUHI1_MANAGER = 'org.freedesktop.tuhi1.Manager'
|
||||||
ORG_FREEDESKTOP_TUHI1_DEVICE = 'org.freedesktop.tuhi1.Device'
|
ORG_FREEDESKTOP_TUHI1_DEVICE = 'org.freedesktop.tuhi1.Device'
|
||||||
ROOT_PATH = '/org/freedesktop/tuhi1'
|
ROOT_PATH = '/org/freedesktop/tuhi1'
|
||||||
|
|
||||||
|
ORG_BLUEZ_DEVICE1 = 'org.bluez.Device1'
|
||||||
|
|
||||||
# remove ':' from the completer delimiters of readline so we can match on
|
# remove ':' from the completer delimiters of readline so we can match on
|
||||||
# device addresses
|
# device addresses
|
||||||
completer_delims = readline.get_completer_delims()
|
completer_delims = readline.get_completer_delims()
|
||||||
|
@ -92,7 +94,7 @@ class _DBusObject(GObject.Object):
|
||||||
self.objpath = objpath
|
self.objpath = objpath
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.proxy = Gio.DBusProxy.new_sync(_DBusObject._connection,
|
self.proxy = Gio.DBusProxy.new_sync(self._connection,
|
||||||
Gio.DBusProxyFlags.NONE, None,
|
Gio.DBusProxyFlags.NONE, None,
|
||||||
name, objpath, interface, None)
|
name, objpath, interface, None)
|
||||||
except GLib.Error as e:
|
except GLib.Error as e:
|
||||||
|
@ -133,6 +135,30 @@ class _DBusObject(GObject.Object):
|
||||||
return p
|
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):
|
class TuhiKeteDevice(_DBusObject):
|
||||||
def __init__(self, manager, objpath):
|
def __init__(self, manager, objpath):
|
||||||
_DBusObject.__init__(self, TUHI_DBUS_NAME,
|
_DBusObject.__init__(self, TUHI_DBUS_NAME,
|
||||||
|
@ -140,6 +166,7 @@ class TuhiKeteDevice(_DBusObject):
|
||||||
objpath)
|
objpath)
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
self.is_pairing = False
|
self.is_pairing = False
|
||||||
|
self._bluez_device = BlueZDevice(self.property('BlueZDevice'))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_device_address(cls, string):
|
def is_device_address(cls, string):
|
||||||
|
@ -149,11 +176,11 @@ class TuhiKeteDevice(_DBusObject):
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def address(self):
|
def address(self):
|
||||||
return self.property('Address')
|
return self._bluez_device.property('Address')
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.property('Name')
|
return self._bluez_device.property('Name')
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def listening(self):
|
def listening(self):
|
||||||
|
|
|
@ -86,6 +86,10 @@ class TuhiDevice(GObject.Object):
|
||||||
def address(self):
|
def address(self):
|
||||||
return self._bluez_device.address
|
return self._bluez_device.address
|
||||||
|
|
||||||
|
@GObject.Property
|
||||||
|
def bluez_device(self):
|
||||||
|
return self._bluez_device
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def dbus_device(self):
|
def dbus_device(self):
|
||||||
return self._tuhi_dbus_device
|
return self._tuhi_dbus_device
|
||||||
|
|
|
@ -47,8 +47,7 @@ INTROSPECTION_XML = '''
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name='org.freedesktop.tuhi1.Device'>
|
<interface name='org.freedesktop.tuhi1.Device'>
|
||||||
<property type='s' name='Name' access='read'/>
|
<property type='o' name='BlueZDevice' access='read'/>
|
||||||
<property type='s' name='Address' access='read'/>
|
|
||||||
<property type='uu' name='Dimensions' access='read'/>
|
<property type='uu' name='Dimensions' access='read'/>
|
||||||
<property type='b' name='Listening' access='read'>
|
<property type='b' name='Listening' access='read'>
|
||||||
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
||||||
|
@ -144,8 +143,8 @@ class TuhiDBusDevice(_TuhiDBus):
|
||||||
objpath = f'{BASE_PATH}/{objpath}'
|
objpath = f'{BASE_PATH}/{objpath}'
|
||||||
_TuhiDBus.__init__(self, connection, objpath, INTF_DEVICE)
|
_TuhiDBus.__init__(self, connection, objpath, INTF_DEVICE)
|
||||||
|
|
||||||
|
self.bluez_device_objpath = device.bluez_device.objpath
|
||||||
self.name = device.name
|
self.name = device.name
|
||||||
self.btaddr = device.address
|
|
||||||
self.width, self.height = 0, 0
|
self.width, self.height = 0, 0
|
||||||
self.drawings = {}
|
self.drawings = {}
|
||||||
self.paired = device.paired
|
self.paired = device.paired
|
||||||
|
@ -240,10 +239,8 @@ class TuhiDBusDevice(_TuhiDBus):
|
||||||
if interface != INTF_DEVICE:
|
if interface != INTF_DEVICE:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if propname == 'Name':
|
if propname == 'BlueZDevice':
|
||||||
return GLib.Variant.new_string(self.name)
|
return GLib.Variant.new_object_path(self.bluez_device_objpath)
|
||||||
elif propname == 'Address':
|
|
||||||
return GLib.Variant.new_string(self.btaddr)
|
|
||||||
elif propname == 'Dimensions':
|
elif propname == 'Dimensions':
|
||||||
w = GLib.Variant.new_uint32(self.width)
|
w = GLib.Variant.new_uint32(self.width)
|
||||||
h = GLib.Variant.new_uint32(self.height)
|
h = GLib.Variant.new_uint32(self.height)
|
||||||
|
|
Loading…
Reference in New Issue