mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2025-11-15 07:38:12 +00:00
virtual-device: Make cancellation support toggable
We may want to have the device to sleep while releasing an operation, this will allow to do it.
This commit is contained in:
@@ -80,6 +80,7 @@ struct _FpDeviceVirtualDevice
|
||||
guint wait_command_id;
|
||||
guint sleep_timeout_id;
|
||||
guint enroll_stages_passed;
|
||||
gboolean supports_cancellation;
|
||||
};
|
||||
|
||||
/* Not really final here, but we can do this to share the FpDeviceVirtualDevice
|
||||
|
||||
@@ -43,6 +43,7 @@ G_DEFINE_TYPE (FpDeviceVirtualDevice, fpi_device_virtual_device, FP_TYPE_DEVICE)
|
||||
#define SLEEP_CMD_PREFIX "SLEEP "
|
||||
#define SET_ENROLL_STAGES_PREFIX "SET_ENROLL_STAGES "
|
||||
#define SET_SCAN_TYPE_PREFIX "SET_SCAN_TYPE "
|
||||
#define SET_CANCELLATION_PREFIX "SET_CANCELLATION_ENABLED "
|
||||
|
||||
#define LIST_CMD "LIST"
|
||||
#define UNPLUG_CMD "UNPLUG"
|
||||
@@ -257,6 +258,14 @@ recv_instruction_cb (GObject *source_object,
|
||||
else
|
||||
g_warning ("Scan type '%s' not found", scan_type);
|
||||
}
|
||||
else if (g_str_has_prefix (cmd, SET_CANCELLATION_PREFIX))
|
||||
{
|
||||
self->supports_cancellation = g_ascii_strtoull (
|
||||
cmd + strlen (SET_CANCELLATION_PREFIX), NULL, 10) != 0;
|
||||
|
||||
g_debug ("Cancellation support toggled: %d",
|
||||
self->supports_cancellation);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_ptr_array_add (self->pending_commands, g_steal_pointer (&cmd));
|
||||
@@ -471,6 +480,9 @@ dev_cancel (FpDevice *dev)
|
||||
{
|
||||
FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (dev);
|
||||
|
||||
if (!self->supports_cancellation)
|
||||
return;
|
||||
|
||||
g_debug ("Got cancellation!");
|
||||
g_clear_handle_id (&self->sleep_timeout_id, g_source_remove);
|
||||
|
||||
@@ -505,6 +517,7 @@ fpi_device_virtual_device_finalize (GObject *object)
|
||||
static void
|
||||
fpi_device_virtual_device_init (FpDeviceVirtualDevice *self)
|
||||
{
|
||||
self->supports_cancellation = TRUE;
|
||||
self->pending_commands = g_ptr_array_new_with_free_func (g_free);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user