Class: Orocos::Local::NameService
- Inherits:
-
NameServiceBase
- Object
- NameServiceBase
- Orocos::Local::NameService
- 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
Constant Summary
Constants included from Namespace
Instance Attribute Summary collapse
-
#registered_tasks ⇒ Object
readonly
Returns the value of attribute registered_tasks.
Instance Method Summary collapse
-
#deregister(name) ⇒ Object
Deregisters the given name or task from the name service.
-
#get(name, options = Hash.new) ⇒ Orocos::TaskContext, Orocos::Log::TaskContext
Gets an handle to a local/remote Orocos Task having the given name.
-
#initialize(tasks = []) ⇒ NameService
constructor
A new NameService instance.
-
#name ⇒ Object
return [String] the name of the name service.
-
#names ⇒ Array<String>
Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.
- #register(task, name = nil) ⇒ Object
-
#same_namespace?(name_space) ⇒ Boolean
Local is a collection of name spaces.
-
#to_async(options = Hash.new) ⇒ Object
Returns an Async object that maps to this name service.
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
The namespace is always “Local”
A new NameService instance
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_tasks ⇒ Object (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.
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.
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,=Hash.new) = Kernel. ,: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 |
#name ⇒ Object
return [String] the name of the name service
411 412 413 |
# File 'lib/orocos/name_service.rb', line 411 def name super + ":Local" end |
#names ⇒ Array<String>
Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.
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
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
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( = Hash.new) Orocos::Async::Local::NameService.new(:tasks => registered_tasks) end |