Module: Orocos::InputPortBase
- Included in:
- InputPort, ROS::InputTopic
- Defined in:
- lib/orocos/ports_base.rb
Overview
Generic implementation of some methods for all input-port-like objects
For #reader to work, the mixed-in class must provide a writer_class singleton method, and must be able to connect to an input port
Instance Method Summary collapse
-
#connect_to(other, policy = Hash.new) ⇒ Object
For convenience, automatically reverts the connection direction.
-
#resolve_connection_from(source, policy = Hash.new) ⇒ Object
This method is part of the connection protocol.
-
#resolve_disconnection_from(source) ⇒ Object
This method is part of the connection protocol.
-
#write(sample) ⇒ Object
Writes one sample with a default policy.
-
#writer(distance: PortBase::D_UNKNOWN, **policy) ⇒ Object
Returns a InputWriter object that allows you to write data to the remote input port.
Instance Method Details
#connect_to(other, policy = Hash.new) ⇒ Object
For convenience, automatically reverts the connection direction
155 156 157 158 159 160 |
# File 'lib/orocos/ports_base.rb', line 155 def connect_to(other, policy = Hash.new) if other.respond_to?(:writer) # This is also an input port ! raise ArgumentError, "cannot connect #{self} with #{other}, as they are both inputs" end other.connect_to(self, policy) end |
#resolve_connection_from(source, policy = Hash.new) ⇒ Object
This method is part of the connection protocol
Whenever an output is connected to an input, if the receiver object cannot resolve the connection, it calls #resolve_connection_from on its target
199 200 201 |
# File 'lib/orocos/ports_base.rb', line 199 def resolve_connection_from(source, policy = Hash.new) raise ArgumentError, "I don't know how to connect #{source} to #{self}" end |
#resolve_disconnection_from(source) ⇒ Object
This method is part of the connection protocol
Whenever an output is disconnected from an input, if the receiver object cannot resolve the connection, it calls #resolve_disconnection_from on its target
213 214 215 |
# File 'lib/orocos/ports_base.rb', line 213 def resolve_disconnection_from(source) raise ArgumentError, "I don't know how to disconnect #{source} to #{self}" end |
#write(sample) ⇒ Object
Writes one sample with a default policy.
While convenient, this is quite ressource consuming, as each time one will need to create a new connection between the ruby interpreter and the remote component.
Use #writer if you need to write on the same port repeatedly.
186 187 188 |
# File 'lib/orocos/ports_base.rb', line 186 def write(sample) writer.write(sample) end |
#writer(distance: PortBase::D_UNKNOWN, **policy) ⇒ Object
Returns a InputWriter object that allows you to write data to the remote input port.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/orocos/ports_base.rb', line 164 def writer(distance: PortBase::D_UNKNOWN, **policy) ensure_type_available writer = Orocos.ruby_task_access do Orocos.ruby_task.create_output_port( self.class.transient_local_port_name(full_name), orocos_type_name, permanent: false, class: self.class.writer_class) end writer.port = self writer.policy = policy writer.connect_to(self, distance: distance, **policy) writer end |