Re: Deleting a timer



On Monday 02 January 2006 14:36, N poleone wrote:
> Hi,
> I used g_timeout_add to call a function every tot seconds (or minutes).
> Now I'd want to delete and add dynamically the timer. In other words,
> i've a button that initialize the timer, and another button that stop
> the timer. So if i click the first button:
> std::cout << "Inizialiting timer...\n";
> 	guint timer_id;
> 	timer_id =
> g_timeout_add(30000,(GSourceFunc)scansioneDB::acquisisciAux,true);
>
> and
>
> gboolean scansioneDB::acquisisciAux(bool start)
> {
> 	if (!start)
> 		return 0;
> 	else {
> 		std::cout << "Eseguo operazione pianificata...\n";
> 		return 1;
> 	}
> }
>
> If, from the clicked event of the stop button, I call acquisisciAux
> with false parameter this stop the timer??? Or i've to call
> g_timeout_add(30000,(GSourceFunc)scansioneDB::acquisisciAux,false)???

You are on the wrong list, but in any event, the timer is removed if either:

1. g_source_remove() is called on the timer id returned by g_timeout_add, or
2. the callback returns false.

Passing a boolean value to the third argument of g_timeout_add() should fail 
to compile (the third argument is a void* and not an int), and it is also 
pointless since the assigned value will be passed to every invocation of the 
callback, not just the first one.  (You could pass an unsigned integer value 
with the GUINT_TO_POINTER() macro and then cast it back in the callback with 
the GPOINTER_TO_UINT() macro, but it would remain pointless.)

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]