diff options
author | chatty | 1994-03-14 08:40:16 +0000 |
---|---|---|
committer | chatty | 1994-03-14 08:40:16 +0000 |
commit | 33c173febd67cf6b558eb86ba552dc9369ab4b24 (patch) | |
tree | 0af984e138144b6ff9d8ec98b0ea7245dd003bef /dnn/Reaction.cc | |
parent | 1ed65383fc2b49e22929862dd5705c93f79a60c2 (diff) | |
download | ivy-league-33c173febd67cf6b558eb86ba552dc9369ab4b24.zip ivy-league-33c173febd67cf6b558eb86ba552dc9369ab4b24.tar.gz ivy-league-33c173febd67cf6b558eb86ba552dc9369ab4b24.tar.bz2 ivy-league-33c173febd67cf6b558eb86ba552dc9369ab4b24.tar.xz |
Initial revision
Diffstat (limited to 'dnn/Reaction.cc')
-rw-r--r-- | dnn/Reaction.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/dnn/Reaction.cc b/dnn/Reaction.cc new file mode 100644 index 0000000..62a6849 --- /dev/null +++ b/dnn/Reaction.cc @@ -0,0 +1,94 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1994 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Reactions. + * + * $Id$ + * $CurLog$ + */ + +#include "Reaction.h" +#include "Trigger.h" + +/*?class DnnBaseReaction +The class \typ{DnnBaseReaction} is the base class for event handling. +A reaction implements a behaviour (through the virtual function \fun{Manage}), +and can be associated to one or more triggers, generally located in a sensor. +?*/ + +/*? +Create a reaction. +?*/ +DnnBaseReaction :: DnnBaseReaction () +{ +} + +/*?nodoc?*/ +DnnBaseReaction :: ~DnnBaseReaction () +{ + CcuListIterOf <DnnTrigger> ti (Triggers); + while (++ti) + (*ti)->Unsubscribe (*this); +} + +/*?nextdoc?*/ +void +DnnBaseReaction :: SubscribeTo (DnnTrigger& t) +{ + Triggers.Append (&t); + t.Subscribe (*this); +} + +/*? +Tell that a reaction should (resp. should no more) be activated when the trigger \var{t} +causes the emission of an event. +?*/ +void +DnnBaseReaction :: UnsubscribeTo (DnnTrigger& t) +{ + Triggers.Remove (&t); + t.Unsubscribe (*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 +behaviours. +?*/ +void +DnnBaseReaction :: Manage (DnnEvent&) +{ +} + +/*?class DnnReaction +The class \typ{DnnReaction} is a ready-to-use derived class of \typ{DnnBaseReaction}. +In this class, the function \fun{Manage} is redefined to call a function passed when creating +the reaction. +?*/ + +/*? +Build a reaction that will call \var{f} to handle events. +\fun{f} has to take a \typ{DnnEvent\&} parameter and return \typ{void}. +?*/ +DnnReaction :: DnnReaction (DnnHandlingFunction f) +: DnnBaseReaction (), + Handler (f) +{ +} + +/*?nodoc?*/ +DnnReaction :: ~DnnReaction () +{ +} + +/*?nodoc?*/ +void +DnnReaction :: Manage (DnnEvent& ev) +{ + (*Handler) (ev); +} |