ahodgson@athena.mit.edu (Antony Hodgson) (02/20/91)
Is it possible to have a class member function of type "interrupt"? E.g., I want to do something like the following: class InterruptHandler { public: InterruptHandler(); void install( int InterruptNumber ); void interrupt handler(); ... }; void InterruptHandler::install( int InterruptNumber ) { ... setvect( InterruptNumber, InterruptHandler::handler ); ... } Turbo C++ accepts the class declaration, but returns a type mismatch message when it hits the setvect call. Apparently, handler is not something it can deal with. If I define another handler routine that's not a member function, all is well (e.g., void altHandler();) and I can properly install it. What am I missing here? Another thing I would like to be able to do would be to pass an argument to handler when it gets invoked (e.g., handler( someObject O ) ). Is there any way this can be done? I will be very grateful for help with these questions. Tony Hodgson ahodgson@hstbme.mit.edu
jeppe@iesd.auc.dk (Jeppe Sommer) (02/20/91)
>In article <1991Feb19.191356.25123@athena.mit.edu> ahodgson@athena.mit.edu (Antony Hodgson) writes: > Is it possible to have a class member function of type "interrupt"? > E.g., I want to do something like the following: > class InterruptHandler > { > public: InterruptHandler(); > void install( int InterruptNumber ); > void interrupt handler(); > ... > }; > void InterruptHandler::install( int InterruptNumber ) > { > ... > setvect( InterruptNumber, InterruptHandler::handler ); > ... > } > Turbo C++ accepts the class declaration, but returns a type mismatch > message when it hits the setvect call. Apparently, handler is not > something it can deal with. If I define another handler routine that's > not a member function, all is well (e.g., void altHandler();) and I > can properly install it. What am I missing here? Well since you have noticed the error message from your compiler, you are not missing anything :-). setvect() expects a pointer to a function - not a pointer to a member function. However, even if setvect() had accepted a pointer to a member function, knowledge of which object to apply the member function on _would_ be missing. Furthermore, don't try to typecast InterruptHandler::handler to a function pointer - it is likely that a pointer to a member function occupies more storage than a function pointer (I don't know Turbo C++). A solution to your problem would be to use the strategy shown below : class InterruptHandler { InterruptHandler (int IntrNo) {/* Install interrupt handler */} ~InterruptHandler () {/* If last instance, de-install interrupt handler */} friend void handler(); doHandle(); static int noOfInstances; static InterruptHandler* instances[MAX_INTR_HANDLERS][MAX_INTR_NO]; ... }; void handler() { // 1. Find out the current interrupt no (can you do that on a PC?) // 2. Determine which instance the interrupt should be directed to. // How this can be accomplished (if at all), depends on the // context of the interrupt and the members of the // instances (accessible through InterruptHandler::instances). // 3. Invoke doHandle on the found instance: // InterruptHandler::instances[foundIndex][intrNo]->doHandle(); } The 2 dimensional static array of instances is of course a naive representation. Improve it if naivity annoys you. This is obviously just a sketch of a solution. But it should give you enough to be able to complete it. Regards Jeppe Sommer Aalborg University, Department of Mathematics and Computer Science.