From 829fb9f873a54fdb0caaf9126eb09f0e27e3e2bf Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Fri, 10 Jan 2020 17:10:44 +0100 Subject: [PATCH] device: Add early match reporting to sync API This makes the sync/async APIs more similar again. It also simplifies testing as otherwise we would need the async methods for some tests. --- libfprint/fp-device.c | 12 ++++++++++-- libfprint/fp-device.h | 4 ++++ tests/test-fpi-device.c | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libfprint/fp-device.c b/libfprint/fp-device.c index 3b36ae6c..40b3efa2 100644 --- a/libfprint/fp-device.c +++ b/libfprint/fp-device.c @@ -1341,6 +1341,8 @@ fp_device_enroll_sync (FpDevice *device, * @device: a #FpDevice * @enrolled_print: a #FpPrint to verify * @cancellable: (nullable): a #GCancellable, or %NULL + * @match_cb: (nullable) (scope call): match reporting callback + * @match_data: (closure match_cb): user data for @match_cb * @match: (out): Whether the user presented the correct finger * @print: (out) (transfer full) (nullable): Location to store the scanned print, or %NULL to ignore * @error: Return location for errors, or %NULL to ignore @@ -1353,6 +1355,8 @@ gboolean fp_device_verify_sync (FpDevice *device, FpPrint *enrolled_print, GCancellable *cancellable, + FpMatchCb match_cb, + gpointer match_data, gboolean *match, FpPrint **print, GError **error) @@ -1364,7 +1368,7 @@ fp_device_verify_sync (FpDevice *device, fp_device_verify (device, enrolled_print, cancellable, - NULL, NULL, NULL, + match_cb, match_data, NULL, async_result_ready, &task); while (!task) g_main_context_iteration (NULL, TRUE); @@ -1377,6 +1381,8 @@ fp_device_verify_sync (FpDevice *device, * @device: a #FpDevice * @prints: (element-type FpPrint) (transfer none): #GPtrArray of #FpPrint * @cancellable: (nullable): a #GCancellable, or %NULL + * @match_cb: (nullable) (scope call): match reporting callback + * @match_data: (closure match_cb): user data for @match_cb * @match: (out) (transfer full) (nullable): Location for the matched #FpPrint, or %NULL * @print: (out) (transfer full) (nullable): Location for the new #FpPrint, or %NULL * @error: Return location for errors, or %NULL to ignore @@ -1389,6 +1395,8 @@ gboolean fp_device_identify_sync (FpDevice *device, GPtrArray *prints, GCancellable *cancellable, + FpMatchCb match_cb, + gpointer match_data, FpPrint **match, FpPrint **print, GError **error) @@ -1400,7 +1408,7 @@ fp_device_identify_sync (FpDevice *device, fp_device_identify (device, prints, cancellable, - NULL, NULL, NULL, + match_cb, match_data, NULL, async_result_ready, &task); while (!task) g_main_context_iteration (NULL, TRUE); diff --git a/libfprint/fp-device.h b/libfprint/fp-device.h index 5b7cf86d..69ac5c79 100644 --- a/libfprint/fp-device.h +++ b/libfprint/fp-device.h @@ -261,12 +261,16 @@ FpPrint * fp_device_enroll_sync (FpDevice *device, gboolean fp_device_verify_sync (FpDevice *device, FpPrint *enrolled_print, GCancellable *cancellable, + FpMatchCb match_cb, + gpointer match_data, gboolean *match, FpPrint **print, GError **error); gboolean fp_device_identify_sync (FpDevice *device, GPtrArray *prints, GCancellable *cancellable, + FpMatchCb match_cb, + gpointer match_data, FpPrint **match, FpPrint **print, GError **error); diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c index 6af8eb93..8d4c116a 100644 --- a/tests/test-fpi-device.c +++ b/tests/test-fpi-device.c @@ -555,7 +555,7 @@ test_driver_verify (void) gboolean match; fake_dev->ret_result = FPI_MATCH_SUCCESS; - fp_device_verify_sync (device, enrolled_print, NULL, &match, &out_print, &error); + fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error); g_assert (fake_dev->last_called_function == dev_class->verify); g_assert (fake_dev->action_data == enrolled_print); @@ -577,7 +577,7 @@ test_driver_verify_fail (void) gboolean match; fake_dev->ret_result = FPI_MATCH_FAIL; - fp_device_verify_sync (device, enrolled_print, NULL, &match, &out_print, &error); + fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error); g_assert (fake_dev->last_called_function == dev_class->verify); g_assert_no_error (error); @@ -599,7 +599,7 @@ test_driver_verify_error (void) fake_dev->ret_result = FPI_MATCH_ERROR; fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL); - fp_device_verify_sync (device, enrolled_print, NULL, &match, &out_print, &error); + fp_device_verify_sync (device, enrolled_print, NULL, NULL, NULL, &match, &out_print, &error); g_assert (fake_dev->last_called_function == dev_class->verify); g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL); @@ -658,7 +658,7 @@ test_driver_identify (void) g_assert_true (fp_device_supports_identify (device)); fake_dev->ret_print = fp_print_new (device); - fp_device_identify_sync (device, prints, NULL, &matched_print, &print, &error); + fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error); g_assert (fake_dev->last_called_function == dev_class->identify); g_assert (fake_dev->action_data == prints); @@ -686,7 +686,7 @@ test_driver_identify_fail (void) g_assert_true (fp_device_supports_identify (device)); fake_dev->ret_print = fp_print_new (device); - fp_device_identify_sync (device, prints, NULL, &matched_print, &print, &error); + fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error); g_assert (fake_dev->last_called_function == dev_class->identify); g_assert_no_error (error); @@ -717,7 +717,7 @@ test_driver_identify_error (void) g_assert_true (fp_device_supports_identify (device)); fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL); - fp_device_identify_sync (device, prints, NULL, &matched_print, &print, &error); + fp_device_identify_sync (device, prints, NULL, NULL, NULL, &matched_print, &print, &error); g_assert (fake_dev->last_called_function == dev_class->identify); g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);