Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable timeouts in GLib

Tags:

c

gtk

glib

I need to modify a GLib's time-out interval while it is in execution. Is that possible? I took a look to the source code and it seems possible to me, but is required use some non-public functions from GLib internals. Should I reimplement GTimeoutSource or there are a way to do it?

like image 964
Matachana Avatar asked Jun 01 '10 09:06

Matachana


1 Answers

In your timeout function, you could re-add the function with the new timeout interval and then return FALSE to remove the timeout with the old interval:

gboolean 
my_timeout_function(gpointer data)
{
    // do stuff
    // ...

    if(need_to_change_interval)
    {
        g_timeout_add(new_interval, (GSourceFunc)my_timeout_function, data);
        return FALSE;
    }
    return TRUE;
}
like image 188
ptomato Avatar answered Sep 19 '22 06:09

ptomato