device: Deprecate fp_device_{supports,has}_* functions for has_feature

We can avoid having multiple device feature-check functions now and
just rely on a few.

Add uncrustify config to properly handle begin/end deprecation macros.
This commit is contained in:
Marco Trevisan (Treviño) 2021-04-09 22:01:00 +02:00
parent ef805f2341
commit 41f8737b48
11 changed files with 69 additions and 29 deletions

View file

@ -526,7 +526,7 @@ libfprint_demo_window_init (LibfprintDemoWindow *window)
return;
}
if (!fp_device_supports_capture (g_ptr_array_index (devices, 0)))
if (!fp_device_has_feature (g_ptr_array_index (devices, 0), FP_DEVICE_FEATURE_CAPTURE))
{
libfprint_demo_set_mode (window, NOIMAGING_MODE);
return;

View file

@ -76,7 +76,7 @@ on_enroll_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
enroll_data->ret_value = EXIT_SUCCESS;
if (fp_device_has_storage (dev))
if (fp_device_has_feature (dev, FP_DEVICE_FEATURE_STORAGE))
g_debug ("Device has storage, saving a print reference locally");
else
g_debug ("Device has not storage, saving print only locally");

View file

@ -212,7 +212,7 @@ on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
static void
start_identification (FpDevice *dev, IdentifyData *identify_data)
{
if (fp_device_has_storage (dev))
if (fp_device_has_feature (dev, FP_DEVICE_FEATURE_STORAGE))
{
g_print ("Creating finger template, using device storage...\n");
fp_device_list_prints (dev, NULL,
@ -293,7 +293,7 @@ main (void)
return EXIT_FAILURE;
}
if (!fp_device_supports_identify (dev))
if (!fp_device_has_feature (dev, FP_DEVICE_FEATURE_IDENTIFY))
{
g_warning ("Device %s does not support identification.",
fp_device_get_name (dev));

View file

@ -162,7 +162,7 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
if (!fp_device_supports_capture (dev))
if (!fp_device_has_feature (dev, FP_DEVICE_FEATURE_CAPTURE))
{
g_warning ("Device %s doesn't support capture",
fp_device_get_name (dev));

View file

@ -231,7 +231,7 @@ on_device_opened (FpDevice *dev,
return;
}
if (!fp_device_has_storage (dev))
if (!fp_device_has_feature (dev, FP_DEVICE_FEATURE_STORAGE))
{
g_warning ("Device %s doesn't support storage", fp_device_get_name (dev));
g_main_loop_quit (list_data->loop);

View file

@ -260,7 +260,7 @@ start_verification (FpDevice *dev, VerifyData *verify_data)
return;
}
if (fp_device_has_storage (dev))
if (fp_device_has_feature (dev, FP_DEVICE_FEATURE_STORAGE))
{
g_print ("Creating finger template, using device storage...\n");
fp_device_list_prints (dev, NULL,

View file

@ -621,6 +621,7 @@ fp_device_get_nr_enroll_stages (FpDevice *device)
* Check whether the device supports identification.
*
* Returns: Whether the device supports identification
* Deprecated: 1.92.0: Use fp_device_has_feature() instead.
*/
gboolean
fp_device_supports_identify (FpDevice *device)
@ -639,6 +640,7 @@ fp_device_supports_identify (FpDevice *device)
* Check whether the device supports capturing images.
*
* Returns: Whether the device supports image capture
* Deprecated: 1.92.0: Use fp_device_has_feature() instead.
*/
gboolean
fp_device_supports_capture (FpDevice *device)
@ -658,6 +660,7 @@ fp_device_supports_capture (FpDevice *device)
* prints stored on the with fp_device_list_prints() and you should
* always delete prints from the device again using
* fp_device_delete_print().
* Deprecated: 1.92.0: Use fp_device_has_feature() instead.
*/
gboolean
fp_device_has_storage (FpDevice *device)
@ -1073,6 +1076,7 @@ fp_device_identify (FpDevice *device,
{
g_autoptr(GTask) task = NULL;
FpDevicePrivate *priv = fp_device_get_instance_private (device);
FpDeviceClass *cls = FP_DEVICE_GET_CLASS (device);
FpMatchData *data;
int i;
@ -1094,7 +1098,7 @@ fp_device_identify (FpDevice *device,
return;
}
if (!fp_device_supports_identify (device))
if (!cls->identify || !(cls->features & FP_DEVICE_FEATURE_IDENTIFY))
{
g_task_return_error (task,
fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
@ -1121,7 +1125,7 @@ fp_device_identify (FpDevice *device,
// Attach the match data as task data so that it is destroyed
g_task_set_task_data (priv->current_task, data, (GDestroyNotify) match_data_free);
FP_DEVICE_GET_CLASS (device)->identify (device);
cls->identify (device);
}
/**
@ -1352,6 +1356,7 @@ fp_device_list_prints (FpDevice *device,
{
g_autoptr(GTask) task = NULL;
FpDevicePrivate *priv = fp_device_get_instance_private (device);
FpDeviceClass *cls = FP_DEVICE_GET_CLASS (device);
task = g_task_new (device, cancellable, callback, user_data);
if (g_task_return_error_if_cancelled (task))
@ -1371,7 +1376,7 @@ fp_device_list_prints (FpDevice *device,
return;
}
if (!fp_device_has_storage (device))
if (!cls->list || !(cls->features & FP_DEVICE_FEATURE_STORAGE))
{
g_task_return_error (task,
fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
@ -1383,7 +1388,7 @@ fp_device_list_prints (FpDevice *device,
priv->current_task = g_steal_pointer (&task);
maybe_cancel_on_cancelled (device, cancellable);
FP_DEVICE_GET_CLASS (device)->list (device);
cls->list (device);
}
/**

View file

@ -206,10 +206,6 @@ FpDeviceFeature fp_device_get_features (FpDevice *device);
gboolean fp_device_has_feature (FpDevice *device,
FpDeviceFeature feature);
gboolean fp_device_supports_identify (FpDevice *device);
gboolean fp_device_supports_capture (FpDevice *device);
gboolean fp_device_has_storage (FpDevice *device);
/* Opening the device */
void fp_device_open (FpDevice *device,
GCancellable *cancellable,
@ -335,5 +331,12 @@ GPtrArray * fp_device_list_prints_sync (FpDevice *device,
GCancellable *cancellable,
GError **error);
/* Deprecated functions */
G_DEPRECATED_FOR (fp_device_get_features)
gboolean fp_device_supports_identify (FpDevice *device);
G_DEPRECATED_FOR (fp_device_get_features)
gboolean fp_device_supports_capture (FpDevice *device);
G_DEPRECATED_FOR (fp_device_get_features)
gboolean fp_device_has_storage (FpDevice *device);
G_END_DECLS

View file

@ -137,3 +137,7 @@ pos_conditional Trail
# custom keywords
set FOR udev_list_entry_foreach
# macros
macro-open G_GNUC_BEGIN_IGNORE_DEPRECATIONS
macro-close G_GNUC_END_IGNORE_DEPRECATIONS

View file

@ -203,7 +203,9 @@ test_device_supports_identify (void)
fp_device_open_sync (tctx->device, NULL, NULL);
g_assert_true (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_IDENTIFY));
g_assert_true (fp_device_supports_identify (tctx->device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (tctx->device));
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -213,7 +215,9 @@ test_device_supports_capture (void)
fp_device_open_sync (tctx->device, NULL, NULL);
g_assert_true (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_CAPTURE));
g_assert_true (fp_device_supports_capture (tctx->device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_capture (tctx->device));
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@ -223,7 +227,9 @@ test_device_has_storage (void)
fp_device_open_sync (tctx->device, NULL, NULL);
g_assert_false (fp_device_has_feature (tctx->device, FP_DEVICE_FEATURE_STORAGE));
g_assert_false (fp_device_has_storage (tctx->device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_storage (tctx->device));
G_GNUC_END_IGNORE_DEPRECATIONS
}
int

View file

@ -1588,7 +1588,9 @@ test_driver_supports_identify (void)
dev_class->identify = fake_device_stub_identify;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_true (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
}
@ -1601,7 +1603,9 @@ test_driver_do_not_support_identify (void)
dev_class->features &= ~FP_DEVICE_FEATURE_IDENTIFY;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_false (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_false (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
}
@ -1621,7 +1625,9 @@ test_driver_identify (void)
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
g_assert_true (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
match_data->gallery = prints;
@ -1655,7 +1661,9 @@ test_driver_identify_fail (void)
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_assert_true (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
fake_dev->ret_print = make_fake_print (device, NULL);
@ -1692,7 +1700,9 @@ test_driver_identify_retry (void)
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
g_assert_true (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL);
@ -1727,7 +1737,9 @@ test_driver_identify_error (void)
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
g_assert_true (fp_device_supports_identify (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_identify (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_IDENTIFY));
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
@ -1935,7 +1947,9 @@ test_driver_supports_capture (void)
dev_class->capture = fake_device_stub_capture;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_true (fp_device_supports_capture (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_supports_capture (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_CAPTURE));
}
@ -1949,7 +1963,9 @@ test_driver_do_not_support_capture (void)
dev_class->capture = NULL;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_false (fp_device_supports_capture (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_false (fp_device_supports_capture (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_feature (device, FP_DEVICE_FEATURE_CAPTURE));
}
@ -2023,7 +2039,9 @@ test_driver_has_storage (void)
dev_class->features |= FP_DEVICE_FEATURE_STORAGE;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_true (fp_device_has_storage (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_storage (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_true (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE));
}
@ -2036,7 +2054,9 @@ test_driver_has_not_storage (void)
dev_class->features &= ~FP_DEVICE_FEATURE_STORAGE;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_assert_false (fp_device_has_storage (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_storage (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE));
}
@ -2089,7 +2109,9 @@ test_driver_list_no_storage (void)
dev_class->features &= ~FP_DEVICE_FEATURE_STORAGE;
device = auto_close_fake_device_new ();
g_assert_false (fp_device_has_storage (device));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_storage (device));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert_false (fp_device_has_feature (device, FP_DEVICE_FEATURE_STORAGE));
prints = fp_device_list_prints_sync (device, NULL, &error);