class Orocos::Log::Property

Simulated Property based on a configuration log file It is automatically replayed if at least one OutputPort of the task is replayed

Attributes

name[R]

The property/attribute name

stream[R]

dedicated stream for simulating the port

task[R]

The underlying TaskContext instance

tracked[RW]

true –> this property shall be replayed

type[R]

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

type_name[R]

Public Class Methods

new(task, stream) click to toggle source
# File lib/orocos/log/task_context.rb, line 513
def initialize(task, stream)
    if !stream.respond_to?(:name) || !stream.respond_to?(:type) || !stream.respond_to?(:typename) || !stream.respond_to?(:metadata)
        raise "Cannot create Property out of #{stream.class}"
    end
    @stream = stream
    @name = stream.name.to_s.match(/\.(.*$)/)
    raise 'Stream name does not follow the convention TASKNAME.PROPERTYNAME' if @name == nil
    @name = @name[1]
    @type = stream.type
    @task = task
    @current_data = nil
    @type_name = stream.typename
    @notify_blocks =[]
end

Public Instance Methods

aligned?() click to toggle source

returns true if Log::Replay is aligned

# File lib/orocos/log/task_context.rb, line 535
def aligned?
    task.log_replay.aligned?
end
doc?() click to toggle source
# File lib/orocos/log/task_context.rb, line 539
def doc?
    false
end
full_name() click to toggle source

Give the full name for this property. It is the stream name.

# File lib/orocos/log/task_context.rb, line 596
def full_name
    stream.name
end
metadata() click to toggle source

returns the metadata associated with the underlying stream

# File lib/orocos/log/task_context.rb, line 605
def metadata
    stream.metadata
end
new_sample() click to toggle source
# File lib/orocos/log/task_context.rb, line 578
def new_sample
    type.new
end
notify(&block) click to toggle source

registers a code block which will be called when the property changes

# File lib/orocos/log/task_context.rb, line 574
def notify(&block)
    @notify_blocks << block
end
number_of_samples() click to toggle source

Returns the number of samples for the property.

# File lib/orocos/log/task_context.rb, line 591
def number_of_samples
    return @stream.size
end
on_change(&block) click to toggle source

registers a code block which will be called when the property changes

# File lib/orocos/log/task_context.rb, line 565
def on_change(&block)
    self.tracked = true
    notify do
        block.call(read)
    end
end
orocos_type_name() click to toggle source
# File lib/orocos/log/task_context.rb, line 582
def orocos_type_name
    if metadata && metadata.has_key?(:rock_orocos_type_name)
        metadata[:rock_orocos_type_name]
    else
        type_name
    end
end
raw_read() click to toggle source
# File lib/orocos/log/task_context.rb, line 555
def raw_read
    if @sample_info && !@current_data
        stream, position = *@sample_info
        @current_data = stream.read_one_raw_data_sample(position)
    end
    @current_data
end
read() click to toggle source

Read the current value of the property/attribute

# File lib/orocos/log/task_context.rb, line 549
def read
    if sample = raw_read
        Typelib.to_ruby(sample)
    end
end
tracked=(value) click to toggle source

If set to true the port is replayed.

# File lib/orocos/log/task_context.rb, line 529
def tracked=(value)
    raise "can not track property #{stream.name} after the replay has started" if !used? && aligned?
    @tracked = value
end
update(sample_info) click to toggle source
# File lib/orocos/log/task_context.rb, line 543
def update(sample_info)
    @current_data = nil
    @sample_info = sample_info
end
used?() click to toggle source
# File lib/orocos/log/task_context.rb, line 609
def used?
    tracked
end