class Orocos::OutputPort

This class represents output ports on remote task contexts.

They are obtained from Orocos::TaskContext#port or Orocos::TaskContext#each_port

Public Instance Methods

connect_to(input_port, options = Hash.new) click to toggle source

Connect this output port to an input port. options defines the connection policy for the connection. If a task is given instead of an input port the method will try to find the right input port by type and will raise an error if there are none or more than one matching input ports

The following options are available:

Data connections. In that connection, the reader will see only the last sample he received. Such a connection is set up with

input_port.connect_to output_port, :type => :data

Buffered connections. In that case, the reader will be able to read all the samples received since the last read. A buffer in between the output and input port will keep the samples that have not been read already. Such a connection is set up with:

output_port.connect_to input_port, :type => :buffer, :size => 10

Where the size option gives the size of the intermediate buffer. Note that new samples will be lost if they are received when the buffer is full.

# File lib/orocos/ports.rb, line 415
def connect_to(input_port, options = Hash.new)
    input_port = if input_port.respond_to? :find_port
                      #assuming input_port is a TaskContext
                      if !(port = input_port.find_input_port(type,nil))
                          raise NotFound, "port #{name} does not match any input port of the TaskContext #{input_port.name}."
                      end
                      port.to_orocos_port
                  else
                      input_port.to_orocos_port
                  end

    if !input_port.kind_of?(InputPort)
        raise ArgumentError, "an output port can only connect to an input port"
    elsif input_port.type_name != type_name
        raise ArgumentError, "trying to connect an output port of type #{type_name} to an input port of type #{input_port.type_name}"
    end

    policy = Port.prepare_policy(options)
    policy = handle_mq_transport(input_port.full_name, policy) do
        task.process != input_port.task.process && task.process.host_id == input_port.task.process.host_id
    end
    begin
        do_connect_to(input_port, policy)
    rescue Orocos::ConnectionFailed => e
        if policy[:transport] == TRANSPORT_MQ && Orocos::MQueue.auto_fallback_to_corba?
            policy[:transport] = TRANSPORT_CORBA
            Orocos.warn "failed to create a connection from #{full_name} to #{input_port.full_name} using the MQ transport, falling back to CORBA"
            retry
        end
        raise
    end
            
    self
rescue Orocos::ConnectionFailed => e
    raise e, "failed to connect #{full_name} => #{input_port.full_name} with policy #{policy.inspect}"
end
disconnect_from(input) click to toggle source

Require this port to disconnect from the provided input port

# File lib/orocos/ports.rb, line 357
def disconnect_from(input)
    input = input.to_orocos_port
    refine_exceptions(input) do
        do_disconnect_from(input)
    end
end
reader(policy = Hash.new) click to toggle source

Returns an OutputReader object that is connected to that port

The policy dictates how data should flow between the port and the reader object. See #prepare_policy

# File lib/orocos/ports.rb, line 373
def reader(policy = Hash.new)
    policy = Port.prepare_policy(policy)
    policy = handle_mq_transport("#{full_name}.reader", policy) do
        task.process && task.process.on_localhost?
    end
    begin
        do_reader(OutputReader, orocos_type_name, policy)
    rescue Orocos::ConnectionFailed => e
        if policy[:transport] == TRANSPORT_MQ && Orocos::MQueue.auto_fallback_to_corba?
            policy[:transport] = TRANSPORT_CORBA
            Orocos.warn "failed to create a port reader on #{full_name} using the MQ transport, falling back to CORBA"
            retry
        end
        raise
    end
rescue Orocos::ConnectionFailed => e
    raise e, "failed to create a port reader on #{full_name} of type #{type_name} with policy #{policy.inspect}"
end