From 27c2466bda6aff40438232f65a40a4440f56b80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 28 Jan 2021 03:23:43 +0100 Subject: [PATCH] fpi-device: Mark the device as open and notify it on idle callback We're delaying any completed operation until we've completed an idle, but the open/close state is changed and notified as soon as the device completes the operation. While this can be true, it means that we notify earlier than the finish callback is actually called, while iterations are still needed to get the actual state completed, and the current_task reset. So if we'd open/close and iterate till fp_device_is_open() returns TRUE we'd end up in a state in which the device is marked as ready, but it's actually still busy since it's priv->current_task isn't unset yet. The same if we'd try to do any action on notify::opened. --- libfprint/fpi-device.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/libfprint/fpi-device.c b/libfprint/fpi-device.c index be5b0e9..231dde9 100644 --- a/libfprint/fpi-device.c +++ b/libfprint/fpi-device.c @@ -752,6 +752,21 @@ fp_device_task_return_in_idle_cb (gpointer user_data) priv->current_action = FPI_DEVICE_ACTION_NONE; priv->current_task_idle_return_source = NULL; + if (action == FPI_DEVICE_ACTION_OPEN && + data->type != FP_DEVICE_TASK_RETURN_ERROR) + { + priv->is_open = TRUE; + g_object_notify (G_OBJECT (data->device), "open"); + } + else if (action == FPI_DEVICE_ACTION_CLOSE) + { + /* Always consider the device closed. Drivers should try hard to close the + * device. Generally, e.g. cancellations should be ignored. + */ + priv->is_open = FALSE; + g_object_notify (G_OBJECT (data->device), "open"); + } + /* Return FP_DEVICE_ERROR_REMOVED if the device is removed, * with the exception of a successful open, which is an odd corner case. */ if (priv->is_removed && @@ -921,12 +936,6 @@ fpi_device_open_complete (FpDevice *device, GError *error) clear_device_cancel_action (device); fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE); - if (!error) - { - priv->is_open = TRUE; - g_object_notify (G_OBJECT (device), "open"); - } - if (!error) fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL, GUINT_TO_POINTER (TRUE)); @@ -977,12 +986,6 @@ fpi_device_close_complete (FpDevice *device, GError *error) return; } - /* Always consider the device closed. Drivers should try hard to close the - * device. Generally, e.g. cancellations should be ignored. - */ - priv->is_open = FALSE; - g_object_notify (G_OBJECT (device), "open"); - if (!error) fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL, GUINT_TO_POINTER (TRUE));