diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt index e0d96b2..aeaef13 100644 --- a/doc/libfprint-sections.txt +++ b/doc/libfprint-sections.txt @@ -165,6 +165,7 @@ fpi_ssm_start fpi_ssm_start_subsm fpi_ssm_next_state +fpi_ssm_next_state_timeout_cb fpi_ssm_jump_to_state fpi_ssm_mark_completed fpi_ssm_mark_failed diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c index 699f4cf..8f48bda 100644 --- a/libfprint/drivers/elan.c +++ b/libfprint/drivers/elan.c @@ -583,13 +583,6 @@ static void elan_capture(struct fp_img_dev *dev) fpi_ssm_start(ssm, capture_complete); } -static void -fpi_ssm_next_state_async(struct fp_dev *dev, - void *data) -{ - fpi_ssm_next_state((fpi_ssm *)data); -} - /* this function needs to have elandev->background and elandev->last_read to be * the calibration mean */ static int elan_need_calibration(struct elan_dev *elandev) @@ -680,7 +673,7 @@ static void calibrate_run_state(fpi_ssm *ssm, struct fp_dev *_dev, void *user_da if (elandev->calib_status == 0x00 && elandev->last_read[0] == 0x01) elandev->calib_status = 0x01; - if (!fpi_timeout_add(50, fpi_ssm_next_state_async, _dev, ssm)) + if (!fpi_timeout_add(50, fpi_ssm_next_state_timeout_cb, _dev, ssm)) fpi_ssm_mark_failed(ssm, -ETIME); } break; diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c index c3e17bc..1d8d7a1 100644 --- a/libfprint/drivers/vfs0050.c +++ b/libfprint/drivers/vfs0050.c @@ -520,15 +520,6 @@ another_scan(struct fp_dev *dev, fpi_ssm_jump_to_state(ssm, SSM_TURN_ON); } -/* Another SSM stub to continue after waiting for probable vdev->active changes */ -static void -scan_completed(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - fpi_ssm_next_state(ssm); -} - /* Main SSM loop */ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) { @@ -652,7 +643,7 @@ static void activate_ssm(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) clear_data(vdev); /* Wait for probable vdev->active changing */ - fpi_timeout_add(VFS_SSM_TIMEOUT, scan_completed, _dev, ssm); + fpi_timeout_add(VFS_SSM_TIMEOUT, fpi_ssm_next_state_timeout_cb, _dev, ssm); break; case SSM_NEXT_RECEIVE: diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c index 6f7d7f0..e4400f8 100644 --- a/libfprint/drivers/vfs101.c +++ b/libfprint/drivers/vfs101.c @@ -105,9 +105,6 @@ struct vfs101_dev /* Ignore usb error */ int ignore_error; - /* Timeout */ - fpi_timeout *timeout; - /* Loop counter */ int counter; @@ -470,32 +467,13 @@ async_load(fpi_ssm *ssm, } } -/* Callback of asynchronous sleep */ -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - struct vfs101_dev *vdev = FP_INSTANCE_DATA(dev); - - /* Cleanup timeout */ - vdev->timeout = NULL; - - fpi_ssm_next_state(ssm); -} - /* Submit asynchronous sleep */ static void async_sleep(unsigned int msec, fpi_ssm *ssm, struct fp_img_dev *dev) { - struct vfs101_dev *vdev = FP_INSTANCE_DATA(FP_DEV(dev)); - - /* Add timeout */ - vdev->timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); - - if (vdev->timeout == NULL) + if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL) { /* Failed to add timeout */ fp_err("failed to add timeout"); @@ -1505,7 +1483,7 @@ static void dev_deactivate(struct fp_img_dev *dev) vdev->active = FALSE; /* Handle eventualy existing events */ - while (vdev->transfer || vdev->timeout) + while (vdev->transfer) fp_handle_events(); /* Notify deactivate complete */ diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c index a7854f4..815c0ab 100644 --- a/libfprint/drivers/vfs301.c +++ b/libfprint/drivers/vfs301.c @@ -26,28 +26,14 @@ /************************** GENERIC STUFF *************************************/ -/* Callback of asynchronous sleep */ -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - - fpi_ssm_next_state(ssm); -} - /* Submit asynchronous sleep */ static void async_sleep(unsigned int msec, fpi_ssm *ssm, struct fp_img_dev *dev) { - fpi_timeout *timeout; - /* Add timeout */ - timeout = fpi_timeout_add(msec, async_sleep_cb, FP_DEV(dev), ssm); - - if (timeout == NULL) { + if (fpi_timeout_add(msec, fpi_ssm_next_state_timeout_cb, FP_DEV(dev), ssm) == NULL) { /* Failed to add timeout */ fp_err("failed to add timeout"); fpi_imgdev_session_error(dev, -ETIME); diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c index 11766dc..24e4868 100644 --- a/libfprint/drivers/vfs5011.c +++ b/libfprint/drivers/vfs5011.c @@ -472,15 +472,6 @@ static int capture_chunk_async(struct vfs5011_data *data, return libusb_submit_transfer(data->flying_transfer); } -static void -async_sleep_cb(struct fp_dev *dev, - void *data) -{ - fpi_ssm *ssm = data; - - fpi_ssm_next_state(ssm); -} - /* * Device initialization. Windows driver only does it when the device is * plugged in, but it doesn't harm to do this every time before scanning the @@ -721,7 +712,7 @@ static void activate_loop(fpi_ssm *ssm, struct fp_dev *_dev, void *user_data) break; case DEV_ACTIVATE_DATA_COMPLETE: - timeout = fpi_timeout_add(1, async_sleep_cb, _dev, ssm); + timeout = fpi_timeout_add(1, fpi_ssm_next_state_timeout_cb, _dev, ssm); if (timeout == NULL) { /* Failed to add timeout */ diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 2c7df5b..a7b2e8b 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -249,6 +249,28 @@ void fpi_ssm_next_state(fpi_ssm *machine) } } +/** + * fpi_ssm_next_state_timeout_cb: + * @dev: a struct #fp_dev + * @data: a pointer to an #fpi_ssm state machine + * + * Same as fpi_ssm_next_state(), but to be used as a callback + * for an fpi_timeout_add() callback, when the state change needs + * to happen after a timeout. + * + * Make sure to pass the #fpi_ssm as the `user_data` argument + * for that fpi_timeout_add() call. + */ +void +fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, + void *data) +{ + g_return_if_fail (dev != NULL); + g_return_if_fail (data != NULL); + + fpi_ssm_next_state(data); +} + /** * fpi_ssm_jump_to_state: * @machine: an #fpi_ssm state machine diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 63656a9..709928c 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -76,6 +76,7 @@ void fpi_ssm_start_subsm(fpi_ssm *parent, fpi_ssm *child); /* for drivers */ void fpi_ssm_next_state(fpi_ssm *machine); +void fpi_ssm_next_state_timeout_cb(struct fp_dev *dev, void *data); void fpi_ssm_jump_to_state(fpi_ssm *machine, int state); void fpi_ssm_mark_completed(fpi_ssm *machine); void fpi_ssm_mark_failed(fpi_ssm *machine, int error);