summaryrefslogtreecommitdiff
path: root/comm/TimeOut.cc
blob: e52413c5331a7722261f9b7cd1b9003cfa43655d (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
101
102
103
104
105
106
/*
 *	Ivy League
 *
 *	Scheduler-based timers
 *
 *	Copyright 1993-2000
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	code by Stephane Chatty
 *
 *	$Id$
 *
 */

#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