/tutorial/sequencer/example4.e

http://github.com/tybor/Liberty · Specman e · 58 lines · 38 code · 10 blank · 10 comment · 2 complexity · c9378b24f8af1c9d3b72a009bdd3edc2 MD5 · raw file

  1. class EXAMPLE4
  2. -- This example shows that you can enter a new loop and when it
  3. -- terminates, the halted loop continues. Loops are managed on a stack.
  4. -- This is like opening some modal window, others elements from the
  5. -- interface don't work until the modal window is closed.
  6. -- NOTE: in real life applications, jobs will probably be complex. In
  7. -- this case you have to write a class for that job, inheriting from
  8. -- BACKGROUND_JOB or PERIODIC_JOB instead of just using SIMPLE_* versions.
  9. create {ANY}
  10. make
  11. feature {}
  12. ls: LOOP_STACK
  13. counter: INTEGER
  14. make
  15. do
  16. create ls.make
  17. ls.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent work1, Void, 1))
  18. ls.run
  19. end
  20. work1: BOOLEAN
  21. do
  22. io.put_integer(counter)
  23. io.put_new_line
  24. counter := counter + 1
  25. if counter = 5 then
  26. io.put_string("Starting %"modal%" code%N")
  27. ls.new_loop
  28. -- This new loop will stop when all it's jobs are done.
  29. -- The loop can be stopped using 'ls.break' for example
  30. -- if the 'Cancel' button in the modal window is pressed.
  31. ls.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent work2, Void, 1))
  32. io.put_string("The new loop is ready.%N")
  33. end
  34. Result := counter < 10
  35. end
  36. close: BOOLEAN
  37. work2: BOOLEAN
  38. do
  39. io.put_string("Modal work%N")
  40. if close then
  41. io.put_string("Stop modal%N")
  42. Result := False
  43. else
  44. close := True
  45. Result := True
  46. end
  47. end
  48. end -- class EXAMPLE4