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.



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

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



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

def execution_context
  @execution_context
end

#modelCoordination::Models::Task (readonly)



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

def model
  @model
end

Instance Method Details

#find_child(role, child_model = nil) ⇒ Object



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

def find_child(role, child_model = nil)
    child_model ||= model.find_child_model(role)
    if !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



41
42
43
44
45
# File 'lib/roby/coordination/task_base.rb', line 41

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

#find_through_method_missing(m, args) ⇒ Object



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

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)


54
55
56
57
58
59
60
# File 'lib/roby/coordination/task_base.rb', line 54

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)


20
21
22
# File 'lib/roby/coordination/task_base.rb', line 20

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



64
# File 'lib/roby/coordination/task_base.rb', line 64

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