class Syskit::Models::CompositionChild
Used by Composition to define its children. Values returned by {Models::Composition#find_child} are instances of that class.
Attributes
- String
-
the name of this child on {#composition_model}
- Models::Composition
-
the model of the composition this child is
part of
The set of models that this child should fullfill. It is a Set which contains at most one Component model and any number of data service models
@return [CompositionChild,nil] the composition child model from which
this model has been overloaded
Public Class Methods
# File lib/syskit/models/composition_child.rb, line 28 def initialize(composition_model, child_name, models = Set.new, dependency_options = Hash.new, parent_model = nil) @composition_model, @child_name = composition_model, child_name super(models) @dependency_options = Roby::TaskStructure::Dependency.validate_options(dependency_options) @parent_model = parent_model end
Public Instance Methods
# File lib/syskit/models/composition_child.rb, line 181 def attach(composition_model) result = dup result.instance_variable_set :@composition_model, composition_model result end
# File lib/syskit/models/composition_child.rb, line 187 def bind(component) composition = composition_model.bind(component.parent_task) composition.find_required_composition_child_from_role( child_name, composition_model.to_component_model) end
(see Component#connect_ports)
# File lib/syskit/models/composition_child.rb, line 137 def connect_ports(other_component, connections) if !other_component.respond_to?(:composition_model) raise ArgumentError, "cannot connect ports of #{self} to ports of #{other_component}: #{other_component} is not a composition child" elsif other_component.composition_model != composition_model raise ArgumentError, "cannot connect ports of #{self} to ports of #{other_component}: they are children of different composition models" end cmp_connections = composition_model.explicit_connections[[child_name, other_component.child_name]] connections.each do |port_pair, policy| cmp_connections[port_pair] = policy end end
Automatically computes the connections between the output ports of self to the given port or component interface
@param [Port,CompositionChild] the sink side of the connection. If
a Port is given, it has to be a port on a CompositionChild of the same composition than self
@return [Array<Port>] the set of created connections
# File lib/syskit/models/composition_child.rb, line 107 def connect_to(sink, policy = Hash.new) Syskit.connect(self, sink, policy) end
@api private
Tests whether two ports are connected
This is a delegated call from Syskit::Models::Port#connected_to?. Always use the former unless you know what you are doing
# File lib/syskit/models/composition_child.rb, line 124 def connected?(source_port, sink_port) if !self_port?(source_port) raise ArgumentError, "source port #{source_port} in connected? is not a port of #{self}" elsif !composition_model.child_port?(sink_port) return false end cmp_connections = composition_model. explicit_connections[[child_name, sink_port.component_model.child_name]] cmp_connections.has_key?([source_port.name,sink_port.name]) end
# File lib/syskit/models/composition_child.rb, line 42 def eql?(other) other.respond_to?(:child_name) && other.child_name == child_name && super end
# File lib/syskit/models/composition_child.rb, line 36 def initialize_copy(old) super @dependency_options = old.dependency_options.dup @overload_info = nil end
# File lib/syskit/models/composition_child.rb, line 96 def optional @optional = true end
- InstanceSelection
-
information needed to update the composition's
parent models about the child (mainly port mappings)
# File lib/syskit/models/composition_child.rb, line 17 def overload_info @overload_info ||= InstanceSelection.new(nil, self, @parent_model || InstanceRequirements.new) end
The port mappings from this child's parent model to this model
# File lib/syskit/models/composition_child.rb, line 92 def port_mappings overload_info.port_mappings end
# File lib/syskit/models/composition_child.rb, line 169 def pretty_print(pp) pp.text "child #{child_name} of type " super pp.breakable pp.text "of #{composition_model}" end
Resolves the task that corresponds to self, using task as the
root composition
@return [Roby::Task] @raise [ArgumentError] if task does not fullfill the required
composition model, or if it does not have the required children
# File lib/syskit/models/composition_child.rb, line 83 def resolve_child(task) if resolved_task = try_resolve_child(task) return resolved_task else raise ArgumentError, "cannot find #{self} from #{task}" end end
Test whether the given port object is a port of self
@param [Port] port
# File lib/syskit/models/composition_child.rb, line 114 def self_port?(port) port.component_model == self end
# File lib/syskit/models/composition_child.rb, line 177 def short_name "#{composition_model.short_name}.#{child_name}_child[#{model.short_name}]" end
# File lib/syskit/models/composition_child.rb, line 155 def state if @state return @state elsif component_model = models.find { |c| c <= Component } @state = Roby::StateFieldModel.new(component_model.state) @state.__object = self return @state else raise ArgumentError, "cannot create a state model on elements that are only data services" end end
# File lib/syskit/models/composition_child.rb, line 193 def to_instance_requirements ir = InstanceRequirements.new ir.do_copy(self) ir end
# File lib/syskit/models/composition_child.rb, line 167 def to_s; "#{composition_model}.#{child_name}_child[#{super}]" end
Tries to resolve the task that corresponds to self, assuming that the child's parent is the given task
@return [nil,Roby::Task]
# File lib/syskit/models/composition_child.rb, line 51 def try_resolve_child(task) if task = composition_model.try_resolve(task) return task.find_required_composition_child_from_role(child_name, composition_model) end end
Tries to resolve the task that corresponds to self starting the resolution at the given root
If this child's parent is not itself a CompositionChild, this is equivalent to {#try_resolve_child}.
Otherwise, it resolves the children one by one starting at the given root
@return [nil,Roby::Task]
# File lib/syskit/models/composition_child.rb, line 67 def try_resolve_child_recursive(root) if composition_model.respond_to?(:try_resolve_child_recursive) if resolved_parent = composition_model.try_resolve_child_recursive(root) try_resolve_child(resolved_parent) end else try_resolve_child(root) end end