From 8f3b48e261a50304cde13a74c4a81515b59e6013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 2 Mar 2021 16:01:46 +0100 Subject: [PATCH] device: Add utility function to load all user prints We may want to be able to load the user prints to check whether they are usable, so add an utility function for this. And use it also in load_all_prints(). --- src/device.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/device.c b/src/device.c index df7c868..1d317c7 100644 --- a/src/device.c +++ b/src/device.c @@ -1081,11 +1081,39 @@ fprint_device_release (FprintDBusDevice *dbus_dev, } /* NOTE: This should probably be moved to the storage layer. */ +static GPtrArray * +load_user_prints (FprintDevice *rdev, + const char *username) +{ + g_autoptr(GPtrArray) res = g_ptr_array_new_with_free_func (g_object_unref); + g_autoptr(GSList) fingers = NULL; + FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev); + GSList *l; + + fingers = store.discover_prints (priv->dev, username); + + for (l = fingers; l; l = l->next) + { + g_autoptr(FpPrint) print = NULL; + + store.print_data_load (priv->dev, + GPOINTER_TO_UINT (l->data), + username, + &print); + + if (!print) + continue; + + g_ptr_array_add (res, g_steal_pointer (&print)); + } + + return g_steal_pointer (&res); +} + static GPtrArray * load_all_prints (FprintDevice *rdev) { g_autoptr(GPtrArray) res = g_ptr_array_new_with_free_func (g_object_unref); - FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev); GSList *user, *users = NULL; users = store.discover_users (); @@ -1093,25 +1121,9 @@ load_all_prints (FprintDevice *rdev) for (user = users; user; user = user->next) { const char *username = user->data; - g_autoptr(GSList) fingers = NULL; - GSList *finger; + g_autoptr(GPtrArray) prints = load_user_prints (rdev, username); - fingers = store.discover_prints (priv->dev, username); - - for (finger = fingers; finger; finger = finger->next) - { - g_autoptr(FpPrint) print = NULL; - - store.print_data_load (priv->dev, - GPOINTER_TO_UINT (finger->data), - username, - &print); - - if (!print) - continue; - - g_ptr_array_add (res, g_steal_pointer (&print)); - } + g_ptr_array_extend_and_steal (res, g_steal_pointer (&prints)); } g_slist_free_full (users, g_free);