mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 12:23:34 +02:00
device: Add auto-cleanup function to unset the current action
This is useful in the functions where we have to unset the device's current action but we may use early-return to handle multiple conditions such as in open, close and delete functions. The latest also currently is a bit buggy as it won't reset the state on some failures.
This commit is contained in:
24
src/device.c
24
src/device.c
@ -210,6 +210,16 @@ session_data_set_new (FprintDevicePrivate *priv, gchar *sender, gchar *username)
|
|||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef FprintDevice FprintDeviceActionUnset;
|
||||||
|
static void
|
||||||
|
auto_device_action_unset (FprintDeviceActionUnset *self)
|
||||||
|
{
|
||||||
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (self);
|
||||||
|
|
||||||
|
priv->current_action = ACTION_NONE;
|
||||||
|
}
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FprintDeviceActionUnset, auto_device_action_unset);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fprint_device_dispose (GObject *object)
|
fprint_device_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
@ -838,11 +848,12 @@ dev_open_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
|
|
||||||
g_autoptr(SessionData) session = NULL;
|
g_autoptr(SessionData) session = NULL;
|
||||||
g_autoptr(GDBusMethodInvocation) invocation = NULL;
|
g_autoptr(GDBusMethodInvocation) invocation = NULL;
|
||||||
|
g_autoptr(FprintDeviceActionUnset) action_unset = NULL;
|
||||||
|
|
||||||
|
action_unset = rdev;
|
||||||
session = session_data_get (priv);
|
session = session_data_get (priv);
|
||||||
invocation = g_steal_pointer (&session->invocation);
|
invocation = g_steal_pointer (&session->invocation);
|
||||||
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
if (!fp_device_open_finish (dev, res, &error))
|
if (!fp_device_open_finish (dev, res, &error))
|
||||||
{
|
{
|
||||||
g_autoptr(GError) dbus_error = NULL;
|
g_autoptr(GError) dbus_error = NULL;
|
||||||
@ -939,12 +950,13 @@ dev_close_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
|
|
||||||
g_autoptr(SessionData) session = NULL;
|
g_autoptr(SessionData) session = NULL;
|
||||||
g_autoptr(GDBusMethodInvocation) invocation = NULL;
|
g_autoptr(GDBusMethodInvocation) invocation = NULL;
|
||||||
|
g_autoptr(FprintDeviceActionUnset) action_unset = NULL;
|
||||||
|
|
||||||
session = session_data_get (priv);
|
session = session_data_get (priv);
|
||||||
session_data_set_new (priv, NULL, NULL);
|
session_data_set_new (priv, NULL, NULL);
|
||||||
invocation = g_steal_pointer (&session->invocation);
|
invocation = g_steal_pointer (&session->invocation);
|
||||||
|
action_unset = rdev;
|
||||||
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
if (!fp_device_close_finish (dev, res, &error))
|
if (!fp_device_close_finish (dev, res, &error))
|
||||||
{
|
{
|
||||||
g_autoptr(GError) dbus_error = NULL;
|
g_autoptr(GError) dbus_error = NULL;
|
||||||
@ -1822,6 +1834,7 @@ fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
FprintDevice *rdev = FPRINT_DEVICE (dbus_dev);
|
||||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||||
|
|
||||||
|
g_autoptr(FprintDeviceActionUnset) action_unset = NULL;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
g_autofree char *user = NULL;
|
g_autofree char *user = NULL;
|
||||||
const char *sender;
|
const char *sender;
|
||||||
@ -1839,6 +1852,7 @@ fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
priv->current_action = ACTION_DELETE;
|
priv->current_action = ACTION_DELETE;
|
||||||
|
action_unset = rdev;
|
||||||
|
|
||||||
if (!_fprint_device_check_claimed (rdev, invocation, &error))
|
if (!_fprint_device_check_claimed (rdev, invocation, &error))
|
||||||
{
|
{
|
||||||
@ -1872,8 +1886,6 @@ fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_dev,
|
|||||||
if (!opened && fp_device_has_storage (priv->dev))
|
if (!opened && fp_device_has_storage (priv->dev))
|
||||||
fp_device_close_sync (priv->dev, NULL, NULL);
|
fp_device_close_sync (priv->dev, NULL, NULL);
|
||||||
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
|
|
||||||
fprint_dbus_device_complete_delete_enrolled_fingers (dbus_dev,
|
fprint_dbus_device_complete_delete_enrolled_fingers (dbus_dev,
|
||||||
invocation);
|
invocation);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -1888,6 +1900,7 @@ fprint_device_delete_enrolled_fingers2 (FprintDBusDevice *dbus_dev,
|
|||||||
|
|
||||||
g_autoptr(SessionData) session = NULL;
|
g_autoptr(SessionData) session = NULL;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
g_autoptr(FprintDeviceActionUnset) action_unset = NULL;
|
||||||
|
|
||||||
if (!_fprint_device_check_claimed (rdev, invocation, &error))
|
if (!_fprint_device_check_claimed (rdev, invocation, &error))
|
||||||
{
|
{
|
||||||
@ -1902,13 +1915,12 @@ fprint_device_delete_enrolled_fingers2 (FprintDBusDevice *dbus_dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
priv->current_action = ACTION_DELETE;
|
priv->current_action = ACTION_DELETE;
|
||||||
|
action_unset = rdev;
|
||||||
|
|
||||||
session = session_data_get (priv);
|
session = session_data_get (priv);
|
||||||
|
|
||||||
delete_enrolled_fingers (rdev, session->username);
|
delete_enrolled_fingers (rdev, session->username);
|
||||||
|
|
||||||
priv->current_action = ACTION_NONE;
|
|
||||||
|
|
||||||
fprint_dbus_device_complete_delete_enrolled_fingers2 (dbus_dev,
|
fprint_dbus_device_complete_delete_enrolled_fingers2 (dbus_dev,
|
||||||
invocation);
|
invocation);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
Reference in New Issue
Block a user