class Orocos::RobyPlugin::ProvidedDataService

Data structure used internally to represent the data services that are provided by a given component model

Attributes

component_model[R]

The task model which provides this service

declared_dynamic_slaves[R]
full_name[R]

The service’s full name, i.e. the name with which it is referred to in the task model

master[R]

The master service (if there is one)

model[R]

The service model

name[R]

The service name

port_mappings[R]

The mappings needed between the ports in the service interface and the actual ports on the component

Public Class Methods

new(name, component_model, master, model, port_mappings) click to toggle source
# File lib/orocos/roby/component.rb, line 25
def initialize(name, component_model, master, model, port_mappings)
    @name, @component_model, @master, @model, @port_mappings = 
        name, component_model, master, model, port_mappings

    @full_name =
        if master
            "#{master.name}.#{name}"
        else
            name
        end

    @declared_dynamic_slaves = Array.new
end

Public Instance Methods

add_slaves(&block) click to toggle source

Provides an instanciation context that can be used to add multiple slaves easily, e.g.:

driver_for(‘NewDevice’).add_slaves do

provides Srv::Camera, :as => 'lcamera'
provides Srv::Laser, :as => 'scans'
...

end

# File lib/orocos/roby/component.rb, line 269
def add_slaves(&block)
    context = SlaveDefinitionContext.new(component_model, name)
    context.instance_eval(&block)
    self
end
as(service_model) click to toggle source

Returns a view of this service as a provider of service_model

It allows to transparently apply port mappings as if self was a service of type service_model

# File lib/orocos/roby/component.rb, line 57
def as(service_model)
    result = dup
    result.instance_variable_set(:@model, service_model)

    mappings = port_mappings.dup
    mappings.delete_if do |srv, _|
        !service_model.fullfills?(srv)
    end
    result.instance_variable_set(:@port_mappings, mappings)
    result
end
bind(task) click to toggle source

Returns the DataServiceInstance object that binds this provided service to an actual task

# File lib/orocos/roby/component.rb, line 277
def bind(task)
    if !task.fullfills?(component_model)
        raise ArgumentError, "cannot bind #{self} on #{task}: does not fullfill #{component_model}"
    end
    DataServiceInstance.new(task, self)
end
config_type() click to toggle source
# File lib/orocos/roby/component.rb, line 123
def config_type
    model.config_type
end
dynamic_slaves(model, options = Hash.new, &block) click to toggle source
# File lib/orocos/roby/component.rb, line 198
def dynamic_slaves(model, options = Hash.new, &block)
    source_model = component_model.system_model.
        query_or_create_service_model(model, self.model.class, options)

    declared_dynamic_slaves << [source_model, block, model, options]
    source_model
end
each_data_service(&block) click to toggle source
# File lib/orocos/roby/component.rb, line 103
def each_data_service(&block)
    self
end
each_fullfilled_model() { |m| ... } click to toggle source
# File lib/orocos/roby/component.rb, line 233
def each_fullfilled_model
    model.ancestors.each do |m|
        if m <= Component || m <= DataService
            yield(m)
        end
    end
end
each_input_port(with_slaves = false, &block) click to toggle source
# File lib/orocos/roby/component.rb, line 135
def each_input_port(with_slaves = false, &block)
    if !block_given?
        return enum_for(:each_input_port, with_slaves)
    end

    model.each_input_port(&block)
    if with_slaves
        each_slave do |name, srv|
            srv.each_input_port(true, &block)
        end
    end
end
each_output_port(with_slaves = false, &block) click to toggle source
# File lib/orocos/roby/component.rb, line 148
def each_output_port(with_slaves = false, &block)
    if !block_given?
        return enum_for(:each_output_port, with_slaves)
    end

    model.each_output_port(&block)
    if with_slaves
        each_slave do |name, srv|
            srv.each_output_port(true, &block)
        end
    end
end
each_slave(&block) click to toggle source
# File lib/orocos/roby/component.rb, line 183
def each_slave(&block)
    component_model.each_slave_data_service(self, &block)
end
each_task_input_port(with_slaves = false) { |find_input_port| ... } click to toggle source
# File lib/orocos/roby/component.rb, line 161
def each_task_input_port(with_slaves = false, &block)
    if !block_given?
        return enum_for(:each_task_input_port, with_slaves)
    end

    mappings = port_mappings_for_task
    each_input_port do |port|
        yield(component_model.find_input_port(mappings[port.name]))
    end
end
each_task_output_port(with_slaves = false) { |find_output_port| ... } click to toggle source
# File lib/orocos/roby/component.rb, line 172
def each_task_output_port(with_slaves = false, &block)
    if !block_given?
        return enum_for(:each_task_output_port, with_slaves)
    end

    mappings = port_mappings_for_task
    each_output_port do |port|
        yield(component_model.find_output_port(mappings[port.name]))
    end
end
find_all_services_from_type(m) click to toggle source
# File lib/orocos/roby/component.rb, line 115
def find_all_services_from_type(m)
    if self.model.fullfills?(m)
        [self]
    else
        []
    end
end
find_input_port(name) click to toggle source
# File lib/orocos/roby/component.rb, line 107
def find_input_port(name)
    model.find_input_port(name)
end
find_output_port(name) click to toggle source
# File lib/orocos/roby/component.rb, line 111
def find_output_port(name)
    model.find_output_port(name)
end
fullfills?(models) click to toggle source
# File lib/orocos/roby/component.rb, line 69
def fullfills?(models)
    if !models.respond_to?(:each)
        models = [models]
    end
    components, services = models.partition { |m| m <= Component }
    (components.empty? || self.component_model.fullfills?(components)) &&
        (services.empty? || self.model.fullfills?(services))
end
has_input_port?(name) click to toggle source
# File lib/orocos/roby/component.rb, line 131
def has_input_port?(name)
    !!find_input_port(name)
end
has_output_port?(name) click to toggle source
# File lib/orocos/roby/component.rb, line 127
def has_output_port?(name)
    !!find_output_port(name)
end
master?() click to toggle source

True if this service is not a slave service

# File lib/orocos/roby/component.rb, line 23
def master?; !@master end
method_missing(name, *args) click to toggle source

If an unknown method is called on this object, try to return the corresponding slave service (if there is one)

Calls superclass method
# File lib/orocos/roby/component.rb, line 189
def method_missing(name, *args)
    if subservice = component_model.find_data_service("#{full_name}.#{name}")
        return subservice
    end
    super
end
overload(new_component_model) click to toggle source
# File lib/orocos/roby/component.rb, line 39
def overload(new_component_model)
    result = dup
    result.instance_variable_set :@component_model, new_component_model
    result
end
port_mappings_for(service_model) click to toggle source

Returns the port mappings that should be applied from the service model service_model to the providing task

The returned value is a hash of the form

service_port_name => task_port_name
# File lib/orocos/roby/component.rb, line 96
def port_mappings_for(service_model)
    if !(result = port_mappings[service_model])
        raise ArgumentError, "#{service_model} is not provided by #{model.short_name}"
    end
    result
end
port_mappings_for_task() click to toggle source

Returns the port mappings that should be applied from the service model model to the providing task

The returned value is a hash of the form

service_port_name => task_port_name
# File lib/orocos/roby/component.rb, line 85
def port_mappings_for_task
    port_mappings_for(model)
end
require_dynamic_slave(required_service, service_name, reason, component_model = nil) click to toggle source
# File lib/orocos/roby/component.rb, line 206
def require_dynamic_slave(required_service, service_name, reason, component_model = nil)
    model, specialization_block, _ =
        declared_dynamic_slaves.find do |model, specialization_block, _|
            model == required_service
        end

    return if !model

    component_model ||= self.component_model
    if !component_model.private_specialization?
        component_model = component_model.
            specialize("#{component_model.name}<#{reason}>")

        SystemModel.debug { "created the specialized submodel #{component_model.short_name} of #{component_model.superclass.short_name} as a singleton model for #{reason}" }
    end

    service_model = required_service.
        new_submodel(component_model.name + "." + required_service.short_name + "<" + service_name + ">")

    if specialization_block
        service_model.apply_block(service_name, &specialization_block)
    end
    srv = component_model.require_dynamic_service(service_model, :as => service_name, :slave_of => name)

    return component_model, srv
end
short_name() click to toggle source
# File lib/orocos/roby/component.rb, line 49
def short_name
    "#{component_model.short_name}:#{full_name}"
end
to_s() click to toggle source
# File lib/orocos/roby/component.rb, line 45
def to_s
    "#<ProvidedDataService: #{component_model.short_name} #{full_name}>"
end