module Syskit::Coordination::Models::DataMonitoringTable

Model-level API for data monitoring tables

@see Syskit::Coordination::DataMonitoringTable

Public Instance Methods

apply_block(&block) click to toggle source
Calls superclass method
# File lib/syskit/coordination/models/data_monitoring_table.rb, line 60
def apply_block(&block)
    super
    validate_monitors(monitors)
end
attach_to(query) click to toggle source

Declares that this table should be attached to the tasks matching the given query

If none is defined, it is going to be attached to every instance of the root model (i.e. the table's root task model)

@param [#===] query object used to match tasks in the Roby

plan. It must obviously match subclasses of the table's root
task model
# File lib/syskit/coordination/models/data_monitoring_table.rb, line 95
def attach_to(query)
    attachment_points << query
end
find_monitor(name) click to toggle source
# File lib/syskit/coordination/models/data_monitoring_table.rb, line 79
def find_monitor(name)
    each_monitor do |m|
        return m if m.name == name
    end
    nil
end
find_through_method_missing(m, args) click to toggle source
Calls superclass method
# File lib/syskit/coordination/models/data_monitoring_table.rb, line 104
def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        root, m, args, "_port".freeze => :find_port) || super
end
has_through_method_missing?(m) click to toggle source
Calls superclass method
# File lib/syskit/coordination/models/data_monitoring_table.rb, line 99
def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        root, m, "_port".freeze => :has_port?) || super
end
monitor(name, *data_streams) click to toggle source

Define a new data monitor

Data monitors are objects that watch some data streams and either emit events and/or raise exceptions

@example Register a block and emit an event when it returns true

monitor(:low_battery, battery_status_port).
    trigger_on { |level| # level < 1 }.
    emit battery_low_event

@example Register a block and generate a DataMonitoringError when it returns true

monitor(:low_battery, battery_status_port).
    trigger_on { |level| # level < 1 }.
    raise_exception

@return [DataMonitor] the new data monitor model

# File lib/syskit/coordination/models/data_monitoring_table.rb, line 42
def monitor(name, *data_streams)
    name = name.to_str

    # Allow giving a data stream as a port
    data_streams = data_streams.map do |obj|
        if obj.respond_to?(:reader)
            obj.reader
        elsif obj.respond_to?(:port)
            obj
        else raise ArgumentError, "#{obj} does not seem to be a valid data source. Expected a port or a data reader"
        end
    end

    monitor = DataMonitor.new(name, data_streams)
    monitors << monitor
    monitor
end
validate_monitors(monitors) click to toggle source

Validate that the given monitors are proper definitions (i.e. that all their required parameters are set)

@raise InvalidDataMonitor

# File lib/syskit/coordination/models/data_monitoring_table.rb, line 69
def validate_monitors(monitors)
    monitors.each do |m|
        if !m.predicate
            raise InvalidDataMonitor.new(m), "#{m} has no associated predicate"
        elsif m.emitted_events.empty? && !m.raises?
            raise InvalidDataMonitor.new(m), "#{m} has no effect (it neither emits events nor generates an exception). You must either call #emit or #raise_exception on it"
        end
    end
end