Module: Syskit::Coordination::Models::DataMonitoringTable

Includes:
MetaRuby::DSLs::FindThroughMethodMissing, Roby::Coordination::Models::Base
Included in:
DataMonitoringTable
Defined in:
lib/syskit/coordination/models/data_monitoring_table.rb

Overview

Model-level API for data monitoring tables

Instance Method Summary collapse

Instance Method Details

#all_attachment_pointArray<#===>

The union, along the class hierarchy, of all the values stored in attachment_point

Returns:

  • (Array<#===>)


20
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 20

inherited_attribute(:attachment_point, :attachment_points) { Array.new }

#all_monitorArray<DataMonitor>

The union, along the class hierarchy, of all the values stored in monitor

Returns:



24
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 24

inherited_attribute(:monitor, :monitors) { Array.new }

#apply_block(&block) ⇒ Object



60
61
62
63
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 60

def apply_block(&block)
    super
    validate_monitors(monitors)
end

#attach_to(query) ⇒ Object

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)

Parameters:

  • query (#===)

    object used to match tasks in the Roby plan. It must obviously match subclasses of the table's root task model



95
96
97
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 95

def attach_to(query)
    attachment_points << query
end

#attachment_pointArray<#===>

Returns set of Roby task matchers that describe where this data monitor should be attached. They must obviously match the table's root task model

Returns:

  • (Array<#===>)

    set of Roby task matchers that describe where this data monitor should be attached. They must obviously match the table's root task model

See Also:

  • {attach_to}


20
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 20

inherited_attribute(:attachment_point, :attachment_points) { Array.new }

#each_attachment_point {|element| ... } ⇒ Object

Enumerates all objects registered in attachment_point

Yields:

  • (element)

Yield Parameters:

  • element (#===)

Returns:



20
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 20

inherited_attribute(:attachment_point, :attachment_points) { Array.new }

#each_monitor {|element| ... } ⇒ Object

Enumerates all objects registered in monitor

Yields:

  • (element)

Yield Parameters:

Returns:



24
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 24

inherited_attribute(:monitor, :monitors) { Array.new }

#find_monitor(name) ⇒ Object



79
80
81
82
83
84
# 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) ⇒ Object



104
105
106
107
# 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) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
# 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) ⇒ DataMonitor

Define a new data monitor

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

Examples:

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

Register a block and generate a DataMonitoringError when it returns true

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

Returns:



24
# File 'lib/syskit/coordination/models/data_monitoring_table.rb', line 24

inherited_attribute(:monitor, :monitors) { Array.new }

#validate_monitors(monitors) ⇒ Object

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

Raises:

  • InvalidDataMonitor



69
70
71
72
73
74
75
76
77
# 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