summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1994-05-10 08:50:04 +0000
committerchatty1994-05-10 08:50:04 +0000
commit6d32f3eda675ac0c36d835e69054eba2b1a777c8 (patch)
treee59397a630f2e47ad38393eece7a30e3aebda87f
parent9e5332136b567af8c9fd6a6b91338d2d68349562 (diff)
downloadivy-league-6d32f3eda675ac0c36d835e69054eba2b1a777c8.zip
ivy-league-6d32f3eda675ac0c36d835e69054eba2b1a777c8.tar.gz
ivy-league-6d32f3eda675ac0c36d835e69054eba2b1a777c8.tar.bz2
ivy-league-6d32f3eda675ac0c36d835e69054eba2b1a777c8.tar.xz
Added Grab/Release
-rw-r--r--dnn/Reaction.cc27
-rw-r--r--dnn/Trigger.cc34
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 <DnnTrigger> ti (Triggers);
+ CcuListIterOf <DnnTrigger> 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 <DnnBaseReaction> subscribers = Subscribers;
- CcuListIterOf <DnnBaseReaction> ai (subscribers);
- while (++ai)
- (*ai)->Manage (ev);
+ DnnBaseReaction* r = Grabs.First ();
+ if (r) {
+ r->Manage (ev);
+ } else {
+ CcuListOf <DnnBaseReaction> subscribers = Subscribers;
+ CcuListIterOf <DnnBaseReaction> ai = subscribers;
+ while (++ai)
+ (*ai)->Manage (ev);
+ }
}