Blame SOURCES/0057-fpi-device-Make-possible-to-set-a-DestroyNotify-for-.patch

73b847
From 9f9a94d7a0c18dd62794f0172d3a306d2f38c4fd Mon Sep 17 00:00:00 2001
73b847
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
73b847
Date: Fri, 22 Nov 2019 17:11:29 +0100
73b847
Subject: [PATCH 057/181] fpi-device: Make possible to set a DestroyNotify for
73b847
 timeout data
73b847
73b847
Since GSource data can be automatically cleaned up on source destruction, we
73b847
can mimic this for the devices timeout easily as well.
73b847
73b847
Add an extra parameter, and let's use this cocci file to adapt all the
73b847
drivers like magic:
73b847
73b847
	@@
73b847
	expression e1, e2, e3, e4;
73b847
	@@
73b847
	fpi_device_add_timeout (e1, e2, e3, e4
73b847
	+  , NULL
73b847
  	)
73b847
---
73b847
 libfprint/drivers/elan.c    |  4 ++--
73b847
 libfprint/drivers/uru4000.c |  6 +++---
73b847
 libfprint/drivers/vfs0050.c |  4 ++--
73b847
 libfprint/drivers/vfs101.c  |  2 +-
73b847
 libfprint/drivers/vfs301.c  |  2 +-
73b847
 libfprint/drivers/vfs5011.c |  2 +-
73b847
 libfprint/fp-device.c       | 14 ++++++++------
73b847
 libfprint/fpi-device.h      | 10 +++++-----
73b847
 8 files changed, 23 insertions(+), 21 deletions(-)
73b847
73b847
diff --git a/libfprint/drivers/elan.c b/libfprint/drivers/elan.c
73b847
index e2767dd..f9e8763 100644
73b847
--- a/libfprint/drivers/elan.c
73b847
+++ b/libfprint/drivers/elan.c
73b847
@@ -756,7 +756,7 @@ calibrate_run_state (FpiSsm *ssm, FpDevice *dev)
73b847
             self->calib_status = 0x01;
73b847
           timeout = fpi_device_add_timeout (dev, 50,
73b847
                                             fpi_ssm_next_state_timeout_cb,
73b847
-                                            ssm);
73b847
+                                            ssm, NULL);
73b847
           g_source_set_name (timeout, "calibrate_run_state");
73b847
         }
73b847
       break;
73b847
@@ -1020,7 +1020,7 @@ dev_change_state (FpImageDevice *dev, FpImageDeviceState state)
73b847
         self->dev_state_next = state;
73b847
         timeout = fpi_device_add_timeout (FP_DEVICE (dev), 10,
73b847
                                           elan_change_state_async,
73b847
-                                          NULL);
73b847
+                                          NULL, NULL);
73b847
 
73b847
         name = g_strdup_printf ("dev_change_state to %d", state);
73b847
         g_source_set_name (timeout, name);
73b847
diff --git a/libfprint/drivers/uru4000.c b/libfprint/drivers/uru4000.c
73b847
index 7e28724..1deadd3 100644
73b847
--- a/libfprint/drivers/uru4000.c
73b847
+++ b/libfprint/drivers/uru4000.c
73b847
@@ -875,7 +875,7 @@ rebootpwr_run_state (FpiSsm *ssm, FpDevice *_dev)
73b847
       break;
73b847
 
73b847
     case REBOOTPWR_PAUSE:
73b847
-      fpi_device_add_timeout (_dev, 10, rebootpwr_pause_cb, ssm);
73b847
+      fpi_device_add_timeout (_dev, 10, rebootpwr_pause_cb, ssm, NULL);
73b847
       break;
73b847
     }
73b847
 }
73b847
@@ -971,7 +971,7 @@ powerup_run_state (FpiSsm *ssm, FpDevice *_dev)
73b847
       break;
73b847
 
73b847
     case POWERUP_PAUSE:
73b847
-      fpi_device_add_timeout (_dev, 10, powerup_pause_cb, ssm);
73b847
+      fpi_device_add_timeout (_dev, 10, powerup_pause_cb, ssm, NULL);
73b847
       break;
73b847
 
73b847
     case POWERUP_CHALLENGE_RESPONSE:
73b847
@@ -1130,7 +1130,7 @@ init_run_state (FpiSsm *ssm, FpDevice *_dev)
73b847
       self->scanpwr_irq_timeout = fpi_device_add_timeout (_dev,
73b847
                                                           300,
73b847
                                                           init_scanpwr_timeout,
73b847
-                                                          ssm);
73b847
+                                                          ssm, NULL);
73b847
       break;
73b847
 
73b847
     case INIT_DONE:
73b847
diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c
73b847
index 43252c0..6377639 100644
73b847
--- a/libfprint/drivers/vfs0050.c
73b847
+++ b/libfprint/drivers/vfs0050.c
73b847
@@ -619,7 +619,7 @@ activate_ssm (FpiSsm *ssm, FpDevice *dev)
73b847
 
73b847
       /* Wait for probable vdev->active changing */
73b847
       fpi_device_add_timeout (dev, VFS_SSM_TIMEOUT,
73b847
-                              fpi_ssm_next_state_timeout_cb, ssm);
73b847
+                              fpi_ssm_next_state_timeout_cb, ssm, NULL);
73b847
       break;
73b847
 
73b847
     case SSM_NEXT_RECEIVE:
73b847
@@ -639,7 +639,7 @@ activate_ssm (FpiSsm *ssm, FpDevice *dev)
73b847
     case SSM_WAIT_ANOTHER_SCAN:
73b847
       /* Orange light is on now */
73b847
       fpi_device_add_timeout (dev, VFS_SSM_ORANGE_TIMEOUT,
73b847
-                              another_scan, ssm);
73b847
+                              another_scan, ssm, NULL);
73b847
       break;
73b847
 
73b847
     default:
73b847
diff --git a/libfprint/drivers/vfs101.c b/libfprint/drivers/vfs101.c
73b847
index 5dedab7..0df9b73 100644
73b847
--- a/libfprint/drivers/vfs101.c
73b847
+++ b/libfprint/drivers/vfs101.c
73b847
@@ -376,7 +376,7 @@ async_sleep (unsigned int   msec,
73b847
              FpImageDevice *dev)
73b847
 {
73b847
   fpi_device_add_timeout (FP_DEVICE (dev), msec,
73b847
-                          fpi_ssm_next_state_timeout_cb, ssm);
73b847
+                          fpi_ssm_next_state_timeout_cb, ssm, NULL);
73b847
 }
73b847
 
73b847
 /* Swap ssm states */
73b847
diff --git a/libfprint/drivers/vfs301.c b/libfprint/drivers/vfs301.c
73b847
index 7219792..1d0f066 100644
73b847
--- a/libfprint/drivers/vfs301.c
73b847
+++ b/libfprint/drivers/vfs301.c
73b847
@@ -36,7 +36,7 @@ async_sleep (unsigned int   msec,
73b847
 {
73b847
   /* Add timeout */
73b847
   fpi_device_add_timeout (FP_DEVICE (dev), msec,
73b847
-                          fpi_ssm_next_state_timeout_cb, ssm);
73b847
+                          fpi_ssm_next_state_timeout_cb, ssm, NULL);
73b847
 }
73b847
 
73b847
 static int
73b847
diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c
73b847
index dbf8276..4fac03c 100644
73b847
--- a/libfprint/drivers/vfs5011.c
73b847
+++ b/libfprint/drivers/vfs5011.c
73b847
@@ -706,7 +706,7 @@ activate_loop (FpiSsm *ssm, FpDevice *_dev)
73b847
     case DEV_ACTIVATE_DATA_COMPLETE:
73b847
       fpi_device_add_timeout (_dev, 1,
73b847
                               fpi_ssm_next_state_timeout_cb,
73b847
-                              ssm);
73b847
+                              ssm, NULL);
73b847
 
73b847
       break;
73b847
 
73b847
diff --git a/libfprint/fp-device.c b/libfprint/fp-device.c
73b847
index 0a1f8de..182be51 100644
73b847
--- a/libfprint/fp-device.c
73b847
+++ b/libfprint/fp-device.c
73b847
@@ -1475,7 +1475,8 @@ fpi_device_set_scan_type (FpDevice  *device,
73b847
  * @device: The #FpDevice
73b847
  * @interval: The interval in milliseconds
73b847
  * @func: The #FpTimeoutFunc to call on timeout
73b847
- * @user_data: User data to pass to the callback
73b847
+ * @user_data: (nullable): User data to pass to the callback
73b847
+ * @destroy_notify: (nullable): #GDestroyNotify for @user_data
73b847
  *
73b847
  * Register a timeout to run. Drivers should always make sure that timers are
73b847
  * cancelled when appropriate.
73b847
@@ -1483,10 +1484,11 @@ fpi_device_set_scan_type (FpDevice  *device,
73b847
  * Returns: (transfer none): A newly created and attached #GSource
73b847
  */
73b847
 GSource *
73b847
-fpi_device_add_timeout (FpDevice     *device,
73b847
-                        gint          interval,
73b847
-                        FpTimeoutFunc func,
73b847
-                        gpointer      user_data)
73b847
+fpi_device_add_timeout (FpDevice      *device,
73b847
+                        gint           interval,
73b847
+                        FpTimeoutFunc  func,
73b847
+                        gpointer       user_data,
73b847
+                        GDestroyNotify destroy_notify)
73b847
 {
73b847
   FpDevicePrivate *priv = fp_device_get_instance_private (device);
73b847
   FpDeviceTimeoutSource *source;
73b847
@@ -1497,7 +1499,7 @@ fpi_device_add_timeout (FpDevice     *device,
73b847
   source->user_data = user_data;
73b847
 
73b847
   g_source_attach (&source->source, NULL);
73b847
-  g_source_set_callback (&source->source, (GSourceFunc) func, user_data, NULL);
73b847
+  g_source_set_callback (&source->source, (GSourceFunc) func, user_data, destroy_notify);
73b847
   g_source_set_ready_time (&source->source,
73b847
                            g_source_get_time (&source->source) + interval * (guint64) 1000);
73b847
   priv->sources = g_slist_prepend (priv->sources, source);
73b847
diff --git a/libfprint/fpi-device.h b/libfprint/fpi-device.h
73b847
index d83a5a3..2333ae2 100644
73b847
--- a/libfprint/fpi-device.h
73b847
+++ b/libfprint/fpi-device.h
73b847
@@ -203,11 +203,11 @@ void fpi_device_get_delete_data (FpDevice *device,
73b847
 GCancellable *fpi_device_get_cancellable (FpDevice *device);
73b847
 
73b847
 
73b847
-
73b847
-GSource * fpi_device_add_timeout (FpDevice     *device,
73b847
-                                  gint          interval,
73b847
-                                  FpTimeoutFunc func,
73b847
-                                  gpointer      user_data);
73b847
+GSource * fpi_device_add_timeout (FpDevice      *device,
73b847
+                                  gint           interval,
73b847
+                                  FpTimeoutFunc  func,
73b847
+                                  gpointer       user_data,
73b847
+                                  GDestroyNotify destroy_notify);
73b847
 
73b847
 void fpi_device_set_nr_enroll_stages (FpDevice *device,
73b847
                                       gint      enroll_stages);
73b847
-- 
73b847
2.24.1
73b847