Module: Orocos::PortBase

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

Constant Summary collapse

D_UNKNOWN =
0
D_SAME_PROCESS =
1
D_SAME_HOST =
2
D_DIFFERENT_HOSTS =
3

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



59
60
61
62
# File 'lib/orocos/ports_base.rb', line 59

def ==(other)
    return false if !other.kind_of?(PortBase)
    other.task == self.task && other.name == self.name
end

#distance_to(input_port) ⇒ Object

How “far” from the given input port this port is

Returns:

  • one of the D_ constants



43
44
45
46
47
48
49
50
51
52
# File 'lib/orocos/ports_base.rb', line 43

def distance_to(input_port)
    if !task.process || !input_port.task.process
        return D_UNKNOWN
    elsif task.process == input_port.task.process
        return D_SAME_PROCESS
    elsif task.process.host_id == input_port.task.process.host_id
        return D_SAME_HOST
    else return D_DIFFERENT_HOSTS
    end
end

#ensure_type_available(options = Hash.new) ⇒ Object



64
65
66
67
68
# File 'lib/orocos/ports_base.rb', line 64

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/orocos/ports_base.rb', line 76

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,
        'rock_cxx_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.



144
145
146
# File 'lib/orocos/ports_base.rb', line 144

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)
    


131
132
133
134
135
136
# File 'lib/orocos/ports_base.rb', line 131

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



71
72
73
74
# File 'lib/orocos/ports_base.rb', line 71

def new_sample
    ensure_type_available
    @type.new
end

#to_sObject



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

def to_s
    "#{full_name}"
end