From 8a6f1932f8ceeef6ae6ac634b588c2e52f7f069e Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 16 Nov 2020 19:00:43 +0100 Subject: [PATCH] virtual-image: Add a notify::removed handler In general, we rely on the underlying transport layer to throw errors which will abort the current operation. This does not work for the virtual image device though, but we need it there for testing purposes. Add a notify::removed handler that makes things work as expected. Let it throw a protocol error which should not be visible to the outside. --- libfprint/drivers/virtual-image.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libfprint/drivers/virtual-image.c b/libfprint/drivers/virtual-image.c index b5164f3..5c30c52 100644 --- a/libfprint/drivers/virtual-image.c +++ b/libfprint/drivers/virtual-image.c @@ -367,9 +367,36 @@ dev_deactivate (FpImageDevice *dev) fpi_device_add_timeout (FP_DEVICE (dev), 10, (FpTimeoutFunc) fpi_image_device_deactivate_complete, NULL, NULL); } +static void +dev_notify_removed_cb (FpDevice *dev) +{ + FpiImageDeviceState state; + gboolean removed; + + g_object_get (dev, + "fpi-image-device-state", &state, + "removed", &removed, + NULL); + + if (!removed || state == FPI_IMAGE_DEVICE_STATE_INACTIVE) + return; + + /* This error will be converted to an FP_DEVICE_ERROR_REMOVED by the + * surrounding layers. */ + fpi_image_device_session_error (FP_IMAGE_DEVICE (dev), + fpi_device_error_new (FP_DEVICE_ERROR_PROTO)); +} + static void fpi_device_virtual_image_init (FpDeviceVirtualImage *self) { + /* NOTE: This is not nice, but we can generally rely on the underlying + * system to throw errors on the transport layer. + */ + g_signal_connect (self, + "notify::removed", + G_CALLBACK (dev_notify_removed_cb), + NULL); } static const FpIdEntry driver_ids[] = {