fp-print: Use a switch to match the print type

This commit is contained in:
Marco Trevisan (Treviño)
2026-06-19 15:43:45 +02:00
parent 59ecce0a99
commit debc6c601e
+72 -64
View File
@@ -605,18 +605,16 @@ fp_print_equal (FpPrint *self, FpPrint *other)
if (g_strcmp0 (self->device_id, other->device_id)) if (g_strcmp0 (self->device_id, other->device_id))
return FALSE; return FALSE;
if (self->type == FPI_PRINT_RAW) switch (self->type)
{ {
case FPI_PRINT_RAW:
return g_variant_equal (self->data, other->data); return g_variant_equal (self->data, other->data);
}
else if (self->type == FPI_PRINT_NBIS)
{
guint i;
case FPI_PRINT_NBIS:
if (self->prints->len != other->prints->len) if (self->prints->len != other->prints->len)
return FALSE; return FALSE;
for (i = 0; i < self->prints->len; i++) for (guint i = 0; i < self->prints->len; i++)
{ {
struct xyt_struct *a = g_ptr_array_index (self->prints, i); struct xyt_struct *a = g_ptr_array_index (self->prints, i);
struct xyt_struct *b = g_ptr_array_index (other->prints, i); struct xyt_struct *b = g_ptr_array_index (other->prints, i);
@@ -626,11 +624,12 @@ fp_print_equal (FpPrint *self, FpPrint *other)
} }
return TRUE; return TRUE;
}
else case FPI_PRINT_UNDEFINED:
{
g_assert_not_reached (); g_assert_not_reached ();
} }
g_return_val_if_reached (FALSE);
} }
#define FPI_PRINT_VARIANT_TYPE G_VARIANT_TYPE ("(issbymsmsia{sv}v)") #define FPI_PRINT_VARIANT_TYPE G_VARIANT_TYPE ("(issbymsmsia{sv}v)")
@@ -821,72 +820,81 @@ fp_print_deserialize (const guchar *data,
finger = finger_int8; finger = finger_int8;
/* Assume data is valid at this point if the values are somewhat sane. */ /* Assume data is valid at this point if the values are somewhat sane. */
if (type == FPI_PRINT_NBIS) switch (type)
{ {
g_autoptr(GVariant) prints = g_variant_get_child_value (print_data, 0); case FPI_PRINT_NBIS:
guint i; {
g_autoptr(GVariant) prints = g_variant_get_child_value (print_data, 0);
guint i;
result = g_object_new (FP_TYPE_PRINT, result = g_object_new (FP_TYPE_PRINT,
"driver", driver, "driver", driver,
"device-id", device_id, "device-id", device_id,
"device-stored", device_stored, "device-stored", device_stored,
NULL); NULL);
g_object_ref_sink (result); g_object_ref_sink (result);
fpi_print_set_type (result, FPI_PRINT_NBIS); fpi_print_set_type (result, FPI_PRINT_NBIS);
for (i = 0; i < g_variant_n_children (prints); i++) for (i = 0; i < g_variant_n_children (prints); i++)
{ {
g_autofree struct xyt_struct *xyt = NULL; g_autofree struct xyt_struct *xyt = NULL;
const gint32 *xcol, *ycol, *thetacol; const gint32 *xcol, *ycol, *thetacol;
gsize xlen, ylen, thetalen; gsize xlen, ylen, thetalen;
g_autoptr(GVariant) xyt_data = NULL; g_autoptr(GVariant) xyt_data = NULL;
GVariant *child; GVariant *child;
xyt_data = g_variant_get_child_value (prints, i); xyt_data = g_variant_get_child_value (prints, i);
child = g_variant_get_child_value (xyt_data, 0); child = g_variant_get_child_value (xyt_data, 0);
xcol = g_variant_get_fixed_array (child, &xlen, sizeof (gint32)); xcol = g_variant_get_fixed_array (child, &xlen, sizeof (gint32));
g_variant_unref (child); g_variant_unref (child);
child = g_variant_get_child_value (xyt_data, 1); child = g_variant_get_child_value (xyt_data, 1);
ycol = g_variant_get_fixed_array (child, &ylen, sizeof (gint32)); ycol = g_variant_get_fixed_array (child, &ylen, sizeof (gint32));
g_variant_unref (child); g_variant_unref (child);
child = g_variant_get_child_value (xyt_data, 2); child = g_variant_get_child_value (xyt_data, 2);
thetacol = g_variant_get_fixed_array (child, &thetalen, sizeof (gint32)); thetacol = g_variant_get_fixed_array (child, &thetalen, sizeof (gint32));
g_variant_unref (child); g_variant_unref (child);
if (xlen != ylen || xlen != thetalen) if (xlen != ylen || xlen != thetalen)
goto invalid_format; goto invalid_format;
if (xlen > G_N_ELEMENTS (xyt->xcol)) if (xlen > G_N_ELEMENTS (xyt->xcol))
goto invalid_format; goto invalid_format;
xyt = g_new0 (struct xyt_struct, 1); xyt = g_new0 (struct xyt_struct, 1);
xyt->nrows = xlen; xyt->nrows = xlen;
memcpy (xyt->xcol, xcol, sizeof (xcol[0]) * xlen); memcpy (xyt->xcol, xcol, sizeof (xcol[0]) * xlen);
memcpy (xyt->ycol, ycol, sizeof (xcol[0]) * xlen); memcpy (xyt->ycol, ycol, sizeof (xcol[0]) * xlen);
memcpy (xyt->thetacol, thetacol, sizeof (xcol[0]) * xlen); memcpy (xyt->thetacol, thetacol, sizeof (xcol[0]) * xlen);
g_ptr_array_add (result->prints, g_steal_pointer (&xyt)); g_ptr_array_add (result->prints, g_steal_pointer (&xyt));
} }
} }
else if (type == FPI_PRINT_RAW) break;
{
g_autoptr(GVariant) fp_data = g_variant_get_child_value (print_data, 0);
result = g_object_new (FP_TYPE_PRINT, case FPI_PRINT_RAW:
"fpi-type", type, {
"driver", driver, g_autoptr(GVariant) fp_data = g_variant_get_child_value (print_data, 0);
"device-id", device_id,
"device-stored", device_stored, result = g_object_new (FP_TYPE_PRINT,
"fpi-data", fp_data, "fpi-type", type,
NULL); "driver", driver,
g_object_ref_sink (result); "device-id", device_id,
} "device-stored", device_stored,
else "fpi-data", fp_data,
{ NULL);
g_warning ("Invalid print type: 0x%X", type); g_object_ref_sink (result);
goto invalid_format; }
break;
case FPI_PRINT_UNDEFINED:
{
g_autofree char *type_str = g_enum_to_string (fpi_print_type_get_type (), type);
g_warning ("Invalid print type: 0x%X (%s)", type, type_str);
goto invalid_format;
}
} }
date = g_date_new_julian (julian_date); date = g_date_new_julian (julian_date);