Re: Interface signals.



Tim Janik <timj gtk org> writes: 
> urm, yes, type_init is probably a bad idea, but interfaces have no
> common one-time initializer. haven't actually run into this yet,
> for the moment, it's probably best if you use the base_init function
> of the interface's GTypeInfo structure and guard that against multiple
> invocations, i.e.:
> 
> static void
> my_interface_base_class_init (gpointer g_class)
> {
>   static gboolean signals_setup = FALSE;
>   
>   if (!signals_setup)
>     {
>       signals_setup = TRUE;
>       
>       /* do signal_new here */
>     }
> }
> 

I'm looking at converting GtkTreeModel now - what's wrong with just
keeping a class struct around for interfaces, and calling class_init
and class_finalize on that class struct, as we do for object classes?

It could even be useful to provide default implementations of some
functions in an interface. For example, in GtkTreeModel, you can
implement some of the methods entirely in terms of the other
methods. So default implementations make sense, even though the base
interface doesn't know anything about the instance struct.

The other advantage of this is that interfaces will work exactly like
objects with respect to signals.

Havoc






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