Ejemplo n.º 1
0
        /// <summary>
        /// Do a internal transition to another state using signalName
        /// </summary>
        /// <returns>
        /// true if handled
        /// </returns>
        /// <param name='signalName'>
        /// The name of the signal that will transition to another state
        /// </param>
        /// <param name='data'>
        /// any object that is passed between states
        /// </param>
        public bool StateTransitionInternal(string stateName, GQHSMParameters Params, string signalName)
        {
            GQHSMTransition transition         = null;
            string          fullTransitionName = stateName + "." + signalName;
            // if we know about the transition
            bool retVal = false;

            retVal = GetGuardedTransition(fullTransitionName, Params, ref transition);

            if (transition != null)
            {
                GQHSMState toState      = GetState(transition.GetDestinationStateID());
                GQHSMState fromState    = GetState(transition.GetSourceStateID());
                QState     stateHandler = GetTopState();
                if (toState != null)
                {
                    stateHandler = toState.GetStateHandler();
                }

                if (_instrument && !transition.DoNotInstrument)
                {
                    LogStateEvent(StateLogType.EventTransition, GetCurrentState(), stateHandler, transition.Name, signalName);
                }

                if (!transition.IsInnerTransition)
                {
                    DoTransitionTo(stateHandler, transition.GetSlot());
                }

                // still execute actions on this inner transition
                transition.InvokeActions();

                retVal = true;
            }
            else if (signalName == "Internal.TransitionTo")
            {
                if (Params.Count == 1)
                {
                    GQHSMState state = (GQHSMState)Params[0].Value;
                    DoTransitionTo(state.GetStateHandler());
                    return(true);
                }

                return(false);
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        public QState StateHandler(IQEvent ev)
        {
            GQHSMManager manager = GQHSMManager.Instance;

            switch (ev.QSignal)
            {
            case QSignals.Init:
            {
                GQHSMState childStartState = GetChildStartState();
                if (childStartState != null)
                {
                    if (_parentHSM.Instrument && !DoNotInstrument)
                    {
                        _parentHSM.LogStateEvent(StateLogType.Init, _stateHandler, childStartState.GetStateHandler());
                    }
                    _parentHSM.InitState(childStartState.GetStateHandler());
                    return(null);
                }
                _parentHSM.ResetTimeOuts(Id);
            }
            break;

            case QSignals.Entry:
            {
                if (_parentHSM.Instrument && !DoNotInstrument)
                {
                    _parentHSM.LogStateEvent(StateLogType.Entry, _stateHandler);
                }
                if (_entryActions != null)
                {
                    _entryActions.InvokeActionHandlers();
                }
                _parentHSM.SetTimeOuts(Id);
            }
                return(null);

            case QSignals.Exit:
            {
                _parentHSM.ClearTimeOuts(Id);
                if (_parentHSM.Instrument && !DoNotInstrument)
                {
                    _parentHSM.LogStateEvent(StateLogType.Exit, _stateHandler);
                }
                if (_exitActions != null)
                {
                    _exitActions.InvokeActionHandlers();
                }
            }
                return(null);

            case QSignals.Empty:
            {
            }
            break;

            default:
            {
                GQHSMParameters evParams;
                if (ev.QData is GQHSMParameters)
                {
                    evParams = (GQHSMParameters)ev.QData;
                }
                else
                {
                    evParams = new GQHSMParameters(ev.QData);
                }

                if (evParams[0] != null)
                {
                    manager.Globals["ev"].Copy(evParams[0]);
                }


                if (_parentHSM.StateTransitionInternal(_fullName, evParams, ev.QSignal))
                {
                    return(null);
                }
            }
            break;
            }

            return(_parentHSM.GetStateHandler(ParentId));
        }