Class: Roby::Coordination::TaskBase

Inherits:
Object
  • Object
show all
Includes:
MetaRuby::DSLs::FindThroughMethodMissing
Defined in:
lib/roby/coordination/task_base.rb

Overview

Base functionality for task-like objects in coordination models (Task, Child)

Direct Known Subclasses

Child, Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(execution_context, model) ⇒ TaskBase

Returns a new instance of TaskBase.



15
16
17
18
# File 'lib/roby/coordination/task_base.rb', line 15

def initialize(execution_context, model)
    @execution_context = execution_context
    @model = model
end

Instance Attribute Details

#execution_contextBase (readonly)

Returns the underlying execution context.

Returns:

  • (Base)

    the underlying execution context



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

def execution_context
  @execution_context
end

#modelCoordination::Models::Task (readonly)



13
14
15
# File 'lib/roby/coordination/task_base.rb', line 13

def model
  @model
end

Instance Method Details

#find_child(role, child_model = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/roby/coordination/task_base.rb', line 26

def find_child(role, child_model = nil)
    child_model ||= model.find_child_model(role)
    unless child_model
        begin
            task = self.resolve
            if child_task = task.find_child_from_role(role)
                child_model = child_task.model
            end
        rescue ResolvingUnboundObject
        end
    end

    if child = model.find_child(role, child_model)
        execution_context.instance_for(child)
    end
end

#find_event(symbol) ⇒ Object



43
44
45
46
47
# File 'lib/roby/coordination/task_base.rb', line 43

def find_event(symbol)
    if event = model.find_event(symbol)
        execution_context.instance_for(event)
    end
end

#find_through_method_missing(m, args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/roby/coordination/task_base.rb', line 49

def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        self, m, args,
        "_child" => :find_child,
        "_port" => :find_port,
        "_event" => :find_event) || super
end

#has_through_method_missing?(m) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'lib/roby/coordination/task_base.rb', line 57

def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        self, m,
        "_child" => :has_child?,
        "_port" => :has_port?,
        "_event" => :has_event?) || super
end

#resolveObject

Method that must be reimplemented in the task objects actually used in the coordination primitives

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/roby/coordination/task_base.rb', line 22

def resolve
    raise NotImplementedError, "#resolve must be reimplemented in objects meant to be used in the coordination primitives"
end

#to_coordination_task(task_model) ⇒ Object



67
68
69
# File 'lib/roby/coordination/task_base.rb', line 67

def to_coordination_task(task_model)
    model.to_coordination_task(task_model)
end