From 65d0d5e3e0884369687cd6214a76e167d3e1a1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 27 Nov 2019 19:36:24 +0100 Subject: [PATCH] fpi-ssm: Add a usb transfer callback with data as weak pointer Allow to pass a double-pointer to be nullified as the transfer data in order to mark it as NULL when the transfer is done. This is useful if we're keeping the transfer around in order to check that no one is currently running. --- libfprint/fpi-ssm.c | 29 +++++++++++++++++++++++++++++ libfprint/fpi-ssm.h | 6 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index a614860d..6a02a2c7 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -413,3 +413,32 @@ fpi_ssm_usb_transfer_cb (FpiUsbTransfer *transfer, FpDevice *device, else fpi_ssm_next_state (transfer->ssm); } + +/** + * fpi_ssm_usb_transfer_with_weak_pointer_cb: + * @transfer: a #FpiUsbTransfer + * @device: a #FpDevice + * @weak_ptr: A #gpointer pointer to nullify. You can pass a pointer to any + * #gpointer to nullify when the callback is completed. I.e a + * pointer to the current #FpiUsbTransfer. + * @error: The #GError or %NULL + * + * Can be used in as a #FpiUsbTransfer callback handler to automatically + * advance or fail a statemachine on transfer completion. + * Passing a #gpointer* as @weak_ptr permits to nullify it once we're done + * with the transfer. + * + * Make sure to set the #FpiSsm on the transfer. + */ +void +fpi_ssm_usb_transfer_with_weak_pointer_cb (FpiUsbTransfer *transfer, + FpDevice *device, gpointer weak_ptr, + GError *error) +{ + g_return_if_fail (transfer->ssm); + + if (weak_ptr) + g_nullify_pointer ((gpointer *) weak_ptr); + + fpi_ssm_usb_transfer_cb (transfer, device, weak_ptr, error); +} diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 8d45162f..704271d4 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -91,5 +91,9 @@ void fpi_ssm_next_state_timeout_cb (FpDevice *dev, void *data); void fpi_ssm_usb_transfer_cb (FpiUsbTransfer *transfer, FpDevice *device, - gpointer user_data, + gpointer user_date, GError *error); +void fpi_ssm_usb_transfer_with_weak_pointer_cb (FpiUsbTransfer *transfer, + FpDevice *device, + gpointer weak_ptr, + GError *error);