Class: Orocos::AttributeBase
- Inherits:
-
Object
- Object
- Orocos::AttributeBase
- Defined in:
- lib/orocos/task_context_base.rb
Overview
This class represents both RTT attributes and properties
Direct Known Subclasses
Instance Attribute Summary collapse
-
#log_port ⇒ Object
If set, this is an input port object in which new values set from within Ruby are sent.
-
#log_stream ⇒ Object
If set, this is a Pocolog::DataStream object in which new values set from within Ruby are set.
-
#name ⇒ Object
readonly
The property/attribute name.
-
#orocos_type_name ⇒ Object
readonly
The type name as registered in the orocos type system.
-
#task ⇒ Object
readonly
The underlying TaskContext instance.
-
#type ⇒ Object
readonly
The attribute type, as a subclass of Typelib::Type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #doc ⇒ Object
- #doc? ⇒ Boolean
- #ensure_type_available(options = Hash.new) ⇒ Object
- #full_name ⇒ Object
-
#initialize(task, name, orocos_type_name) ⇒ AttributeBase
constructor
A new instance of AttributeBase.
-
#log_current_value(timestamp = Time.now) ⇒ Object
Write the current value of the property or attribute to #log_stream.
- #log_metadata ⇒ Object
- #log_value(value, timestamp = Time.now) ⇒ Object
- #new_sample ⇒ Object
-
#pretty_print(pp) ⇒ Object
:nodoc:.
- #raw_read ⇒ Object
-
#read ⇒ Object
Read the current value of the property/attribute.
- #type_name ⇒ Object deprecated Deprecated.
-
#write(value, timestamp = Time.now, direct: false) ⇒ Object
Sets a new value for the property/attribute.
Constructor Details
#initialize(task, name, orocos_type_name) ⇒ AttributeBase
Returns a new instance of AttributeBase
22 23 24 25 26 |
# File 'lib/orocos/task_context_base.rb', line 22 def initialize(task, name, orocos_type_name) @task, @name = task, name @orocos_type_name = orocos_type_name ensure_type_available(:fallback_to_null_type => true) end |
Instance Attribute Details
#log_port ⇒ Object
If set, this is an input port object in which new values set from within Ruby are sent
18 19 20 |
# File 'lib/orocos/task_context_base.rb', line 18 def log_port @log_port end |
#log_stream ⇒ Object
If set, this is a Pocolog::DataStream object in which new values set from within Ruby are set
15 16 17 |
# File 'lib/orocos/task_context_base.rb', line 15 def log_stream @log_stream end |
#name ⇒ Object (readonly)
The property/attribute name
10 11 12 |
# File 'lib/orocos/task_context_base.rb', line 10 def name @name end |
#orocos_type_name ⇒ Object (readonly)
The type name as registered in the orocos type system
20 21 22 |
# File 'lib/orocos/task_context_base.rb', line 20 def orocos_type_name @orocos_type_name end |
#task ⇒ Object (readonly)
The underlying TaskContext instance
8 9 10 |
# File 'lib/orocos/task_context_base.rb', line 8 def task @task end |
#type ⇒ Object (readonly)
The attribute type, as a subclass of Typelib::Type
12 13 14 |
# File 'lib/orocos/task_context_base.rb', line 12 def type @type end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'lib/orocos/task_context_base.rb', line 40 def ==(other) name == other.name && task == other.task end |
#doc ⇒ Object
106 107 108 109 110 111 |
# File 'lib/orocos/task_context_base.rb', line 106 def doc if task.model property = task.model.find_property(name) property.doc if property end end |
#doc? ⇒ Boolean
102 103 104 |
# File 'lib/orocos/task_context_base.rb', line 102 def doc? (doc && !doc.empty?) end |
#ensure_type_available(options = Hash.new) ⇒ Object
52 53 54 55 56 |
# File 'lib/orocos/task_context_base.rb', line 52 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
29 30 31 |
# File 'lib/orocos/task_context_base.rb', line 29 def full_name "#{task.name}.#{name}" end |
#log_current_value(timestamp = Time.now) ⇒ Object
Write the current value of the property or attribute to #log_stream
80 81 82 |
# File 'lib/orocos/task_context_base.rb', line 80 def log_current_value( = Time.now) log_value(read) end |
#log_metadata ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/orocos/task_context_base.rb', line 44 def Hash['rock_task_model' => (task.model.name || ''), 'rock_task_name' => task.name, 'rock_task_object_name' => name, 'rock_orocos_type_name' => orocos_type_name, 'rock_cxx_type_name' => orocos_type_name] end |
#log_value(value, timestamp = Time.now) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/orocos/task_context_base.rb', line 84 def log_value(value, = Time.now) if log_stream log_stream.write(, , value) end if log_port log_port.write(value) end end |
#new_sample ⇒ Object
93 94 95 96 |
# File 'lib/orocos/task_context_base.rb', line 93 def new_sample ensure_type_available type.new end |
#pretty_print(pp) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/orocos/task_context_base.rb', line 98 def pretty_print(pp) # :nodoc: pp.text "attribute #{name} (#{type.name})" end |
#raw_read ⇒ Object
58 59 60 61 62 63 |
# File 'lib/orocos/task_context_base.rb', line 58 def raw_read ensure_type_available value = type.new do_read(@orocos_type_name, value) value end |
#read ⇒ Object
Read the current value of the property/attribute
66 67 68 |
# File 'lib/orocos/task_context_base.rb', line 66 def read Typelib.to_ruby(raw_read) end |
#type_name ⇒ Object
Returns the name of the typelib type. Use #type.name instead.
35 36 37 38 |
# File 'lib/orocos/task_context_base.rb', line 35 def type_name ensure_type_available type.name end |
#write(value, timestamp = Time.now, direct: false) ⇒ Object
Sets a new value for the property/attribute
71 72 73 74 75 76 77 |
# File 'lib/orocos/task_context_base.rb', line 71 def write(value, = Time.now, direct: false) ensure_type_available value = Typelib.from_ruby(value, type) do_write(@orocos_type_name, value, direct: direct) log_value(value, ) value end |