/src/lib/sequencer/time_events.e

http://github.com/tybor/Liberty · Specman e · 110 lines · 75 code · 8 blank · 27 comment · 9 complexity · 7d54a25500f190962c4f1f2ebf49bf5e MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. expanded class TIME_EVENTS
  5. feature {ANY}
  6. timeout (timeout_ms: INTEGER): TIMEOUT_EVENT
  7. -- `timeout_ms' is the max time in milliseconds to wait, starting from when EVENTS_SET.wait
  8. -- is called.
  9. do
  10. Result ::= item(timeout_events)
  11. if Result = Void then
  12. create Result.make
  13. if empty_slot = -1 then
  14. timeout_events.add_last(create {WEAK_REFERENCE[TIMEOUT_EVENT]}.set_item(Result))
  15. else
  16. timeout_events.item(empty_slot).set_item(Result)
  17. end
  18. end
  19. Result.set_timeout(timeout_ms)
  20. end
  21. in_time (timeout_ms: INTEGER): DATE_EVENT
  22. -- `timeout_ms' is the maximum time in milliseconds to wait starting from now on.
  23. do
  24. Result ::= item(date_events)
  25. if Result = Void then
  26. create Result.make
  27. if empty_slot = -1 then
  28. date_events.add_last(create {WEAK_REFERENCE[DATE_EVENT]}.set_item(Result))
  29. else
  30. date_events.item(empty_slot).set_item(Result)
  31. end
  32. end
  33. Result.in_time(timeout_ms)
  34. end
  35. at_date (date: MICROSECOND_TIME): DATE_EVENT
  36. -- `date' is the latest moment `wait' can wait.
  37. do
  38. Result ::= item(date_events)
  39. if Result = Void then
  40. create Result.make
  41. if empty_slot = -1 then
  42. date_events.add_last(create {WEAK_REFERENCE[DATE_EVENT]}.set_item(Result))
  43. else
  44. date_events.item(empty_slot).set_item(Result)
  45. end
  46. end
  47. Result.at_date(date)
  48. end
  49. feature {}
  50. item (events: FAST_ARRAY[WEAK_REFERENCE[TIME_EVENT]]): TIME_EVENT
  51. local
  52. i: INTEGER
  53. do
  54. from
  55. empty_slot := -1
  56. i := events.lower
  57. until
  58. Result /= Void or else i > events.upper
  59. loop
  60. Result := events.item(i).item
  61. if Result = Void then
  62. empty_slot := i
  63. elseif Result.is_expected then
  64. Result := Void
  65. end
  66. i := i + 1
  67. end
  68. ensure
  69. Result /= Void implies not Result.is_expected
  70. Result = Void implies empty_slot = -1 or else events.item(empty_slot) = Void
  71. end
  72. feature {}
  73. timeout_events: FAST_ARRAY[WEAK_REFERENCE[TIMEOUT_EVENT]]
  74. once
  75. create Result.make(0)
  76. end
  77. date_events: FAST_ARRAY[WEAK_REFERENCE[DATE_EVENT]]
  78. once
  79. create Result.make(0)
  80. end
  81. empty_slot: INTEGER
  82. end -- class TIME_EVENTS
  83. --
  84. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  85. --
  86. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  87. -- of this software and associated documentation files (the "Software"), to deal
  88. -- in the Software without restriction, including without limitation the rights
  89. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  90. -- copies of the Software, and to permit persons to whom the Software is
  91. -- furnished to do so, subject to the following conditions:
  92. --
  93. -- The above copyright notice and this permission notice shall be included in
  94. -- all copies or substantial portions of the Software.
  95. --
  96. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  97. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  98. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  99. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  100. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  101. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  102. -- THE SOFTWARE.