/* * Ivy League * * Scheduler-based signal handlers * * Copyright 1993-2000 * Centre d'Etudes de la Navigation Aerienne (CENA) * * code by Stephane Chatty * * $Id$ * */ #ifdef __GNUG__ #pragma implementation "SignalHandler.h" #endif #include "SignalHandler.h" #include "Scheduler.h" /*?class IvlBaseScheduledHandler The class \typ{IvlBaseScheduledHandler} is provided as a base class for safe signal handlers, ie. signal handlers that are activated only when no data is being transferred on a channel. It is a derived class of \typ{IvlBaseScheduledHandler}, in which the method \fun{Handle} is defined to hold the signal until safe times. The virtual function \fun{DeferredHandle}, that should be redefined in derived classes, is called later. The class \typ{IvlBaseScheduledHandler} comes with a derived class \typ{IvlScheduledHandler} that can be used as is, without any derivation. ?*/ /*? Create a signal handler associated to the multiplexer \var{m}, for the signal \var{sig}. ?*/ IvlBaseScheduledHandler :: IvlBaseScheduledHandler (IvlBaseScheduler& m, int sig) : IvlBaseSignalHandler (sig), MyScd (m) { } /*?nodoc?*/ IvlBaseScheduledHandler :: ~IvlBaseScheduledHandler () { } /*! Ask the multiplexer to hold the signal and call us when it is safe. !*/ /*?hidden?*/ void IvlBaseScheduledHandler :: Handle () { MyScd.HandleSignal (*this); } /*? This virtual function should be redefined in derived classes. It is called when a signal should be handled. As the handling of the signal was deferred, it may happen that a signal was received more than once before being handled; \var{nb} holds the number of identical signals that were received. This function is not called during an interruption, and does not suffer any constraint. ?*/ void IvlBaseScheduledHandler :: DeferredHandle (int nb) { } /*?class IvlScheduledHandler The class \typ{IvlScheduledHandler} is a derived class of \typ{IvlBaseScheduledHandler} that can be used without deriving a new class. Each \typ{IvlScheduledHandler} holds a pointer to a function which is called when a signal is received. This function, which is passed to the constructor, must take an \typ{int} argument and return \typ{void}. ?*/ /*? Create a signal handler for signal \var{sig}. The function \var{h} will be called when a signal has to be handled. Its two arguments are the identification of the signal, and the number of signals that were received. ?*/ IvlScheduledHandler :: IvlScheduledHandler (IvlBaseScheduler& m, int sig, void (*h) (int, int)) : IvlBaseScheduledHandler (m, sig), Handler (h) { } /*?nodoc?*/ IvlScheduledHandler :: ~IvlScheduledHandler () { } /*?hidden?*/ void IvlScheduledHandler :: DeferredHandle (int nb) { (*Handler) (Signal, nb); }