summaryrefslogtreecommitdiff
path: root/comm/TimeOut.cc
blob: 72a30e281507d6e9ad09ebe18850a00a90ee7c77 (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
/*
 *	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"

UchBaseTimeOut :: UchBaseTimeOut (UchBaseMultiplexer& m, Millisecond period, int pulses)
: CcuCoreTimer (period, pulses, m.GetTimerSet ()),
  MyMpx (m)
{
	CcuSignalBlocker b (SigAlrm);

	if (PulsesLeft != 0)
		Activate ();
}

/*?hidden?*/
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 ()
{
}

/*?nodoc?*/
void
UchTimeOut :: Handle (Millisecond ref)
{
	(*Handler) (ref);
}