implement a basic Start/StopListening
This implements the ListeningStopped signal (especially the EAGAIN if we're already listening) but does not yet actually trigger the listening on the device. There is still no timeout, and no signal gets emitted. The current way of testing this is: - call StartListening() on the DBus device - start discovery on the adapter by some other mean - press the button on the device -> the sync will happen - call StopDiscovery() - press the button on the device -> the sync will *not* happen
This commit is contained in:
parent
0e6d82dd14
commit
e3fff4015a
8
tuhi.py
8
tuhi.py
|
@ -119,6 +119,10 @@ class TuhiDevice(GObject.Object):
|
||||||
self._tuhi_dbus_device = device
|
self._tuhi_dbus_device = device
|
||||||
self._tuhi_dbus_device.connect('pair-requested', self._on_pair_requested)
|
self._tuhi_dbus_device.connect('pair-requested', self._on_pair_requested)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def listening(self):
|
||||||
|
return self._tuhi_dbus_device.listening
|
||||||
|
|
||||||
def connect_device(self):
|
def connect_device(self):
|
||||||
self._bluez_device.connect_device()
|
self._bluez_device.connect_device()
|
||||||
|
|
||||||
|
@ -264,8 +268,12 @@ class Tuhi(GObject.Object):
|
||||||
d.dbus_device = self.server.create_device(d)
|
d.dbus_device = self.server.create_device(d)
|
||||||
self.devices[bluez_device.address] = d
|
self.devices[bluez_device.address] = d
|
||||||
|
|
||||||
|
d = self.devices[bluez_device.address]
|
||||||
|
|
||||||
if Tuhi._is_pairing_device(bluez_device):
|
if Tuhi._is_pairing_device(bluez_device):
|
||||||
logger.debug('{}: call Pair() on device'.format(bluez_device.objpath))
|
logger.debug('{}: call Pair() on device'.format(bluez_device.objpath))
|
||||||
|
elif d.listening:
|
||||||
|
d.connect_device()
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import errno
|
||||||
|
|
||||||
from gi.repository import GObject, Gio, GLib
|
from gi.repository import GObject, Gio, GLib
|
||||||
|
|
||||||
|
@ -45,6 +46,9 @@ INTROSPECTION_XML = """
|
||||||
<property type='s' name='Name' access='read'/>
|
<property type='s' name='Name' access='read'/>
|
||||||
<property type='s' name='Address' 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'>
|
||||||
|
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
||||||
|
</property>
|
||||||
<property type='u' name='DrawingsAvailable' access='read'>
|
<property type='u' name='DrawingsAvailable' access='read'>
|
||||||
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
<annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='true'/>
|
||||||
</property>
|
</property>
|
||||||
|
@ -53,7 +57,11 @@ INTROSPECTION_XML = """
|
||||||
<arg name='result' type='i' direction='out'/>
|
<arg name='result' type='i' direction='out'/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
<method name='Listen'>
|
<method name='StartListening'>
|
||||||
|
<annotation name='org.freedesktop.DBus.Method.NoReply' value='true'/>
|
||||||
|
</method>
|
||||||
|
|
||||||
|
<method name='StopListening'>
|
||||||
<annotation name='org.freedesktop.DBus.Method.NoReply' value='true'/>
|
<annotation name='org.freedesktop.DBus.Method.NoReply' value='true'/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
@ -94,6 +102,7 @@ class TuhiDBusDevice(GObject.Object):
|
||||||
self.width, self.height = 0, 0
|
self.width, self.height = 0, 0
|
||||||
self.drawings = []
|
self.drawings = []
|
||||||
self.paired = device.paired
|
self.paired = device.paired
|
||||||
|
self._listening = False
|
||||||
objpath = device.address.replace(':', '_')
|
objpath = device.address.replace(':', '_')
|
||||||
self.objpath = "{}/{}".format(BASE_PATH, objpath)
|
self.objpath = "{}/{}".format(BASE_PATH, objpath)
|
||||||
|
|
||||||
|
@ -101,6 +110,34 @@ class TuhiDBusDevice(GObject.Object):
|
||||||
self._dbusid = self._register_object(connection)
|
self._dbusid = self._register_object(connection)
|
||||||
device.connect('notify::paired', self._on_device_paired)
|
device.connect('notify::paired', self._on_device_paired)
|
||||||
|
|
||||||
|
@GObject.Property
|
||||||
|
def listening(self):
|
||||||
|
return self._listening
|
||||||
|
|
||||||
|
@listening.setter
|
||||||
|
def listening(self, value):
|
||||||
|
if self._listening == value:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._listening = value
|
||||||
|
|
||||||
|
props = GLib.VariantBuilder(GLib.VariantType('a{sv}'))
|
||||||
|
de = GLib.Variant.new_dict_entry(GLib.Variant.new_string('Listening'),
|
||||||
|
GLib.Variant.new_variant(
|
||||||
|
GLib.Variant.new_boolean(value)))
|
||||||
|
props.add_value(de)
|
||||||
|
props = props.end()
|
||||||
|
inval_props = GLib.VariantBuilder(GLib.VariantType('as'))
|
||||||
|
inval_props = inval_props.end()
|
||||||
|
|
||||||
|
self._connection.emit_signal(None, self.objpath,
|
||||||
|
"org.freedesktop.DBus.Properties",
|
||||||
|
"PropertiesChanged",
|
||||||
|
GLib.Variant.new_tuple(
|
||||||
|
GLib.Variant.new_string(INTF_DEVICE),
|
||||||
|
props,
|
||||||
|
inval_props))
|
||||||
|
|
||||||
@GObject.Property
|
@GObject.Property
|
||||||
def paired(self):
|
def paired(self):
|
||||||
return self._paired
|
return self._paired
|
||||||
|
@ -132,8 +169,11 @@ class TuhiDBusDevice(GObject.Object):
|
||||||
self._pair()
|
self._pair()
|
||||||
result = GLib.Variant.new_int32(0)
|
result = GLib.Variant.new_int32(0)
|
||||||
invocation.return_value(GLib.Variant.new_tuple(result))
|
invocation.return_value(GLib.Variant.new_tuple(result))
|
||||||
elif methodname == 'Listen':
|
elif methodname == 'StartListening':
|
||||||
self._listen()
|
self._start_listening(connection, sender)
|
||||||
|
invocation.return_value()
|
||||||
|
elif methodname == 'StopListening':
|
||||||
|
self._stop_listening(connection, sender)
|
||||||
invocation.return_value()
|
invocation.return_value()
|
||||||
elif methodname == 'GetJSONData':
|
elif methodname == 'GetJSONData':
|
||||||
json = GLib.Variant.new_string(self._json_data(args))
|
json = GLib.Variant.new_string(self._json_data(args))
|
||||||
|
@ -153,6 +193,8 @@ class TuhiDBusDevice(GObject.Object):
|
||||||
return GLib.Variant.new_tuple(w, h)
|
return GLib.Variant.new_tuple(w, h)
|
||||||
elif propname == 'DrawingsAvailable':
|
elif propname == 'DrawingsAvailable':
|
||||||
return GLib.Variant.new_uint32(len(self.drawings))
|
return GLib.Variant.new_uint32(len(self.drawings))
|
||||||
|
elif propname == 'Listening':
|
||||||
|
return GLib.Variant.new_boolean(self.listening)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -165,10 +207,29 @@ class TuhiDBusDevice(GObject.Object):
|
||||||
def _on_device_paired(self, device, pspec):
|
def _on_device_paired(self, device, pspec):
|
||||||
self.paired = device.paired
|
self.paired = device.paired
|
||||||
|
|
||||||
def _listen(self):
|
def _start_listening(self, connection, sender):
|
||||||
# FIXME: start listen asynchronously
|
if self.listening:
|
||||||
# FIXME: update property when listen finishes
|
logger.debug("{} - already listening".format(self))
|
||||||
pass
|
status = GLib.Variant.new_int32(-errno.EAGAIN)
|
||||||
|
status = GLib.Variant.new_tuple(status)
|
||||||
|
connection.emit_signal(sender, self.objpath, INTF_DEVICE,
|
||||||
|
"ListeningStopped", status)
|
||||||
|
return
|
||||||
|
|
||||||
|
# FIXME: notify the server to start discovery
|
||||||
|
self.listening = True
|
||||||
|
|
||||||
|
def _stop_listening(self, connection, sender):
|
||||||
|
if not self.listening:
|
||||||
|
return
|
||||||
|
|
||||||
|
# FIXME: notify the server to stop discovery
|
||||||
|
self.listening = False
|
||||||
|
|
||||||
|
status = GLib.Variant.new_int32(0)
|
||||||
|
status = GLib.Variant.new_tuple(status)
|
||||||
|
connection.emit_signal(sender, self.objpath, INTF_DEVICE,
|
||||||
|
"ListeningStopped", status)
|
||||||
|
|
||||||
def _json_data(self, args):
|
def _json_data(self, args):
|
||||||
index = args[0]
|
index = args[0]
|
||||||
|
|
Loading…
Reference in New Issue