mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 04:13:33 +02:00
device: Add common stoppable_action_completed function
The stoppable actions (Verify/Enroll) have the same logic during completion. Create a common function to share this logic instead of copying it in each of the handlers. Fixes: #97
This commit is contained in:
committed by
Benjamin Berg
parent
fd02922608
commit
938c1aac5a
93
src/device.c
93
src/device.c
@ -1110,6 +1110,47 @@ can_start_action (FprintDevice *rdev, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stoppable_action_completed (FprintDevice *rdev)
|
||||||
|
{
|
||||||
|
g_autoptr(SessionData) session = NULL;
|
||||||
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||||
|
FprintDBusDevice *dbus_dev = FPRINT_DBUS_DEVICE (rdev);
|
||||||
|
|
||||||
|
session = session_data_get (priv);
|
||||||
|
|
||||||
|
/* Return the cancellation or reset action right away if vanished. */
|
||||||
|
if (priv->current_cancel_invocation)
|
||||||
|
{
|
||||||
|
switch (priv->current_action)
|
||||||
|
{
|
||||||
|
case ACTION_VERIFY:
|
||||||
|
case ACTION_IDENTIFY:
|
||||||
|
fprint_dbus_device_complete_verify_stop (dbus_dev,
|
||||||
|
g_steal_pointer (&priv->current_cancel_invocation));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTION_ENROLL:
|
||||||
|
fprint_dbus_device_complete_enroll_stop (dbus_dev,
|
||||||
|
g_steal_pointer (&priv->current_cancel_invocation));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->current_action = ACTION_NONE;
|
||||||
|
session->verify_status_reported = FALSE;
|
||||||
|
}
|
||||||
|
else if (g_cancellable_is_cancelled (priv->current_cancellable))
|
||||||
|
{
|
||||||
|
priv->current_action = ACTION_NONE;
|
||||||
|
session->verify_status_reported = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_clear_object (&priv->current_cancellable);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
match_cb (FpDevice *device,
|
match_cb (FpDevice *device,
|
||||||
FpPrint *match,
|
FpPrint *match,
|
||||||
@ -1136,10 +1177,8 @@ static void
|
|||||||
verify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
verify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
||||||
{
|
{
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
g_autoptr(SessionData) session = NULL;
|
|
||||||
FprintDevice *rdev = user_data;
|
FprintDevice *rdev = user_data;
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||||
FprintDBusDevice *dbus_dev = FPRINT_DBUS_DEVICE (rdev);
|
|
||||||
gboolean success;
|
gboolean success;
|
||||||
const char *name;
|
const char *name;
|
||||||
gboolean match;
|
gboolean match;
|
||||||
@ -1148,8 +1187,6 @@ verify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
g_assert (!!success == !error);
|
g_assert (!!success == !error);
|
||||||
name = verify_result_to_name (match, error);
|
name = verify_result_to_name (match, error);
|
||||||
|
|
||||||
session = session_data_get (priv);
|
|
||||||
|
|
||||||
g_debug ("verify_cb: result %s", name);
|
g_debug ("verify_cb: result %s", name);
|
||||||
|
|
||||||
/* Automatically restart the operation for retry failures */
|
/* Automatically restart the operation for retry failures */
|
||||||
@ -1175,21 +1212,7 @@ verify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
error->message);
|
error->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the cancellation or reset action right away if vanished. */
|
stoppable_action_completed (rdev);
|
||||||
if (priv->current_cancel_invocation)
|
|
||||||
{
|
|
||||||
fprint_dbus_device_complete_verify_stop (dbus_dev,
|
|
||||||
g_steal_pointer (&priv->current_cancel_invocation));
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
session->verify_status_reported = FALSE;
|
|
||||||
}
|
|
||||||
else if (g_cancellable_is_cancelled (priv->current_cancellable))
|
|
||||||
{
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
session->verify_status_reported = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_clear_object (&priv->current_cancellable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1200,7 +1223,6 @@ identify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
g_autoptr(FpPrint) match = NULL;
|
g_autoptr(FpPrint) match = NULL;
|
||||||
FprintDevice *rdev = user_data;
|
FprintDevice *rdev = user_data;
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||||
FprintDBusDevice *dbus_dev = FPRINT_DBUS_DEVICE (rdev);
|
|
||||||
const char *name;
|
const char *name;
|
||||||
gboolean success;
|
gboolean success;
|
||||||
|
|
||||||
@ -1233,22 +1255,7 @@ identify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
error->message);
|
error->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the cancellation or reset action right away if vanished. */
|
stoppable_action_completed (rdev);
|
||||||
if (priv->current_cancel_invocation)
|
|
||||||
{
|
|
||||||
fprint_dbus_device_complete_verify_stop (dbus_dev,
|
|
||||||
g_steal_pointer (&priv->current_cancel_invocation));
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
}
|
|
||||||
else if (g_cancellable_is_cancelled (priv->current_cancellable))
|
|
||||||
{
|
|
||||||
g_autoptr(SessionData) session = NULL;
|
|
||||||
session = session_data_get (priv);
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
session->verify_status_reported = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_clear_object (&priv->current_cancellable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1545,7 +1552,6 @@ enroll_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
FprintDevice *rdev = user_data;
|
FprintDevice *rdev = user_data;
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||||
FprintDBusDevice *dbus_dev = FPRINT_DBUS_DEVICE (rdev);
|
|
||||||
|
|
||||||
g_autoptr(FpPrint) print = NULL;
|
g_autoptr(FpPrint) print = NULL;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -1593,18 +1599,7 @@ enroll_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
g_warning ("Device reported an error during enroll: %s", error->message);
|
g_warning ("Device reported an error during enroll: %s", error->message);
|
||||||
|
|
||||||
/* Return the cancellation or reset action right away if vanished. */
|
stoppable_action_completed (rdev);
|
||||||
if (priv->current_cancel_invocation)
|
|
||||||
{
|
|
||||||
fprint_dbus_device_complete_enroll_stop (dbus_dev,
|
|
||||||
g_steal_pointer (&priv->current_cancel_invocation));
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
}
|
|
||||||
else if (g_cancellable_is_cancelled (priv->current_cancellable))
|
|
||||||
{
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
}
|
|
||||||
g_clear_object (&priv->current_cancellable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user