public void AddTransitionNameMap(GQHSMTransition transition) { string tName = transition.GetFullName(); // find state this transition is associated with GQHSMState state = GetState(transition.GetSourceStateID()); if (state != null) { tName = state.GetFullName() + "." + tName; } if (transition.GuardCondition.Length == 0) { if (!_nameToTransitionMap.ContainsKey(tName)) { _nameToTransitionMap.Add(tName, transition); } else { Logger.Error("Duplicate name in transitions {0}\n", tName); } } else { _nameToGuardedTransitionMultiMap.Add(tName, transition); } }
public void Init(GQHSMState parent) { base.Init(); _parent = parent; if (ChildStates != null) { foreach (GQHSMState gs in ChildStates) { gs.Init(this); } } if (EntryAction.Length > 0) { _entryActions = new GQHSMActions(_parentHSM, EntryAction); } if (ExitAction.Length > 0) { _exitActions = new GQHSMActions(_parentHSM, ExitAction); } if ((_stateCommands != null) && (_stateCommands.Length > 0)) { _actions = new GQHSMActions(_parentHSM, _stateCommands); } }
public GQHSMState GetState(Guid Id) { GQHSMState foundState = null; // see if it is in the list and if so return it's QState delegate _guidToStateMap.TryGetValue(Id, out foundState); return(foundState); }
public string RegisterState(GQHSMState qState) { // see if it is in the list and if so return it's QState delegate if (_guidToStateMap.ContainsKey(qState.Id)) { Logger.Error("Can't have duplicate Guids for states : {0}", qState.Id); return(null); } _guidToStateMap.Add(qState.Id, qState); return(AddStateNameMap(qState)); }
/// <summary> /// The default constructor for the object /// </summary> public GQHSMState() { Name = ""; DoNotInstrument = false; Id = System.Guid.NewGuid(); EntryAction = ""; ExitAction = ""; IsStartState = false; Note = ""; _parent = null; _parentHSM = null; _stateCommands = null; }
public string AddStateNameMap(GQHSMState state) { GQHSMState curState = state; string fullName = state.Name; while ((curState = curState.GetParent()) != null) { fullName = curState.Name + "." + fullName; } _nameToStateMap.Add(fullName, state); return(fullName); }
/// <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); }
public override void PreInit(GQHSM parentHSM) { base.PreInit(parentHSM); _fullName = _parentHSM.RegisterState(this); if (ChildStates != null) { foreach (GQHSMState gs in ChildStates) { gs.PreInit(parentHSM); if (gs.IsStartState) { _childStartState = gs; } } } _stateHandler = new QState(this, StateHandler, Name); }
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)); }