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

Instance Method Details

#connect_to(other, policy = Hash.new) ⇒ Object

For convenience, automatically reverts the connection direction


136
137
138
139
140
141
# File 'lib/orocos/ports_base.rb', line 136

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

Parameters:

  • source

    the source object in the connection that is being created

Raises:

  • (ArgumentError)

    if the connection cannot be created


178
179
180
# File 'lib/orocos/ports_base.rb', line 178

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

Parameters:

  • source

    the source object in the connection that is being destroyed

Raises:

  • (ArgumentError)

    if the connection cannot be undone (or if it could not exist in the first place)


192
193
194
# File 'lib/orocos/ports_base.rb', line 192

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.


165
166
167
# File 'lib/orocos/ports_base.rb', line 165

def write(sample)
    writer.write(sample)
end

#writer(policy = Hash.new) ⇒ Object

Returns a InputWriter object that allows you to write data to the remote input port.


145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/orocos/ports_base.rb', line 145

def writer(policy = Hash.new)
    ensure_type_available
    writer = Orocos.ruby_task.create_output_port(
        self.class.transient_local_port_name(full_name),
        orocos_type_name,
        :permanent => false,
        :class => self.class.writer_class) 
    writer.port = self
    writer.policy = policy
    writer.connect_to(self, policy)
    writer
end