class Orocos::Log::OutputReader

Simulates an output port based on log files. It has the same behavior like an OutputReader

Attributes

filter[RW]

filter for log data the filter is applied during read the buffer is not effected

policy[R]
port[R]

Handle to the port the reader is reading from

Public Class Methods

new(port,policy=default_policy) click to toggle source

Creates a new OutputReader

port => handle to the port the reader shall read from policy => policy for reading data

see project orocos.rb for more information

# File lib/orocos/log/task_context.rb, line 33
def initialize(port,policy=default_policy)
    @policy = default_policy if !policy
    @port = port
    @buffer = Array.new
    @filter, policy = Kernel.filter_options(policy,[:filter])
    @filter = @filter[:filter]
    policy = Orocos::Port.prepare_policy(policy)
    @policy_type = policy[:type]
    @buffer_size = policy[:size]
    @last_update = Time.now
end

Public Instance Methods

clear() click to toggle source
# File lib/orocos/log/task_context.rb, line 63
def clear
    @buffer.clear
end
clear_buffer() click to toggle source

Clears the buffer of the reader.

# File lib/orocos/log/task_context.rb, line 59
def clear_buffer 
    @buffer.clear
end
connected?() click to toggle source
# File lib/orocos/log/task_context.rb, line 67
def connected?
    true
end
doc?() click to toggle source
# File lib/orocos/log/task_context.rb, line 110
def doc?
    false
end
new_sample() click to toggle source
# File lib/orocos/log/task_context.rb, line 106
def new_sample
    @port.new_sample
end
raw_read(sample = nil) click to toggle source
# File lib/orocos/log/task_context.rb, line 89
def raw_read(sample = nil)
    if new_sample = raw_read_new(sample)
        return new_sample
    else @raw_last_sample
    end
end
raw_read_new(sample = nil) click to toggle source
# File lib/orocos/log/task_context.rb, line 71
def raw_read_new(sample = nil)
    if sample = @buffer.shift
        sample =
            if @filter
                @filter.call(sample)
            else sample
            end
        @raw_last_sample = sample
        return sample
    end
end
read(sample = nil) click to toggle source
# File lib/orocos/log/task_context.rb, line 96
def read(sample = nil)
    if sample = raw_read(sample)
        return Typelib.to_ruby(sample)
    end
end
read_new(sample = nil) click to toggle source
# File lib/orocos/log/task_context.rb, line 83
def read_new(sample = nil)
    if sample = raw_read_new(sample)
        return Typelib.to_ruby(sample)
    end
end
type_name() click to toggle source
# File lib/orocos/log/task_context.rb, line 102
def type_name
    @port.type_name
end
update(raw_data) click to toggle source

This method is called each time new data are availabe.

# File lib/orocos/log/task_context.rb, line 46
def update(raw_data) 
    if @policy_type == :buffer
        if @buffer.size != @buffer_size
            @buffer << raw_data
        end
    elsif @policy_type == :data
        @buffer = [raw_data]
    else
        raise "port policy #{@policy_type} is not supported by #{self.class}"
    end
end