Class: Orocos::CORBA::NameService

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

Overview

Name service client to access the CORBA name service and retrieve an handle to registered Orocos Tasks. By default there is one global instance accessible via name_service which is also by default added to Orocos.name_service

The default name_service is used to register all Orocos Tasks started by the ruby instance no matter if it was removed from Orocos.name_service or not.

See Also:

Author:

  • Alexander Duda

Constant Summary

Constants included from Namespace

Namespace::DELIMATOR

Instance Method Summary collapse

Methods included from Namespace

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

Methods inherited from NameServiceBase

#each_task, #find_one_running, #get_provides, #reachable?, #same_namespace?, #task_reachable?

Constructor Details

#initialize(port = "", ip = "", options = Hash.new) ⇒ NameService #initialize(ip, options) ⇒ NameService #initialize(options) ⇒ NameService

A new instance of NameService


549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/orocos/name_service.rb', line 549

def initialize(ip="",port="",options = Hash.new)
    ip,port,options = if ip.is_a? Hash
                          ["",port,ip]
                      elsif port.is_a? Hash
                          [ip,"",port]
                      else
                          [ip,port,options]
                      end

    # no support for options at the moment
    options = Kernel.validate_options options
end

Instance Method Details

#bind(task, name) ⇒ Object

Bind an existing task under an alternative name


592
593
594
# File 'lib/orocos/name_service.rb', line 592

def bind(task, name)
    do_bind(task, name)
end

#cleanupObject

Removes dangling references from the name service

This method removes objects that are not accessible anymore from the name service


677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/orocos/name_service.rb', line 677

def cleanup
    names = names().dup
    names.each do |n|
        begin
            CORBA.info "trying task context #{n}"
            get(n)
        rescue Orocos::NotFound => e
            deregister(n)
            CORBA.warn "deregistered dangling CORBA name #{n}: #{e.message}"
        end
    end
end

#deregister(name) ⇒ Object

Deregisters the given name or task from the name service.


654
655
656
657
658
659
660
661
662
663
664
# File 'lib/orocos/name_service.rb', line 654

def deregister(name)
    name = if name.respond_to? :name
               name.name
           else
               name
           end
    verify_same_namespace(name)
    CORBA.refine_exceptions("corba naming service #{ip}") do
        do_unbind(basename(name))
    end
end

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

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

Options Hash (options):

  • :name (String)

    Overwrites The real name of the task

  • :process (Orocos::Process)

    The process supporting the task

Raises:

See Also:


628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/orocos/name_service.rb', line 628

def get(name,options = Hash.new)
    options = Kernel.validate_options options,:name,:namespace,:process
    ns,_ = split_name(name)
    ns = if !ns || ns.empty?
             namespace
         else
             ns
         end
    options[:namespace] ||= ns
    Orocos::TaskContext.new(ior(name),options)
rescue ComError => e
    raise Orocos::NotFound, "task context #{name} is registered but cannot be reached."
end

#ior(name) ⇒ String

Gets the IOR for the given Orocos Task having the given name.

Raises:


612
613
614
615
616
617
# File 'lib/orocos/name_service.rb', line 612

def ior(name)
    verify_same_namespace(name)
    CORBA.refine_exceptions("corba naming service(#{ip})") do
        do_ior(basename(name))
    end
end

#ipString


579
580
581
# File 'lib/orocos/name_service.rb', line 579

def ip
    do_ip
end

#ip=(host) ⇒ Object

Sets the ip address or host name where the CORBA name service is running


574
575
576
# File 'lib/orocos/name_service.rb', line 574

def ip=(host)
    reset(host)
end

#nameObject

return [String] the name of the name service


563
564
565
# File 'lib/orocos/name_service.rb', line 563

def name
    "CORBA:#{namespace}"
end

#namesArray<String>

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


620
621
622
623
624
625
# File 'lib/orocos/name_service.rb', line 620

def names
    result = CORBA.refine_exceptions("corba naming service(#{ip})") do
        do_task_context_names.find_all { |n| n !~ /^orocosrb_(\d+)$/ }
    end
    map_to_namespace(result)
end

#namespaceObject


567
568
569
# File 'lib/orocos/name_service.rb', line 567

def namespace
    ip
end

#portString


584
585
586
# File 'lib/orocos/name_service.rb', line 584

def port
    do_port
end

#register(task, name = task.name) ⇒ Object

Registers the IOR of the given TaskContext on the CORBA name service.


646
647
648
649
# File 'lib/orocos/name_service.rb', line 646

def register(task,name=task.name)
    verify_same_namespace(name)
    do_bind(task,basename(name))
end

#reset(ip = ip(), port = port()) ⇒ Object

Resets the CORBA name service client.


607
608
609
# File 'lib/orocos/name_service.rb', line 607

def reset(ip=ip(),port=port())
    do_reset(ip,port)
end

#to_async(options = Hash.new) ⇒ Orocos::Async::CORBA::NameService

The async-access object for this name service


599
600
601
# File 'lib/orocos/name_service.rb', line 599

def to_async(options = Hash.new)
    Orocos::Async::CORBA::NameService.new(ip,port,options)
end

#validatenil

Checks if the name service is reachable if not it raises a ComError.

Raises:


667
668
669
670
671
# File 'lib/orocos/name_service.rb', line 667

def validate
    CORBA.refine_exceptions("corba naming service #{ip}") do
        do_validate
    end
end