virtual-device: Implement cancel vfunc, to stop timeouts

This commit is contained in:
Marco Trevisan (Treviño) 2021-01-25 16:47:19 +01:00
parent 18db20d160
commit 993109a7f8
2 changed files with 23 additions and 3 deletions

View file

@ -92,6 +92,15 @@ process_cmds (FpDeviceVirtualDevice * self,
gboolean scan, gboolean scan,
GError **error) GError **error)
{ {
if (g_cancellable_is_cancelled (self->cancellable) ||
(fpi_device_get_current_action (FP_DEVICE (self)) != FPI_DEVICE_ACTION_NONE &&
g_cancellable_is_cancelled (fpi_device_get_cancellable (FP_DEVICE (self)))))
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED,
"Operation was cancelled");
return NULL;
}
while (self->pending_commands->len > 0) while (self->pending_commands->len > 0)
{ {
gchar *cmd = g_ptr_array_index (self->pending_commands, 0); gchar *cmd = g_ptr_array_index (self->pending_commands, 0);
@ -457,6 +466,17 @@ dev_enroll (FpDevice *dev)
} }
} }
static void
dev_cancel (FpDevice *dev)
{
FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (dev);
g_debug ("Got cancellation!");
g_clear_handle_id (&self->sleep_timeout_id, g_source_remove);
maybe_continue_current_action (self);
}
static void static void
dev_deinit (FpDevice *dev) dev_deinit (FpDevice *dev)
{ {
@ -511,4 +531,5 @@ fpi_device_virtual_device_class_init (FpDeviceVirtualDeviceClass *klass)
dev_class->close = dev_deinit; dev_class->close = dev_deinit;
dev_class->verify = dev_verify; dev_class->verify = dev_verify;
dev_class->enroll = dev_enroll; dev_class->enroll = dev_enroll;
dev_class->cancel = dev_cancel;
} }

View file

@ -440,8 +440,6 @@ class VirtualDevice(unittest.TestCase):
self.dev.close_sync() self.dev.close_sync()
def test_device_sleep(self): def test_device_sleep(self):
enrolled = self.enroll_print('testprint', FPrint.Finger.LEFT_LITTLE)
timeout_reached = False timeout_reached = False
def on_timeout(): def on_timeout():
nonlocal timeout_reached nonlocal timeout_reached
@ -450,7 +448,8 @@ class VirtualDevice(unittest.TestCase):
self.send_command('SLEEP', 1500) self.send_command('SLEEP', 1500)
GLib.timeout_add(300, on_timeout) GLib.timeout_add(300, on_timeout)
self.start_verify(enrolled, identify=self.dev.supports_identify()) self.start_verify(FPrint.Print.new(self.dev),
identify=self.dev.supports_identify())
while not timeout_reached: while not timeout_reached:
ctx.iteration(False) ctx.iteration(False)