class Orocos::AttributeBase

This class represents both RTT attributes and properties

Attributes

log_port[RW]

If set, this is an input port object in which new values set from within Ruby are sent

log_stream[RW]

If set, this is a Pocolog::DataStream object in which new values set from within Ruby are set

name[R]

The property/attribute name

orocos_type_name[R]

The type name as registered in the orocos type system

task[R]

The underlying TaskContext instance

type[R]

The attribute type, as a subclass of Typelib::Type

Public Class Methods

new(task, name, orocos_type_name) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# File lib/orocos/task_context_base.rb, line 40
def ==(other)
    name == other.name && task == other.task
end
doc() click to toggle source
# File lib/orocos/task_context_base.rb, line 105
def doc
    if task.model
        property = task.model.find_property(name)
        property.doc if property
    end
end
doc?() click to toggle source
# File lib/orocos/task_context_base.rb, line 101
def doc?
    (doc && !doc.empty?)
end
ensure_type_available(options = Hash.new) click to toggle source
# File lib/orocos/task_context_base.rb, line 51
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_name() click to toggle source
# File lib/orocos/task_context_base.rb, line 29
def full_name
    "#{task.name}.#{name}"
end
log_current_value(timestamp = Time.now) click to toggle source

Write the current value of the property or attribute to log_stream

# File lib/orocos/task_context_base.rb, line 79
def log_current_value(timestamp = Time.now)
    log_value(read)
end
log_metadata() click to toggle source
# File lib/orocos/task_context_base.rb, line 44
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
log_value(value, timestamp = Time.now) click to toggle source
# File lib/orocos/task_context_base.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
new_sample() click to toggle source
# File lib/orocos/task_context_base.rb, line 92
def new_sample
    ensure_type_available
    type.new
end
raw_read() click to toggle source
# File lib/orocos/task_context_base.rb, line 57
def raw_read
    ensure_type_available
    value = type.new
    do_read(@orocos_type_name, value)
    value
end
read() click to toggle source

Read the current value of the property/attribute

# File lib/orocos/task_context_base.rb, line 65
def read
    Typelib.to_ruby(raw_read)
end
type_name() click to toggle source

@deprecated Returns the name of the typelib type. Use type.name instead.

# 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) click to toggle source

Sets a new value for the property/attribute

# File lib/orocos/task_context_base.rb, line 70
def write(value, timestamp = Time.now, direct: false)
    ensure_type_available
    value = Typelib.from_ruby(value, type)
    do_write(@orocos_type_name, value, direct: direct)
    log_value(value, timestamp)
    value
end