dbus: implement StartPairing on the manager
And call the discovery on the bluetooth adapter Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>pull/2/head
parent
52b4536e77
commit
c9897d55ed
4
tuhi.py
4
tuhi.py
|
@ -138,6 +138,7 @@ class Tuhi(GObject.Object):
|
|||
GObject.Object.__init__(self)
|
||||
self.server = TuhiDBusServer()
|
||||
self.server.connect('bus-name-acquired', self._on_tuhi_bus_name_acquired)
|
||||
self.server.connect('start-pairing-requested', self._on_start_pairing_requested)
|
||||
self.bluez = BlueZDeviceManager()
|
||||
self.bluez.connect('device-added', self._on_bluez_device_added)
|
||||
|
||||
|
@ -146,6 +147,9 @@ class Tuhi(GObject.Object):
|
|||
def _on_tuhi_bus_name_acquired(self, dbus_server):
|
||||
self.bluez.connect_to_bluez()
|
||||
|
||||
def _on_start_pairing_requested(self, dbus_server):
|
||||
self.bluez.start_discovery(30)
|
||||
|
||||
def _on_bluez_device_added(self, manager, bluez_device):
|
||||
if bluez_device.vendor_id != WACOM_COMPANY_ID:
|
||||
return
|
||||
|
|
31
tuhi/ble.py
31
tuhi/ble.py
|
@ -285,6 +285,37 @@ class BlueZDeviceManager(GObject.Object):
|
|||
for obj in self._om.get_objects():
|
||||
self._process_object(obj)
|
||||
|
||||
def _discovery_timeout_expired(self):
|
||||
for obj in self._om.get_objects():
|
||||
i = obj.get_interface(ORG_BLUEZ_ADAPTER1)
|
||||
if i is None:
|
||||
continue
|
||||
|
||||
objpath = obj.get_object_path()
|
||||
i.StopDiscovery()
|
||||
logger.debug('Discovery stopped on: {}'.format(objpath))
|
||||
|
||||
# FIXME: we should notify the client that the timeout expired
|
||||
return False
|
||||
|
||||
def start_discovery(self, timeout):
|
||||
"""
|
||||
Start discovery mode for the specified timeout.
|
||||
|
||||
A value of 0 for the timeout means infinite.
|
||||
"""
|
||||
for obj in self._om.get_objects():
|
||||
i = obj.get_interface(ORG_BLUEZ_ADAPTER1)
|
||||
if i is None:
|
||||
continue
|
||||
|
||||
objpath = obj.get_object_path()
|
||||
i.StartDiscovery()
|
||||
logger.debug('Discovery started on: {}'.format(objpath))
|
||||
if timeout >= 0:
|
||||
logger.debug('Setting the timeout to {}'.format(timeout))
|
||||
GObject.timeout_add_seconds(timeout, self._discovery_timeout_expired)
|
||||
|
||||
def _on_om_object_added(self, om, obj):
|
||||
"""Callback for ObjectManager's object-added"""
|
||||
objpath = obj.get_object_path()
|
||||
|
|
|
@ -23,6 +23,11 @@ INTROSPECTION_XML = """
|
|||
<property type='ao' name='Devices' access='read'>
|
||||
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
||||
</property>
|
||||
|
||||
<method name='StartPairing'>
|
||||
<annotation name='org.freedesktop.DBus.Method.NoReply' value='true'/>
|
||||
</method>
|
||||
|
||||
</interface>
|
||||
|
||||
<interface name='org.freedesktop.tuhi1.Device'>
|
||||
|
@ -131,6 +136,8 @@ class TuhiDBusServer(GObject.Object):
|
|||
__gsignals__ = {
|
||||
"bus-name-acquired":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
"start-pairing-requested":
|
||||
(GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
|
@ -161,8 +168,13 @@ class TuhiDBusServer(GObject.Object):
|
|||
def _bus_name_lost(self, connection, name):
|
||||
pass
|
||||
|
||||
def _method_cb(self):
|
||||
pass
|
||||
def _method_cb(self, connection, sender, objpath, interface, methodname, args, invocation):
|
||||
if interface != INTF_MANAGER:
|
||||
return None
|
||||
|
||||
if methodname == 'StartPairing':
|
||||
self._start_pairing()
|
||||
invocation.return_value()
|
||||
|
||||
def _property_read_cb(self, connection, sender, objpath, interface, propname):
|
||||
if interface != INTF_MANAGER:
|
||||
|
@ -176,6 +188,9 @@ class TuhiDBusServer(GObject.Object):
|
|||
def _property_write_cb(self):
|
||||
pass
|
||||
|
||||
def _start_pairing(self):
|
||||
self.emit("start-pairing-requested")
|
||||
|
||||
def cleanup(self):
|
||||
Gio.bus_unown_name(self._dbus)
|
||||
|
||||
|
|
Loading…
Reference in New Issue