mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2025-11-15 07:38:12 +00:00
fpi-device: Add FpiDeviceFeature flags to FpDeviceClass
Allows drivers to define more fine grained features for devices, not strictly depending on assumptions we can make depending on the implemented vfuncs. We keep this per class but could be in theory moved to each instance. In any case, added an utility function to initialize it in the way we can ensure that we've a consistent way for setting them across all the devices.
This commit is contained in:
@@ -1579,4 +1579,7 @@ fpi_device_goodixmoc_class_init (FpiDeviceGoodixMocClass *klass)
|
||||
dev_class->cancel = gx_fp_cancel;
|
||||
dev_class->verify = gx_fp_verify_identify;
|
||||
dev_class->identify = gx_fp_verify_identify;
|
||||
|
||||
fpi_device_class_auto_initialize_features (dev_class);
|
||||
dev_class->features |= FPI_DEVICE_FEATURE_DUPLICATES_CHECK;
|
||||
}
|
||||
|
||||
@@ -1405,4 +1405,6 @@ fpi_device_synaptics_class_init (FpiDeviceSynapticsClass *klass)
|
||||
dev_class->delete = delete_print;
|
||||
dev_class->cancel = cancel;
|
||||
dev_class->list = list;
|
||||
|
||||
fpi_device_class_auto_initialize_features (dev_class);
|
||||
}
|
||||
|
||||
@@ -1555,4 +1555,6 @@ fpi_device_upekts_class_init (FpiDeviceUpektsClass *klass)
|
||||
dev_class->verify = verify;
|
||||
dev_class->enroll = enroll;
|
||||
/* dev_class->cancel = cancel; */
|
||||
|
||||
fpi_device_class_auto_initialize_features (dev_class);
|
||||
}
|
||||
|
||||
@@ -244,4 +244,7 @@ fpi_device_virtual_device_storage_class_init (FpDeviceVirtualDeviceStorageClass
|
||||
dev_class->identify = dev_identify;
|
||||
dev_class->list = dev_list;
|
||||
dev_class->delete = dev_delete;
|
||||
|
||||
fpi_device_class_auto_initialize_features (dev_class);
|
||||
dev_class->features |= FPI_DEVICE_FEATURE_DUPLICATES_CHECK;
|
||||
}
|
||||
|
||||
@@ -776,4 +776,6 @@ fpi_device_virtual_device_class_init (FpDeviceVirtualDeviceClass *klass)
|
||||
dev_class->verify = dev_verify;
|
||||
dev_class->enroll = dev_enroll;
|
||||
dev_class->cancel = dev_cancel;
|
||||
|
||||
fpi_device_class_auto_initialize_features (dev_class);
|
||||
}
|
||||
|
||||
@@ -140,6 +140,8 @@ fp_device_constructed (GObject *object)
|
||||
FpDeviceClass *cls = FP_DEVICE_GET_CLASS (self);
|
||||
FpDevicePrivate *priv = fp_device_get_instance_private (self);
|
||||
|
||||
g_assert (cls->features != FPI_DEVICE_FEATURE_NONE);
|
||||
|
||||
priv->type = cls->type;
|
||||
if (cls->nr_enroll_stages)
|
||||
priv->nr_enroll_stages = cls->nr_enroll_stages;
|
||||
@@ -627,7 +629,7 @@ fp_device_supports_identify (FpDevice *device)
|
||||
|
||||
g_return_val_if_fail (FP_IS_DEVICE (device), FALSE);
|
||||
|
||||
return cls->identify != NULL;
|
||||
return cls->identify && !!(cls->features & FPI_DEVICE_FEATURE_IDENTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,7 +647,7 @@ fp_device_supports_capture (FpDevice *device)
|
||||
|
||||
g_return_val_if_fail (FP_IS_DEVICE (device), FALSE);
|
||||
|
||||
return cls->capture != NULL;
|
||||
return cls->capture && !!(cls->features & FPI_DEVICE_FEATURE_CAPTURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -664,7 +666,7 @@ fp_device_has_storage (FpDevice *device)
|
||||
|
||||
g_return_val_if_fail (FP_IS_DEVICE (device), FALSE);
|
||||
|
||||
return cls->list != NULL;
|
||||
return !!(cls->features & FPI_DEVICE_FEATURE_STORAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1254,6 +1256,7 @@ fp_device_delete_print (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))
|
||||
@@ -1274,7 +1277,7 @@ fp_device_delete_print (FpDevice *device,
|
||||
}
|
||||
|
||||
/* Succeed immediately if delete is not implemented. */
|
||||
if (!FP_DEVICE_GET_CLASS (device)->delete)
|
||||
if (!cls->delete || !(cls->features & FPI_DEVICE_FEATURE_STORAGE_DELETE))
|
||||
{
|
||||
g_task_return_boolean (task, TRUE);
|
||||
return;
|
||||
@@ -1288,7 +1291,7 @@ fp_device_delete_print (FpDevice *device,
|
||||
g_object_ref (enrolled_print),
|
||||
g_object_unref);
|
||||
|
||||
FP_DEVICE_GET_CLASS (device)->delete (device);
|
||||
cls->delete (device);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -220,6 +220,8 @@ fp_image_device_class_init (FpImageDeviceClass *klass)
|
||||
|
||||
fp_device_class->cancel = fp_image_device_cancel_action;
|
||||
|
||||
fpi_device_class_auto_initialize_features (fp_device_class);
|
||||
|
||||
/* Default implementations */
|
||||
klass->activate = fp_image_device_default_activate;
|
||||
klass->deactivate = fp_image_device_default_deactivate;
|
||||
|
||||
@@ -46,6 +46,40 @@ fp_device_get_instance_private (FpDevice *self)
|
||||
g_type_class_get_instance_private_offset (dev_class));
|
||||
}
|
||||
|
||||
/**
|
||||
* fpi_device_class_auto_initialize_features:
|
||||
*
|
||||
* Initializes the #FpDeviceClass @features flags checking what device vfuncs
|
||||
* are implemented.
|
||||
* Drivers should call this at the end of the class initialization.
|
||||
*/
|
||||
void
|
||||
fpi_device_class_auto_initialize_features (FpDeviceClass *device_class)
|
||||
{
|
||||
g_return_if_fail (FP_IS_DEVICE_CLASS (device_class));
|
||||
|
||||
if (device_class->capture)
|
||||
device_class->features |= FPI_DEVICE_FEATURE_CAPTURE;
|
||||
|
||||
if (device_class->verify)
|
||||
device_class->features |= FPI_DEVICE_FEATURE_VERIFY;
|
||||
|
||||
if (device_class->identify)
|
||||
device_class->features |= FPI_DEVICE_FEATURE_IDENTIFY;
|
||||
|
||||
if (device_class->list)
|
||||
{
|
||||
device_class->features |= FPI_DEVICE_FEATURE_STORAGE;
|
||||
device_class->features |= FPI_DEVICE_FEATURE_STORAGE_LIST;
|
||||
}
|
||||
|
||||
if (device_class->delete)
|
||||
{
|
||||
device_class->features |= FPI_DEVICE_FEATURE_STORAGE;
|
||||
device_class->features |= FPI_DEVICE_FEATURE_STORAGE_DELETE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fpi_device_retry_new:
|
||||
* @error: The #FpDeviceRetry error value describing the issue
|
||||
|
||||
@@ -69,6 +69,30 @@ struct _FpIdEntry
|
||||
guint64 driver_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* FpiDeviceFeature:
|
||||
* @FPI_DEVICE_FEATURE_NONE: Device does not support any feature
|
||||
* @FPI_DEVICE_FEATURE_CAPTURE: Supports image capture
|
||||
* @FPI_DEVICE_FEATURE_IDENTIFY: Supports finger identification
|
||||
* @FPI_DEVICE_FEATURE_VERIFY: Supports finger verification
|
||||
* @FPI_DEVICE_FEATURE_STORAGE: Device has a persistent storage
|
||||
* @FPI_DEVICE_FEATURE_STORAGE_LIST: Supports listing the storage templates
|
||||
* @FPI_DEVICE_FEATURE_STORAGE_DELETE: Supports deleting stored templates
|
||||
* @FPI_DEVICE_FEATURE_STORAGE_CLEAR: Supports clearing the whole storage
|
||||
* @FPI_DEVICE_FEATURE_DUPLICATES_CHECK: Natively supports duplicates detection
|
||||
*/
|
||||
typedef enum /*< flags >*/ {
|
||||
FPI_DEVICE_FEATURE_NONE = 0,
|
||||
FPI_DEVICE_FEATURE_CAPTURE = 1 << 0,
|
||||
FPI_DEVICE_FEATURE_IDENTIFY = 1 << 1,
|
||||
FPI_DEVICE_FEATURE_VERIFY = 1 << 2,
|
||||
FPI_DEVICE_FEATURE_STORAGE = 1 << 3,
|
||||
FPI_DEVICE_FEATURE_STORAGE_LIST = 1 << 4,
|
||||
FPI_DEVICE_FEATURE_STORAGE_DELETE = 1 << 5,
|
||||
FPI_DEVICE_FEATURE_STORAGE_CLEAR = 1 << 6,
|
||||
FPI_DEVICE_FEATURE_DUPLICATES_CHECK = 1 << 7,
|
||||
} FpiDeviceFeature;
|
||||
|
||||
/**
|
||||
* FpDeviceClass:
|
||||
* @id: ID string for the driver. Should be a valid C identifier and should
|
||||
@@ -76,6 +100,8 @@ struct _FpIdEntry
|
||||
* @full_name: Human readable description of the driver
|
||||
* @type: The type of driver
|
||||
* @id_table: The table of IDs to bind the driver to
|
||||
* @features: The features the device supports, it can be initialized using
|
||||
* fpi_device_class_auto_initialize_features() on @class_init.
|
||||
* @nr_enroll_stages: The number of enroll stages supported devices need; use
|
||||
* fpi_device_set_nr_enroll_stages() from @probe if this is dynamic.
|
||||
* @scan_type: The scan type of supported devices; use
|
||||
@@ -133,6 +159,7 @@ struct _FpDeviceClass
|
||||
const gchar *full_name;
|
||||
FpDeviceType type;
|
||||
const FpIdEntry *id_table;
|
||||
FpiDeviceFeature features;
|
||||
|
||||
/* Defaults for device properties */
|
||||
gint nr_enroll_stages;
|
||||
@@ -153,6 +180,8 @@ struct _FpDeviceClass
|
||||
void (*cancel) (FpDevice *device);
|
||||
};
|
||||
|
||||
void fpi_device_class_auto_initialize_features (FpDeviceClass *device_class);
|
||||
|
||||
/**
|
||||
* FpTimeoutFunc:
|
||||
* @device: The #FpDevice passed to fpi_device_add_timeout()
|
||||
|
||||
Reference in New Issue
Block a user