Class: Roby::StateMachineDefinitionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/coordination/task_state_machine.rb

Overview

Helper to get a more roby-like feeling to the state machine definitions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_model, state_machine) ⇒ StateMachineDefinitionContext

Returns a new instance of StateMachineDefinitionContext.



10
11
12
13
# File 'lib/roby/coordination/task_state_machine.rb', line 10

def initialize(task_model, state_machine)
    @task_model = task_model
    @state_machine = state_machine
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



46
47
48
# File 'lib/roby/coordination/task_state_machine.rb', line 46

def method_missing(m, *args, &block)
    state_machine.public_send(m, *args, &block)
end

Instance Attribute Details

#state_machineObject (readonly)

Returns the value of attribute state_machine.



8
9
10
# File 'lib/roby/coordination/task_state_machine.rb', line 8

def state_machine
  @state_machine
end

#task_modelObject (readonly)

Returns the value of attribute task_model.



8
9
10
# File 'lib/roby/coordination/task_state_machine.rb', line 8

def task_model
  @task_model
end

Instance Method Details

#on(event, &block) ⇒ Object



38
39
40
# File 'lib/roby/coordination/task_state_machine.rb', line 38

def on(event, &block)
    state_machine.event(event, &block)
end

#poll_in_state(state, &block) ⇒ Object



32
33
34
35
36
# File 'lib/roby/coordination/task_state_machine.rb', line 32

def poll_in_state(state, &block)
    state_machine.state(state) do
        define_method(:poll, &block)
    end
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/roby/coordination/task_state_machine.rb', line 42

def respond_to_missing?(m, include_private)
    state_machine.respond_to?(m)
end

#script_in_state(state, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roby/coordination/task_state_machine.rb', line 15

def script_in_state(state, &block)
    script_engine = task_model.create_script(&block)

    state_machine.before_transition state_machine.any => state, do: lambda { |proxy|
        proxy.instance_variable_set :@script_engine, nil
    }
    state_machine.state(state) do
        define_method(:poll) do |task|
            unless @script_engine
                @script_engine = script_engine.bind(task)
                @script_engine.prepare
                @script_engine.step
            end
        end
    end
end