Use a source identifier for fb_data_add_timeout

Sun, 13 Mar 2022 22:06:00 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Sun, 13 Mar 2022 22:06:00 -0500
changeset 41295
2f1bed3c4738
parent 41294
3f0b065e58f7
child 41296
05fa2feb07f4

Use a source identifier for fb_data_add_timeout

And have the caller add the timeout itself. This avoids us having to define a
scope for the data parameter.

libpurple/protocols/facebook/data.c file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/data.h file | annotate | diff | comparison | revisions
libpurple/protocols/facebook/facebook.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/facebook/data.c	Sun Mar 13 22:06:00 2022 -0500
+++ b/libpurple/protocols/facebook/data.c	Sun Mar 13 22:06:00 2022 -0500
@@ -288,21 +288,16 @@
 }
 
 void
-fb_data_add_timeout(FbData *fata, const gchar *name, guint interval,
-                    GSourceFunc func, gpointer data)
+fb_data_save_timeout(FbData *fata, const gchar *name, guint id)
 {
 	FbDataPrivate *priv;
-	gchar *key;
-	guint id;
 
 	g_return_if_fail(FB_IS_DATA(fata));
 	priv = fata->priv;
 
 	fb_data_clear_timeout(fata, name, TRUE);
 
-	key = g_strdup(name);
-	id = g_timeout_add_seconds(interval, func, data);
-	g_hash_table_replace(priv->evs, key, GUINT_TO_POINTER(id));
+	g_hash_table_replace(priv->evs, g_strdup(name), GUINT_TO_POINTER(id));
 }
 
 void
--- a/libpurple/protocols/facebook/data.h	Sun Mar 13 22:06:00 2022 -0500
+++ b/libpurple/protocols/facebook/data.h	Sun Mar 13 22:06:00 2022 -0500
@@ -93,20 +93,18 @@
 fb_data_save(FbData *fata);
 
 /**
- * fb_data_add_timeout:
+ * fb_data_save_timeout:
  * @fata: The #FbData.
  * @name: The name of the timeout.
- * @interval: The time, in seconds, between calls to @func.
- * @func: The #GSourceFunc.
- * @data: The data passed to @func.
+ * @id: The source id of the timeout.
  *
- * Adds a new callback timer. The callback is called repeatedly on the
- * basis of @interval, until @func returns #FALSE. The timeout should
- * be cleared with #fb_data_clear_timeout() when no longer needed.
+ * Saves a new callback timer. The callback should be added to the main loop
+ * with `g_timeout_add` or similar, and the returned source identifier passed
+ * to this function. The timeout should be cleared with
+ * #fb_data_clear_timeout() when no longer needed.
  */
 void
-fb_data_add_timeout(FbData *fata, const gchar *name, guint interval,
-                    GSourceFunc func, gpointer data);
+fb_data_save_timeout(FbData *fata, const gchar *name, guint id);
 
 /**
  * fb_data_clear_timeout:
--- a/libpurple/protocols/facebook/facebook.c	Sun Mar 13 22:06:00 2022 -0500
+++ b/libpurple/protocols/facebook/facebook.c	Sun Mar 13 22:06:00 2022 -0500
@@ -213,8 +213,8 @@
 	}
 
 	sync *= 60;
-	fb_data_add_timeout(fata, "sync-contacts", sync, fb_cb_sync_contacts,
-	                    fata);
+	fb_data_save_timeout(fata, "sync-contacts",
+	                     g_timeout_add_seconds(sync, fb_cb_sync_contacts, fata));
 }
 
 static void
@@ -889,7 +889,8 @@
 		/* Use event loop for purple_conversation_has_focus() */
 		name = purple_conversation_get_name(conv);
 		tname = g_strconcat("conv-read-", name, NULL);
-		fb_data_add_timeout(fata, tname, 0, fb_cb_conv_read, conv);
+		fb_data_save_timeout(fata, tname,
+		                     g_timeout_add_seconds(0, fb_cb_conv_read, conv));
 		g_free(tname);
 	}
 }

mercurial