Class: MINT::Wheel

Inherits:
Interactor show all
Defined in:
lib/MINT-core/model/ir/wheel.rb

Constant Summary

Constants inherited from Interactor

Interactor::PUBLISH_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Interactor

class_from_channel_name, #create_attribute_channel_name, create_channel_name, #create_channel_w_name, get, getModel, #getSCXML, get_dm, #init_statemachine, #is_in?, #new_states, notify, #process_event, #process_event!, #process_event_vars, #publish_update, #states, #states=, #sync_event, #sync_states, #to_dot, wait

Methods included from InteractorHelpers

#restart_timeout

Instance Method Details

#initialize_statemachineObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/MINT-core/model/ir/wheel.rb', line 4

def initialize_statemachine
  if @statemachine.blank?
    @statemachine = Statemachine.build do

      trans :disconnected,:connect, :connected
      trans :connected, :disconnect, :disconnected

      superstate :connected do
        trans :stopped,:regress, :regressing
        trans :stopped,:progress, :progressing

        trans :regressing, :regress, :regressing
        trans :regressing, :stop, :stopped
        trans :regressing, :progress, :progressing

        trans :progressing, :progress, :progressing
        trans :progressing, :stop, :stopped
        trans :progressing, :regress, :regressing

        state :regressing do
          on_entry :start_timeout
          on_exit :stop_timeout
        end
        state :progressing do
          on_entry :start_timeout
          on_exit :stop_timeout
        end
      end
    end
  end
end

#start_timeoutObject



35
36
37
38
39
40
41
42
43
# File 'lib/MINT-core/model/ir/wheel.rb', line 35

def start_timeout
  if not @timer
    @timer = EventMachine::Timer.new(0.3) do
      process_event("stop")
    end
  else
    puts "timer already started!!!"
  end
end

#stop_timeoutObject



44
45
46
47
48
49
# File 'lib/MINT-core/model/ir/wheel.rb', line 44

def stop_timeout
  if @timer
    @timer.cancel
    @timer = nil
  end
end