/* * The Unix Channel * * by Michel Beaudouin-Lafon and Stephane Chatty * * Copyright 1990-1993 * Laboratoire de Recherche en Informatique (LRI) * Centre d'Etudes de la Navigation Aerienne * * Multiplexer-based timers * * $Id$ * $CurLog$ */ #include "TimeOut.h" #include "ccu/Signal.h" #include "Multiplexer.h" /*?class UchBaseTimeOut The class \typ{UchBaseTimeOut} is provided as a base class for multiplexer-based timers. It is a derived class of \typ{CcuCoreTimer}. It comes with a derived class \typ{UchTimeOut} 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. ?*/ UchBaseTimeOut :: UchBaseTimeOut (UchBaseMultiplexer& m, Millisecond period, int pulses) : CcuCoreTimer (period, pulses, m.GetTimerSet ()), MyMpx (m) { CcuSignalBlocker b (SigAlrm); if (PulsesLeft != 0) Activate (); } /*?nodoc?*/ UchBaseTimeOut :: ~UchBaseTimeOut () { /* stop it */ if (StatusFlag == Active) Stop (); } /*?hidden?*/ void UchBaseTimeOut :: StopAlarm () { MyMpx.SuppressTimeOut (); } /*?hidden?*/ void UchBaseTimeOut :: SetAlarm (Millisecond delay) { MyMpx.SetTimeOut (delay); } /*?class UchTimeOut The class \typ{UchTimeOut} is a derived class of \typ{UchBaseTimeOut} that can be used without deriving a new class. Each \typ{UchTimeOut} 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}. ?*/ UchTimeOut :: UchTimeOut (UchBaseMultiplexer& m, Millisecond period, void (*handler) (Millisecond), int pulses) : UchBaseTimeOut (m, period, pulses), Handler (handler) { } /*?nodoc?*/ UchTimeOut :: ~UchTimeOut () { } /*?hidden?*/ void UchTimeOut :: Handle (Millisecond ref) { (*Handler) (ref); } /*? Change the handling function of a timer. ?*/ #ifdef DOC void UchTimeOut :: SetHandler ((void)(*h)(Millisecond)) { } #endif