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
-
#model ⇒ OroGen::Spec::Port?
readonly
The port's model.
-
#name ⇒ Object
readonly
The port name.
-
#orocos_type_name ⇒ Object
readonly
The port's type name as used by the RTT.
-
#task ⇒ Object
readonly
The task this port is part of.
-
#type ⇒ Object
readonly
The port's type as a Typelib::Type object.
Instance Method Summary collapse
-
#==(other) ⇒ Object
True if
self
andother
represent the same port. -
#distance_to(input_port) ⇒ Object
How “far” from the given input port this port is.
- #ensure_type_available(options = Hash.new) ⇒ Object
-
#full_name ⇒ Object
The port full name.
- #initialize(task, name, orocos_type_name, model) ⇒ Object
- #log_metadata ⇒ Object
-
#max_marshalling_size ⇒ Object
Returns the maximum marshalled size of a sample from this port, as marshalled by typelib.
- #max_sizes ⇒ Object
-
#new_sample ⇒ Object
Returns a new object of this port's type.
- #to_s ⇒ Object
Instance Attribute Details
#model ⇒ OroGen::Spec::Port? (readonly)
The port's model
15 16 17 |
# File 'lib/orocos/ports_base.rb', line 15 def model @model end |
#name ⇒ Object (readonly)
The port name
6 7 8 |
# File 'lib/orocos/ports_base.rb', line 6 def name @name end |
#orocos_type_name ⇒ Object (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 |
#task ⇒ Object (readonly)
The task this port is part of
4 5 6 |
# File 'lib/orocos/ports_base.rb', line 4 def task @task end |
#type ⇒ Object (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
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( = Hash.new) if !type || type.null? @type = Orocos.find_type_by_orocos_type_name(orocos_type_name, ) end end |
#full_name ⇒ Object
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_metadata ⇒ Object
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. # 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_size ⇒ Object
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
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_sample ⇒ Object
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_s ⇒ Object
54 55 56 |
# File 'lib/orocos/ports_base.rb', line 54 def to_s "#{full_name}" end |