Class: Roby::Coordination::Models::Task
- Includes:
- MetaRuby::DSLs::FindThroughMethodMissing
- Defined in:
- lib/roby/coordination/models/task.rb
Overview
A model-level coordination task
Coordination models are built using instances of Task (or its subclasses). When they get instanciated into actual coordination objects, these are uniquely associated with instances of Task (or its subclasses).
This class is the base class for all model-level coordination tasks. It is typed (i.e. we know the Roby task model that it represents) and optionally has a name.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Model<Roby::Task>
The underlying Roby task model.
-
#name ⇒ nil, String
The task name.
Instance Method Summary collapse
-
#can_resolve_child_models? ⇒ Boolean
Test if this coordination task can tell us something about the models of its children.
-
#find_child(role, child_model = nil) ⇒ Coordination::Models::Child?
Returns a representation of this task’s child that can be used in a coordination model.
-
#find_child_model(role) ⇒ Model<Roby::Task>?
Returns the model of a given child of this task.
-
#find_event(event_name) ⇒ Coordination::Models::Event
Returns an model-level coordination event that can be used to represent an event on this task.
- #find_through_method_missing(m, args) ⇒ Object
-
#has_child?(role) ⇒ Boolean
Tests if this task has a child with the given role.
-
#has_event?(event_name) ⇒ Boolean
Tests if this task has a given event.
- #has_through_method_missing?(m) ⇒ Boolean
-
#initialize(model) ⇒ Task
constructor
Creates this model-level coordination task to represent a given Roby task model.
-
#instanciate(plan, variables = {}) ⇒ Object
This method must be overloaded in the tasks that will be actually used in the coordination primitives.
-
#map_tasks(mapping) ⇒ Object
private
Used in Actions#rebind to update the internal relationships between coordination tasks.
-
#new(execution_context) ⇒ Coordination::Task
Returns an instance-level coordination task that can be used to represent self.
-
#rebind(coordination_model) ⇒ Object
Create a new coordination task based on a different coordination model.
- #setup_instanciated_task(coordination_context, task, arguments = {}) ⇒ Object
- #to_coordination_task(task_model = Roby::Task) ⇒ Object
Constructor Details
#initialize(model) ⇒ Task
Creates this model-level coordination task to represent a given Roby task model
37 38 39 |
# File 'lib/roby/coordination/models/task.rb', line 37 def initialize(model) @model = model end |
Instance Attribute Details
#model ⇒ Model<Roby::Task>
The underlying Roby task model
If it responds to #find_child, the coordination task model will allow to validate the task’s own children.
25 26 27 |
# File 'lib/roby/coordination/models/task.rb', line 25 def model @model end |
#name ⇒ nil, String
The task name
30 31 32 |
# File 'lib/roby/coordination/models/task.rb', line 30 def name @name end |
Instance Method Details
#can_resolve_child_models? ⇒ Boolean
Test if this coordination task can tell us something about the models of its children
It uses the presence or absence of a #find_child method on #model to determine it.
96 97 98 |
# File 'lib/roby/coordination/models/task.rb', line 96 def can_resolve_child_models? model&.respond_to?(:find_child) end |
#find_child(role, child_model = nil) ⇒ Coordination::Models::Child?
Returns a representation of this task’s child that can be used in a coordination model
144 145 146 147 148 |
# File 'lib/roby/coordination/models/task.rb', line 144 def find_child(role, child_model = nil) if has_child?(role) Child.new(self, role, child_model || find_child_model(role)) end end |
#find_child_model(role) ⇒ Model<Roby::Task>?
Returns the model of a given child of this task
It always returns Roby::Task if #model does not allow us to resolve children. The rationale is that these methods are used to type-validate tasks in e.g. action state machines and we need to simply be permissive if the models does not allow us to validate anything. Use #can_resolve_child_models? to know whether validation is meaningful.
127 128 129 130 131 |
# File 'lib/roby/coordination/models/task.rb', line 127 def find_child_model(role) if can_resolve_child_models? model.find_child(role) end end |
#find_event(event_name) ⇒ Coordination::Models::Event
Returns an model-level coordination event that can be used to represent an event on this task
82 83 84 85 86 |
# File 'lib/roby/coordination/models/task.rb', line 82 def find_event(event_name) if has_event?(event_name) Event.new(self, event_name) end end |
#find_through_method_missing(m, args) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/roby/coordination/models/task.rb', line 150 def find_through_method_missing(m, args) MetaRuby::DSLs.find_through_method_missing( self, m, args, "_event" => :find_event, "_child" => :find_child) || super end |
#has_child?(role) ⇒ Boolean
Tests if this task has a child with the given role
It always returns true if #model does not allow us to resolve children. The rationale is that these methods are used to type-validate tasks in e.g. action state machines and we need to simply be permissive if the models does not allow us to validate anything. Use #can_resolve_child_models? to know whether validation is meaningful.
111 112 113 114 |
# File 'lib/roby/coordination/models/task.rb', line 111 def has_child?(role) find_child_model(role) || !can_resolve_child_models? end |
#has_event?(event_name) ⇒ Boolean
Tests if this task has a given event
70 71 72 73 74 |
# File 'lib/roby/coordination/models/task.rb', line 70 def has_event?(event_name) return true unless model.respond_to?(:find_event) model.find_event(event_name.to_sym) end |
#has_through_method_missing?(m) ⇒ Boolean
158 159 160 161 162 163 164 |
# File 'lib/roby/coordination/models/task.rb', line 158 def has_through_method_missing?(m) MetaRuby::DSLs.has_through_method_missing?( self, m, "_event" => :has_event?, "_child" => :has_child?) || super end |
#instanciate(plan, variables = {}) ⇒ Object
This method must be overloaded in the tasks that will be actually used in the coordination primitives
174 175 176 |
# File 'lib/roby/coordination/models/task.rb', line 174 def instanciate(plan, variables = {}) raise NotImplementedError, "must reimplement #instanciate in the task objects used in coordination primitives" 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.
Used in Actions#rebind to update the internal relationships between coordination tasks
51 |
# File 'lib/roby/coordination/models/task.rb', line 51 def map_tasks(mapping); end |
#new(execution_context) ⇒ Coordination::Task
Returns an instance-level coordination task that can be used to represent self
It is delegated to the task model, as the actual class that is used to represent self in a coordination object might depend on the class of the model-level coordination task.
61 62 63 |
# File 'lib/roby/coordination/models/task.rb', line 61 def new(execution_context) Coordination::Task.new(execution_context, self) end |
#rebind(coordination_model) ⇒ Object
Create a new coordination task based on a different coordination model
43 44 45 |
# File 'lib/roby/coordination/models/task.rb', line 43 def rebind(coordination_model) dup end |
#setup_instanciated_task(coordination_context, task, arguments = {}) ⇒ Object
178 |
# File 'lib/roby/coordination/models/task.rb', line 178 def setup_instanciated_task(coordination_context, task, arguments = {}); end |
#to_coordination_task(task_model = Roby::Task) ⇒ Object
168 169 170 |
# File 'lib/roby/coordination/models/task.rb', line 168 def to_coordination_task(task_model = Roby::Task) self end |