Exemplo n.º 1
0
 /// <summary>Constructor</summary>
 /// <param name="wrappedObject">Has common data and functions for all states</param>
 /// <param name="state">The state machine's main state</param>
 /// <remarks>
 /// The main state will be a super state or parallel super state implementation. You
 /// can use a single state implementation if you only want the wrapped object to be
 /// driven by periodic timer and have access to the messaging architecture
 /// </remarks>
 public SpMachine([NotNull] TMachine?wrappedObject, [NotNull] ISpState <TMsgId>?state)
 {
     WrapErr.ChkParam(wrappedObject, "wrappedObject", 50170);
     WrapErr.ChkParam(state, "state", 50171);
     this.wrappedObject = wrappedObject;
     this.state         = state;
 }
Exemplo n.º 2
0
        public Level2Ss(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level2, dataClass)
        {
            MySuperState level3Ss = new Level3Ss(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(level3Ss);
            //this.AddSubState(active);

            //// Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            ////idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition

            // Register as the result event from previous state comming from abort to it
            //level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            //// Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(level3Ss);
        }
Exemplo n.º 3
0
        /// <summary>
        /// One of the substates must be listed as the start state of
        /// this superstate. It also becomes the current state for the first tick
        /// </summary>
        /// <param name="state"></param>
        public void SetEntryState(ISpState state)
        {
            this.entryState = state;

            // Set the current state at the same time
            this.currentState = this.entryState;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor with DI injectable main state
 /// </summary>
 /// <param name="wrappedObject"></param>
 /// <param name="state">The state machine's main state</param>
 /// <remarks>
 /// The main state will be a super state or parallel super state implementation. You
 /// can use a single state implementation if you only want the wrapped object to be
 /// driven by periodic timer and have access to the messaging architecture
 /// </remarks>
 public SpMachine(T wrappedObject, ISpState state)
 {
     WrapErr.ChkParam(wrappedObject, "wrappedObject", 50170);
     WrapErr.ChkParam(state, "state", 50171);
     this.wrappedObject = wrappedObject;
     this.state         = state;
 }
Exemplo n.º 5
0
        public Level3Ss(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level3, dataClass)
        {
            MyState idle   = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(MyMsgId.Start, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition
            //idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnResultTransition(MyMsgId.Start, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, active, null));


            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(MyMsgId.Stop, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            active.RegisterOnResultTransition(MyMsgId.Stop, new SpStateTransition <MyMsgId>(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition <MyMsgId>(SpStateTransitionType.ExitState, null, null));

            this.SetEntryState(idle);
        }
Exemplo n.º 6
0
        public RecoverySs(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Recovery, dataClass)
        {
            this.idle   = new IdleSt(this, dataClass);
            this.active = new ActiveSt(this, dataClass);

            this.AddSubState(this.idle);
            this.AddSubState(this.active);

            // Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));

            //idle.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            this.idle.ToNextOnEvent(MyMsgId.Start, this.active);
            this.idle.ToExitOnEvent(MyMsgId.Abort);

            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition<MyEventType>(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition<MyEventType>(SpStateTransitionType.ExitState, null, null));

            this.active.ToNextOnEvent(MyMsgId.Stop, this.idle);
            this.active.ToExitOnEvent(MyMsgId.Abort);

            // Only on events registered.  On abor goes exit state


            this.SetEntryState(idle);
        }
Exemplo n.º 7
0
        public SuperStateIdle(ISpState <DemoMsgId> parent, DemoStateId id, DemoMachineObj machine)
            : base(parent, id, machine)
        {
            this.waitOnStart = this.AddSubState(new StateWaitOnStart(this, DemoStateId.WaitOnStart, machine));

            this.SetEntryState(this.waitOnStart);
        }
Exemplo n.º 8
0
        public Level2Ss(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level2, dataClass)
        {
            MySuperState level3Ss = new Level3Ss(this, dataClass);

            //MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(level3Ss);
            //this.AddSubState(active);


            //// Register Idle state transitions
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            ////idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition

            // Register as the result event from previous state comming from abort to it
            //level3Ss.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //level3Ss.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition<MyMsgId>(SpStateTransitionType.ExitState, null, new MyTickMsg()));
            level3Ss.RegisterOnResultTransition(MyMsgId.Abort, new SpStateTransition <MyMsgId>(SpStateTransitionType.ExitState, null, null));


            //// Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            //active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(level3Ss);
        }
Exemplo n.º 9
0
 /// <summary>Constructor</summary>
 /// <param name="parent">The parent state</param>
 /// <param name="msgFactory">Message Factory</param>
 /// <param name="idConverter">The integer id to string converter</param>
 /// <param name="id">Unique state id converter</param>
 /// <param name="wrappedObject">The generic object that the states represent</param>
 public SpStateBase(ISpState parent, ISpMsgFactory msgFactory, ISpIdConverter idConverter, ISpToInt id, T wrappedObject)
 {
     WrapErr.ChkParam(msgFactory, "msgFactory", 9999);
     WrapErr.ChkParam(wrappedObject, "wrappedObject", 50200);
     this.msgFactory  = msgFactory;
     this.idConverter = idConverter;
     this.InitStateIds(parent, id.ToInt());
     this.wrappedObject = wrappedObject;
 }
Exemplo n.º 10
0
        public SS_A2(ISpState <MyMsgId> parent, MyStateID id, MyDataClass dataClass)
            : base(parent, id, dataClass)
        {
            // This super state will exit on entry of first state
            this.stDone = this.AddSubState(new S_ExitDoneOnEntry(this, MyStateID.S_A1_ExitEntry, dataClass));
            this.stDone.ToExitOnResult(MyMsgId.RespDone);

            this.SetEntryState(this.stDone);
        }
Exemplo n.º 11
0
        public SS_A(ISpState <MyMsgId> parent, MyDataClass dataClass)
            : base(parent, MyStateID.SS_A1, dataClass)
        {
            this.doneSt = this.AddSubState(new S_A1(this, dataClass));

            // The Done state will trigger the exit on 4th ticks. The first tick causes the entry
            this.doneSt.ToExitOnResult(MyMsgId.RespDone);

            this.SetEntryState(this.doneSt);
        }
Exemplo n.º 12
0
        public SS_M(MyDataClass dataClass)
            : base(MyStateID.SS_M, dataClass)
        {
            this.ssA = this.AddSubState(new SS_A(this, dataClass));
            this.ssB = this.AddSubState(new SS_B(this, dataClass));

            this.ssA.ToNextOnResult(MyMsgId.RespDone, this.ssB);

            this.SetEntryState(this.ssA);
        }
 private void DoTick(ISpEventListner listner, ISpState <MyMsgId> st, string expected, bool assertOnFail = true)
 {
     listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Tick));
     Thread.Sleep(600);
     //Log.Warning(9, () => string.Format("State:{0}", st.CurrentStateName));
     Log.Warning(0, () => string.Format(" -*-*- Current state: {0} -*-*-", st.CurrentStateName));
     if (assertOnFail)
     {
         Assert.AreEqual(expected, st.CurrentStateName);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Override and seal the ExecOnExit to automate common super state
        /// entry functionality. After execution the SuperStateOnExit()
        /// is called.
        /// </summary>
        /// <param name="msg">The incoming message</param>
        /// <returns>The appropriate return message</returns>
        protected sealed override void ExecOnExit()
        {
            Log.Info(this.className, "ExecOnExit", this.FullName);
            WrapErr.ChkTrue(this.IsEntryExcecuted, 9999, () => {
                return(String.Format("ExecOnExit called Before OnEntry {0} State", this.FullName));
            });

            if (this.currentState != null)
            {
                this.currentState.OnExit();
            }
            this.currentState = this.entryState;
        }
Exemplo n.º 15
0
        public SuperStateNotStarted(ISpState <DemoMsgId> parent, DemoStateId id, DemoMachineObj machine)
            : base(parent, id, machine)
        {
            // Create sub-states
            this.recovery     = this.AddSubState(new StateSimpleRecovery(this, DemoStateId.SimpleRecovery, machine));
            this.initialising = this.AddSubState(new StateInitIO(this, machine));

            // Register events and internal result returns
            this.recovery.ToNextOnResult(DemoMsgId.RecoveryComplete, this.initialising);
            this.initialising.ToExitOnResult(DemoMsgId.InitComplete);

            this.SetEntryState(this.recovery);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initialise the state id chain from ancestors to this state
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="id"></param>
 private void InitStateIds(ISpState parent, int id)
 {
     // Add any ancestor state ids to the chain
     WrapErr.ToErrorReportException(50207, () => {
         if (parent != null)
         {
             WrapErr.ChkVar(parent.IdChain, 50206, "The Parent has a Null Id Chain");
             this.idChain.Clear();
             parent.IdChain.ForEach((item) => this.idChain.Add(item));
         }
         // This state id is the leaf
         this.idChain.Add(id);
         this.BuildName();
     });
 }
Exemplo n.º 17
0
        public SS_M2(MyDataClass dataClass)
            : base(MyStateID.SS_M2, dataClass)
        {
            //this.firstState = this.AddSubState(new EntryState(this, MyStateID.Level3, dataClass));
            this.ssADoneOnEntry = this.AddSubState(new SS_A2(this, MyStateID.SS_A1, dataClass));
            this.ssB            = this.AddSubState(new SS_B(this, dataClass));

            // Add first state to just handle initial tick
            //this.firstState.ToNextOnResult(MyMsgId.RespDone, this.ssADoneOnEntry);

            this.ssADoneOnEntry.ToNextOnResult(MyMsgId.RespDone, this.ssB);

            //this.SetEntryState(this.firstState);
            this.SetEntryState(this.ssADoneOnEntry);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Handle the NextState Transition type by setting the next state as
        /// </summary>
        /// <param name="tr"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        private ISpStateTransition HandleNextStateTransitionType(ISpStateTransition tr, ISpEventMessage msg)
        {
            Log.Info(this.className, "HandleNextStateTransitionType", String.Format("'{0}' State", this.FullName));

            WrapErr.ChkTrue(tr.TransitionType == SpStateTransitionType.NextState, 9999,
                            () => { return(String.Format("{0} is not NextState", tr.TransitionType)); });

            WrapErr.ChkVar(tr.NextState, 9999, () => { return
                                                       (String.Format(
                                                            "State {0} Specified Next State on Event {1} but Next State Null",
                                                            this.currentState.FullName, this.GetCachedEventId(msg.EventId))); });

            this.currentState.OnExit();
            this.currentState = tr.NextState;
            return(this.currentState.OnEntry(this.MsgFactory.GetDefaultResponse(msg)));
        }
Exemplo n.º 19
0
        public MainSs(MyDataClass dataClass)
            : base(MyStateID.Main, dataClass)
        {
            // Create and add the sub-states of this super state
            this.notStarted = new NotStartedSs(this, dataClass);
            this.recovery   = new RecoverySs(this, dataClass);
            this.AddSubState(this.notStarted);
            this.AddSubState(this.recovery);

            // Register Started state transitions


            //notStarted.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition(SpStateTransitionType.NextState, recovery, null));
            //notStarted.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            // Register OnResult so that the Superstate can handle its state's ExitState transitions
            //            notStarted.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, null));

            // Register a transition based on on internal processing
            //notStarted.RegisterOnResultTransition(
            //    new SpEnumToInt(MyEventType.Abort),
            //    new SpStateTransition<MyEventType>(SpStateTransitionType.NextState,
            //    this.recovery, new MyTickMsg()));

            //notStarted.RegisterOnResultTransition(
            //    MyEventType.Abort,
            //    new SpStateTransition<MyEventType>(SpStateTransitionType.NextState,
            //    this.recovery, new MyTickMsg()));

            notStarted.ToNextOnResult(MyMsgId.Abort, this.recovery, new MyTickMsg());


            //// Register active state transitions
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));


            //// Only on events registered.  On abor goes exit state


            //this.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, new MyTickMsg()));

            // Set the entry state as the not Started SS
            this.SetEntryState(this.notStarted);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Execute logic on entry into this superstate
        /// </summary>
        /// <param name="msg">The incoming message with event</param>
        /// <returns>The return transition object with result information</returns>
        public sealed override ISpStateTransition OnEntry(ISpEventMessage msg)
        {
            Log.Info(this.className, "OnEntry", String.Format("'{0}' State Event {1}", this.FullName, this.GetCachedEventId(msg.EventId)));
            WrapErr.ChkVar(this.entryState, 9999, "The 'SentEntryState() Must be Called in the Constructor");

            // Find if there are exit conditions OnEntry at the SuperState level and excecute them first
            // This will check OnEvent transitions queue and transitions from the overriden ExecOnEntry
            ISpStateTransition t = base.OnEntry(msg);

            if (t.TransitionType != SpStateTransitionType.SameState)
            {
                return(t);
            }

            // return transition
            this.currentState = this.entryState;
            return(this.currentState.OnEntry(msg));
        }
Exemplo n.º 21
0
        public RecoverySs(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Recovery, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Register active state transitions
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Only on events registered.  On abor goes exit state

            this.SetEntryState(idle);
        }
Exemplo n.º 22
0
        public NotStartedSs(ISpState <MyMsgId>?parent, MyDataClass dataClass)
            : base(parent, MyStateID.NotStarted, dataClass)
        {
            // Setup sub-states
            this.StateIdle   = (MyState)this.AddSubState(new IdleSt(this, dataClass));
            this.StateActive = (MyState)this.AddSubState(new ActiveSt(this, dataClass));

            // Idle State event and results transitions
            this.StateIdle.ToNextOnEvent(MyMsgId.Start, this.StateActive);
            this.StateIdle.ToExitOnEvent(MyMsgId.Abort);
            this.StateIdle.ToNextOnResult(MyMsgId.Start, this.StateActive);

            // Active State event and results transitions
            this.StateActive.ToNextOnEvent(MyMsgId.Stop, this.StateIdle, new MyTickMsg());
            this.StateActive.ToDeferedOnEvent(MyMsgId.Abort);
            this.StateActive.ToNextOnResult(MyMsgId.Stop, this.StateIdle, new MyTickMsg());

            // Super state transitions
            this.ToNextOnResult(MyMsgId.Stop, this.StateIdle);

            this.SetEntryState(this.StateIdle);
        }
Exemplo n.º 23
0
        public SuperStateMain(DemoMachineObj machine)
            : base(DemoStateId.Initial, machine)
        {
            this.notStarted = this.AddSubState(new SuperStateNotStarted(this, DemoStateId.NotStarted, machine));
            this.idle       = this.AddSubState(new SuperStateIdle(this, DemoStateId.Idle, machine));

            this.notStarted.ToNextOnResult(DemoMsgId.InitComplete, this.idle);

            //this.notStarted.ToNextOnResult(DemoMsgId.Tick, this.idle, new MsgTick());



            Log.Warning(0, "----- Not started transitions -----");
            //this.notStarted.DebugDumpTransitions();

            //Log.Warning(0, "----- Main transitions -----");
            //            this.DebugDumpTransitions();



            this.SetEntryState(this.notStarted);
        }
Exemplo n.º 24
0
        public NotStartedSs(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.NotStarted, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            // results
            idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, new MyTickMsg()));

            // Register active state transitions
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, new MyTickMsg()));

            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.Defered, null, null));

            //            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, new MyTickMsg()));

            // Register my defered
            // If I get an abort handed to me by a state I will push the internal transition to idle

            // TODO - use this to provoque a check error
            //this.RegisterOnResultTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));

            this.SetEntryState(idle);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">The parent state</param>
 /// <param name="msgFactory">Message Factory</param>
 /// <param name="id">Unique state id</param>
 /// <param name="wrappedObject">The generic object that the states represent</param>
 public SpState(ISpState <TMsgId> parent, ISpMsgFactory msgFactory, TState id, TMachine wrappedObject)
     : base(parent, msgFactory, id, wrappedObject)
 {
 }
Exemplo n.º 26
0
 public DemoStateMachine(DemoMachineObj wrappedObject, ISpState <DemoMsgId> entryState)
     : base(wrappedObject, entryState)
 {
 }
        private SpStateMachineEngine GetEngine(out ISpEventListner listner, MyDataClass dataClass, ISpState firstState)
        {
            ISpStateMachine sm = new MyStateMachine(dataClass, firstState);
            ISpEventStore store = new SimpleDequeEventStore(new MyTickMsg());
            ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
            ISpPeriodicTimer timer = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 500));
            //ISpEventListner listner = new SimpleEventListner();
            listner = new SimpleEventListner();

            listner.ResponseReceived += new Action<ISpEventMessage>((msg) => { });

            // Simulates DI
            return new SpStateMachineEngine(listner, store, behavior, sm, timer);
        }
Exemplo n.º 28
0
 //        private int triggerCount = 0;
 public Level2Idle(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }
Exemplo n.º 29
0
        public Level3Ss(ISpState parent, MyDataClass dataClass)
            : base(parent, MyStateID.Level3, dataClass)
        {
            MyState idle = new IdleSt(this, dataClass);
            MyState active = new ActiveSt(this, dataClass);

            this.AddSubState(idle);
            this.AddSubState(active);

            // Register Idle state transitions
            idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));
            //idle.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this idle class just returns whatever msg we send in. So send Start and it will return it as its return value and provok this transition
            idle.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Start), new SpStateTransition(SpStateTransitionType.NextState, active, null));

            // Register active state transitions
            active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // results - this class just returns whatever msg we send in. So send Stop and it will return it as its return value and provok this transition
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            active.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            this.SetEntryState(idle);
        }
Exemplo n.º 30
0
 public WaitOnInput(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }
Exemplo n.º 31
0
 public S_ExitDoneOnEntry(ISpState <MyMsgId> parent, MyStateID id, MyDataClass dataClass)
     : base(parent, id, dataClass)
 {
 }
Exemplo n.º 32
0
 //        private int triggerCount = 0;
 public ActiveSt(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Active, dataClass)
 {
 }
 public smDerivedNativeFail(IDisposable wo, ISpState <MyMsgId> state)
     : base(wo, state)
 {
 }
Exemplo n.º 34
0
 public StateInitIO(ISpState <DemoMsgId> parent, DemoMachineObj machine)
     : base(parent, DemoStateId.InitIO, machine)
 {
     this.inputs  = DummyDI.InputsInstance;
     this.outputs = DummyDI.OutputsInstance;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">The transition type</param>
 /// <param name="nextState">The next state for next state transitions</param>
 /// <param name="returnMsg">The repsponse to return to the caller</param>
 public SpStateTransition(SpStateTransitionType type, ISpState nextState, ISpEventMessage returnMsg)
 {
     this.type = type;
     this.nextState = nextState;
     this.returnMsg = returnMsg;
 }
Exemplo n.º 36
0
 //        private int triggerCount = 0;
 public IdleSt(ISpState parent, MyDataClass dataClass)
     : base(parent, MyStateID.Idle, dataClass)
 {
 }
Exemplo n.º 37
0
 public MyState(ISpState <MyMsgId> parent, MyStateID id, MyDataClass dataClass)
     : base(parent, MyDummyDI.MsgFactoryInstance, id, dataClass)
 {
 }
Exemplo n.º 38
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">The parent state</param>
 /// <param name="msgFactory">Message Factory</param>
 /// <param name="idConverter">The integer id to string converter</param>
 /// <param name="id">Unique state id</param>
 /// <param name="wrappedObject">The generic object that the states represent</param>
 public SpSuperState(ISpState parent, ISpMsgFactory msgFactory, ISpIdConverter idConverter, ISpToInt id, T wrappedObject)
     : base(parent, msgFactory, idConverter, id, wrappedObject)
 {
 }
Exemplo n.º 39
0
 public SS_B(ISpState <MyMsgId> parent, MyDataClass dataClass)
     : base(parent, MyStateID.SS_B1, dataClass)
 {
     this.bSt = this.AddSubState(new S_B1(this, dataClass));
     this.SetEntryState(this.bSt);
 }
Exemplo n.º 40
0
 /// <summary>
 /// Add a state to the list of sub states
 /// </summary>
 /// <param name="state"></param>
 public void AddSubState(ISpState state)
 {
     this.substates.Add(state);
 }