Re: g_signal_lookup for interfaces



On Wed, 17 Oct 2001, Bill Haneman wrote:

> Hi:
> 
> I guess this one is for you, Tim...
> 
> We have defined a number of signals in ATK on interfaces.  We know we 
> can't define properties on interfaces now, but we have been using 
> signals on interfaces, which is supported.
> 
> However in order to intercept these signals we need to register an 
> emission hook.  In the bridge to at-spi this is done via a string-based 
> register call containing the names of the signal and type.
> [where type_name = "AtkText", signal_name = "text-caret-moved"]
> 
> GType *type = g_type_from_name(type_name);
> 
> However, if we call 
> 
> g_signal_lookup (signal_name, type); 
> 
> we get an error from g_signal_lookup saying that it cannot lookup 
> signals for non-instantiable types.
> 
> I have been looking at gsignal.c, it seems that the error is only 
> printed if the signal lookup actually fails to return a non-null 
> signal_id.  It's not clear to me why the lookup fails, seems like the 
> intention was for it to work for interfaces. 

yes:
  g_return_val_if_fail (G_TYPE_IS_INSTANTIATABLE (itype) || G_TYPE_IS_INTERFACE (itype), 0);
  SIGNAL_LOCK ();
  signal_id = signal_id_lookup (g_quark_try_string (name), itype);
  SIGNAL_UNLOCK ();
  if (!signal_id)
    {
      /* give elaborate warnings */
      if (!g_type_name (itype))
        g_warning (G_STRLOC ": unable to lookup signal \"%s\" for invalid type id `%u'",
                   name, itype);
      else if (!G_TYPE_IS_INSTANTIATABLE (itype))
        g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type `%s'",
                   name, g_type_name (itype));
      else if (!g_type_class_peek (itype))
        g_warning (G_STRLOC ": unable to lookup signal \"%s\" of unloaded type `%s'",
                   name, g_type_name (itype));
    }
there's one bug here, the lines
      else if (!G_TYPE_IS_INSTANTIATABLE (itype))
        g_warning (G_STRLOC ": unable to lookup signal \"%s\" for non instantiatable type `%s'",
                   name, g_type_name (itype));
should just be nuked, because upon function enbtry we already
checked that we either have an instantiatable or an interface
type at hand (i have to leave now and can't commit this, so
if you want to go for that in the meanwhile that'd be ok).

> Could you help me diagnose the problem?  If I hard-code a call to 
> g_signal_new() just before my lookup, to make sure the new signal is 
> registered when I make the call, no diagnostics are printed...

hum that sounds odd. when you hardcode that call, do you actually
get back a signal_id!=0? if not, you're probably looking up the
signal wrongly, either with a different name, or a different type
than you registered with. if you indeed get an id back, there's
probably a bug in your normal code path to register the signal, that
causes g_signal_new() not to be triggered.

> 
> -Bill
> 

---
ciaoTJ




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