diff options
author | Benjamin Berg <bberg@redhat.com> | 2021-12-02 13:44:57 +0100 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2021-12-02 13:54:59 +0100 |
commit | 3981c42d3e26e3cbae808533963d14910b427ca5 (patch) | |
tree | b358f5c087f3b47814611a65d27c54c2f3c646be | |
parent | 31afd3ba5c24974c6030220154a8f93dd85429c2 (diff) |
ssm: Add API to silence most state change debug messages
Otherwise tightly looping SSMs (primarily SPI transfers), will flood the
logs in inappropriate ways.
-rw-r--r-- | doc/libfprint-2-sections.txt | 1 | ||||
-rw-r--r-- | libfprint/fpi-ssm.c | 32 | ||||
-rw-r--r-- | libfprint/fpi-ssm.h | 2 |
3 files changed, 28 insertions, 7 deletions
diff --git a/doc/libfprint-2-sections.txt b/doc/libfprint-2-sections.txt index 91258b6..0fb0cfa 100644 --- a/doc/libfprint-2-sections.txt +++ b/doc/libfprint-2-sections.txt @@ -260,6 +260,7 @@ fpi_ssm_get_device fpi_ssm_get_error fpi_ssm_dup_error fpi_ssm_get_cur_state +fpi_ssm_silence_debug fpi_ssm_spi_transfer_cb fpi_ssm_spi_transfer_with_weak_pointer_cb fpi_ssm_usb_transfer_cb diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c index 8ceab67..c34498a 100644 --- a/libfprint/fpi-ssm.c +++ b/libfprint/fpi-ssm.c @@ -81,6 +81,7 @@ struct _FpiSsm int start_cleanup; int cur_state; gboolean completed; + gboolean silence; GSource *timeout; GError *error; FpiSsmCompletedCallback callback; @@ -245,10 +246,11 @@ fpi_ssm_free (FpiSsm *machine) /* Invoke the state handler */ static void -__ssm_call_handler (FpiSsm *machine) +__ssm_call_handler (FpiSsm *machine, gboolean force_msg) { - fp_dbg ("[%s] %s entering state %d", fp_device_get_driver (machine->dev), - machine->name, machine->cur_state); + if (force_msg || !machine->silence) + fp_dbg ("[%s] %s entering state %d", fp_device_get_driver (machine->dev), + machine->name, machine->cur_state); machine->handler (machine, machine->dev); } @@ -275,7 +277,7 @@ fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback) ssm->cur_state = 0; ssm->completed = FALSE; ssm->error = NULL; - __ssm_call_handler (ssm); + __ssm_call_handler (ssm, TRUE); } static void @@ -346,7 +348,7 @@ fpi_ssm_mark_completed (FpiSsm *machine) if (next_state < machine->nr_states) { machine->cur_state = next_state; - __ssm_call_handler (machine); + __ssm_call_handler (machine, TRUE); return; } @@ -460,7 +462,7 @@ fpi_ssm_next_state (FpiSsm *machine) if (machine->cur_state == machine->nr_states) fpi_ssm_mark_completed (machine); else - __ssm_call_handler (machine); + __ssm_call_handler (machine, FALSE); } void @@ -537,7 +539,7 @@ fpi_ssm_jump_to_state (FpiSsm *machine, int state) if (machine->cur_state == machine->nr_states) fpi_ssm_mark_completed (machine); else - __ssm_call_handler (machine); + __ssm_call_handler (machine, FALSE); } typedef struct @@ -643,6 +645,22 @@ fpi_ssm_dup_error (FpiSsm *machine) } /** + * fpi_ssm_silence_debug: + * @machine: an #FpiSsm state machine + * + * Turn off state change debug messages from this SSM. This does not disable + * all messages, as e.g. the initial state, SSM completion and cleanup states + * are still printed out. + * + * Use if the SSM loops and would flood the debug log otherwise. + */ +void +fpi_ssm_silence_debug (FpiSsm *machine) +{ + machine->silence = TRUE; +} + +/** * fpi_ssm_usb_transfer_cb: * @transfer: a #FpiUsbTransfer * @device: a #FpDevice diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h index 235e84a..d2601c8 100644 --- a/libfprint/fpi-ssm.h +++ b/libfprint/fpi-ssm.h @@ -96,6 +96,8 @@ GError * fpi_ssm_get_error (FpiSsm *machine); GError * fpi_ssm_dup_error (FpiSsm *machine); int fpi_ssm_get_cur_state (FpiSsm *machine); +void fpi_ssm_silence_debug (FpiSsm *machine); + /* Callbacks to be used by the driver instead of implementing their own * logic. */ |