one-shot interface initializers
- From: Tim Janik <timj gtk org>
- To: Gtk+ Developers <gtk-devel-list gnome org>
- Cc: Jonathan Blandford <jrb redhat com>, Bill Haneman <Bill Haneman Sun COM>
- Subject: one-shot interface initializers
- Date: Fri, 19 Oct 2001 04:38:35 +0200 (CEST)
owen and me have been doing some pondering on irc about the current
signals-for-interfaces situation, where people basically have to do:
static guint base_counter = 0;
void interface_base_init (Iface *iface)
{
if (base_counter++ == 0)
{
iface->sig_id = g_signal_new ("some-iface_signal", TYPE_IFACE);
}
else
{
iface->sig_id = g_signal_lookup ("some-iface-signal", TYPE_IFACE);
}
}
void interface_base_finalize (IFace *iface)
{
base_counter--;
if (base_counter == 0)
_g_signals_destroy (TYPE_IFACE);
}
things can easily be changed to eliminate the need to call
_g_signals_destroy() at all, and the base_counter/interface_base_init()
"hack" could be changed to read:
void interface_init (gpointer dummy_pointer,
gpointer class_data)
{
g_signal_new ("some-iface_signal", TYPE_IFACE);
}
void interface_base_init (Iface *iface)
{
iface->sig_id = g_signal_lookup ("some-iface-signal", TYPE_IFACE);
}
by setting interface_init() and it's second argument class_data as
the class_init and class_data arguments in the interfaces GTypeInfo
structure.
there're two things to consider here, for normal classes,
base_init(class) is called prior to class_init(class, class_data).
for interfaces, class_init(NULL, class_data) would be called prior
to base_init(iface), and the class_init()'s "class" argument
would actually be a dummy pointer of NULL, as it's going to
be called _prior_ to creations of any interfaces of this type.
i'd apprechiate comments from especially jrb and bill, as i
remember both expressing concern about the current need for
a base_counter type hack for creating signals of interfaces.
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]