Class: Roby::Coordination::Base
- Extended by:
- Models::Base
- Defined in:
- lib/roby/coordination/base.rb
Overview
Context for all the execution objects that can be attached to the action interface and/or tasks, such as state machines and scripts
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arguments ⇒ Hash
readonly
The set of arguments given to this execution context.
-
#instances ⇒ Object
readonly
A mapping from the model-level description of the context to the instance-level description.
-
#parent ⇒ nil, Base
readonly
The parent coordination object.
Instance Method Summary collapse
- #attach_fault_response_tables_to(_task) ⇒ Object
-
#bind_coordination_task_to_instance(coordination_task, instance, options = {}) ⇒ void
Binds a task instance to the coordination task.
-
#initialize(root_task = nil, arguments = {}, options = {}) ⇒ Base
constructor
Create a new coordination instance.
-
#instance_for(object) ⇒ Coordination::Task
Returns the instance-level coordination task that is used to represent a model-level coordination task.
-
#model ⇒ Model<Base>
The execution context model.
-
#plan ⇒ Object
The plan this coordination object is part of.
-
#root_task ⇒ Model<Roby::Task>
The task on which this execution context is being executed.
Constructor Details
#initialize(root_task = nil, arguments = {}, options = {}) ⇒ Base
Create a new coordination instance. The model is represented by this object’s class
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/roby/coordination/base.rb', line 61 def initialize(root_task = nil, arguments = {}, = {}) = Kernel. , on_replace: :drop, parent: nil @arguments = model.validate_arguments(arguments) @parent = [:parent] @instances = {} if root_task bind_coordination_task_to_instance( instance_for(model.root), root_task, on_replace: [:on_replace]) root_task.add_coordination_object(self) attach_fault_response_tables_to(root_task) if [:on_replace] == :copy root_task.as_service.on_replacement do |old_task, new_task| old_task.remove_coordination_object(self) new_task.add_coordination_object(self) attach_fault_response_tables_to(new_task) end end end end |
Instance Attribute Details
#arguments ⇒ Hash (readonly)
The set of arguments given to this execution context
29 30 31 |
# File 'lib/roby/coordination/base.rb', line 29 def arguments @arguments end |
#instances ⇒ Object (readonly)
A mapping from the model-level description of the context to the instance-level description
35 36 37 |
# File 'lib/roby/coordination/base.rb', line 35 def instances @instances end |
#parent ⇒ nil, Base (readonly)
The parent coordination object
13 14 15 |
# File 'lib/roby/coordination/base.rb', line 13 def parent @parent end |
Instance Method Details
#attach_fault_response_tables_to(_task) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/roby/coordination/base.rb', line 86 def attach_fault_response_tables_to(_task) model.each_used_fault_response_table do |table, arguments| arguments = arguments.transform_values do |val| if val.kind_of?(Models::Variable) self.arguments[val.name] else val end end root_task.use_fault_response_table(table, arguments) end end |
#bind_coordination_task_to_instance(coordination_task, instance, options = {}) ⇒ void
This method returns an undefined value.
Binds a task instance to the coordination task
This method binds a task instance to the coordination task it represents, and optionally installs the handlers necessary to track replacement
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/roby/coordination/base.rb', line 112 def bind_coordination_task_to_instance(coordination_task, instance, = {}) = Kernel. , on_replace: :drop coordination_task.bind(instance) if [:on_replace] == :copy instance.as_service.on_replacement do |old_task, new_task| coordination_task.bind(new_task) end end end |
#instance_for(object) ⇒ Coordination::Task
Returns the instance-level coordination task that is used to represent a model-level coordination task
Coordination models are built using instances of Models::Task (or its subclasses). When they get instanciated into actual coordination objects, these are uniquely associated with instances of Task (or its subclasses).
This method can be used to retrieve the unique object associated with a given model-level coordination task
137 138 139 140 141 142 143 144 145 |
# File 'lib/roby/coordination/base.rb', line 137 def instance_for(object) if (ins = instances[object]) ins elsif parent && (ins = parent.instances[object]) ins else instances[object] = object.new(self) end end |
#model ⇒ Model<Base>
The execution context model
39 40 41 |
# File 'lib/roby/coordination/base.rb', line 39 def model self.class end |
#plan ⇒ Object
The plan this coordination object is part of
23 24 25 |
# File 'lib/roby/coordination/base.rb', line 23 def plan root_task.plan end |
#root_task ⇒ Model<Roby::Task>
The task on which this execution context is being executed. It must fullfill model.task
18 19 20 |
# File 'lib/roby/coordination/base.rb', line 18 def root_task instance_for(model.root).task end |