PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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