From 1ba95db379ff1225b2e3cf7955c353072f168a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 22 Nov 2019 18:22:50 +0100 Subject: [PATCH] drivers: Use fpi_ssm_next_state_delayed instead of custom callbacks As per this fpi_ssm_next_state_timeout_cb can be removed --- libfprint/drivers/elan.c | 7 +------ libfprint/drivers/vfs0050.c | 3 +-- libfprint/drivers/vfs101.c | 24 +++++++----------------- libfprint/drivers/vfs301.c | 15 ++------------- libfprint/drivers/vfs5011.c | 5 +---- libfprint/fpi-ssm.c | 30 ++++-------------------------- libfprint/fpi-ssm.h | 2 -- 7 files changed, 16 insertions(+), 70 deletions(-) diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index f9e8763..f622988 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -749,15 +749,10 @@ calibrate_run_state (FpiSsm *ssm, FpDevice *dev) } else { - GSource *timeout; - if (self->calib_status == 0x00 && self->last_read[0] == 0x01) self->calib_status = 0x01; - timeout = fpi_device_add_timeout (dev, 50, - fpi_ssm_next_state_timeout_cb, - ssm, NULL); - g_source_set_name (timeout, "calibrate_run_state"); + fpi_ssm_next_state_delayed (ssm, 50); } break; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index 6377639..af70db5 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -618,8 +618,7 @@ activate_ssm (FpiSsm *ssm, FpDevice *dev) clear_data (self); /* Wait for probable vdev->active changing */ - fpi_device_add_timeout (dev, VFS_SSM_TIMEOUT, - fpi_ssm_next_state_timeout_cb, ssm, NULL); + fpi_ssm_next_state_delayed (ssm, VFS_SSM_TIMEOUT); break; case SSM_NEXT_RECEIVE: diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 0df9b73..7020726 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -369,16 +369,6 @@ async_load (FpiSsm *ssm, async_load_cb, NULL); } -/* Submit asynchronous sleep */ -static void -async_sleep (unsigned int msec, - FpiSsm *ssm, - FpImageDevice *dev) -{ - fpi_device_add_timeout (FP_DEVICE (dev), msec, - fpi_ssm_next_state_timeout_cb, ssm, NULL); -} - /* Swap ssm states */ enum { M_SWAP_SEND, @@ -795,7 +785,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) case M_LOOP_0_SLEEP: /* Wait fingerprint scanning */ - async_sleep (50, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 50); break; case M_LOOP_0_GET_STATE: @@ -838,7 +828,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) img_extract (ssm, dev); /* Wait handling image */ - async_sleep (10, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 10); break; case M_LOOP_0_CHECK_ACTION: @@ -861,7 +851,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) if (vfs_finger_state (self) == VFS_FINGER_PRESENT) { fpi_image_device_report_finger_status (dev, TRUE); - async_sleep (250, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 250); } else { @@ -891,7 +881,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) case M_LOOP_1_SLEEP: /* Wait fingerprint scanning */ - async_sleep (10, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 10); break; case M_LOOP_2_ABORT_PRINT: @@ -927,7 +917,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) { /* Wait aborting */ self->counter++; - async_sleep (100, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 100); } else { @@ -1065,7 +1055,7 @@ m_init_state (FpiSsm *ssm, FpDevice *_dev) { /* Wait aborting */ self->counter++; - async_sleep (100, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 100); } else { @@ -1094,7 +1084,7 @@ m_init_state (FpiSsm *ssm, FpDevice *_dev) { /* Wait removing finger */ self->counter++; - async_sleep (250, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 250); } else { diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index 1d0f066..3870879 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -28,17 +28,6 @@ G_DEFINE_TYPE (FpDeviceVfs301, fpi_device_vfs301, FP_TYPE_IMAGE_DEVICE) /************************** GENERIC STUFF *************************************/ -/* Submit asynchronous sleep */ -static void -async_sleep (unsigned int msec, - FpiSsm *ssm, - FpImageDevice *dev) -{ - /* Add timeout */ - fpi_device_add_timeout (FP_DEVICE (dev), msec, - fpi_ssm_next_state_timeout_cb, ssm, NULL); -} - static int submit_image (FpiSsm *ssm, FpImageDevice *dev) @@ -108,7 +97,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) case M_WAIT_PRINT: /* Wait fingerprint scanning */ - async_sleep (200, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 200); break; case M_CHECK_PRINT: @@ -126,7 +115,7 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev) case M_READ_PRINT_WAIT: /* Wait fingerprint scanning */ - async_sleep (200, ssm, dev); + fpi_ssm_next_state_delayed (ssm, 200); break; case M_READ_PRINT_POLL: diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 4fac03c..b769e31 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -704,10 +704,7 @@ activate_loop (FpiSsm *ssm, FpDevice *_dev) break; case DEV_ACTIVATE_DATA_COMPLETE: - fpi_device_add_timeout (_dev, 1, - fpi_ssm_next_state_timeout_cb, - ssm, NULL); - + fpi_ssm_next_state_delayed (ssm, 1); break; case DEV_ACTIVATE_PREPARE_NEXT_CAPTURE: diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 38186d2..931c8fe 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -359,7 +359,7 @@ fpi_ssm_next_state_delayed (FpiSsm *machine, g_clear_pointer (&machine->timeout, g_source_destroy); machine->timeout = fpi_device_add_timeout (machine->dev, delay, on_device_timeout_next_state, - machine); + machine, NULL); source_name = g_strdup_printf ("[%s] ssm %p jump to next state %d", fp_device_get_device_id (machine->dev), @@ -430,9 +430,9 @@ fpi_ssm_jump_to_state_delayed (FpiSsm *machine, data->next_state = state; g_clear_pointer (&machine->timeout, g_source_destroy); - machine->timeout = fpi_device_add_timeout_full (machine->dev, delay, - on_device_timeout_jump_to_state, - data, g_free); + machine->timeout = fpi_device_add_timeout (machine->dev, delay, + on_device_timeout_jump_to_state, + data, g_free); source_name = g_strdup_printf ("[%s] ssm %p jump to state %d", fp_device_get_device_id (machine->dev), @@ -486,28 +486,6 @@ fpi_ssm_dup_error (FpiSsm *machine) return NULL; } -/** - * fpi_ssm_next_state_timeout_cb: - * @dev: a struct #fp_dev - * @data: a pointer to an #FpiSsm state machine - * - * Same as fpi_ssm_next_state(), but to be used as a callback - * for an fpi_device_add_timeout() callback, when the state - * change needs to happen after a timeout. - * - * Make sure to pass the #FpiSsm as the `ssm_data` argument - * for that fpi_device_add_timeout() call. - */ -void -fpi_ssm_next_state_timeout_cb (FpDevice *dev, - void *data) -{ - g_return_if_fail (dev != NULL); - g_return_if_fail (data != NULL); - - fpi_ssm_next_state (data); -} - /** * fpi_ssm_usb_transfer_cb: * @transfer: a #FpiUsbTransfer diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 05e6cf0..b426fff 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -93,8 +93,6 @@ int fpi_ssm_get_cur_state (FpiSsm *machine); /* Callbacks to be used by the driver instead of implementing their own * logic. */ -void fpi_ssm_next_state_timeout_cb (FpDevice *dev, - void *data); void fpi_ssm_usb_transfer_cb (FpiUsbTransfer *transfer, FpDevice *device, gpointer unused_data,