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.
This commit is contained in:
Benjamin Berg 2020-01-10 17:10:44 +01:00
parent 4d5c34e11a
commit 829fb9f873
3 changed files with 20 additions and 8 deletions

View file

@ -1341,6 +1341,8 @@ fp_device_enroll_sync (FpDevice *device,
* @device: a #FpDevice * @device: a #FpDevice
* @enrolled_print: a #FpPrint to verify * @enrolled_print: a #FpPrint to verify
* @cancellable: (nullable): a #GCancellable, or %NULL * @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 * @match: (out): Whether the user presented the correct finger
* @print: (out) (transfer full) (nullable): Location to store the scanned print, or %NULL to ignore * @print: (out) (transfer full) (nullable): Location to store the scanned print, or %NULL to ignore
* @error: Return location for errors, or %NULL to ignore * @error: Return location for errors, or %NULL to ignore
@ -1353,6 +1355,8 @@ gboolean
fp_device_verify_sync (FpDevice *device, fp_device_verify_sync (FpDevice *device,
FpPrint *enrolled_print, FpPrint *enrolled_print,
GCancellable *cancellable, GCancellable *cancellable,
FpMatchCb match_cb,
gpointer match_data,
gboolean *match, gboolean *match,
FpPrint **print, FpPrint **print,
GError **error) GError **error)
@ -1364,7 +1368,7 @@ fp_device_verify_sync (FpDevice *device,
fp_device_verify (device, fp_device_verify (device,
enrolled_print, enrolled_print,
cancellable, cancellable,
NULL, NULL, NULL, match_cb, match_data, NULL,
async_result_ready, &task); async_result_ready, &task);
while (!task) while (!task)
g_main_context_iteration (NULL, TRUE); g_main_context_iteration (NULL, TRUE);
@ -1377,6 +1381,8 @@ fp_device_verify_sync (FpDevice *device,
* @device: a #FpDevice * @device: a #FpDevice
* @prints: (element-type FpPrint) (transfer none): #GPtrArray of #FpPrint * @prints: (element-type FpPrint) (transfer none): #GPtrArray of #FpPrint
* @cancellable: (nullable): a #GCancellable, or %NULL * @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 * @match: (out) (transfer full) (nullable): Location for the matched #FpPrint, or %NULL
* @print: (out) (transfer full) (nullable): Location for the new #FpPrint, or %NULL * @print: (out) (transfer full) (nullable): Location for the new #FpPrint, or %NULL
* @error: Return location for errors, or %NULL to ignore * @error: Return location for errors, or %NULL to ignore
@ -1389,6 +1395,8 @@ gboolean
fp_device_identify_sync (FpDevice *device, fp_device_identify_sync (FpDevice *device,
GPtrArray *prints, GPtrArray *prints,
GCancellable *cancellable, GCancellable *cancellable,
FpMatchCb match_cb,
gpointer match_data,
FpPrint **match, FpPrint **match,
FpPrint **print, FpPrint **print,
GError **error) GError **error)
@ -1400,7 +1408,7 @@ fp_device_identify_sync (FpDevice *device,
fp_device_identify (device, fp_device_identify (device,
prints, prints,
cancellable, cancellable,
NULL, NULL, NULL, match_cb, match_data, NULL,
async_result_ready, &task); async_result_ready, &task);
while (!task) while (!task)
g_main_context_iteration (NULL, TRUE); g_main_context_iteration (NULL, TRUE);

View file

@ -261,12 +261,16 @@ FpPrint * fp_device_enroll_sync (FpDevice *device,
gboolean fp_device_verify_sync (FpDevice *device, gboolean fp_device_verify_sync (FpDevice *device,
FpPrint *enrolled_print, FpPrint *enrolled_print,
GCancellable *cancellable, GCancellable *cancellable,
FpMatchCb match_cb,
gpointer match_data,
gboolean *match, gboolean *match,
FpPrint **print, FpPrint **print,
GError **error); GError **error);
gboolean fp_device_identify_sync (FpDevice *device, gboolean fp_device_identify_sync (FpDevice *device,
GPtrArray *prints, GPtrArray *prints,
GCancellable *cancellable, GCancellable *cancellable,
FpMatchCb match_cb,
gpointer match_data,
FpPrint **match, FpPrint **match,
FpPrint **print, FpPrint **print,
GError **error); GError **error);

View file

@ -555,7 +555,7 @@ test_driver_verify (void)
gboolean match; gboolean match;
fake_dev->ret_result = FPI_MATCH_SUCCESS; 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->last_called_function == dev_class->verify);
g_assert (fake_dev->action_data == enrolled_print); g_assert (fake_dev->action_data == enrolled_print);
@ -577,7 +577,7 @@ test_driver_verify_fail (void)
gboolean match; gboolean match;
fake_dev->ret_result = FPI_MATCH_FAIL; 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 (fake_dev->last_called_function == dev_class->verify);
g_assert_no_error (error); g_assert_no_error (error);
@ -599,7 +599,7 @@ test_driver_verify_error (void)
fake_dev->ret_result = FPI_MATCH_ERROR; fake_dev->ret_result = FPI_MATCH_ERROR;
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL); 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 (fake_dev->last_called_function == dev_class->verify);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL); 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)); g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_print = fp_print_new (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->last_called_function == dev_class->identify);
g_assert (fake_dev->action_data == prints); g_assert (fake_dev->action_data == prints);
@ -686,7 +686,7 @@ test_driver_identify_fail (void)
g_assert_true (fp_device_supports_identify (device)); g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_print = fp_print_new (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->last_called_function == dev_class->identify);
g_assert_no_error (error); g_assert_no_error (error);
@ -717,7 +717,7 @@ test_driver_identify_error (void)
g_assert_true (fp_device_supports_identify (device)); g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL); 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 (fake_dev->last_called_function == dev_class->identify);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL); g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);