summaryrefslogtreecommitdiff
path: root/dnn/Trigger.cc
blob: 59a3b336fa493d65e260bd0a2679aa71b0c121a8 (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
/*
 *	DNN - Data News Network
 *
 *	by Stephane Chatty
 *
 *	Copyright 1993-1994
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	Event triggers.
 *
 *	$Id$
 *	$CurLog$
 */

#include "Trigger.h"
#include "Reaction.h"

/*?class DnnTrigger
\typ{DnnTrigger}s are the core of event detection and emission. The presence of a trigger
(generally in a sensor) determines whether a certain situation, or the reception
of an event from the underlying window system, should provoke the emission of an event.
Each trigger holds a list of reactions (of type \typ{DnnBaseReaction}). These reactions will
receive all the events whose creation and emission was caused by the presence of
the trigger.
?*/

/*?
Create a trigger with an empty list of associated reaction.
?*/
DnnTrigger :: DnnTrigger ()
: Subscribers ()
{
}

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

/*?nextdoc?*/
void
DnnTrigger :: Subscribe (DnnBaseReaction& a)
{
	Subscribers.Append (&a);
}

/*?
Add (resp. Remove) a reaction to (resp. from) the list of reactions that should receive
events caused by this trigger.
?*/
void
DnnTrigger :: Unsubscribe (DnnBaseReaction& a)
{
	Subscribers.Remove (&a);
}

/*?
Have a trigger dispatch the event \var{ev} to its associated reactions.
?*/
void
DnnTrigger :: Dispatch (DnnEvent& ev)
{
	CcuListOf <DnnBaseReaction> subscribers = Subscribers;
	CcuListIterOf <DnnBaseReaction> ai (subscribers);
	while (++ai)
		(*ai)->Manage (ev);
}