CompositeStateMachine.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. using System;
  21. using System.Collections.Generic;
  22. using System.Text;
  23. namespace Wayne.Lib.StateEngine
  24. {
  25. internal class CompositeStateMachine : StateMachine
  26. {
  27. #region Fields
  28. CompositeState ownerState;
  29. #endregion
  30. #region Construction
  31. public CompositeStateMachine(CompositeState ownerState)
  32. : base(ownerState.GetType().FullName, null, null) //The debug logger properties are assigned later.
  33. {
  34. this.ownerState = ownerState;
  35. }
  36. #endregion
  37. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "Wayne.Lib.StateEngine.StateEngineException.#ctor(System.String)")]
  38. public override void Start()
  39. {
  40. throw new StateEngineException("You may not call Start on a state machine in a composite state.");
  41. }
  42. /// <summary>
  43. /// Sends an event to the child state machine.
  44. /// </summary>
  45. /// <param name="stateEngineEvent"></param>
  46. public override void IncomingEvent(StateEngineEvent stateEngineEvent)
  47. {
  48. if (ParentStateMachine != null)
  49. ParentStateMachine.IncomingEvent(stateEngineEvent);
  50. }
  51. /// <summary>
  52. /// A composite state machine will alway return true for started.
  53. /// </summary>
  54. public override bool Started
  55. {
  56. get { return true; }
  57. }
  58. /// <summary>
  59. /// Override of the Create state method. This adds the functionality to equip the
  60. /// newly created state with a reference to the the parent composite state.
  61. /// </summary>
  62. /// <param name="factoryName"></param>
  63. /// <returns></returns>
  64. protected internal override State CreateState(string factoryName)
  65. {
  66. State newState = base.CreateState(factoryName);
  67. if (newState != null)
  68. newState.AssignParentState(ownerState);
  69. return newState;
  70. }
  71. }
  72. }