class Syskit::Models::DynamicDataService

Representation of a dynamic service registered with Syskit::Models::Component#dynamic_service

Attributes

block[R]

The service definition block

component_model[R]

The component model we are bound to

demoted[R]

The actual dynamic data service model we've been promoted from

See {BoundDataService} documentation for a discussion on promotion

name[R]

The dynamic service name

service_model[R]

The service model

Public Class Methods

directional_port_mapping(component_model, direction, port, expected_name) click to toggle source

Validates the setup for a single data service port, and computes the port mapping for it. It validates the port creation rule that a mapping must be given for a port to be created.

# File lib/syskit/models/dynamic_data_service.rb, line 160
def self.directional_port_mapping(component_model, direction, port, expected_name)
    # Filter out the ports that already exist on the component
    if expected_name
        if component_model.send("find_#{direction}_port", expected_name)
            return expected_name
        end
    else
        expected_name = component_model.find_directional_port_mapping(direction, port, nil)
        if !expected_name
            raise InvalidPortMapping, "no explicit mapping has been given for the service port #{port.name} and no port on #{component_model.short_name} matches. You must give an explicit mapping of the form 'service_port_name' => 'task_port_name' if you expect the port to be dynamically created."
        end
        return expected_name
    end

    # Now verify that the rest can be instanciated
    if !component_model.send("has_dynamic_#{direction}_port?", expected_name, port.type)
        raise InvalidPortMapping, "there are no dynamic #{direction} ports declared in #{component_model.short_name} that match #{expected_name}:#{port.type_name}"
    end
    return expected_name
end
new(component_model, name, service_model, block, addition_requires_reconfiguration: true, remove_when_unused: false) click to toggle source
# File lib/syskit/models/dynamic_data_service.rb, line 20
def initialize(component_model, name, service_model, block, addition_requires_reconfiguration: true, remove_when_unused: false)
    @component_model, @name, @service_model, @block = component_model, name, service_model, block
    @addition_requires_reconfiguration = addition_requires_reconfiguration
    @remove_when_unused = remove_when_unused
    @demoted = self
end
update_component_model_interface(component_model, service_model, user_port_mappings) click to toggle source

Updates the #component_model's oroGen interface description to include the ports needed for the given dynamic service model

@return [Hash{String=>String}] the updated port mappings

# File lib/syskit/models/dynamic_data_service.rb, line 136
def self.update_component_model_interface(component_model, service_model, user_port_mappings)
    user_port_mappings = user_port_mappings.dup
    port_mappings = Hash.new
    service_model.each_output_port do |service_port|
        port_mappings[service_port.name] = directional_port_mapping(component_model, 'output', service_port, user_port_mappings.delete(service_port.name))
    end
    service_model.each_input_port do |service_port|
        port_mappings[service_port.name] = directional_port_mapping(component_model, 'input', service_port, user_port_mappings.delete(service_port.name))
    end

    if !user_port_mappings.empty?
        raise Syskit::InvalidPortMapping, "port mappings #{user_port_mappings} do not match either the ports of #{service_model} or the ports of #{component_model}"
    end

    # Unlike #data_service, we need to add the service's interface
    # to our own
    component_model.merge_service_model(service_model, port_mappings)
    port_mappings
end

Public Instance Methods

==(other) click to toggle source
# File lib/syskit/models/dynamic_data_service.rb, line 36
def ==(other)
    eql?(other)
end
attach(component_model) click to toggle source
# File lib/syskit/models/dynamic_data_service.rb, line 40
def attach(component_model)
    result = dup
    result.instance_variable_set(:@component_model, component_model)
    result
end
eql?(other) click to toggle source
# File lib/syskit/models/dynamic_data_service.rb, line 27
def eql?(other)
    component_model == other.component_model &&
        name == other.name
end
hash() click to toggle source
# File lib/syskit/models/dynamic_data_service.rb, line 32
def hash
    [component_model, name].hash
end
instanciate(name, **options) click to toggle source

Instanciates a new bound dynamic service on the underlying component

@param [String] the name of the bound service @param options options that should be given to {#block}. These

options are available to the block as an 'options' local variable

@return [BoundDynamicDataService]

# File lib/syskit/models/dynamic_data_service.rb, line 123
def instanciate(name, **options)
    instantiator = component_model.create_dynamic_instantiation_context(name, self, **options)
    instantiator.instance_eval(&block)
    if !instantiator.service
        raise InvalidDynamicServiceBlock.new(self), "the block #{block} used to instantiate the dynamic service #{name} on #{component_model.short_name} with options #{options} did not provide any service"
    end
    instantiator.service
end