summaryrefslogtreecommitdiff
path: root/comm/TimeOut.cc
blob: c6cb78e39b93660320fb12473cdf49b6a162b309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 *	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);
}