Module: Roby::Coordination::Models::Actions

Includes:
Base
Included in:
ActionScript, ActionStateMachine, FaultHandler
Defined in:
lib/roby/coordination/models/actions.rb

Overview

Metamodel for Coordination::Actions

Instance Attribute Summary collapse

Attributes included from Base

#name, #root

Instance Method Summary collapse

Methods included from Base

#find_event, #find_task_by_name, #parse_names, #task, #task_model, #use_fault_response_table, #used_fault_response_table, #validate_event, #validate_or_create_task, #validate_task

Methods included from Arguments

#argument, #validate_arguments

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, **kw) ⇒ Object



188
189
190
191
192
193
# File 'lib/roby/coordination/models/actions.rb', line 188

def method_missing(m, *args, **kw)
    action = action_interface&.find_action_by_name(m.to_s)
    return super unless action

    action.new(*args, **kw)
end

Instance Attribute Details

#action_interfaceActions::Models::Interface, Actions::Models::Library

The action interface model this state machine model is defined on



14
15
16
# File 'lib/roby/coordination/models/actions.rb', line 14

def action_interface
  @action_interface
end

Instance Method Details

#dependencySet<Task>

A set of tasks that should always be active when self is active

Returns:



60
# File 'lib/roby/coordination/models/actions.rb', line 60

inherited_attribute(:dependency, :dependencies) { Set.new }

#depends_on(task, role: nil) ⇒ Task

Adds a toplevel dependency

This declares that the given task should always run while self is running

Parameters:

Returns:

  • (Task)

    the task itself



142
143
144
145
146
# File 'lib/roby/coordination/models/actions.rb', line 142

def depends_on(task, role: nil)
    task = validate_task(task)
    dependencies << [task, role]
    task
end

#event_active_in_state?(event, state) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raise if an event is not “active” while in a particular state

Returns:

  • (Boolean)


123
124
125
126
# File 'lib/roby/coordination/models/actions.rb', line 123

def event_active_in_state?(event, state)
    event.task == root ||
        required_tasks_for(state).has_key?(event.task)
end

#forward(state.my_event, target_event) ⇒ Object #forward(state, event, target_event) ⇒ Object

Declares that the given event on the root task of the state should be forwarded to an event on this task

Overloads:

  • #forward(state.my_event, target_event) ⇒ Object

    declares that, while in state ‘state’, forward ‘my_event’ to the given event name on the state machine task

  • #forward(state, event, target_event) ⇒ Object

    declares that, while in state ‘state’, forward ‘event’ to the given event name on the state machine task



55
# File 'lib/roby/coordination/models/actions.rb', line 55

inherited_attribute(:forward, :forwards) { [] }

#from(object) ⇒ Object

Helper to build delayed arguments



170
171
172
# File 'lib/roby/coordination/models/actions.rb', line 170

def from(object)
    Roby::Task.from(object)
end

#from_state(state_object = State) ⇒ Object

Helper to build delayed arguments



175
176
177
# File 'lib/roby/coordination/models/actions.rb', line 175

def from_state(state_object = State)
    Roby::Task.from_state(state_object)
end

#map_tasks(mapping) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Transform the model by exchanging tasks

Parameters:

  • mapping (#[])

    a mapping that replaces an existing task by a new one. All tasks must be mapped



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roby/coordination/models/actions.rb', line 32

def map_tasks(mapping)
    super

    @forwards = forwards.map do |state, event, target_event|
        state = mapping[state]
        event = mapping[event.task].find_event(event.symbol)
        target_event = mapping[target_event.task].find_event(target_event.symbol)
        [state, event, target_event]
    end

    @dependencies = dependencies.map do |task, role|
        [mapping[task], role]
    end

    @captures = captures.transform_values do |(state, event)|
        [mapping[state], mapping[event.task]
            .find_event(event.symbol)]
    end
end

#parse(&block) ⇒ Object

Evaluates a state machine definition block



180
181
182
# File 'lib/roby/coordination/models/actions.rb', line 180

def parse(&block)
    class_eval(&block)
end

#rebind(action_interface) ⇒ Object

Create a new coordination model based on a different action interface



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/roby/coordination/models/actions.rb', line 18

def rebind(action_interface)
    m = dup
    m.action_interface = action_interface

    task_mapping = {}
    task_mapping[root] = root.rebind(m)
    tasks.each do |task|
        task_mapping[task] = task.rebind(m)
    end
    m.map_tasks(task_mapping)
    m
end

#required_tasks_for(task) ⇒ {Task=>Set<String>}

Returns the set of actions that should be active when the given task is active, as a mapping from the Task object to the roles that this object has (as “dependency roles”)

It includes task itself, as task should run when it is active

Returns:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/roby/coordination/models/actions.rb', line 154

def required_tasks_for(task)
    result = {}
    task.dependencies.each do |action, role|
        result[action] ||= Set.new
        result[action] << role if role
    end
    each_dependency do |action, role|
        result[action] ||= Set.new
        result[action] << role if role
    end
    result[task] ||= Set.new
    result[task] << "current_task"
    result
end

#respond_to_missing?(m, include_private) ⇒ Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/roby/coordination/models/actions.rb', line 184

def respond_to_missing?(m, include_private)
    action_interface&.find_action_by_name(m.to_s) || super
end

#root_event?(event) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises if the event is not an event of the root task

Returns:

  • (Boolean)


131
132
133
# File 'lib/roby/coordination/models/actions.rb', line 131

def root_event?(event)
    event.task == root
end

#setup_submodel(submodel, action_interface: nil, **super_options) ⇒ Object

Creates a new state machine model as a submodel of self

Parameters:

  • submodel (Model<Coordination::Actions>)

    the submodel that is being setup

  • options (Hash)

    a customizable set of options



73
74
75
76
77
# File 'lib/roby/coordination/models/actions.rb', line 73

def setup_submodel(submodel, action_interface: nil, **super_options)
    super(submodel, **super_options)
    submodel.action_interface = action_interface
    submodel
end

#toplevel_state?(state) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raise if the given state is not a toplevel state

Returns:

  • (Boolean)


116
117
118
# File 'lib/roby/coordination/models/actions.rb', line 116

def toplevel_state?(state)
    true
end