[gtkada] Signal handler
Emmanuel Briot
briot at adacore.com
Wed Aug 3 12:23:16 CEST 2011
> If you are about to change GtkAda, why not to consider making handlers
> type-safe? The existing schema only appears safe, it adds Ada types, but
> does not ensure them matching the actual types of the signal or that signal
> names are correct.
We are not changing the API in GtkAda, we want to stay backward compatible. The
generated code looks almost like the old one.
I have yet to encounter a case where my code fails because of wrong typing in my
GtkAda interface.
> A type-/event-safe schema might be based on Ada 2005 interfaces. E.g.
We also do not want to make GtkAda and Ada05 library, we have customers using it
from Ada95.
> type Clicked_Handler is limited interface;
> procedure Connect
> ( Button : not null access Gtk_Button_Record;
> Handler : in out Clicked_Handler'Class
> );
> procedure Connect
> ( Button : not null access Gtk_Button_Record;
> Handler : in out Clicked_Handler'Class;
> ID : out Handler_Id
> );
We could indeed generate one Connect function per signal, why not. I would not
use interfaces for the callbacks though, and I am not sure either that using
objects for the callback is a good approach (that's what Java used to do before
they also decided it wasn't good). The only interesting aspect (non-negligible)
is to remove the need to user data since it can then be encapsulated in the
callback object, but that makes the code harder to write (can you show an
example of user-code using your API) ?
> This schema can be implemented on top of the existing one.
Right, and that would be easier to do with the generate API indeed.
One other thing we are changing in the generated API is the handling of gtk+'s
interfaces (still not using Ada interfaces, since we do not want to force
Ada05). But we are now duplicating the inherited subprograms, thus remove the
need for the "+" conversions in the user code...
Emmanuel
More information about the gtkada
mailing list