class Orocos::Local::NameService
Name service which is used by {Orocos::Log::Replay} to register {Orocos::Log::TaskContext} on the global name service {Orocos.name_service} @author Alexander Duda
Attributes
Public Class Methods
A new NameService instance
@param [Hash<String,Orocos::TaskContext>] tasks The tasks which are known by the name service. @note The namespace is always “Local”
# File lib/orocos/name_service.rb, line 401 def initialize(tasks =[]) raise ArgumentError, "wrong argument - Array was expected" unless tasks.is_a? Array @registered_tasks = Array.new @alias = {} tasks.each do |task| register(task) end end
Public Instance Methods
Deregisters the given name or task from the name service.
@param [String,TaskContext] name The name or task
# File lib/orocos/name_service.rb, line 459 def deregister(name) # deregister from alias task = @alias[name] @alias.delete name if task # and also the task list task = get(name) @registered_tasks.delete task rescue Orocos::NotFound end
(see Orocos::NameServiceBase#get)
# File lib/orocos/name_service.rb, line 421 def get(name,options=Hash.new) options = Kernel.validate_options options,:name,:namespace,:process # search alias hash first task = @alias[name] return task if task # otherwise look in the registered tasks task = @registered_tasks.find do |task| if task.name == name || task.basename == name true end end raise Orocos::NotFound, "task context #{name} cannot be found." unless task task end
(see Orocos::NameServiceBase#name)
# File lib/orocos/name_service.rb, line 411 def name super + ":Local" end
(see Orocos::NameServiceBase#names)
# File lib/orocos/name_service.rb, line 471 def names ns = registered_tasks.map &:name ns + @alias.keys end
Registers the given {Orocos::TaskContext} on the name service. If a name is provided, it will be used as an alias. If no name is provided, the name of the task is used. This is true even if the task name is renamed later.
@param [Orocos::TaskContext] task The task. @param [String] name Optional name which is used to register the task.
# File lib/orocos/name_service.rb, line 443 def register(task, name = nil) if name.nil? @registered_tasks << task unless @registered_tasks.include? task else @alias[name] = task end end
Local is a collection of name spaces
# File lib/orocos/name_service.rb, line 452 def same_namespace?(name_space) true end
Returns an Async object that maps to this name service
# File lib/orocos/name_service.rb, line 416 def to_async(options = Hash.new) Orocos::Async::Local::NameService.new(:tasks => registered_tasks) end