virtual-device: Add support for reporting device Retry "errors"

This commit is contained in:
Marco Trevisan (Treviño) 2021-01-24 17:16:48 +01:00
parent 546f35132c
commit f0443ba2f3
3 changed files with 27 additions and 2 deletions

View file

@ -72,6 +72,10 @@ dev_identify (FpDevice *dev)
new_scan, new_scan,
NULL); NULL);
} }
else if (error && error->domain == FP_DEVICE_RETRY)
{
fpi_device_identify_report (dev, NULL, NULL, g_steal_pointer (&error));
}
fpi_device_identify_complete (dev, g_steal_pointer (&error)); fpi_device_identify_complete (dev, g_steal_pointer (&error));
} }

View file

@ -38,6 +38,7 @@ G_DEFINE_TYPE (FpDeviceVirtualDevice, fpi_device_virtual_device, FP_TYPE_DEVICE)
#define REMOVE_CMD_PREFIX "REMOVE " #define REMOVE_CMD_PREFIX "REMOVE "
#define SCAN_CMD_PREFIX "SCAN " #define SCAN_CMD_PREFIX "SCAN "
#define ERROR_CMD_PREFIX "ERROR " #define ERROR_CMD_PREFIX "ERROR "
#define RETRY_CMD_PREFIX "RETRY "
#define LIST_CMD "LIST" #define LIST_CMD "LIST"
@ -111,6 +112,14 @@ process_cmds (FpDeviceVirtualDevice * self,
g_propagate_error (error, g_propagate_error (error,
fpi_device_error_new (g_ascii_strtoull (cmd + strlen (ERROR_CMD_PREFIX), NULL, 10))); fpi_device_error_new (g_ascii_strtoull (cmd + strlen (ERROR_CMD_PREFIX), NULL, 10)));
g_ptr_array_remove_index (self->pending_commands, 0);
return NULL;
}
else if (g_str_has_prefix (cmd, RETRY_CMD_PREFIX))
{
g_propagate_error (error,
fpi_device_retry_new (g_ascii_strtoull (cmd + strlen (RETRY_CMD_PREFIX), NULL, 10)));
g_ptr_array_remove_index (self->pending_commands, 0); g_ptr_array_remove_index (self->pending_commands, 0);
return NULL; return NULL;
} }
@ -302,6 +311,9 @@ dev_verify (FpDevice *dev)
g_debug ("Virtual device scan failed with error: %s", error->message); g_debug ("Virtual device scan failed with error: %s", error->message);
} }
if (error && error->domain == FP_DEVICE_RETRY)
fpi_device_verify_report (dev, FPI_MATCH_ERROR, NULL, g_steal_pointer (&error));
fpi_device_verify_complete (dev, g_steal_pointer (&error)); fpi_device_verify_complete (dev, g_steal_pointer (&error));
} }
@ -337,6 +349,9 @@ dev_enroll (FpDevice *dev)
} }
else else
{ {
if (error && error->domain == FP_DEVICE_RETRY)
fpi_device_enroll_progress (dev, 0, NULL, g_steal_pointer (&error));
else
fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error)); fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error));
} }
} }

View file

@ -93,7 +93,7 @@ class VirtualDevice(unittest.TestCase):
super().tearDown() super().tearDown()
def send_command(self, command, *args): def send_command(self, command, *args):
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR']) self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY'])
with Connection(self.sockaddr) as con: with Connection(self.sockaddr) as con:
params = ' '.join(str(p) for p in args) params = ' '.join(str(p) for p in args)
@ -133,6 +133,8 @@ class VirtualDevice(unittest.TestCase):
self.send_command('SCAN', scan_nick) self.send_command('SCAN', scan_nick)
elif isinstance(scan_nick, FPrint.DeviceError): elif isinstance(scan_nick, FPrint.DeviceError):
self.send_command('ERROR', int(scan_nick)) self.send_command('ERROR', int(scan_nick))
elif isinstance(scan_nick, FPrint.DeviceRetry):
self.send_command('RETRY', int(scan_nick))
def verify_cb(dev, res): def verify_cb(dev, res):
try: try:
@ -186,6 +188,10 @@ class VirtualDevice(unittest.TestCase):
with self.assertRaisesRegex(GLib.Error, r"An unspecified error occurred"): with self.assertRaisesRegex(GLib.Error, r"An unspecified error occurred"):
self.check_verify(matching, FPrint.DeviceError.GENERAL, match=False) self.check_verify(matching, FPrint.DeviceError.GENERAL, match=False)
def test_enroll_verify_retry(self):
with self.assertRaisesRegex(GLib.GError, 'too short'):
self.check_verify(FPrint.Print.new(self.dev),
FPrint.DeviceRetry.TOO_SHORT, match=False)
class VirtualDeviceStorage(VirtualDevice): class VirtualDeviceStorage(VirtualDevice):