From 00ab83b8e8909cdaad4af57e33db4ed2b4fc6d93 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 18 Jun 2007 16:55:50 +0000 Subject: [PATCH] Add full variant to the approximate timeout functiont The g_timeout_add_seconds() API lacks a _full() counterpart, allowing the setting of a destroy notification function to be invoked when the timeout source is removed. This patch adds g_timeout_add_seconds_full() to the public API and reimplements g_timeout_add_seconds() as a call to g_timeout_add_seconds_full(). svn path=/trunk/; revision=5575 --- ChangeLog | 8 +++++ docs/reference/ChangeLog | 4 +++ docs/reference/glib/glib-sections.txt | 1 + glib/glib.symbols | 1 + glib/gmain.c | 59 ++++++++++++++++++++++++++++------- glib/gmain.h | 57 ++++++++++++++++++--------------- 6 files changed, 92 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index d10b989..ffbee90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-06-18 Emmanuele Bassi + + * glib/gmain.h: + * glib/gmain.c: + * glib/glib.symbols: Add g_timeout_add_seconds_full() variant + to g_timeout_add_seconds(), accepting a destroy notification + function and a priority. (#448819) + 2007-06-17 Matthias Clasen * glib/gutils (g_get_current_dir): Prevent segfaults on diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f0be2ad..b7ff369 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2007-06-18 Emmanuele Bassi + + * glib/glib-sections.txt: Add g_timeout_add_seconds_full(). + 2007-06-17 Behdad Esfahbod * glib/tmpl/quarks.sgml: diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 4de9920..3fa118c 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -442,6 +442,7 @@ g_timeout_source_new_seconds g_timeout_add g_timeout_add_full g_timeout_add_seconds +g_timeout_add_seconds_full g_idle_source_new diff --git a/glib/glib.symbols b/glib/glib.symbols index a0645e4..5434e24 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -622,6 +622,7 @@ g_idle_source_new g_timeout_add g_timeout_add_seconds g_timeout_add_full +g_timeout_add_seconds_full g_timeout_source_new g_timeout_source_new_seconds #endif diff --git a/glib/gmain.c b/glib/gmain.c index bb0b305..1653a5b 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -3560,13 +3560,13 @@ g_timeout_source_new_seconds (guint interval) /** * g_timeout_add_full: - * @priority: the priority of the idle source. Typically this will be in the - * range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE. + * @priority: the priority of the timeout source. Typically this will be in + * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH. * @interval: the time between calls to the function, in milliseconds * (1/1000ths of a second) * @function: function to call * @data: data to pass to @function - * @notify: function to call when the idle is removed, or %NULL + * @notify: function to call when the timeout is removed, or %NULL * * Sets a function to be called at regular intervals, with the given * priority. The function is called repeatedly until it returns @@ -3643,15 +3643,18 @@ g_timeout_add (guint32 interval, } /** - * g_timeout_add_seconds: + * g_timeout_add_seconds_full: + * @priority: the priority of the timeout source. Typically this will be in + * the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH. * @interval: the time between calls to the function, in seconds * @function: function to call * @data: data to pass to @function + * @notify: function to call when the timeout is removed, or %NULL * - * Sets a function to be called at regular intervals, with the default - * priority, #G_PRIORITY_DEFAULT. The function is called repeatedly - * until it returns %FALSE, at which point the timeout is automatically - * destroyed and the function will not be called again. + * Sets a function to be called at regular intervals, with @priority. + * The function is called repeatedly until it returns %FALSE, at which + * point the timeout is automatically destroyed and the function will + * not be called again. * * Unlike g_timeout_add(), this function operates at whole second granularity. * The initial starting point of the timer is determined by the implementation @@ -3679,9 +3682,11 @@ g_timeout_add (guint32 interval, * Since: 2.14 **/ guint -g_timeout_add_seconds (guint32 interval, - GSourceFunc function, - gpointer data) +g_timeout_add_seconds_full (gint priority, + guint32 interval, + GSourceFunc function, + gpointer data, + GDestroyNotify notify) { GSource *source; guint id; @@ -3690,13 +3695,43 @@ g_timeout_add_seconds (guint32 interval, source = g_timeout_source_new_seconds (interval); - g_source_set_callback (source, function, data, NULL); + if (priority != G_PRIORITY_DEFAULT) + g_source_set_priority (source, priority); + + g_source_set_callback (source, function, data, notify); id = g_source_attach (source, NULL); g_source_unref (source); return id; } +/** + * g_timeout_add_seconds: + * @interval: the time between calls to the function, in seconds + * @function: function to call + * @data: data to pass to @function + * + * Sets a function to be called at regular intervals with the default + * priority, #G_PRIORITY_DEFAULT. The function is called repeatedly until + * it returns %FALSE, at which point the timeout is automatically destroyed + * and the function will not be called again. + * + * See g_timeout_add_seconds_full() for the differences between + * g_timeout_add() and g_timeout_add_seconds(). + * + * Return value: the ID (greater than 0) of the event source. + * + * Since: 2.14 + **/ +guint +g_timeout_add_seconds (guint interval, + GSourceFunc function, + gpointer data) +{ + g_return_val_if_fail (function != NULL, 0); + + return g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, interval, function, data, NULL); +} /* Child watch functions */ diff --git a/glib/gmain.h b/glib/gmain.h index 1d201dd..67250da 100644 --- a/glib/gmain.h +++ b/glib/gmain.h @@ -295,32 +295,37 @@ gboolean g_source_remove_by_funcs_user_data (GSourceFuncs *funcs, gpointer user_data); /* Idles, child watchers and timeouts */ -guint g_timeout_add_full (gint priority, - guint interval, - GSourceFunc function, - gpointer data, - GDestroyNotify notify); -guint g_timeout_add (guint interval, - GSourceFunc function, - gpointer data); -guint g_timeout_add_seconds (guint interval, - GSourceFunc function, - gpointer data); -guint g_child_watch_add_full (gint priority, - GPid pid, - GChildWatchFunc function, - gpointer data, - GDestroyNotify notify); -guint g_child_watch_add (GPid pid, - GChildWatchFunc function, - gpointer data); -guint g_idle_add (GSourceFunc function, - gpointer data); -guint g_idle_add_full (gint priority, - GSourceFunc function, - gpointer data, - GDestroyNotify notify); -gboolean g_idle_remove_by_data (gpointer data); +guint g_timeout_add_full (gint priority, + guint interval, + GSourceFunc function, + gpointer data, + GDestroyNotify notify); +guint g_timeout_add (guint interval, + GSourceFunc function, + gpointer data); +guint g_timeout_add_seconds_full (gint priority, + guint interval, + GSourceFunc function, + gpointer data, + GDestroyNotify notify); +guint g_timeout_add_seconds (guint interval, + GSourceFunc function, + gpointer data); +guint g_child_watch_add_full (gint priority, + GPid pid, + GChildWatchFunc function, + gpointer data, + GDestroyNotify notify); +guint g_child_watch_add (GPid pid, + GChildWatchFunc function, + gpointer data); +guint g_idle_add (GSourceFunc function, + gpointer data); +guint g_idle_add_full (gint priority, + GSourceFunc function, + gpointer data, + GDestroyNotify notify); +gboolean g_idle_remove_by_data (gpointer data); /* Hook for GClosure / GSource integration. Don't touch */ GLIB_VAR GSourceFuncs g_timeout_funcs; -- 2.7.4