Class: Syskit::Port
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
The component model this port is part of.
-
#model ⇒ Models::Port
readonly
The port model.
Instance Method Summary collapse
- #==(other_port) ⇒ Object
-
#connect_to(in_port, policy = Hash.new) ⇒ Object
Connects this port to the other given port, using the given policy.
- #connected? ⇒ Boolean
- #connected_to?(in_port) ⇒ Boolean
- #disconnect_from(in_port) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(model, component) ⇒ Port
constructor
A new instance of Port.
-
#input? ⇒ Boolean
True if this is an input port, false otherwise.
- #inspect ⇒ Object
-
#name ⇒ Object
The port name.
- #new_sample ⇒ Object
-
#output? ⇒ Boolean
True if this is an output port, false otherwise.
- #pretty_print(pp) ⇒ Object
- #static? ⇒ Boolean
-
#to_actual_port ⇒ Port
Returns the port attached to a TaskContext instance that corresponds to self.
-
#to_component_port ⇒ Port
Returns the port attached to a proper Component instance that corresponds to self.
-
#to_orocos_port ⇒ Orocos::Port
Returns the orocos port attached that corresponds to self.
- #to_s ⇒ Object
-
#type ⇒ Object
The port type.
Constructor Details
#initialize(model, component) ⇒ Port
Returns a new instance of Port
25 26 27 |
# File 'lib/syskit/port.rb', line 25 def initialize(model, component) @model, @component = model, component end |
Instance Attribute Details
#component ⇒ Object (readonly)
The component model this port is part of
13 14 15 |
# File 'lib/syskit/port.rb', line 13 def component @component end |
#model ⇒ Models::Port (readonly)
The port model
11 12 13 |
# File 'lib/syskit/port.rb', line 11 def model @model end |
Instance Method Details
#==(other_port) ⇒ Object
19 20 21 22 23 |
# 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 |
#connect_to(in_port, policy = Hash.new) ⇒ Object
Connects this port to the other given port, using the given policy
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# 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 |
#connected? ⇒ Boolean
135 136 137 138 |
# File 'lib/syskit/port.rb', line 135 def connected? each_connection { return true } false end |
#connected_to?(in_port) ⇒ Boolean
109 110 111 112 113 114 115 116 117 118 |
# 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 |
#disconnect_from(in_port) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# 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 |
#eql?(other) ⇒ Boolean
30 31 32 |
# File 'lib/syskit/port.rb', line 30 def eql?(other) self == other end |
#hash ⇒ Object
29 |
# File 'lib/syskit/port.rb', line 29 def hash; component.hash | name.hash end |
#input? ⇒ Boolean
Returns true if this is an input port, false otherwise. The default implementation returns false
129 |
# File 'lib/syskit/port.rb', line 129 def input?; false end |
#inspect ⇒ Object
34 |
# File 'lib/syskit/port.rb', line 34 def inspect; to_s end |
#new_sample ⇒ Object
120 121 122 |
# File 'lib/syskit/port.rb', line 120 def new_sample model.new_sample end |
#output? ⇒ Boolean
Returns true if this is an output port, false otherwise. The default implementation returns false
126 |
# File 'lib/syskit/port.rb', line 126 def output?; false end |
#pretty_print(pp) ⇒ Object
35 36 37 38 |
# File 'lib/syskit/port.rb', line 35 def pretty_print(pp) pp.text "port #{name} of " component.pretty_print(pp) end |
#static? ⇒ Boolean
140 |
# File 'lib/syskit/port.rb', line 140 def static?; model.orogen_model.static? end |
#to_actual_port ⇒ Port
Returns the port attached to a TaskContext instance that corresponds to self
59 60 61 62 |
# 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 |
#to_component_port ⇒ Port
Returns the port attached to a proper Component instance that corresponds to self
46 47 48 49 50 51 |
# 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 |
#to_orocos_port ⇒ Orocos::Port
Returns the orocos port attached that corresponds to self
69 70 71 72 |
# 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 |
#to_s ⇒ Object
131 132 133 |
# File 'lib/syskit/port.rb', line 131 def to_s "#{component}.#{name}" end |