Module: Orocos::PortBase

Included in:
Port, ROS::Topic
Defined in:
lib/orocos/ports_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelOroGen::Spec::Port? (readonly)

The port's model

Returns:

  • (OroGen::Spec::Port, nil)

    the port model


15
16
17
# File 'lib/orocos/ports_base.rb', line 15

def model
  @model
end

#nameObject (readonly)

The port name


6
7
8
# File 'lib/orocos/ports_base.rb', line 6

def name
  @name
end

#orocos_type_nameObject (readonly)

The port's type name as used by the RTT


10
11
12
# File 'lib/orocos/ports_base.rb', line 10

def orocos_type_name
  @orocos_type_name
end

#taskObject (readonly)

The task this port is part of


4
5
6
# File 'lib/orocos/ports_base.rb', line 4

def task
  @task
end

#typeObject (readonly)

The port's type as a Typelib::Type object


12
13
14
# File 'lib/orocos/ports_base.rb', line 12

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object

True if self and other represent the same port


40
41
42
43
44
# File 'lib/orocos/ports_base.rb', line 40

def ==(other)
    other.class == self.class &&
        other.task == self.task &&
        other.name == self.name
end

#ensure_type_available(options = Hash.new) ⇒ Object


46
47
48
49
50
# File 'lib/orocos/ports_base.rb', line 46

def ensure_type_available(options = Hash.new)
    if !type || type.null?
        @type = Orocos.find_type_by_orocos_type_name(orocos_type_name, options)
    end
end

#full_nameObject

The port full name. It is task_name.port_name


8
# File 'lib/orocos/ports_base.rb', line 8

def full_name; "#{task.name}.#{name}" end

#initialize(task, name, orocos_type_name, model) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/orocos/ports_base.rb', line 17

def initialize(task, name, orocos_type_name, model)
    @task = task
    @name = name
    @orocos_type_name = orocos_type_name
    @model = model

    ensure_type_available(:fallback_to_null_type => true)

    if model
        @max_sizes = model.max_sizes.dup
    else
        @max_sizes = Hash.new
    end
    @max_sizes.merge!(Orocos.max_sizes_for(type))

    super() if defined? super
end

#log_metadataObject


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/orocos/ports_base.rb', line 58

def 
     = Hash['rock_task_model' => (task.model.name || ''),
        'rock_task_name' => task.name,
        'rock_task_object_name' => name,
        'rock_stream_type' => 'port',
        'rock_orocos_type_name' => orocos_type_name]

	    if Orocos.logger_guess_timestamp_field?
		# see if we can find a time field in the type, which
		# would qualify as being used as the default time stamp
		if @type.respond_to? :each_field
		    @type.each_field do |name, type|
			if type.name == "/base/Time"
			    ['rock_timestamp_field'] = name
			    break
			end
		    end
		else
		    # TODO what about if the type is a base::Time itself
		end
	    end

	    
end

#max_marshalling_sizeObject

Returns the maximum marshalled size of a sample from this port, as marshalled by typelib

If the type contains variable-size containers, the result is dependent on the values given to #max_sizes. If not enough is known, this method will return nil.


125
126
127
# File 'lib/orocos/ports_base.rb', line 125

def max_marshalling_size
    OroGen::Spec::OutputPort.compute_max_marshalling_size(type, max_sizes)
end

#max_sizes('name.to[].field' = >value, 'name.other' = >value) ⇒ Object #max_sizes( = >currentsizespecification) ⇒ Object

Overloads:

  • #max_sizes('name.to[].field' = >value, 'name.other' = >value) ⇒ Object

    Sets the maximum allowed size for the variable-size containers in type. If the type is a compound, the mapping is given as path.to.field => size. If it is a container, the size of the container itself is given as first argument, and the sizes for the contained values as a second map argument.

    For instance, with the types

    struct A
    {
        std::vector<int> values;
    };
    struct B
    {
        std::vector<A> field;
    };
    

    Then sizes on a port of type B would be given with

    port.max_sizes('field' => 10, 'field[].values' => 20)
    

    while the sizes on a port of type std::vector<A> would be given with

    port.max_sizes(10, 'values' => 20)
    

112
113
114
115
116
117
# File 'lib/orocos/ports_base.rb', line 112

dsl_attribute :max_sizes do |*values|
    # Validate that all values are integers and all names map to
    # known types
    value = OroGen::Spec::OutputPort.validate_max_sizes_spec(type, values)
    max_sizes.merge(value)
end

#new_sampleObject

Returns a new object of this port's type


53
54
55
56
# File 'lib/orocos/ports_base.rb', line 53

def new_sample
    ensure_type_available
    @type.new
end

#to_sObject


35
36
37
# File 'lib/orocos/ports_base.rb', line 35

def to_s
    "#{full_name}"
end