#ifndef APP_SignalResponder_H
#define APP_SignalResponder_H
/******************************************************************************
 **
 **	C++ Class Library for the Amiga© system software.
 **
 **	Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
 **	All Rights Reserved.
 **
 **	$VER: apphome:APlusPlus/exec/SignalResponder.h 1.04 (04.05.94) $
 **	
 ******************************************************************************/


#include <APlusPlus/exec/PriorityList.h>
#include <APlusPlus/environment/APPObject.h>


/******************************************************************************************
      » SignalResponder class «  virtual base class

   Each SignalResponder object is chained into a list of SignalResponder objects
   and waits for its individual signal bit to be set. The virtual method actionCallback()
   is called on the event of that signal being set.
 ******************************************************************************************/

class SignalResponder : private PriorityNode, public APPObject
{
   private:
		static ULONG waitSignalSet;			// signal mask for Wait()
      static PriorityList sigRespChain;	// connects all SignalResponder objects
		
		ULONG waitSignal; 
		BOOL hasAllocatedSig;					// TRUE if 'this' has allocated a new signal
      UBYTE waitSigNr;							// bit number of the signal 'this' catches

      void initSR(BYTE signal_nr,BYTE pri);

      BOOL applyNodeC(APTR any);   // listnode apply inherited from NodeC

   public:
      // set a SRSP to an already allocated signal.
      SignalResponder(UBYTE signal_nr,BYTE pri) { initSR(signal_nr, pri); }
      // allocate a signal for this SRSP.
      SignalResponder(BYTE pri);
      ~SignalResponder();      // must be virtual for inheritance

      static void WaitSignal();

      virtual void actionCallback() = 0;     // overload this with your own action

      void changeSignalBit(UBYTE signal_nr);
};


#define SIGNALRESPONDER_ALLOCSIGNAL_FAILED (SIGRESPONDER_CLASS+1)
#endif
