summaryrefslogtreecommitdiff
path: root/dnn/Trigger.cc
blob: 9b6db60d5120b0ee64d2feceddaeb4c14a07a342 (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
/*
 *	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 (),
  Grabs ()
{
}

/*?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);
	Grabs.Remove (&a);
}

/*?nextdoc?*/
void
DnnTrigger :: Grab (DnnBaseReaction& a)
{
	Grabs.Prepend (&a);
}

/*?
Add (resp. Remove) a reaction onto (resp. from) the stack of reactions that preempt
events caused by this trigger.
?*/
void
DnnTrigger :: Release (DnnBaseReaction& a)
{
	Subscribers.Remove (&a);
}

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