Class: FSEvent
- Inherits:
-
Object
- Object
- FSEvent
- Includes:
- Util
- Defined in:
- lib/fsevent/framework.rb,
lib/fsevent.rb
Overview
framework.rb — fail safe event driven framework
Copyright © 2014 National Institute of Advanced Industrial Science and Technology (AIST)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Modules: Util Classes: AbstractDevice, FailSafeDevice, PeriodicSchedule, ProcessDevice, ProcessDeviceC, ScheduleMerger, SimpleDevice
Instance Attribute Summary collapse
-
#current_time ⇒ Object
readonly
Returns the value of attribute current_time.
Instance Method Summary collapse
-
#add_watch(watchee_device_name, status_name, reaction = :immediate) ⇒ Object
Called from a device.
-
#define_status(status_name, value) ⇒ Object
Called from a device to define the status.
-
#del_watch(watchee_device_name, status_name) ⇒ Object
Called from a device.
-
#initialize(initial_time = Time.now) ⇒ FSEvent
constructor
A new instance of FSEvent.
- #register_device(device, register_time = @current_time) ⇒ Object
-
#set_elapsed_time(t) ⇒ Object
Called from a device to set the elapsed time.
- #start ⇒ Object
-
#status_changed(status_name, value) ⇒ Object
Called from a device to notify the status.
-
#unregister_device(device_name) ⇒ Object
Called from a device.
Methods included from Util
nested_hash, nonempty_hash, reaction_immediate_at_beginning?, reaction_immediate_at_subsequent?
Constructor Details
#initialize(initial_time = Time.now) ⇒ FSEvent
Returns a new instance of FSEvent.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fsevent/framework.rb', line 21 def initialize(initial_time=Time.now) @current_time = initial_time @devices = {} # device_name -> device @status = {} # device_name -> status_name -> value # valid values of reaction: :immediate, :immediate_only_at_beginning, :schedule @watches = nested_hash(3) # watchee_device_name -> status_name -> watcher_device_name -> reaction @watch_patterns = [] # [watchee_device_name_pat, status_name_pat, watcher_device_name, reaction] @watched_status_change = nested_hash(3) # watcher_device_name -> watchee_device_name -> status_name -> value @q = Depq.new @schedule_locator = {} # device_name -> locator end |
Instance Attribute Details
#current_time ⇒ Object (readonly)
Returns the value of attribute current_time.
36 37 38 |
# File 'lib/fsevent/framework.rb', line 36 def current_time @current_time end |
Instance Method Details
#add_watch(watchee_device_name, status_name, reaction = :immediate) ⇒ Object
Called from a device. (mainly from registered().)
80 81 82 |
# File 'lib/fsevent/framework.rb', line 80 def add_watch(watchee_device_name, status_name, reaction = :immediate) Thread.current[:fsevent_device_watch_buffer] << [:add, watchee_device_name, status_name, reaction] end |
#define_status(status_name, value) ⇒ Object
Called from a device to define the status.
90 91 92 |
# File 'lib/fsevent/framework.rb', line 90 def define_status(status_name, value) Thread.current[:fsevent_device_define_buffer] << [status_name, value] end |
#del_watch(watchee_device_name, status_name) ⇒ Object
Called from a device. (mainly from registered().)
85 86 87 |
# File 'lib/fsevent/framework.rb', line 85 def del_watch(watchee_device_name, status_name) Thread.current[:fsevent_device_watch_buffer] << [:del, watchee_device_name, status_name, nil] end |
#register_device(device, register_time = @current_time) ⇒ Object
38 39 40 41 42 |
# File 'lib/fsevent/framework.rb', line 38 def register_device(device, register_time=@current_time) device_name = device.name value = [:register, device_name, device] @schedule_locator[device_name] = @q.insert value, register_time end |
#set_elapsed_time(t) ⇒ Object
Called from a device to set the elapsed time.
105 106 107 108 |
# File 'lib/fsevent/framework.rb', line 105 def set_elapsed_time(t) raise "elapsed time must be positive: #{t}" if t <= 0 Thread.current[:fsevent_device_elapsed_time] = t end |
#start ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fsevent/framework.rb', line 44 def start until @q.empty? loc = @q.delete_min_locator event_type, *args = loc.value @current_time = loc.priority case event_type when :register; at_register(loc, *args) when :wakeup; at_wakeup(loc, *args) when :sleep; at_sleep(loc, *args) else raise "unexpected event type: #{event_type}" end end end |
#status_changed(status_name, value) ⇒ Object
Called from a device to notify the status.
95 96 97 |
# File 'lib/fsevent/framework.rb', line 95 def status_changed(status_name, value) Thread.current[:fsevent_device_changed_buffer] << [status_name, value] end |
#unregister_device(device_name) ⇒ Object
Called from a device.
100 101 102 |
# File 'lib/fsevent/framework.rb', line 100 def unregister_device(device_name) Thread.current[:fsevent_unregister_device_buffer] << device_name end |