From: Berend de B. <be...@po...> - 2007-11-15 23:01:24
|
Hi Eric, Can I callback from C to Eiffel? Need this at a few places in eposix, for example to support signals. For example this the code used for ISE: EIF_TYPE_ID tid; EIF_OBJECT temp; if ( signal_switch !=3D NULL ) { temp =3D signal_switch; signal_switch =3D NULL; eif_unfreeze (frozen_signal_switch); frozen_signal_switch =3D NULL; eif_wean (temp); } if ( a_switch !=3D NULL ) { tid =3D eif_type_id ("STDC_SIGNAL_SWITCH"); signal_callback =3D eif_procedure ("switcher", tid); if (signal_callback =3D=3D 0) { eif_panic ("switcher feature not found."); } frozen_signal_switch =3D eif_freeze (a_switch); signal_switch =3D eif_adopt (a_switch); } I.e. the callback pointer is "calculated" at set time and stored in signal_switch. When a signal occurs, this call is made: (signal_callback) (frozen_signal_switch, sig); SmartEiffel has a different strategy. When a feature is exported, SE simply generates a prototype for it in the cecil.h file: /* Available Eiffel routines via -cecil: */ void stdc_exit_switch_at_exit(void* C); void stdc_signal_switch_switcher(void* C,T2 a1); And within C I can simply call stdc_signal_switch_switcher to make the callback to Eiffel. =2D-=20 Cheers, Berend de Boer |