class Syskit::Port
Representation of a component port on a component instance.
The sibling class Syskit::Models::Port represents a port on a component model. For instance, an object of class Syskit::Models::Port could be used to represent a port on a subclass of TaskContext while Syskit::Port would represent it for an object of that subclass.
Attributes
The component model this port is part of
The port model @return [Models::Port]
Public Class Methods
# File lib/syskit/port.rb, line 25 def initialize(model, component) @model, @component = model, component end
Public Instance Methods
# File lib/syskit/port.rb, line 19 def ==(other_port) other_port.class == self.class && other_port.model == self.model && other_port.component == self.component end
Connects this port to the other given port, using the given policy
# File lib/syskit/port.rb, line 75 def connect_to(in_port, policy = Hash.new) out_port = self.to_component_port if out_port == self if in_port.respond_to?(:to_component_port) in_port = in_port.to_component_port if !output? raise WrongPortConnectionDirection.new(self, in_port), "cannot connect #{self} to #{in_port}: #{self} is not an output port" elsif !in_port.input? raise WrongPortConnectionDirection.new(self, in_port), "cannot connect #{self} to #{in_port}: #{in_port} is not an input port" elsif component == in_port.component raise SelfConnection.new(self, in_port), "cannot connect #{self} to #{in_port}: they are both ports of the same component" elsif self.type != in_port.type raise WrongPortConnectionTypes.new(self, in_port), "cannot connect #{self} to #{in_port}: types mismatch" end component.connect_ports(in_port.component, [name, in_port.name] => policy) else Syskit.connect self, in_port, policy end else out_port.connect_to(in_port, policy) end end
# File lib/syskit/port.rb, line 135 def connected? each_connection { return true } false end
# File lib/syskit/port.rb, line 109 def connected_to?(in_port) out_port = self.to_component_port if out_port == self in_port = in_port.to_component_port component.child_object?(in_port.component, Flows::DataFlow) && component[in_port.component, Flows::DataFlow].has_key?([out_port.name, in_port.name]) else out_port.connected_to?(in_port) end end
# File lib/syskit/port.rb, line 99 def disconnect_from(in_port) out_port = self.to_component_port if out_port == self in_port = in_port.to_component_port component.disconnect_ports(in_port.component, [[out_port.name, in_port.name]]) else out_port.disconnect_from(in_port) end end
# File lib/syskit/port.rb, line 30 def eql?(other) self == other end
# File lib/syskit/port.rb, line 29 def hash; component.hash | name.hash end
@return [Boolean] true if this is an input port, false otherwise.
The default implementation returns false
# File lib/syskit/port.rb, line 129 def input?; false end
# File lib/syskit/port.rb, line 34 def inspect; to_s end
The port name
# File lib/syskit/port.rb, line 15 def name; model.name end
# File lib/syskit/port.rb, line 120 def new_sample model.new_sample end
@return [Boolean] true if this is an output port, false otherwise.
The default implementation returns false
# File lib/syskit/port.rb, line 126 def output?; false end
# File lib/syskit/port.rb, line 35 def pretty_print(pp) pp.text "port #{name} of " component.pretty_print(pp) end
# File lib/syskit/port.rb, line 140 def static?; model.orogen_model.static? end
Returns the port attached to a TaskContext instance that corresponds to self
@raise [ArgumentError] if it is not possible (for instance, ports on
InstanceRequirements are not associated with a component port)
@return [Port] the resolved port
# File lib/syskit/port.rb, line 59 def to_actual_port component_port = to_component_port component_port.component.self_port_to_actual_port(component_port) end
Returns the port attached to a proper Component instance that corresponds to self
@raise [ArgumentError] if it is not possible (for instance, ports on
InstanceRequirements are not associated with a component port)
@return [Port] the resolved port
# File lib/syskit/port.rb, line 46 def to_component_port if !component.respond_to?(:self_port_to_component_port) raise ArgumentError, "cannot call #to_component_port on ports of #{component}" end component.self_port_to_component_port(self) end
Returns the orocos port attached that corresponds to self
@raise [ArgumentError] if it is not possible (for instance, ports on
InstanceRequirements are not associated with a component port)
@return [Orocos::Port] the resolved port
# File lib/syskit/port.rb, line 69 def to_orocos_port component_port = to_actual_port component_port.component.self_port_to_orocos_port(component_port) end
# File lib/syskit/port.rb, line 131 def to_s "#{component}.#{name}" end
The port type
# File lib/syskit/port.rb, line 17 def type; model.type end