diff --git a/doc/libfprint-2-sections.txt b/doc/libfprint-2-sections.txt index 0fb0cfab..8bda7aa9 100644 --- a/doc/libfprint-2-sections.txt +++ b/doc/libfprint-2-sections.txt @@ -247,6 +247,7 @@ fpi_ssm_new_full fpi_ssm_free fpi_ssm_start fpi_ssm_start_subsm +fpi_ssm_set_critical fpi_ssm_next_state fpi_ssm_next_state_delayed fpi_ssm_jump_to_state diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index c34498ab..215d6540 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -81,6 +81,7 @@ struct _FpiSsm int start_cleanup; int cur_state; gboolean completed; + gboolean critical; gboolean silence; GSource *timeout; GError *error; @@ -277,6 +278,10 @@ fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback) ssm->cur_state = 0; ssm->completed = FALSE; ssm->error = NULL; + + if (ssm->critical) + fpi_device_critical_enter (ssm->dev); + __ssm_call_handler (ssm, TRUE); } @@ -366,6 +371,10 @@ fpi_ssm_mark_completed (FpiSsm *machine) machine->callback (machine, machine->dev, error); } + + if (machine->critical) + fpi_device_critical_leave (machine->dev); + fpi_ssm_free (machine); } @@ -660,6 +669,23 @@ fpi_ssm_silence_debug (FpiSsm *machine) machine->silence = TRUE; } +/** + * fpi_ssm_set_critical: + * @machine: an #FpiSsm state machine + * + * Sets up the SSM to hold a critical section in the driver code. See + * fpi_device_critical_enter() for more details. This is useful if the SSM must + * not be interrupted in order to keep the device in a good state. You can e.g. + * guarantee that an image transfer is completed. + * + * This function must be called before starting the SSM. + */ +void +fpi_ssm_set_critical (FpiSsm *machine) +{ + machine->critical = TRUE; +} + /** * fpi_ssm_usb_transfer_cb: * @transfer: a #FpiUsbTransfer diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index d2601c88..71acaa48 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -97,6 +97,7 @@ GError * fpi_ssm_dup_error (FpiSsm *machine); int fpi_ssm_get_cur_state (FpiSsm *machine); void fpi_ssm_silence_debug (FpiSsm *machine); +void fpi_ssm_set_critical (FpiSsm *machine); /* Callbacks to be used by the driver instead of implementing their own * logic.