Class: Orocos::Log::OutputReader

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/log/task_context.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, policy = default_policy) ⇒ OutputReader

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



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/orocos/log/task_context.rb', line 108

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

Instance Attribute Details

#filterObject

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



100
101
102
# File 'lib/orocos/log/task_context.rb', line 100

def filter
  @filter
end

#policyObject (readonly)

Returns the value of attribute policy



95
96
97
# File 'lib/orocos/log/task_context.rb', line 95

def policy
  @policy
end

#portObject (readonly)

Handle to the port the reader is reading from



93
94
95
# File 'lib/orocos/log/task_context.rb', line 93

def port
  @port
end

Instance Method Details

#clearObject



138
139
140
# File 'lib/orocos/log/task_context.rb', line 138

def clear
    @buffer.clear
end

#clear_bufferObject

Clears the buffer of the reader.



134
135
136
# File 'lib/orocos/log/task_context.rb', line 134

def clear_buffer
    @buffer.clear
end

#connected?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/orocos/log/task_context.rb', line 142

def connected?
    true
end

#doc?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/orocos/log/task_context.rb', line 185

def doc?
    false
end

#new_sampleObject



181
182
183
# File 'lib/orocos/log/task_context.rb', line 181

def new_sample
    @port.new_sample
end

#raw_read(sample = nil) ⇒ Object



164
165
166
167
168
169
# File 'lib/orocos/log/task_context.rb', line 164

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) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
# File 'lib/orocos/log/task_context.rb', line 146

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) ⇒ Object



171
172
173
174
175
# File 'lib/orocos/log/task_context.rb', line 171

def read(sample = nil)
    if sample = raw_read(sample)
        return Typelib.to_ruby(sample)
    end
end

#read_new(sample = nil) ⇒ Object



158
159
160
161
162
# File 'lib/orocos/log/task_context.rb', line 158

def read_new(sample = nil)
    if sample = raw_read_new(sample)
        return Typelib.to_ruby(sample)
    end
end

#type_nameObject



177
178
179
# File 'lib/orocos/log/task_context.rb', line 177

def type_name
    @port.type_name
end

#update(raw_data) ⇒ Object

This method is called each time new data are availabe.



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/orocos/log/task_context.rb', line 121

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