Example #1
0
 public PfcStepJoiner(PfcExecutionContext rootStepPfcec, IProcedureFunctionChart[] childPfCs)
 {
     Debug.Assert(rootStepPfcec.IsStepCentric);
     m_rootStepEc = rootStepPfcec;
     m_model      = m_rootStepEc.Model;
     m_idec       = null;
     m_onTransitionStateChanged = new TransitionStateMachineEvent(OnTransitionStateChanged);
     m_pendingActions           = new List <IProcedureFunctionChart>(childPfCs);
     m_pendingActions.ForEach(delegate(IProcedureFunctionChart kid) {
         kid.GetFinishTransition().MyTransitionStateMachine.TransitionStateChanged += m_onTransitionStateChanged;
     });
 }
Example #2
0
        public ExecutionEngine(IProcedureFunctionChart pfc, ExecutionEngineConfiguration eec)
        {
            m_executionEngineConfiguration = eec;
            m_model                   = pfc.Model;
            m_stepStateMachines       = new Dictionary <IPfcStepNode, StepStateMachine>();
            m_transitionStateMachines = new Dictionary <IPfcTransitionNode, TransitionStateMachine>();

            foreach (IPfcStepNode pfcStepNode in pfc.Steps)
            {
                StepStateMachine ssm = new StepStateMachine(pfcStepNode);
                ssm.StructureLocked = m_executionEngineConfiguration.StructureLockedDuringRun;
                m_stepStateMachines.Add(pfcStepNode, ssm);
                ssm.MyStep = pfcStepNode;
                ((PfcStep)pfcStepNode).MyStepStateMachine = ssm;
            }

            foreach (IPfcTransitionNode pfcTransNode in pfc.Transitions)
            {
                TransitionStateMachine tsm = new TransitionStateMachine(pfcTransNode);
                tsm.ScanningPeriod = m_executionEngineConfiguration.ScanningPeriod;
                m_transitionStateMachines.Add(pfcTransNode, tsm);
                tsm.MyTransition = pfcTransNode;
                ((PfcTransition)pfcTransNode).MyTransitionStateMachine = tsm;
            }

            StepStateMachineEvent ssme = new StepStateMachineEvent(anSSM_StepStateChanged);

            foreach (IPfcStepNode step in pfc.Steps)
            {
                step.MyStepStateMachine.StepStateChanged += ssme;
                foreach (IPfcTransitionNode transNode in step.SuccessorNodes)
                {
                    step.MyStepStateMachine.SuccessorStateMachines.Add(transNode.MyTransitionStateMachine);
                }
                if (step.MyStepStateMachine.SuccessorStateMachines.Count == 0)
                {
                    string message =
                        $"Step {step.Name} in PFC {step.Parent.Name} has no successor transition. A PFC must end with a termination transition. (Did you acquire an Execution Engine while the Pfc was still under construction?)";
                    throw new ApplicationException(message);
                }
            }

            TransitionStateMachineEvent tsme = new TransitionStateMachineEvent(aTSM_TransitionStateChanged);

            foreach (IPfcTransitionNode trans in pfc.Transitions)
            {
                TransitionStateMachine thisTsm = m_transitionStateMachines[trans];
                thisTsm.TransitionStateChanged += tsme;
                foreach (IPfcStepNode stepNode in trans.SuccessorNodes)
                {
                    thisTsm.SuccessorStateMachines.Add(m_stepStateMachines[stepNode]);
                }
                foreach (IPfcStepNode stepNode in trans.PredecessorNodes)
                {
                    thisTsm.PredecessorStateMachines.Add(m_stepStateMachines[stepNode]);
                }
            }

            List <IPfcStepNode> startSteps = pfc.GetStartSteps();

            _Debug.Assert(startSteps.Count == 1);
            m_startStep = m_stepStateMachines[startSteps[0]];
        }