class Orocos::Port

Base class for port classes.

See OutputPort and InputPort

Constants

CONNECTION_POLICY_OPTIONS
DEFAULT_CONNECTION_POLICY
MQ_RTT_DEFAULT_QUEUE_LENGTH

Attributes

transport_names[R]

A mapping from a transport ID to its name in plain text

Public Class Methods

prepare_policy(policy = Hash.new) click to toggle source

fills missing policy fields with default values, checks if the generated policy is valid and returns it

# File lib/orocos/port.rb, line 125
def self.prepare_policy(policy = Hash.new)
    policy = DEFAULT_CONNECTION_POLICY.merge policy
    Port.validate_policy(policy)
end
transient_local_port_name(base_name) click to toggle source
# File lib/orocos/port.rb, line 28
def self.transient_local_port_name(base_name)
    "#{base_name}.#{@@transient_port_id_counter += 1}"
end
transport_name(id) click to toggle source

Returns the transport name for the given transport ID or a placeholder sentence if no name is known for this transport ID

# File lib/orocos/port.rb, line 40
def self.transport_name(id)
    transport_names[id] || "unknown transport with ID #{id}"
end
validate_policy(policy) click to toggle source

A connection policy is represented by a hash whose elements are each of the policy parameters. Valid policies are:

  • buffer policy. Values are stored in a FIFO of the specified size. Connecting with a buffer policy is done with:

    output_port.connect_to(input_port, :type => :buffer, :size => 10)
    
  • data policy. The input port will always read the last value pushed by the output port. It is the default policy, but can be explicitly specified with:

    output_port.connect_to(input_port, :type => :data)
    

An additional :pull option specifies if samples should be pushed by the output end (i.e. if all samples that are written on the output port are sent to the input port), or if the values are transmitted only when the input port is read. For instance:

output_port.connect_to(input_port, :type => :data, :pull => true)

Finally, the type of locking can be specified. The lock_free locking policy guarantees that a high-priority thread will not be “taken over” by a low-priority one, but requires a lot of copying – so avoid it in non-hard-realtime contexts with big data samples. The locked locking policy uses mutexes, so is not ideal in hard realtime contexts. Each policy is specified with:

output_port.connect_to(input_port, :lock => :lock_free)
output_port.connect_to(input_port, :lock => :locked)

This method raises ArgumentError if the policy is not valid.

# File lib/orocos/port.rb, line 106
def self.validate_policy(policy)
    policy = validate_options policy, CONNECTION_POLICY_OPTIONS
    if policy.has_key?(:type)
        policy[:type] = policy[:type].to_sym
    end
    if policy.has_key?(:lock)
        policy[:lock] = policy[:lock].to_sym
    end

    if (policy[:type] == :buffer || policy[:type] == :circular_buffer) && !policy[:size]
        raise ArgumentError, "you must provide a 'size' argument for buffer connections"
    elsif policy[:type] == :data && (policy[:size] && policy[:size] != 0)
        raise ArgumentError, "there are no 'size' argument to data connections"
    end
    policy
end

Public Instance Methods

connected? → true or false click to toggle source

Tests if this port is already part of a connection or not

static VALUE port_connected_p(VALUE self)
{
    RTaskContext* task; VALUE name;
    tie(task, tuples::ignore, name) = getPortReference(self);
    bool result = corba_blocking_fct_call_with_result(bind(&_objref_CDataFlowInterface::isConnected,(_objref_CDataFlowInterface*)task->ports,
                                                      StringValuePtr(name)));
    return result ? Qtrue : Qfalse;
}
create_stream(transport, name_id, policy = Hash.new) click to toggle source

Publishes or subscribes this port on a stream

# File lib/orocos/port.rb, line 150
def create_stream(transport, name_id, policy = Hash.new)
    policy = Port.prepare_policy(policy)
    policy[:transport] = transport
    policy[:name_id] = name_id
    do_create_stream(policy)
            
    self
rescue Orocos::ConnectionFailed => e
    raise e, "failed to create stream from #{full_name} on transport #{Port.transport_name(transport)}, name #{name_id} and policy #{policy.inspect}"
end
default_ros_topic_name() click to toggle source
# File lib/orocos/ros/ports.rb, line 3
def default_ros_topic_name
    "#{task.name}/#{self.name}"
end
disconnect_all() click to toggle source

Removes this port from all connections it is part of

# File lib/orocos/port.rb, line 57
def disconnect_all
    refine_exceptions do
        do_disconnect_all
    end
end
do_create_stream(p1) click to toggle source
static VALUE do_port_create_stream(VALUE rport, VALUE _policy)
{
    RTaskContext* task; VALUE name;
    tie(task, tuples::ignore, name) = getPortReference(rport);

    RTT::corba::CConnPolicy policy = policyFromHash(_policy);
    bool result = corba_blocking_fct_call_with_result(bind(&_objref_CDataFlowInterface::createStream,(_objref_CDataFlowInterface*)task->ports,
                StringValuePtr(name),policy));
    if(!result)
        rb_raise(eConnectionFailed, "failed to create stream");
    return Qnil;
}
do_disconnect_all() click to toggle source
static VALUE do_port_disconnect_all(VALUE port)
{
    RTaskContext* task; VALUE name;
    tie(task, tuples::ignore, name) = getPortReference(port);
    corba_blocking_fct_call(bind(&_objref_CDataFlowInterface::disconnectPort,(_objref_CDataFlowInterface*)task->ports,
                            StringValuePtr(name)));
    return Qnil;
}
do_disconnect_from(p1) click to toggle source
static VALUE do_port_disconnect_from(VALUE self, VALUE other)
{
    RTaskContext* self_task; VALUE self_name;
    tie(self_task, tuples::ignore, self_name) = getPortReference(self);
    RTaskContext* other_task; VALUE other_name;
    tie(other_task, tuples::ignore, other_name) = getPortReference(other);
    bool result = corba_blocking_fct_call_with_result(bind(&_objref_CDataFlowInterface::removeConnection,(_objref_CDataFlowInterface*)self_task->ports,
                StringValuePtr(self_name),other_task->ports,StringValuePtr(other_name)));
    return result ? Qtrue : Qfalse;
}
do_remove_stream(p1) click to toggle source
static VALUE do_port_remove_stream(VALUE rport, VALUE stream_name)
{
    RTaskContext* task; VALUE name;
    tie(task, tuples::ignore, name) = getPortReference(rport);

    corba_blocking_fct_call(bind(&_objref_CDataFlowInterface::removeStream,(_objref_CDataFlowInterface*)task->ports,
                            StringValuePtr(name),StringValuePtr(stream_name)));
    return Qnil;
}
doc() click to toggle source

Returns a documentation string describing the port If no documentation is available it returns nil

# File lib/orocos/port.rb, line 138
def doc
    if model
        model.doc
    end
end
doc?() click to toggle source

Returns true if a documentation about the port is available otherwise it retuns false

# File lib/orocos/port.rb, line 132
def doc?
    (doc && !doc.empty?)
end
remove_stream(name_id) click to toggle source

Removes a stream publication. The name should be the same than the one given to the

# File lib/orocos/port.rb, line 163
def remove_stream(name_id)
    do_remove_stream(name_id)
    self
end
to_orocos_port() click to toggle source

Returns the Orocos port

# File lib/orocos/port.rb, line 145
def to_orocos_port
    self
end
type_name() click to toggle source

@deprecated Returns the name of the typelib type. Use type.name instead.

# File lib/orocos/port.rb, line 46
def type_name; type.name end