virtual-device: Support all the configured enrolling stages

This commit is contained in:
Marco Trevisan (Treviño) 2021-01-24 02:02:05 +01:00
parent 3d6fb15b5c
commit e8886dbc6b
3 changed files with 51 additions and 11 deletions

View file

@ -78,6 +78,7 @@ struct _FpDeviceVirtualDevice
GHashTable *prints_storage; GHashTable *prints_storage;
guint wait_command_id; guint wait_command_id;
guint enroll_stages_passed;
}; };
/* Not really final here, but we can do this to share the FpDeviceVirtualDevice /* Not really final here, but we can do this to share the FpDeviceVirtualDevice

View file

@ -352,26 +352,55 @@ dev_enroll (FpDevice *dev)
{ {
GVariant *data; GVariant *data;
if (self->enroll_stages_passed == 0)
{
fpi_print_set_type (print, FPI_PRINT_RAW); fpi_print_set_type (print, FPI_PRINT_RAW);
data = g_variant_new_string (id); data = g_variant_new_string (id);
g_object_set (print, "fpi-data", data, NULL); g_object_set (print, "fpi-data", data, NULL);
}
else
{
gboolean changed;
g_object_get (print, "fpi-data", &data, NULL);
changed = !g_str_equal (id, g_variant_get_string (data, NULL));
g_variant_unref (data);
if (changed)
{
g_set_error (&error, FP_DEVICE_RETRY, FP_DEVICE_RETRY_GENERAL, "ID Mismatch");
fpi_device_enroll_progress (dev, self->enroll_stages_passed, NULL, error);
return;
}
}
self->enroll_stages_passed++;
fpi_device_enroll_progress (dev, self->enroll_stages_passed, print, NULL);
if (self->enroll_stages_passed == FP_DEVICE_GET_CLASS (self)->nr_enroll_stages)
{
if (self->prints_storage) if (self->prints_storage)
{ {
g_hash_table_add (self->prints_storage, g_strdup (id));
fpi_print_set_device_stored (print, TRUE); fpi_print_set_device_stored (print, TRUE);
g_hash_table_add (self->prints_storage, g_strdup (id));
} }
fpi_device_enroll_complete (dev, g_object_ref (print), NULL); fpi_device_enroll_complete (dev, g_object_ref (print), NULL);
self->enroll_stages_passed = 0;
}
} }
else else
{ {
if (error && error->domain == FP_DEVICE_RETRY) if (error && error->domain == FP_DEVICE_RETRY)
fpi_device_enroll_progress (dev, 0, NULL, g_steal_pointer (&error)); {
fpi_device_enroll_progress (dev, self->enroll_stages_passed, NULL, g_steal_pointer (&error));
}
else else
{
self->enroll_stages_passed = 0;
fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error)); fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error));
} }
} }
}
static void static void
dev_deinit (FpDevice *dev) dev_deinit (FpDevice *dev)

View file

@ -120,6 +120,10 @@ class VirtualDevice(unittest.TestCase):
print("Enroll done") print("Enroll done")
self._enrolled = dev.enroll_finish(res) self._enrolled = dev.enroll_finish(res)
def progress_cb(dev, stage, pnt, data, error):
self._enroll_stage = stage
self._enroll_progress_error = error
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE) self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
self.send_command('SCAN', nick) self.send_command('SCAN', nick)
@ -128,14 +132,20 @@ class VirtualDevice(unittest.TestCase):
template.set_finger(finger) template.set_finger(finger)
template.set_username(username) template.set_username(username)
self.dev.enroll(template, None, None, tuple(), done_cb) stage = 1
self.dev.enroll(template, callback=done_cb, progress_cb=progress_cb)
while self._enrolled is None: while self._enrolled is None:
ctx.iteration(False) ctx.iteration(False)
if not self._enrolled: if not self._enrolled:
self.assertEqual(self.dev.get_finger_status(), self.assertEqual(self.dev.get_finger_status(),
FPrint.FingerStatusFlags.NEEDED) FPrint.FingerStatusFlags.NEEDED)
self.assertEqual(self._enroll_stage, stage)
self.assertLess(self._enroll_stage, self.dev.get_nr_enroll_stages())
self.send_command('SCAN', nick)
stage += 1
self.assertEqual(self._enroll_stage, self.dev.get_nr_enroll_stages())
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE) self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
self.assertEqual(self._enrolled.get_device_stored(), self.assertEqual(self._enrolled.get_device_stored(),