Blame SOURCES/0090-fpi-ssm-Support-named-SSMs-and-use-a-fallback-macro.patch

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