Class: Orocos::Local::NameService

Inherits:
NameServiceBase show all
Includes:
Namespace
Defined in:
lib/orocos/name_service.rb

Overview

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

Constant Summary

Constants included from Namespace

Namespace::DELIMATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Namespace

#basename, #map_to_namespace, #namespace, #namespace=, #split_name, split_name, validate_namespace_name, #verify_same_namespace

Methods inherited from NameServiceBase

#each_task, #find_one_running, #get_provides, #ior, #reachable?, #task_reachable?, #validate

Constructor Details

#initialize(tasks = []) ⇒ NameService

Note:

The namespace is always “Local”

A new NameService instance

Parameters:

  • tasks (Hash<String,Orocos::TaskContext>) (defaults to: [])

    The tasks which are known by the name service.

Raises:

  • (ArgumentError)


401
402
403
404
405
406
407
408
# 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

Instance Attribute Details

#registered_tasksObject (readonly)

Returns the value of attribute registered_tasks



395
396
397
# File 'lib/orocos/name_service.rb', line 395

def registered_tasks
  @registered_tasks
end

Instance Method Details

#deregister(name) ⇒ Object

Deregisters the given name or task from the name service.

Parameters:



459
460
461
462
463
464
465
466
467
468
# 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

#get(name, options = Hash.new) ⇒ Orocos::TaskContext, Orocos::Log::TaskContext

Gets an handle to a local/remote Orocos Task having the given name.

Parameters:

  • name (String)

    the name of the TaskContext

  • options (Hash) (defaults to: Hash.new)

    the options used by the name service to find the TaskContext

Options Hash (options):

  • :name (String)

    Overwrites The real name of the task

  • :process (Orocos::Process)

    The process supporting the task

Returns:

Raises:

See Also:



421
422
423
424
425
426
427
428
429
430
431
432
433
434
# 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

#nameObject

return [String] the name of the name service



411
412
413
# File 'lib/orocos/name_service.rb', line 411

def name
    super + ":Local"
end

#namesArray<String>

Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.

Returns:

  • (Array<String>)


471
472
473
474
# File 'lib/orocos/name_service.rb', line 471

def names
    ns = registered_tasks.map &:name 
		ns + @alias.keys
end

#register(task, name = nil) ⇒ Object

Parameters:

  • task (Orocos::TaskContext)

    The task.

  • name (String) (defaults to: nil)

    Optional name which is used to register the task.



443
444
445
446
447
448
449
# 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

#same_namespace?(name_space) ⇒ Boolean

Local is a collection of name spaces

Returns:

  • (Boolean)


452
453
454
# File 'lib/orocos/name_service.rb', line 452

def same_namespace?(name_space)
    true
end

#to_async(options = Hash.new) ⇒ Object

Returns an Async object that maps to this name service



416
417
418
# File 'lib/orocos/name_service.rb', line 416

def to_async(options = Hash.new)
    Orocos::Async::Local::NameService.new(:tasks => registered_tasks)
end