Blob Blame History Raw
From 370137b97f53cec46750d2c984a3861d306bcb9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Tue, 3 Dec 2019 17:22:20 +0100
Subject: [PATCH 064/181] fpi-ssm: Mark a fpi-ssm completed on delay

---
 libfprint/fpi-ssm.c | 40 ++++++++++++++++++++++++++++++++++++++++
 libfprint/fpi-ssm.h |  3 +++
 2 files changed, 43 insertions(+)

diff --git a/libfprint/fpi-ssm.c b/libfprint/fpi-ssm.c
index 4498ce9..09a31e3 100644
--- a/libfprint/fpi-ssm.c
+++ b/libfprint/fpi-ssm.c
@@ -349,6 +349,46 @@ fpi_ssm_mark_completed (FpiSsm *machine)
   fpi_ssm_free (machine);
 }
 
+static void
+on_device_timeout_complete (FpDevice *dev,
+                            gpointer  user_data)
+{
+  FpiSsm *machine = user_data;
+
+  machine->timeout = NULL;
+  fpi_ssm_mark_completed (machine);
+}
+
+/**
+ * fpi_ssm_mark_completed_delayed:
+ * @machine: an #FpiSsm state machine
+ * @delay: the milliseconds to wait before switching to the next state
+ * @cancellable: (nullable): a #GCancellable to cancel the delayed operation
+ *
+ * Mark a ssm as completed successfully with a delay of @delay ms.
+ * The callback set when creating the state machine with fpi_ssm_new () will be
+ * called when the timeout is over.
+ * The request can be cancelled passing a #GCancellable as @cancellable.
+ */
+void
+fpi_ssm_mark_completed_delayed (FpiSsm       *machine,
+                                int           delay,
+                                GCancellable *cancellable)
+{
+  g_autofree char *source_name = NULL;
+
+  g_return_if_fail (machine != NULL);
+
+  fpi_ssm_set_delayed_action_timeout (machine, delay,
+                                      on_device_timeout_complete, cancellable,
+                                      machine, NULL);
+
+  source_name = g_strdup_printf ("[%s] ssm %p complete %d",
+                                 fp_device_get_device_id (machine->dev),
+                                 machine, machine->cur_state + 1);
+  g_source_set_name (machine->timeout, source_name);
+}
+
 /**
  * fpi_ssm_mark_failed:
  * @machine: an #FpiSsm state machine
diff --git a/libfprint/fpi-ssm.h b/libfprint/fpi-ssm.h
index 8dff27d..3ef653e 100644
--- a/libfprint/fpi-ssm.h
+++ b/libfprint/fpi-ssm.h
@@ -82,6 +82,9 @@ void fpi_ssm_jump_to_state_delayed (FpiSsm       *machine,
                                     GCancellable *cancellable);
 void fpi_ssm_cancel_delayed_state_change (FpiSsm *machine);
 void fpi_ssm_mark_completed (FpiSsm *machine);
+void fpi_ssm_mark_completed_delayed (FpiSsm       *machine,
+                                     int           delay,
+                                     GCancellable *cancellable);
 void fpi_ssm_mark_failed (FpiSsm *machine,
                           GError *error);
 void fpi_ssm_set_data (FpiSsm        *machine,
-- 
2.24.1