From: Emmanuel S. [ES] <ma...@ei...> - 2007-11-15 23:36:01
|
The easiest way for doing this kind of callback is to store the eiffel routine address by doing: c_set_address (p: POINTER) is external "C inline use <your.h>" alias "signal_callback = $p" end where you do: c_set_address (your_eiffel_routine_callback) To store the object needed for the call: c_set_object (a: POINTER) is external "C inline use <your.h>" alias "signal_object = eif_protect($a);" end where you do: c_set_object ($Current) -- Current or any other entity Then the C code should simply look like: (signal_callback) (eif_adopt(signal_object), sig) That way there is no need to worry about freezing objects. Manu > -----Original Message----- > From: gob...@li... > [mailto:gob...@li...] On > Behalf Of Berend de Boer > Sent: Thursday, November 15, 2007 3:01 PM > To: Gobo Developers Mailing List > Subject: [gobo-eiffel-develop] Callback from C to Eiffel > > 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 != NULL ) { > temp = signal_switch; > signal_switch = NULL; > eif_unfreeze (frozen_signal_switch); > frozen_signal_switch = NULL; > eif_wean (temp); > } > if ( a_switch != NULL ) { > tid = eif_type_id ("STDC_SIGNAL_SWITCH"); > signal_callback = eif_procedure ("switcher", tid); > if (signal_callback == 0) > { eif_panic ("switcher feature not found."); } > frozen_signal_switch = eif_freeze (a_switch); > signal_switch = 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. > > -- > Cheers, > > Berend de Boer > |