Re: Help, How to mange the id returned by g_timeout_add

On 7/9/06, Anna <christiana hipointcoffee com> wrote:
In C, I handle it by creating file-scoped variables.  not quite global,
but not local either.  If you want to remove as much risk as possible,
I'd recommend declaring a file-scoped variable in a file with only the
few functions that actually need to access the variable directly.
(then, call it a "module".  haha)  example:

//////////////////////////////////////////////// file starts
#include <whatever.h>

static int filescoped_special_timer_id = 0;

start_timer( void )
   filescoped_special_timer_id = whatever( callback );

/* only call this from within this file or through the callback */
static void
callback( void )
    /* do something */

remove_timer( void )
    whatever_3( filescoped_special_timer_id );
//////////////////////////////////////////////// file ends

nothing outside of the file can access filescoped_special_timer_id
directly.  It's only accessible through this "module's public interface"
which is declared in the header file.  This scope is analogous to C++'s
"private" class variables, while the "module" (aka, the file) is
analogous to a C++ class.

- Anna

On Sat, Jul 08, 2006 at 09:23:54AM +0800, chao yeaj wrote:
> Hello,all
>     You know ,we can register a timeout function  using g_timeout_add
>    and g_timeout_add return an  ID
>     And,we must mannually remove the timeout function  using g_source_remove
>     The problem is,in my application,there are several  timeout
> functions ,in many modules
>     In my application,when and how to remove the timeout function is
> depents on  many conditions
>      I have no idea about how to store  the   ID    returned by
> g_timeout_add,I think  using  global  variable is not a good idea
>      How to mange the id?  I need your advise!
> Any comments would be much appreciated , thanks in advance !
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
gtk-list mailing list
gtk-list gnome org

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