This class represents both RTT attributes and properties
If set, this is an input port object in which new values set from within Ruby are sent
If set, this is a Pocolog::DataStream object in which new values set from within Ruby are set
The property/attribute name
The type name as registered in the orocos type system
The underlying TaskContext instance
The attribute type, as a subclass of Typelib::Type
# File lib/orocos/task_context.rb, line 38 def initialize(task, name, orocos_type_name) @task, @name = task, name @orocos_type_name = orocos_type_name @type = begin Orocos.typelib_type_for(orocos_type_name) rescue Typelib::NotFound Orocos.load_typekit_for(orocos_type_name) Orocos.typelib_type_for(orocos_type_name) end @type_name = type.name end
# File lib/orocos/task_context.rb, line 104 def doc property = task.model.find_property(name) property.doc if property end
# File lib/orocos/task_context.rb, line 100 def doc? (doc && !doc.empty?) end
Write the current value of the property or attribute to #log_stream
# File lib/orocos/task_context.rb, line 79 def log_current_value(timestamp = Time.now) log_value(read) end
# File lib/orocos/task_context.rb, line 52 def log_metadata Hash['rock_task_model' => task.model.name, 'rock_task_name' => task.name, 'rock_task_object_name' => name, 'rock_orocos_type_name' => orocos_type_name] end
# File lib/orocos/task_context.rb, line 83 def log_value(value, timestamp = Time.now) if log_stream log_stream.write(timestamp, timestamp, value) end if log_port log_port.write(value) end end
# File lib/orocos/task_context.rb, line 92 def new_sample type.new end
# File lib/orocos/task_context.rb, line 59 def raw_read value = type.new do_read(@orocos_type_name, value) value end
Read the current value of the property/attribute
# File lib/orocos/task_context.rb, line 66 def read Typelib.to_ruby(raw_read) end
Sets a new value for the property/attribute
# File lib/orocos/task_context.rb, line 71 def write(value, timestamp = Time.now) value = Typelib.from_ruby(value, type) do_write(@orocos_type_name, value) log_value(value, timestamp) value end