diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index a614860..6a02a2c 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 8d45162..704271d 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);