QueueRoutine.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.RT.Routine;
  7. namespace Aitex.Core.RT.Routine
  8. {
  9. public class QueueRoutine
  10. {
  11. private Queue<IRoutine> _steps = new Queue<IRoutine>();
  12. private IRoutine _currentStep = null;
  13. public void Add(IRoutine step)
  14. {
  15. _steps.Enqueue(step);
  16. }
  17. public void Reset()
  18. {
  19. _steps.Clear();
  20. _currentStep = null;
  21. }
  22. public void Abort()
  23. {
  24. if (_currentStep != null)
  25. _currentStep.Abort();
  26. Reset();
  27. }
  28. public Result Start(params object[] objs)
  29. {
  30. if (_steps.Count == 0)
  31. return Result.DONE;
  32. _currentStep = _steps.Dequeue();
  33. return _currentStep.Start(objs);
  34. }
  35. public Result Monitor(params object[] objs)
  36. {
  37. Result ret = Result.FAIL;
  38. if (_currentStep != null)
  39. {
  40. ret = _currentStep.Monitor();
  41. }
  42. if (ret == Result.DONE)
  43. {
  44. _currentStep = _steps.Count > 0 ? _steps.Dequeue() : null;
  45. if (_currentStep != null)
  46. {
  47. return _currentStep.Start(objs);
  48. }
  49. }
  50. return ret;
  51. }
  52. }
  53. }