169 lines
6.5 KiB
Diff
169 lines
6.5 KiB
Diff
From 3dcd18da12dfdcd2f0da01c4099dac91c80b16ea Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
|
|
Date: Wed, 4 Dec 2019 20:03:23 +0100
|
|
Subject: [PATCH 090/181] fpi-ssm: Support named SSMs and use a fallback macro
|
|
|
|
Add fpi_ssm_new_full() that allows to pass a name to the state-machine
|
|
constructor, not to change all the drivers, provide a fpi_ssm_new() macro
|
|
that stringifies the nr_parameters value (usually an enum value) as the name
|
|
so that we can use it for better debugging.
|
|
---
|
|
doc/libfprint-sections.txt | 1 +
|
|
libfprint/fpi-ssm.c | 43 +++++++++++++++++++++++++++-----------
|
|
libfprint/fpi-ssm.h | 9 +++++---
|
|
3 files changed, 38 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/doc/libfprint-sections.txt b/doc/libfprint-sections.txt
|
|
index 9fb01bd..9e17f8e 100644
|
|
--- a/doc/libfprint-sections.txt
|
|
+++ b/doc/libfprint-sections.txt
|
|
@@ -211,6 +211,7 @@ fpi_print_bz3_match
|
|
FpiSsmCompletedCallback
|
|
FpiSsmHandlerCallback
|
|
fpi_ssm_new
|
|
+fpi_ssm_new_full
|
|
fpi_ssm_free
|
|
fpi_ssm_start
|
|
fpi_ssm_start_subsm
|
|
diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c
|
|
index 09a31e3..96336e1 100644
|
|
--- a/libfprint/fpi-ssm.c
|
|
+++ b/libfprint/fpi-ssm.c
|
|
@@ -81,6 +81,7 @@
|
|
struct _FpiSsm
|
|
{
|
|
FpDevice *dev;
|
|
+ const char *name;
|
|
FpiSsm *parentsm;
|
|
gpointer ssm_data;
|
|
GDestroyNotify ssm_data_destroy;
|
|
@@ -103,13 +104,29 @@ struct _FpiSsm
|
|
*
|
|
* Allocate a new ssm, with @nr_states states. The @handler callback
|
|
* will be called after each state transition.
|
|
+ * This is a macro that calls fpi_ssm_new_full() using the stringified
|
|
+ * version of @nr_states, so will work better with named parameters.
|
|
+ *
|
|
+ * Returns: a new #FpiSsm state machine
|
|
+ */
|
|
+
|
|
+/**
|
|
+ * fpi_ssm_new_full:
|
|
+ * @dev: a #fp_dev fingerprint device
|
|
+ * @handler: the callback function
|
|
+ * @nr_states: the number of states
|
|
+ * @name: the name of the state machine (for debug purposes)
|
|
+ *
|
|
+ * Allocate a new ssm, with @nr_states states. The @handler callback
|
|
+ * will be called after each state transition.
|
|
*
|
|
* Returns: a new #FpiSsm state machine
|
|
*/
|
|
FpiSsm *
|
|
-fpi_ssm_new (FpDevice *dev,
|
|
- FpiSsmHandlerCallback handler,
|
|
- int nr_states)
|
|
+fpi_ssm_new_full (FpDevice *dev,
|
|
+ FpiSsmHandlerCallback handler,
|
|
+ int nr_states,
|
|
+ const char *name)
|
|
{
|
|
FpiSsm *machine;
|
|
|
|
@@ -120,6 +137,7 @@ fpi_ssm_new (FpDevice *dev,
|
|
machine->handler = handler;
|
|
machine->nr_states = nr_states;
|
|
machine->dev = dev;
|
|
+ machine->name = g_strdup (name);
|
|
machine->completed = TRUE;
|
|
return machine;
|
|
}
|
|
@@ -251,6 +269,7 @@ fpi_ssm_free (FpiSsm *machine)
|
|
if (machine->ssm_data_destroy)
|
|
g_clear_pointer (&machine->ssm_data, machine->ssm_data_destroy);
|
|
g_clear_pointer (&machine->error, g_error_free);
|
|
+ g_clear_pointer (&machine->name, g_free);
|
|
fpi_ssm_clear_delayed_action (machine);
|
|
g_free (machine);
|
|
}
|
|
@@ -259,7 +278,7 @@ fpi_ssm_free (FpiSsm *machine)
|
|
static void
|
|
__ssm_call_handler (FpiSsm *machine)
|
|
{
|
|
- fp_dbg ("%p entering state %d", machine, machine->cur_state);
|
|
+ fp_dbg ("%s entering state %d", machine->name, machine->cur_state);
|
|
machine->handler (machine, machine->dev);
|
|
}
|
|
|
|
@@ -337,9 +356,9 @@ fpi_ssm_mark_completed (FpiSsm *machine)
|
|
machine->completed = TRUE;
|
|
|
|
if (machine->error)
|
|
- fp_dbg ("%p completed with error: %s", machine, machine->error->message);
|
|
+ fp_dbg ("%s completed with error: %s", machine->name, machine->error->message);
|
|
else
|
|
- fp_dbg ("%p completed successfully", machine);
|
|
+ fp_dbg ("%s completed successfully", machine->name);
|
|
if (machine->callback)
|
|
{
|
|
GError *error = machine->error ? g_error_copy (machine->error) : NULL;
|
|
@@ -383,9 +402,9 @@ fpi_ssm_mark_completed_delayed (FpiSsm *machine,
|
|
on_device_timeout_complete, cancellable,
|
|
machine, NULL);
|
|
|
|
- source_name = g_strdup_printf ("[%s] ssm %p complete %d",
|
|
+ source_name = g_strdup_printf ("[%s] ssm %s complete %d",
|
|
fp_device_get_device_id (machine->dev),
|
|
- machine, machine->cur_state + 1);
|
|
+ machine->name, machine->cur_state + 1);
|
|
g_source_set_name (machine->timeout, source_name);
|
|
}
|
|
|
|
@@ -482,9 +501,9 @@ fpi_ssm_next_state_delayed (FpiSsm *machine,
|
|
on_device_timeout_next_state, cancellable,
|
|
machine, NULL);
|
|
|
|
- source_name = g_strdup_printf ("[%s] ssm %p jump to next state %d",
|
|
+ source_name = g_strdup_printf ("[%s] ssm %s jump to next state %d",
|
|
fp_device_get_device_id (machine->dev),
|
|
- machine, machine->cur_state + 1);
|
|
+ machine->name, machine->cur_state + 1);
|
|
g_source_set_name (machine->timeout, source_name);
|
|
}
|
|
|
|
@@ -559,9 +578,9 @@ fpi_ssm_jump_to_state_delayed (FpiSsm *machine,
|
|
on_device_timeout_jump_to_state,
|
|
cancellable, data, g_free);
|
|
|
|
- source_name = g_strdup_printf ("[%s] ssm %p jump to state %d",
|
|
+ source_name = g_strdup_printf ("[%s] ssm %s jump to state %d",
|
|
fp_device_get_device_id (machine->dev),
|
|
- machine, state);
|
|
+ machine->name, state);
|
|
g_source_set_name (machine->timeout, source_name);
|
|
}
|
|
|
|
diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h
|
|
index 3ef653e..d1334b5 100644
|
|
--- a/libfprint/fpi-ssm.h
|
|
+++ b/libfprint/fpi-ssm.h
|
|
@@ -60,9 +60,12 @@ typedef void (*FpiSsmHandlerCallback)(FpiSsm *ssm,
|
|
FpDevice *dev);
|
|
|
|
/* for library and drivers */
|
|
-FpiSsm *fpi_ssm_new (FpDevice *dev,
|
|
- FpiSsmHandlerCallback handler,
|
|
- int nr_states);
|
|
+#define fpi_ssm_new(dev, handler, nr_states) \
|
|
+ fpi_ssm_new_full (dev, handler, nr_states, #nr_states)
|
|
+FpiSsm *fpi_ssm_new_full (FpDevice *dev,
|
|
+ FpiSsmHandlerCallback handler,
|
|
+ int nr_states,
|
|
+ const char *machine_name);
|
|
void fpi_ssm_free (FpiSsm *machine);
|
|
void fpi_ssm_start (FpiSsm *ssm,
|
|
FpiSsmCompletedCallback callback);
|
|
--
|
|
2.24.1
|
|
|