class Syskit::Models::FacetedAccess

Proxy class that gives access to a component under the cover of a certain number of models (e.g. services, …) to make it “look like” one of these components

It can be used on component instances and component models

One rarely creates an instance of this object directly, but uses the as() acessor on component models

Attributes

object[R]

The object to which we are giving a faceted access

port_mappings[R]

@return [{String=>Port}] mapping of ports in {required} to ports in

{object}
ports_on_required[R]

@return [{String=>}] the ports on {required} that provide the

named port

Public Class Methods

new(object, required, mappings = Hash.new) click to toggle source
Calls superclass method Syskit::InstanceSelection.new
# File lib/syskit/models/faceted_access.rb, line 21
def initialize(object, required, mappings = Hash.new)
    super(nil, object.to_instance_requirements, required.to_instance_requirements, mappings)
    @object = object
    @ports_on_required = Hash.new
    @port_mappings = Hash.new
end

Public Instance Methods

connect_to(sink, policy = Hash.new) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 128
def connect_to(sink, policy = Hash.new)
    Syskit.connect(self, sink, policy)
end
each_input_port() { |p| ... } click to toggle source
# File lib/syskit/models/faceted_access.rb, line 108
def each_input_port
    return enum_for(:each_input_port) if !block_given?
    each_port_helper :each_input_port do |p|
        yield(p)
    end
end
each_output_port() { |p| ... } click to toggle source
# File lib/syskit/models/faceted_access.rb, line 115
def each_output_port
    return enum_for(:each_output_port) if !block_given?
    each_port_helper :each_output_port do |p|
        yield(p)
    end
end
each_port() click to toggle source
# File lib/syskit/models/faceted_access.rb, line 122
def each_port
    return enum_for(:each_port) if block_given?
    each_input_port(&proc)
    each_output_port(&proc)
end
each_port_helper(each_method) { |attach| ... } click to toggle source
# File lib/syskit/models/faceted_access.rb, line 97
def each_port_helper(each_method)
    required.each_required_model do |m|
        m.send(each_method) do |p|
            port_mappings[p.name] ||= find_all_port_mappings_for(p.name)
            if port_mappings[p.name].size == 1
                yield(p.attach(self))
            end
        end
    end
end
find_all_port_mappings_for(name) click to toggle source

Find all possible port mappings for the given port name to {#object}

@param [String] name the port name on {#required} @return [Set<Port>] the set of ports on {#object} that are mapped

from {#required}
# File lib/syskit/models/faceted_access.rb, line 58
def find_all_port_mappings_for(name)
    candidates = Set.new
    ports_on_required[name] ||= find_ports_on_required(name)
    ports_on_required[name].each do |p|
        srv = service_selection[p.component_model]
        actual_port_name = srv.port_mappings_for_task[p.name]
        if p = object.find_port(actual_port_name)
            candidates << p
        else
            raise InternalError, "failed to map port from the required facet #{required} to #{object}"
        end
    end
    candidates
end
find_data_service(name) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 38
def find_data_service(name)
    # The name of data services cannot change between the facet and the
    # real object, just return the one from the real object
    object.find_data_service(name)
end
find_data_service_from_type(type) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 44
def find_data_service_from_type(type)
    srv = required.find_data_service_from_type(type)
    if !required.each_required_model.to_a.include?(srv.model)
        return find_data_service(srv.name)
    else
        return srv
    end
end
find_port(name) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 77
def find_port(name)
    if !port_mappings[name]
        port_mappings[name] = find_all_port_mappings_for(name)
    end
    candidates = port_mappings[name]
    if candidates.size > 1
        raise AmbiguousPortOnCompositeModel.new(self, required.each_required_model.to_a, name, candidates),
            "#{name} is an ambiguous port on #{self}: it can be mapped to #{candidates.map(&:to_s).join(", ")}"
    end

    ports = ports_on_required[name]
    if !ports.empty?
        ports.first.attach(self)
    end
end
find_ports_on_required(name) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 28
def find_ports_on_required(name)
    result = []
    required.each_required_model do |m|
        if p = m.find_port(name)
            result << p
        end
    end
    result
end
find_through_method_missing(m, args) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 141
def find_through_method_missing(m, args)
    MetaRuby::DSLs.find_through_method_missing(
        self, m, args, "_port".freeze => :find_port) || super
end
has_port?(name) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 73
def has_port?(name)
    !(port_mappings[name] ||= find_all_port_mappings_for(name)).empty?
end
has_through_method_missing?(m) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 136
def has_through_method_missing?(m)
    MetaRuby::DSLs.has_through_method_missing?(
        self, m, "_port".freeze => :has_port?) || super
end
self_port_to_component_port(port) click to toggle source
# File lib/syskit/models/faceted_access.rb, line 93
def self_port_to_component_port(port)
    port_mappings[port.name].first.to_component_port
end
to_s() click to toggle source
# File lib/syskit/models/faceted_access.rb, line 132
def to_s
    "#{object.to_s}.as(#{required.each_required_model.map(&:name).sort.join(",")})"
end