summaryrefslogtreecommitdiff
path: root/dnn/Trigger.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dnn/Trigger.cc')
-rw-r--r--dnn/Trigger.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/dnn/Trigger.cc b/dnn/Trigger.cc
new file mode 100644
index 0000000..59a3b33
--- /dev/null
+++ b/dnn/Trigger.cc
@@ -0,0 +1,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);
+}