/// <summary> /// Determines if the queuing the an event causes a state to enter before defaultWaitTime elapses. /// </summary> /// <param name="eventToInject">The event to queue.</param> /// <param name="stateToWaitFor">The state to wait for.</param> /// <param name="waitTime">The time in ms to wait for the stateToWaitFor to enter.</param> /// <returns> /// True if the stateToWaitFor is entered. /// False if the stateToWaitFor is not entered before time expires. /// </returns> /// <remarks> /// This is a blocking call, the caller may be blocked for as long as waitTime. /// </remarks> public bool doesEventResultInState(NSFEvent eventToInject, NSFState stateToWaitFor, int waitTime) { firstSignal.clear(); stateToWaitFor.EntryActions += firstSignal.send; if (eventToInject != null) { eventToInject.queueEvent(); } if (stateToWaitFor.isActive()) { stateToWaitFor.EntryActions -= firstSignal.send; return(true); } if (!firstSignal.wait(waitTime)) { stateToWaitFor.EntryActions -= firstSignal.send; return(false); } stateToWaitFor.EntryActions -= firstSignal.send; return(true); }
/// <summary> /// Determines if the queuing the an event causes two states to enter before waitTime elapses. /// </summary> /// <param name="eventToInject">The event to queue.</param> /// <param name="stateToWaitFor">The first of two states to wait for.</param> /// <param name="secondStateToWaitFor">The second of two states to wait for.</param> /// <param name="waitTime">The time in ms to wait for the each state to enter.</param> /// <returns> /// True if both states are entered. /// False if either of the states fails to enter before time expires. /// </returns> /// <remarks> /// This is a blocking call, the caller may be blocked for as long as twice waitTime. /// The states may be congruently entered. /// </remarks> public bool doesEventResultInState(NSFEvent eventToInject, NSFState stateToWaitFor, NSFState secondStateToWaitFor, int waitTime) { secondSignal.clear(); stateToWaitFor.EntryActions += secondSignal.send; secondStateToWaitFor.EntryActions += secondSignal.send; if (!doesEventResultInState(eventToInject, stateToWaitFor, waitTime)) { secondStateToWaitFor.EntryActions -= secondSignal.send; return(false); } if (secondStateToWaitFor.isActive()) { secondStateToWaitFor.EntryActions -= secondSignal.send; return(true); } if (!secondSignal.wait(waitTime)) { secondStateToWaitFor.EntryActions -= secondSignal.send; return(false); } secondStateToWaitFor.EntryActions -= secondSignal.send; return(true); }