/* * 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 subscribers = Subscribers; CcuListIterOf ai = subscribers; while (++ai) (*ai)->Manage (ev); } }