From 6d32f3eda675ac0c36d835e69054eba2b1a777c8 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 10 May 1994 08:50:04 +0000 Subject: Added Grab/Release --- dnn/Reaction.cc | 27 ++++++++++++++++++++++++++- dnn/Trigger.cc | 34 +++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/dnn/Reaction.cc b/dnn/Reaction.cc index 62a6849..845d689 100644 --- a/dnn/Reaction.cc +++ b/dnn/Reaction.cc @@ -25,13 +25,19 @@ and can be associated to one or more triggers, generally located in a sensor. Create a reaction. ?*/ DnnBaseReaction :: DnnBaseReaction () +: Triggers (), + Grabbed () { } /*?nodoc?*/ DnnBaseReaction :: ~DnnBaseReaction () { - CcuListIterOf ti (Triggers); + CcuListIterOf ti = Grabbed; + while (++ti) + (*ti)->Release (*this); + + ti = Triggers; while (++ti) (*ti)->Unsubscribe (*this); } @@ -55,6 +61,25 @@ DnnBaseReaction :: UnsubscribeTo (DnnTrigger& t) t.Unsubscribe (*this); } +/*?nextdoc?*/ +void +DnnBaseReaction :: Grab (DnnTrigger& t) +{ + Grabbed.Append (&t); + t.Grab (*this); +} + +/*? +Tell that a reaction should (resp. should no more) be the only one +activated when the trigger \var{t} causes the emission of an event. +?*/ +void +DnnBaseReaction :: Release (DnnTrigger& t) +{ + Grabbed.Remove (&t); + t.Release (*this); +} + /*? This virtual function is called when an event is emitted because of a trigger to which this reaction was attached. It should be redefined in derived classes to implement diff --git a/dnn/Trigger.cc b/dnn/Trigger.cc index 59a3b33..9b6db60 100644 --- a/dnn/Trigger.cc +++ b/dnn/Trigger.cc @@ -28,7 +28,8 @@ the trigger. Create a trigger with an empty list of associated reaction. ?*/ DnnTrigger :: DnnTrigger () -: Subscribers () +: Subscribers (), + Grabs () { } @@ -52,6 +53,24 @@ 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); } /*? @@ -60,8 +79,13 @@ Have a trigger dispatch the event \var{ev} to its associated reactions. void DnnTrigger :: Dispatch (DnnEvent& ev) { - CcuListOf subscribers = Subscribers; - CcuListIterOf ai (subscribers); - while (++ai) - (*ai)->Manage (ev); + DnnBaseReaction* r = Grabs.First (); + if (r) { + r->Manage (ev); + } else { + CcuListOf subscribers = Subscribers; + CcuListIterOf ai = subscribers; + while (++ai) + (*ai)->Manage (ev); + } } -- cgit v1.1