Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!tut.cis.ohio-state.edu!magnus.ircc.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!dkuug!iesd!iesd.auc.dk!jeppe From: jeppe@iesd.auc.dk (Jeppe Sommer) Newsgroups: comp.lang.c++ Subject: Re: Interrupt member functions Message-ID: Date: 20 Feb 91 13:27:58 GMT References: <1991Feb19.191356.25123@athena.mit.edu> Sender: news@iesd.auc.dk Organization: Mathematics and Computer Science, University of Aalborg Lines: 69 In-reply-to: ahodgson@athena.mit.edu's message of 19 Feb 91 19:13:56 GMT >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.