From ff798edc51f0f0d2a70fbc2b096174fd9cfba890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 22 Jan 2021 16:02:57 +0100 Subject: [PATCH] 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. --- src/device.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/device.c b/src/device.c index 9c315e5..ddef380 100644 --- a/src/device.c +++ b/src/device.c @@ -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,