Class: Roby::Coordination::Models::TaskWithDependencies

Inherits:
Task
  • Object
show all
Defined in:
lib/roby/coordination/models/task_with_dependencies.rb

Overview

Generic representation of an execution context task that can be instanciated

Instance Attribute Summary collapse

Attributes inherited from Task

#model, #name

Instance Method Summary collapse

Methods inherited from Task

#can_resolve_child_models?, #find_child, #find_event, #find_through_method_missing, #has_child?, #has_event?, #has_through_method_missing?, #instanciate, #new, #rebind, #setup_instanciated_task, #to_coordination_task

Constructor Details

#initialize(model) ⇒ TaskWithDependencies

Creates this model-level coordination task to represent a given Roby task model

Parameters:

  • model (Model<Roby::Task>)

    the Roby task model, which is either Roby::Task or one of its subclasses



12
13
14
15
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 12

def initialize(model)
    super
    @dependencies = Set.new
end

Instance Attribute Details

#dependenciesSet<(Task,String)> (readonly)

Returns set of dependencies needed for this task, as a (task,role) pair.

Returns:

  • (Set<(Task,String)>)

    set of dependencies needed for this task, as a (task,role) pair



9
10
11
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 9

def dependencies
  @dependencies
end

Instance Method Details

#depends_on(action, role: nil) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 38

def depends_on(action, role: nil)
    if !action.kind_of?(Coordination::Models::Task)
        raise ArgumentError, "expected a task, got #{action}. You probably forgot to convert it using #task or #state"
    end
    dependencies << [action, role]
    self
end

#find_child_model(name) ⇒ Object



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

def find_child_model(name)
    if d = dependencies.find { |_, role| role == name }
        d[0].model
    else super
    end
end

#initialize_copy(old) ⇒ Object



17
18
19
20
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 17

def initialize_copy(old)
    super
    @dependencies = @dependencies.dup
end

#map_tasks(mapping) ⇒ Object

Modify this task’s internal structure to change relationships between tasks



24
25
26
27
28
29
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 24

def map_tasks(mapping)
    super
    @dependencies = dependencies.map do |task, role|
        [mapping[task] || task, role]
    end
end