summaryrefslogtreecommitdiff
path: root/comm/SignalHandler.cc
blob: 3fc7fab179fa710f7958dac43112a5c5ac495ef2 (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
/*
 *	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 signal handlers
 *
 *	$Id$
 *	$CurLog$
 */

#include "Signal.h"
#include "Multiplexer.h"

/*?class UchBaseSignalHandler
The class \typ{UchBaseSignalHandler} is provided as a base class for safe signal handlers,
ie. signal handlers that are activated only when no data is being transferred on a channel.
It is a derived class of \typ{CcuBaseSignalHandler}, in which the method \fun{Handle} is
defined to hold the signal until safe times. The virtual function \fun{DeferredHandle},
that should be redefined in derived classes, is called later.
The class \typ{UchBaseSignalHandler} comes with a derived class
\typ{CcuSignalHandler} that can be used as is, without any derivation.
?*/

/*?
Create a signal handler associated to the multiplexer \var{m},
for the signal \var{sig}.
?*/
UchBaseSignalHandler :: UchBaseSignalHandler (UchBaseMultiplexer& m, int sig)
: CcuBaseSignalHandler (sig),
  MyMpx (m)
{
}

/*?nodoc?*/
UchBaseSignalHandler :: ~UchBaseSignalHandler ()
{
}

/*!
Ask the multiplexer to hold the signal and call us when it is safe.
!*/
/*?hidden?*/
void
UchBaseSignalHandler :: Handle ()
{
	MyMpx.HandleSignal (*this);
}

/*?
This virtual function should be redefined in derived classes. It is called
when a signal should be handled. As the handling of the signal was
deferred, it may happen that a signal was received more than once
before being handled; \var{nb} holds the number of identical signals
that were received. This function is not called during an
interruption, and does not suffer any constraint.
?*/
void
UchBaseSignalHandler :: DeferredHandle (int nb)
{
}

/*?class UchSignalHandler
The class \typ{UchSignalHandler} is a derived class of \typ{UchBaseSignalHandler} that
can be used without deriving a new class.
Each \typ{UchSignalHandler} holds a pointer to a function which is called when a
signal is received. This function, which is passed to the constructor, must
take an \typ{int} argument and return \typ{void}.
?*/

/*?
Create a signal handler for signal \var{sig}. The function \var{h} will be
called when a signal has to be handled. Its two arguments are the identification
of the signal, and the number of signals that were received.
?*/
UchSignalHandler :: UchSignalHandler (UchBaseMultiplexer& m, int sig, void (*h) (int, int))
: UchBaseSignalHandler (m, sig),
  Handler (h)
{
}

/*?nodoc?*/
UchSignalHandler :: ~UchSignalHandler ()
{
}

/*?hidden?*/
void
UchSignalHandler :: DeferredHandle (int nb)
{
	(*Handler) (Signal, nb);
}