Data structure used internally to represent the data services that are provided by a given component model
The task model which provides this service
The service’s full name, i.e. the name with which it is referred to in the task model
The master service (if there is one)
The service model
The service name
The mappings needed between the ports in the service interface and the actual ports on the component
# 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
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
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
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
# File lib/orocos/roby/component.rb, line 123 def config_type model.config_type end
# 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
# File lib/orocos/roby/component.rb, line 103 def each_data_service(&block) self end
# 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
# 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
# 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
# File lib/orocos/roby/component.rb, line 183 def each_slave(&block) component_model.each_slave_data_service(self, &block) end
# 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
# 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
# File lib/orocos/roby/component.rb, line 115 def find_all_services_from_type(m) if self.model.fullfills?(m) [self] else [] end end
# File lib/orocos/roby/component.rb, line 107 def find_input_port(name) model.find_input_port(name) end
# File lib/orocos/roby/component.rb, line 111 def find_output_port(name) model.find_output_port(name) end
# 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
# File lib/orocos/roby/component.rb, line 131 def has_input_port?(name) !!find_input_port(name) end
# File lib/orocos/roby/component.rb, line 127 def has_output_port?(name) !!find_output_port(name) end
True if this service is not a slave service
# File lib/orocos/roby/component.rb, line 23 def master?; !@master end
If an unknown method is called on this object, try to return the corresponding slave service (if there is one)
# 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
# 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
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
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
# 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
# File lib/orocos/roby/component.rb, line 49 def short_name "#{component_model.short_name}:#{full_name}" end
# File lib/orocos/roby/component.rb, line 45 def to_s "#<ProvidedDataService: #{component_model.short_name} #{full_name}>" end