fpi-ssm: Take ownership of the SSM when completing it

When a machine is completed, we automatically free it since we can't
consider it valid anymore since this point.

Update the drivers not to free the SSM on completion callback anymore.
This commit is contained in:
Marco Trevisan (Treviño) 2019-11-26 16:18:14 +01:00
parent 876924df6a
commit a855c0cc79
18 changed files with 11 additions and 45 deletions

View file

@ -710,7 +710,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{ {
start_finger_detection (dev); start_finger_detection (dev);
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -774,7 +773,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
if (!error) if (!error)
start_finger_detection (dev); start_finger_detection (dev);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -575,7 +575,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{ {
start_finger_detection (dev); start_finger_detection (dev);
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -806,7 +805,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
if (!error) if (!error)
start_finger_detection (FP_IMAGE_DEVICE (dev)); start_finger_detection (FP_IMAGE_DEVICE (dev));
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -391,7 +391,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{ {
start_finger_detection (dev); start_finger_detection (dev);
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -537,7 +536,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
if (!error) if (!error)
start_finger_detection (dev); start_finger_detection (dev);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -215,7 +215,6 @@ finger_det_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
fp_dbg ("Finger detection completed"); fp_dbg ("Finger detection completed");
fpi_image_device_report_finger_status (dev, TRUE); fpi_image_device_report_finger_status (dev, TRUE);
fpi_ssm_free (ssm);
if (priv->deactivating) if (priv->deactivating)
{ {
@ -466,7 +465,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *device, GError *error)
FpiDeviceAesX660Private *priv = fpi_device_aes_x660_get_instance_private (self); FpiDeviceAesX660Private *priv = fpi_device_aes_x660_get_instance_private (self);
fp_dbg ("Capture completed"); fp_dbg ("Capture completed");
fpi_ssm_free (ssm);
if (priv->deactivating) if (priv->deactivating)
{ {
@ -672,7 +670,6 @@ static void
activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error) activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{ {
fpi_image_device_activate_complete (FP_IMAGE_DEVICE (_dev), error); fpi_image_device_activate_complete (FP_IMAGE_DEVICE (_dev), error);
fpi_ssm_free (ssm);
if (!error) if (!error)
start_finger_detection (FP_IMAGE_DEVICE (_dev)); start_finger_detection (FP_IMAGE_DEVICE (_dev));

View file

@ -479,7 +479,6 @@ stop_capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
G_DEBUG_HERE (); G_DEBUG_HERE ();
fpi_ssm_free (ssm);
/* The device is inactive at this point. */ /* The device is inactive at this point. */
self->dev_state = FP_IMAGE_DEVICE_STATE_INACTIVE; self->dev_state = FP_IMAGE_DEVICE_STATE_INACTIVE;
@ -606,7 +605,6 @@ capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
fpi_image_device_session_error (dev, error); fpi_image_device_session_error (dev, error);
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -789,7 +787,6 @@ calibrate_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
elan_capture (dev); elan_capture (dev);
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -886,7 +883,6 @@ activate_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
fpi_image_device_activate_complete (idev, error); fpi_image_device_activate_complete (idev, error);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -789,7 +789,6 @@ m_exit_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
else else
fp_dbg ("The device is now in idle state"); fp_dbg ("The device is now in idle state");
fpi_image_device_deactivate_complete (idev, error); fpi_image_device_deactivate_complete (idev, error);
fpi_ssm_free (ssm);
} }
static void static void
@ -911,7 +910,6 @@ m_capture_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
g_error_free (error); g_error_free (error);
} }
} }
fpi_ssm_free (ssm);
if (self->is_active == TRUE) if (self->is_active == TRUE)
{ {
@ -1061,7 +1059,6 @@ m_finger_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
self->is_active = FALSE; self->is_active = FALSE;
} }
fpi_ssm_free (ssm);
} }
static void static void
@ -1265,7 +1262,6 @@ m_tunevrb_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
if (!self->is_active) if (!self->is_active)
m_exit_start (idev); m_exit_start (idev);
fpi_ssm_free (ssm);
} }
/* /*
@ -1409,7 +1405,6 @@ m_tunedc_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
if (!self->is_active) if (!self->is_active)
m_exit_start (idev); m_exit_start (idev);
fpi_ssm_free (ssm);
} }
static void static void
@ -1543,7 +1538,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
reset_param (FPI_DEVICE_ETES603 (dev)); reset_param (FPI_DEVICE_ETES603 (dev));
fpi_image_device_session_error (idev, error); fpi_image_device_session_error (idev, error);
} }
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -290,7 +290,6 @@ cmd_ssm_done (FpiSsm *ssm, FpDevice *dev, GError *error)
} }
self->cmd_complete_on_removal = FALSE; self->cmd_complete_on_removal = FALSE;
g_clear_pointer (&self->cmd_complete_error, g_error_free); g_clear_pointer (&self->cmd_complete_error, g_error_free);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -1380,7 +1380,6 @@ loopsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev); FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev);
fpi_ssm_free (ssm);
if (self->deactivating) if (self->deactivating)
{ {
@ -1401,7 +1400,6 @@ initsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev); FpiDeviceUpeksonly *self = FPI_DEVICE_UPEKSONLY (_dev);
fpi_ssm_free (ssm);
fpi_image_device_activate_complete (dev, error); fpi_image_device_activate_complete (dev, error);
if (error) if (error)
return; return;

View file

@ -157,7 +157,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
if (!error) if (!error)
start_finger_detection (dev); start_finger_detection (dev);
fpi_ssm_free (ssm);
} }
@ -345,7 +344,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
else else
start_finger_detection (dev); start_finger_detection (dev);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -389,7 +389,6 @@ capture_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error_arg)
g_autoptr(GError) error = error_arg; g_autoptr(GError) error = error_arg;
fpi_ssm_free (ssm);
/* Note: We assume that the error is a cancellation in the deactivation case */ /* Note: We assume that the error is a cancellation in the deactivation case */
if (self->deactivating) if (self->deactivating)
@ -470,7 +469,6 @@ deactivate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev); FpiDeviceUpektcImg *self = FPI_DEVICE_UPEKTC_IMG (_dev);
fp_dbg ("Deactivate completed"); fp_dbg ("Deactivate completed");
fpi_ssm_free (ssm);
self->deactivating = FALSE; self->deactivating = FALSE;
fpi_image_device_deactivate_complete (dev, error); fpi_image_device_deactivate_complete (dev, error);
@ -601,7 +599,6 @@ activate_sm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{ {
FpImageDevice *dev = FP_IMAGE_DEVICE (_dev); FpImageDevice *dev = FP_IMAGE_DEVICE (_dev);
fpi_ssm_free (ssm);
fpi_image_device_activate_complete (dev, error); fpi_image_device_activate_complete (dev, error);
if (!error) if (!error)

View file

@ -990,7 +990,6 @@ enroll_stop_deinit_cb (FpiSsm *ssm, FpDevice *dev, GError *error)
fp_warn ("Error deinitializing: %s", error->message); fp_warn ("Error deinitializing: %s", error->message);
fpi_device_enroll_complete (dev, data->print, data->error); fpi_device_enroll_complete (dev, data->print, data->error);
fpi_ssm_free (ssm);
} }
static void static void
@ -1217,7 +1216,6 @@ enroll_started (FpiSsm *ssm, FpDevice *dev, GError *error)
else else
enroll_iterate (dev); enroll_iterate (dev);
fpi_ssm_free (ssm);
} }
static void static void
@ -1256,7 +1254,6 @@ verify_stop_deinit_cb (FpiSsm *ssm, FpDevice *dev, GError *error)
fp_warn ("Error deinitializing: %s", error->message); fp_warn ("Error deinitializing: %s", error->message);
fpi_device_verify_complete (dev, data->res, NULL, data->error); fpi_device_verify_complete (dev, data->res, NULL, data->error);
fpi_ssm_free (ssm);
} }
static void static void
@ -1540,7 +1537,6 @@ verify_started (FpiSsm *ssm, FpDevice *dev, GError *error)
upekdev->first_verify_iteration = TRUE; upekdev->first_verify_iteration = TRUE;
verify_iterate (dev); verify_iterate (dev);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -789,7 +789,6 @@ imaging_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
{ {
FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev); FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
fpi_ssm_free (ssm);
/* Report error before exiting imaging loop - the error handler /* Report error before exiting imaging loop - the error handler
* can request state change, which needs to be postponed to end of * can request state change, which needs to be postponed to end of

View file

@ -301,7 +301,6 @@ loopsm_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
FpImageDevice *imgdev = FP_IMAGE_DEVICE (dev); FpImageDevice *imgdev = FP_IMAGE_DEVICE (dev);
FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev); FpDeviceVcom5s *self = FPI_DEVICE_VCOM5S (dev);
fpi_ssm_free (ssm);
g_object_unref (self->capture_img); g_object_unref (self->capture_img);
self->capture_img = NULL; self->capture_img = NULL;
self->loop_running = FALSE; self->loop_running = FALSE;

View file

@ -669,7 +669,6 @@ dev_activate_callback (FpiSsm *ssm, FpDevice *dev, GError *error)
g_error_free (error); g_error_free (error);
} }
fpi_ssm_free (ssm);
} }
/* Activate device */ /* Activate device */
@ -710,7 +709,6 @@ dev_open_callback (FpiSsm *ssm, FpDevice *dev, GError *error)
{ {
/* Notify open complete */ /* Notify open complete */
fpi_image_device_open_complete (FP_IMAGE_DEVICE (dev), error); fpi_image_device_open_complete (FP_IMAGE_DEVICE (dev), error);
fpi_ssm_free (ssm);
} }
/* Open device */ /* Open device */

View file

@ -960,7 +960,6 @@ m_loop_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
self->active = FALSE; self->active = FALSE;
fpi_ssm_free (ssm);
} }
/* Init ssm states */ /* Init ssm states */
@ -1268,7 +1267,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
} }
/* Free sequential state machine */ /* Free sequential state machine */
fpi_ssm_free (ssm);
} }
/* Activate device */ /* Activate device */

View file

@ -168,7 +168,6 @@ m_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
g_error_free (error); g_error_free (error);
} }
/* Free sequential state machine */ /* Free sequential state machine */
fpi_ssm_free (ssm);
} }
/* Exec init sequential state machine */ /* Exec init sequential state machine */
@ -201,7 +200,6 @@ m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
} }
/* Free sequential state machine */ /* Free sequential state machine */
fpi_ssm_free (ssm);
} }
/* Activate device */ /* Activate device */

View file

@ -745,7 +745,6 @@ activate_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
submit_image (ssm, self, dev); submit_image (ssm, self, dev);
fpi_image_device_report_finger_status (dev, FALSE); fpi_image_device_report_finger_status (dev, FALSE);
} }
fpi_ssm_free (ssm);
self->loop_running = FALSE; self->loop_running = FALSE;
@ -793,7 +792,6 @@ open_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
self->init_sequence.receive_buf = NULL; self->init_sequence.receive_buf = NULL;
fpi_image_device_open_complete (dev, error); fpi_image_device_open_complete (dev, error);
fpi_ssm_free (ssm);
} }
static void static void

View file

@ -51,6 +51,7 @@
* *
* To start a ssm, you pass in a completion callback function to fpi_ssm_start() * To start a ssm, you pass in a completion callback function to fpi_ssm_start()
* which gets called when the ssm completes (both on error and on failure). * which gets called when the ssm completes (both on error and on failure).
* Starting a ssm also takes ownership of it.
* *
* To iterate to the next state, call fpi_ssm_next_state(). It is legal to * To iterate to the next state, call fpi_ssm_next_state(). It is legal to
* attempt to iterate beyond the final state - this is equivalent to marking * attempt to iterate beyond the final state - this is equivalent to marking
@ -58,6 +59,7 @@
* *
* To mark successful completion of a SSM, either iterate beyond the final * To mark successful completion of a SSM, either iterate beyond the final
* state or call fpi_ssm_mark_completed() from any state. * state or call fpi_ssm_mark_completed() from any state.
* This will also invalidate the machine, freeing it.
* *
* To mark failed completion of a SSM, call fpi_ssm_mark_failed() from any * To mark failed completion of a SSM, call fpi_ssm_mark_failed() from any
* state. You must pass a non-zero error code. * state. You must pass a non-zero error code.
@ -125,7 +127,6 @@ fpi_ssm_new (FpDevice *dev,
* @ssm_data_destroy: (nullable): #GDestroyNotify for @ssm_data * @ssm_data_destroy: (nullable): #GDestroyNotify for @ssm_data
* *
* Sets @machine's data (freeing the existing data, if any). * Sets @machine's data (freeing the existing data, if any).
*
*/ */
void void
fpi_ssm_set_data (FpiSsm *machine, fpi_ssm_set_data (FpiSsm *machine,
@ -182,12 +183,16 @@ __ssm_call_handler (FpiSsm *machine)
/** /**
* fpi_ssm_start: * fpi_ssm_start:
* @ssm: an #FpiSsm state machine * @ssm: (transfer full): an #FpiSsm state machine
* @callback: the #FpiSsmCompletedCallback callback to call on completion * @callback: the #FpiSsmCompletedCallback callback to call on completion
* *
* Starts a state machine. You can also use this function to restart * Starts a state machine. You can also use this function to restart
* a completed or failed state machine. The @callback will be called * a completed or failed state machine. The @callback will be called
* on completion. * on completion.
*
* Note that @ssm will be stolen when this function is called.
* So that all associated data will be free'ed automatically, after the
* @callback is ran.
*/ */
void void
fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback) fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback)
@ -210,7 +215,6 @@ __subsm_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
fpi_ssm_mark_failed (parent, error); fpi_ssm_mark_failed (parent, error);
else else
fpi_ssm_next_state (parent); fpi_ssm_next_state (parent);
fpi_ssm_free (ssm);
} }
/** /**
@ -253,6 +257,7 @@ fpi_ssm_mark_completed (FpiSsm *machine)
machine->callback (machine, machine->dev, error); machine->callback (machine, machine->dev, error);
} }
fpi_ssm_free (machine);
} }
/** /**
@ -260,7 +265,7 @@ fpi_ssm_mark_completed (FpiSsm *machine)
* @machine: an #FpiSsm state machine * @machine: an #FpiSsm state machine
* @error: a #GError * @error: a #GError
* *
* Mark a state machine as failed with @error as the error code. * Mark a state machine as failed with @error as the error code, completing it.
*/ */
void void
fpi_ssm_mark_failed (FpiSsm *machine, GError *error) fpi_ssm_mark_failed (FpiSsm *machine, GError *error)
@ -305,6 +310,8 @@ fpi_ssm_next_state (FpiSsm *machine)
* @state: the state to jump to * @state: the state to jump to
* *
* Jump to the @state state, bypassing intermediary states. * Jump to the @state state, bypassing intermediary states.
* If @state is the last state, the machine won't be completed unless
* fpi_ssm_mark_completed() isn't explicitly called.
*/ */
void void
fpi_ssm_jump_to_state (FpiSsm *machine, int state) fpi_ssm_jump_to_state (FpiSsm *machine, int state)