device: Move duplicated code for stopping a stoppable action into a function

We can handle this in a generic way for all the cancellable cases.
This commit is contained in:
Marco Trevisan (Treviño) 2021-01-22 16:02:57 +01:00
parent 56436fb8b1
commit ff798edc51

View file

@ -1198,6 +1198,23 @@ stoppable_action_completed (FprintDevice *rdev)
g_clear_object (&priv->current_cancellable);
}
static void
stoppable_action_stop (FprintDevice *rdev,
GDBusMethodInvocation *invocation)
{
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
g_assert (priv->current_cancel_invocation == NULL);
priv->current_cancel_invocation = invocation;
/* We return only when the action was cancelled */
if (priv->current_cancellable)
g_cancellable_cancel (priv->current_cancellable);
else
stoppable_action_completed (rdev);
}
static void
match_cb (FpDevice *device,
FpPrint *match,
@ -1457,12 +1474,7 @@ fprint_device_verify_stop (FprintDBusDevice *dbus_dev,
return TRUE;
}
priv->current_cancel_invocation = invocation;
if (priv->current_cancellable)
/* We return only when the action was cancelled */
g_cancellable_cancel (priv->current_cancellable);
else
stoppable_action_completed (rdev);
stoppable_action_stop (rdev, invocation);
return TRUE;
}
@ -1774,15 +1786,11 @@ fprint_device_enroll_stop (FprintDBusDevice *dbus_dev,
return TRUE;
}
priv->current_cancel_invocation = invocation;
if (priv->current_cancellable)
/* We return only when the action was cancelled */
g_cancellable_cancel (priv->current_cancellable);
else
stoppable_action_completed (rdev);
stoppable_action_stop (rdev, invocation);
return TRUE;
}
static gboolean
fprint_device_list_enrolled_fingers (FprintDBusDevice *dbus_dev,
GDBusMethodInvocation *invocation,