device: Use a switch to check current action so we can be more selective

For example we were allowing to verify stop while doing other actions
different from enrolling (such as delete or open/close).
This commit is contained in:
Marco Trevisan (Treviño)
2020-12-03 21:58:17 +01:00
committed by Benjamin Berg
parent c5c81a2ea8
commit 2ca2d5e62c

View File

@ -1101,16 +1101,20 @@ static gboolean fprint_device_verify_start (FprintDBusDevice *dbus_dev,
session = session_data_get (priv); session = session_data_get (priv);
if (priv->current_action != ACTION_NONE) { switch (priv->current_action) {
if (priv->current_action == ACTION_ENROLL) { case ACTION_NONE:
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, break;
"Enrollment in progress"); case ACTION_VERIFY:
} else { case ACTION_IDENTIFY:
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, g_dbus_method_invocation_return_error_literal (
"Verification already in progress"); invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
} "Verification already in progress");
g_dbus_method_invocation_return_gerror (invocation, error); return TRUE;
return TRUE; default:
g_dbus_method_invocation_return_error_literal (
invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Another operation is already in progress");
return TRUE;
} }
if (finger_num == -1) { if (finger_num == -1) {
@ -1202,18 +1206,22 @@ static gboolean fprint_device_verify_stop (FprintDBusDevice *dbus_dev,
return TRUE; return TRUE;
} }
if (priv->current_action == ACTION_NONE) { switch (priv->current_action) {
g_dbus_method_invocation_return_error_literal (invocation, case ACTION_VERIFY:
FPRINT_ERROR, case ACTION_IDENTIFY:
FPRINT_ERROR_NO_ACTION_IN_PROGRESS, break;
"No verification in progress"); case ACTION_NONE:
return TRUE; g_dbus_method_invocation_return_error_literal (
} else if (priv->current_action == ACTION_ENROLL) { invocation, FPRINT_ERROR,
g_dbus_method_invocation_return_error_literal (invocation, FPRINT_ERROR_NO_ACTION_IN_PROGRESS,
FPRINT_ERROR, "No verification in progress");
FPRINT_ERROR_ALREADY_IN_USE, return TRUE;
"Enrollment in progress"); default:
return TRUE; g_dbus_method_invocation_return_error_literal (
invocation, FPRINT_ERROR,
FPRINT_ERROR_ALREADY_IN_USE,
"Another operation is already in progress");
return TRUE;
} }
if (priv->current_cancellable) { if (priv->current_cancellable) {
@ -1423,16 +1431,19 @@ static gboolean fprint_device_enroll_start (FprintDBusDevice *dbus_dev,
return TRUE; return TRUE;
} }
if (priv->current_action != ACTION_NONE) { switch (priv->current_action) {
if (priv->current_action == ACTION_ENROLL) { case ACTION_NONE:
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, break;
"Enrollment already in progress"); case ACTION_ENROLL:
} else { g_dbus_method_invocation_return_error_literal (
g_set_error(&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Verification in progress"); "Enrollment already in progress");
} return TRUE;
g_dbus_method_invocation_return_gerror (invocation, error); default:
return TRUE; g_dbus_method_invocation_return_error_literal (
invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Another operation is already in progress");
return TRUE;
} }
g_debug("start enrollment device %d finger %d", priv->id, finger_num); g_debug("start enrollment device %d finger %d", priv->id, finger_num);
@ -1467,20 +1478,21 @@ static gboolean fprint_device_enroll_stop (FprintDBusDevice *dbus_dev,
return TRUE; return TRUE;
} }
if (priv->current_action != ACTION_ENROLL) { switch (priv->current_action) {
if (priv->current_action == ACTION_NONE) { case ACTION_ENROLL:
g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_NO_ACTION_IN_PROGRESS, break;
"No enrollment in progress"); case ACTION_NONE:
} else if (priv->current_action == ACTION_VERIFY) { g_dbus_method_invocation_return_error_literal (
g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, invocation, FPRINT_ERROR,
"Verification in progress"); FPRINT_ERROR_NO_ACTION_IN_PROGRESS,
} else if (priv->current_action == ACTION_IDENTIFY) { "No enrollment in progress");
g_set_error (&error, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE, return TRUE;
"Identification in progress"); default:
} else g_dbus_method_invocation_return_error_literal (
g_assert_not_reached (); invocation, FPRINT_ERROR,
g_dbus_method_invocation_return_gerror (invocation, error); FPRINT_ERROR_ALREADY_IN_USE,
return TRUE; "Another operation is already in progress");
return TRUE;
} }
if (priv->current_cancellable) { if (priv->current_cancellable) {
@ -1632,12 +1644,19 @@ static gboolean fprint_device_delete_enrolled_fingers (FprintDBusDevice *dbus_de
log_offending_client (invocation); log_offending_client (invocation);
#endif #endif
if (priv->current_action != ACTION_NONE) { switch (priv->current_action) {
g_dbus_method_invocation_return_error_literal (invocation, case ACTION_NONE:
FPRINT_ERROR, break;
FPRINT_ERROR_ALREADY_IN_USE, case ACTION_DELETE:
"Another operation is already in progress"); g_dbus_method_invocation_return_error_literal (
return TRUE; invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Deletion already in progress");
return TRUE;
default:
g_dbus_method_invocation_return_error_literal (
invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Another operation is already in progress");
return TRUE;
} }
priv->current_action = ACTION_DELETE; priv->current_action = ACTION_DELETE;
@ -1690,13 +1709,19 @@ static gboolean fprint_device_delete_enrolled_fingers2 (FprintDBusDevice *dbus_d
return TRUE; return TRUE;
} }
if (priv->current_action != ACTION_NONE) { switch (priv->current_action) {
g_dbus_method_invocation_return_error_literal (invocation, case ACTION_NONE:
FPRINT_ERROR, break;
FPRINT_ERROR_ALREADY_IN_USE, case ACTION_DELETE:
"Another operation is already in progress"); g_dbus_method_invocation_return_error_literal (
g_dbus_method_invocation_return_gerror (invocation, error); invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
return TRUE; "Deletion already in progress");
return TRUE;
default:
g_dbus_method_invocation_return_error_literal (
invocation, FPRINT_ERROR, FPRINT_ERROR_ALREADY_IN_USE,
"Another operation is already in progress");
return TRUE;
} }
priv->current_action = ACTION_DELETE; priv->current_action = ACTION_DELETE;