/tutorial/sequencer/example3.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 62 code · 12 blank · 3 comment · 0 complexity · 6aa24ed094d1f73ec45838b6defd8cb6 MD5 · raw file

  1. class EXAMPLE3
  2. -- This example shows how to use periodic jobs.
  3. -- The user will see a rolling stick, it's position will change 10
  4. -- times per second. Every 3 seconds the program prints the progress report.
  5. create {ANY}
  6. make
  7. feature {}
  8. lm: LOOP_STACK
  9. counter2: INTEGER
  10. counter: INTEGER
  11. old_counter: INTEGER
  12. time: MICROSECOND_TIME
  13. make
  14. do
  15. time.update
  16. create lm.make
  17. lm.add_job(create {SIMPLE_BACKGROUND_JOB}.set_work(agent do_count, Void, 1))
  18. lm.add_job(create {SIMPLE_PERIODIC_JOB}.set_work(agent running, Void, 1, 0.5))
  19. lm.add_job(create {SIMPLE_PERIODIC_JOB}.set_work(agent progress_print, Void, 0, 3))
  20. lm.run
  21. end
  22. done: BOOLEAN
  23. do_count: BOOLEAN
  24. do
  25. counter := counter + 1
  26. Result := not done
  27. end
  28. running: BOOLEAN
  29. local
  30. s: STRING
  31. do
  32. inspect
  33. counter2 \\ 4
  34. when 0 then
  35. s := "%R-"
  36. when 1 then
  37. s := "%R/"
  38. when 2 then
  39. s := "%R|"
  40. when 3 then
  41. s := "%R\"
  42. end
  43. io.put_string(s)
  44. io.flush
  45. counter2 := counter2 + 1
  46. Result := not done
  47. end
  48. progress_print: BOOLEAN
  49. local
  50. now: MICROSECOND_TIME
  51. do
  52. io.put_string("%Rcounter = ")
  53. io.put_integer(counter)
  54. io.put_string(", work done = ")
  55. io.put_integer(counter - old_counter)
  56. io.put_string(", elapsed time : ")
  57. now.update
  58. io.put_real(time.elapsed_seconds(now))
  59. time := now
  60. io.put_new_line
  61. old_counter := counter
  62. done := counter > 10000
  63. Result := not done
  64. end
  65. end -- class EXAMPLE3