class Syskit::Coordination::Models::DataMonitorPredicateFromBlock
Attributes
arguments[R]
@return [Hash] set of arguments that are needed by the predicate block
block[R]
@return [#call] the predicate block. It is called with the
data samples in the same order than defined by the
data_streams argument of {#initialize}
samples[R]
@return [Array<Object,nil>] the per-stream set of samples
last received. The sample order is the same than the
data_streams argument of {#initialize}
stream_to_index[R]
@return [{Syskit::Models::OutputReader=>Integer}] a mapping
from a reader model to the index in the list of samples (and, therefore, in the block's argument list)
Public Class Methods
new(data_streams, predicate_block, arguments = Hash.new)
click to toggle source
@param [Array<Syskit::Models::OutputReader>] data_streams the
data streams, in the same order than expected by the given block
@param [#call] predicate_block the predicate object. See the
documentation of {#block}
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 31 def initialize(data_streams, predicate_block, arguments = Hash.new) check_arity(predicate_block, data_streams.size) @arguments = arguments @stream_to_index = Hash.new data_streams.each_with_index do |s, idx| stream_to_index[s] = idx end @samples = Array.new(data_streams.size) @block = predicate_block # Flag used to know whether we have at least a sample per # stream @full = false @new_sample = false end
Public Instance Methods
bind(table, data_streams)
click to toggle source
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 48 def bind(table, data_streams) self.class.new(data_streams, block, table.arguments) end
call(stream, sample)
click to toggle source
Called when a new sample has been received
@param [Syskit::Models::OutputReader] the data stream on which
the sample has been received
@param [Object] the sample itself
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 57 def call(stream, sample) samples[stream_to_index[stream]] = sample @new_sample = true end
finalize()
click to toggle source
Called to know whether this predicate matched or not @return [Boolean]
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 64 def finalize return if !has_new_sample? if !@full return if samples.compact.size != samples.size @full = true end @new_samples = false instance_exec(*samples, &block) end
has_new_sample?()
click to toggle source
@return [Boolean] indicates whether call has been received
with a new sample since the last call to #finalize
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 19 def has_new_sample? @new_sample end
method_missing(m, *args)
click to toggle source
Calls superclass method
Syskit::Coordination::TaskScriptExtension#method_missing
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 79 def method_missing(m, *args) if arguments.has_key?(m) if !args.empty? raise ArgumentError, "#{args.size} provided to #{m}, zero expected" end return arguments[m] end return super end
respond_to_missing?(m, include_private)
click to toggle source
Calls superclass method
Syskit::Coordination::TaskScriptExtension#respond_to_missing?
# File lib/syskit/coordination/models/data_monitor_predicate_from_block.rb, line 75 def respond_to_missing?(m, include_private) arguments.has_key?(m) || super end