class Syskit::Coordination::DataMonitor

A {Models::DataMonitor} instanciated for a data monitor table attached to an actual component

Attributes

data_streams[R]

@return [Syskit::OutputReader] the data streams that

are monitored
emitted_events[R]

@return [Array<Roby::Coordination::Event>] the set of events that

should be emitted when this monitor triggers
model[R]

@return [Models::DataMonitor] the monitor model

predicate[R]

@return [#call,#finalize] the predicate. It will be called each

time there is a new sample on one of the data streams with the
data stream that got a new sample as well as the sample itself.
In addition, #finalize is called at the end of a data gathering
cycle, i.e. after #call has been called with all new samples. It
must return whether the predicate matches (true) or not (false)

Public Class Methods

new(model, data_streams) click to toggle source
# File lib/syskit/coordination/data_monitor.rb, line 25
def initialize(model, data_streams)
    @model, @data_streams = model, data_streams
    @emitted_events = Array.new
    @raises = false
end

Public Instance Methods

emit(event) click to toggle source
# File lib/syskit/coordination/data_monitor.rb, line 41
def emit(event)
    @emitted_events << event
    self
end
poll(root_task) click to toggle source

Reads the data streams, and pushes the data to the predicate when applicable

# File lib/syskit/coordination/data_monitor.rb, line 48
def poll(root_task)
    data_streams.each do |reader|
        while sample = reader.read_new
            predicate.call(reader, sample)
        end
    end
    if predicate.finalize
        trigger(root_task)
        true
    else
        false
    end
end
ready?() click to toggle source

Whether the data monitor is attached to all its source streams

# File lib/syskit/coordination/data_monitor.rb, line 32
def ready?
    data_streams.all?(&:ready?)
end
to_s() click to toggle source
# File lib/syskit/coordination/data_monitor.rb, line 79
def to_s; "monitor(#{model.name}(#{data_streams.map(&:to_s).join(", ")})" end
trigger(root_task) click to toggle source

Issue an error because the predicate returned true (match)

# File lib/syskit/coordination/data_monitor.rb, line 63
def trigger(root_task)
    emitted_events.each do |ev|
        ev = ev.resolve
        if ev.executable?
            ev.emit
        end
    end
    if raises?
        samples = data_streams.map do |reader|
            reader.read
        end
        error = DataMonitoringError.new(root_task, self, Time.now, samples)
        root_task.plan.add_error(error)
    end
end
trigger_on(predicate) click to toggle source
# File lib/syskit/coordination/data_monitor.rb, line 36
def trigger_on(predicate)
    @predicate = predicate
    self
end