/* * The Unix Channel * * by Michel Beaudouin-Lafon and Stephane Chatty * * Copyright 1990-1997 * Laboratoire de Recherche en Informatique (LRI) * Centre d'Etudes de la Navigation Aerienne * * Scheduler-based timers * * $Id$ * $CurLog$ */ #include "TimeOut.h" #include "ivl/Signal.h" #include "Scheduler.h" /*?class IvlBaseTimeOut The class \typ{IvlBaseTimeOut} is provided as a base class for multiplexer-based timers. It is a derived class of \typ{IvlCoreTimer}. It comes with a derived class \typ{IvlTimeOut} that can be used as is. A timer is created with a period expressed in milliseconds. It will then periodically call the member function \fun{Handle}, which should be redefined in derived classes. ?*/ /*? Create a timer associated to the multiplexer \var{m}, that will send a signal every \var{period} milliseconds, \var{pulses} times. If \var{pulses} is negative, the timer will send signals forever. Timers are activated at creation time. They are disactivated, but not destroyed, after their last pulse. ?*/ IvlBaseTimeOut :: IvlBaseTimeOut (Millisecond period, int pulses, IvlBaseScheduler* m) : IvlCoreTimer (period, pulses, m->GetTimerSet ()), MyScd (m) { IvlSignalBlocker b (SigAlrm); if (PulsesLeft != 0) Activate (); } /*?nodoc?*/ IvlBaseTimeOut :: ~IvlBaseTimeOut () { /* stop it */ if (StatusFlag == Active) Stop (); } /*?hidden?*/ void IvlBaseTimeOut :: StopAlarm () { MyScd->SuppressTimeOut (); } /*?hidden?*/ void IvlBaseTimeOut :: SetAlarm (Millisecond delay) { MyScd->SetTimeOut (delay); } /*?class IvlTimeOut The class \typ{IvlTimeOut} is a derived class of \typ{IvlBaseTimeOut} that can be used without deriving a new class. Each \typ{IvlTimeOut} holds a pointer to a function which is called when the timer expires. This function, which is passed to the constructor, must take a \typ{Millisecond} argument and return \typ{void}. ?*/ /*? Create a timer associated to the multiplexer \var{m}, that will expire every \var{period} milliseconds and call the function \var{handler}. ?*/ IvlTimeOut :: IvlTimeOut (Millisecond period, void (*handler) (Millisecond), int pulses, IvlBaseScheduler* m) : IvlBaseTimeOut (period, pulses, m), Handler (handler) { } /*?nodoc?*/ IvlTimeOut :: ~IvlTimeOut () { } /*?hidden?*/ void IvlTimeOut :: Handle (Millisecond ref) { (*Handler) (ref); } /*? Change the handling function of a timer. ?*/ #ifdef DOC void IvlTimeOut :: SetHandler ((void)(*h)(Millisecond)) { } #endif