public GQHSMTransition GetTransition(string transistionName) { GQHSMTransition foundTransition = null; _nameToTransitionMap.TryGetValue(transistionName, out foundTransition); return(foundTransition); }
public bool GetGuardedTransition(string signalName, GQHSMParameters Params, ref GQHSMTransition transition) { List <GQHSMTransition> guardTansitions; guardTansitions = _nameToGuardedTransitionMultiMap[signalName]; // retrieve unguarded transition if any _nameToTransitionMap.TryGetValue(signalName, out transition); if ((guardTansitions.Count == 0) && (transition == null)) { return(false); } foreach (GQHSMTransition gTransition in guardTansitions) { // call methods directly if any. if (gTransition.InvokeGuards()) { transition = gTransition; break; } if (CallGuardHandler(gTransition.GuardCondition, Params)) { transition = gTransition; break; } } return(true); }
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); } }
/// <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); }
/// <summary> /// Parse Timeout Expressions /// single float (i.e. 1.0, 0.1, etc converts to TimeSpan.FromSeconds(value) /// every float (i.e. "every 1.0") repeats timeout every TimeSpan.FromSeconds(value) /// at DateTime (i.e. "at Sat, 01 Nov 2008 19:35:00 GMT") does single at DateTime.Parse(value) /// </summary> /// <param name="transition"></param> /// <param name="expression"></param> public void RegisterTimeOutExpression(GQHSMTransition transition, string expression) { string timeOutExpression = expression.Trim(); string eventSignal = transition.EventSignal; if (transition.EventSignal.Length > 0) { eventSignal = transition.EventSignal; } else { eventSignal = transition.Name; } if (timeOutExpression.IndexOf(" ") == -1) { double timeOut = 0.0f; GQHSMAction action = null; if (!Double.TryParse(timeOutExpression, out timeOut)) { action = new GQHSMAction(this, timeOutExpression); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), TimeSpan.FromSeconds(timeOut), new QEvent(eventSignal), action)); } else { string[] strList = timeOutExpression.Split(' '); string timeOutValue = strList [strList.Length - 1].Trim(); TimeOutType flag = TimeOutType.Single; if (timeOutExpression.StartsWith("every")) { flag = TimeOutType.Repeat; } if (timeOutExpression.StartsWith("at")) { flag = TimeOutType.Single; DateTime dt; GQHSMAction action = null; if (!DateTime.TryParse(timeOutValue, out dt)) { action = new GQHSMAction(this, timeOutValue); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), dt, new QEvent(eventSignal), action)); } else { Double timeOut = 0.0f; GQHSMAction action = null; if (!Double.TryParse(timeOutValue, out timeOut)) { action = new GQHSMAction(this, timeOutValue); } RegisterTimeOutExpression(transition.GetSourceStateID(), new GQHSMTimeOut(transition.State[0].Name + "." + transition.GetFullName(), TimeSpan.FromSeconds(timeOut), new QEvent(eventSignal), flag, action)); } } }
public void RegisterTransition(GQHSMTransition transition) { AddTransitionNameMap(transition); }