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



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

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



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

def dependencies
  @dependencies
end

Instance Method Details

#depends_on(action, role: nil) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 41

def depends_on(action, role: nil)
    unless 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



33
34
35
36
37
38
39
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 33

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

#initialize_copy(old) ⇒ Object



19
20
21
22
# File 'lib/roby/coordination/models/task_with_dependencies.rb', line 19

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

#map_tasks(mapping) ⇒ Object

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



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

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