From bcb19dbd53973ff7efd9b2838de121d1e23430f4 Mon Sep 17 00:00:00 2001 From: chatty Date: Tue, 28 Nov 2000 14:52:15 +0000 Subject: Lots of files were added around '96 --- dnn/Behaviour.cc | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 dnn/Behaviour.cc (limited to 'dnn/Behaviour.cc') diff --git a/dnn/Behaviour.cc b/dnn/Behaviour.cc new file mode 100755 index 0000000..98a5b8d --- /dev/null +++ b/dnn/Behaviour.cc @@ -0,0 +1,151 @@ +/* + * DNN - Data News Network + * + * by Stephane Chatty + * + * Copyright 1993-1996 + * Centre d'Etudes de la Navigation Aerienne (CENA) + * + * Behaviours. + * + * $Id$ + * $CurLog$ + */ + +#include "Behaviour.h" + +#include +#include + +DnnToken :: DnnToken () +{ +} + +DnnToken :: ~DnnToken () +{ +} + +DnnState :: DnnState (const char* name) +: Name (name), + Transitions () +{ +} + +DnnState :: ~DnnState () +{ + CcuListIterOf t = Transitions; + while (++t) + delete *t; +} + +DnnTransition* +DnnState :: CreateTransition (const char* name, DnnState* s, DnnActivation* a, DnnAction* aa) +{ + DnnTransition* t = new DnnTransition (name, this, s, a, aa); + Transitions.Append (t); + return t; +} + +void +DnnState :: Activate (DnnBehaviour* b, DnnToken* tk) +{ + CcuListIterOf t = Transitions; + while (++t) { + DnnBehaviourReaction* r = new DnnBehaviourReaction (b, *t); + (*t)->Activate (r, tk); + b->AddReaction (r); + } +} + +DnnTransition :: DnnTransition (const char* name, DnnState* from, DnnState* to, DnnActivation* a, DnnAction* aa) +: Name (name), + From (from), + To (to), + Activation (a), + Action (aa) +{ +} + +DnnTransition :: ~DnnTransition () +{ +} + +void +DnnTransition :: Activate (DnnBaseReaction* r, DnnToken* t) +{ + (*Activation) (r, t); +} + +DnnState* +DnnTransition :: Fire (DnnToken* tk, DnnEvent* ev) +{ + (*Action) (tk, ev); + return To; +} + +DnnBehaviourModel :: DnnBehaviourModel () +: Initial (0), + States () +{ +} + +DnnBehaviourModel :: ~DnnBehaviourModel () +{ + CcuListIterOf s = States; + while (++s) + delete *s; +} + +DnnState* +DnnBehaviourModel :: CreateState (const char* name) +{ + DnnState* s = new DnnState (name); + States.Append (s); + return s; +} + +DnnBehaviour :: DnnBehaviour (DnnBehaviourModel& m, DnnToken* tk) +: TheModel (&m), + CurState (m.GetInitial ()), + CurReactions (), + CurToken (tk) +{ + CurState->Activate (this, CurToken); +} + +void +DnnBehaviour :: Fire (DnnTransition* t, DnnEvent* ev) +{ + /* check consistency */ + if (CurState != t->GetOrigin ()) { + fprintf (stderr, "incoherent state in behaviour\n"); + abort (); + } + + /* disactivate */ + DnnBaseReaction* r; + while (r = CurReactions.RemoveFirst ()) + delete r; + + /* fire transition */ + CurState = t->Fire (CurToken, ev); + + /* activate new state */ + CurState->Activate (this, CurToken); +} + +DnnBehaviourReaction :: DnnBehaviourReaction (DnnBehaviour* b, DnnTransition* t) + : TheBehaviour (b), + TheTransition (t) +{ +} + +DnnBehaviourReaction :: ~DnnBehaviourReaction () +{ +} + +void +DnnBehaviourReaction :: Manage (DnnEvent& ev) +{ + TheBehaviour->Fire (TheTransition, &ev); +} -- cgit v1.1