CompositeStateMachine.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/WayneLibraries/Wrk/StateEngine/CompositeStateMachine.cs $
  4. *
  5. * 4 08-02-26 14:07 Mattias.larsson
  6. * Renamed stateName to factoryName.
  7. */
  8. #endregion
  9. #region Old file header
  10. /*===============================================================================
  11. * CompositeState
  12. *
  13. * Change history
  14. * When Who Comment
  15. * ---------- ------ ------------------------------------
  16. * 2006-07-17 RMa Created
  17. *
  18. ---------------------------------------------------------------------------------*/
  19. #endregion
  20. namespace Wayne.Lib.StateEngine
  21. {
  22. internal class CompositeStateMachine : StateMachine
  23. {
  24. #region Fields
  25. CompositeState ownerState;
  26. #endregion
  27. #region Construction
  28. public CompositeStateMachine(CompositeState ownerState)
  29. : base(ownerState.GetType().FullName, null, null) //The debug logger properties are assigned later.
  30. {
  31. this.ownerState = ownerState;
  32. }
  33. #endregion
  34. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "Wayne.Lib.StateEngine.StateEngineException.#ctor(System.String)")]
  35. public override void Start()
  36. {
  37. throw new StateEngineException("You may not call Start on a state machine in a composite state.");
  38. }
  39. /// <summary>
  40. /// Sends an event to the child state machine.
  41. /// </summary>
  42. /// <param name="stateEngineEvent"></param>
  43. public override void IncomingEvent(StateEngineEvent stateEngineEvent)
  44. {
  45. if (ParentStateMachine != null)
  46. ParentStateMachine.IncomingEvent(stateEngineEvent);
  47. }
  48. /// <summary>
  49. /// A composite state machine will alway return true for started.
  50. /// </summary>
  51. public override bool Started
  52. {
  53. get { return true; }
  54. }
  55. /// <summary>
  56. /// Override of the Create state method. This adds the functionality to equip the
  57. /// newly created state with a reference to the the parent composite state.
  58. /// </summary>
  59. /// <param name="factoryName"></param>
  60. /// <returns></returns>
  61. protected internal override State CreateState(string factoryName)
  62. {
  63. State newState = base.CreateState(factoryName);
  64. if (newState != null)
  65. newState.AssignParentState(ownerState);
  66. return newState;
  67. }
  68. }
  69. }