class Orocos::CORBA::NameService

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 {Orocos::CORBA.name_service} which is also by default added to {Orocos.name_service}

The default {Orocos::CORBA.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 Orocos.name_service @author Alexander Duda

Public Class Methods

new(host = "") click to toggle source
# File lib/orocos/name_service.rb, line 534
def initialize(host = "")
    self.ip = host
end

Public Instance Methods

bind(task, name) click to toggle source

Bind an existing task under an alternative name

@param [TaskContext] task the task context @param [String] name the name

# File lib/orocos/name_service.rb, line 568
def bind(task, name)
    do_bind(task, name)
end
cleanup() click to toggle source

Removes dangling references from the name service

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

# File lib/orocos/name_service.rb, line 656
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) click to toggle source

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 633
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 = nil, namespace: nil, process: nil, ior: nil) click to toggle source

(see Orocos::NameServiceBase#get)

# File lib/orocos/name_service.rb, line 604
def get(name = nil, namespace: nil, process: nil, ior: nil)
    if ior
        Orocos::TaskContext.new(ior, namespace: namespace, process: process)
    else
        ns,_ = split_name(name)
        ns = if !ns || ns.empty?
                 self.namespace
             else
                 ns
             end
        namespace ||= (ns || "")
        Orocos::TaskContext.new(ior(name), namespace: namespace, process: process)
    end
rescue ComError => e
    raise Orocos::NotFound, "task context #{name} is registered but cannot be reached."
end
ior(name) click to toggle source

(see Orocos::NameServiceBase#ior)

# File lib/orocos/name_service.rb, line 588
def ior(name)
    verify_same_namespace(name)
    CORBA.refine_exceptions("corba naming service(#{ip})") do
        do_ior(basename(name))
    end
end
ip() click to toggle source

@return [String] The ip where the client tries to reach the CORBA name service

# File lib/orocos/name_service.rb, line 555
def ip
    do_ip
end
ip=(host) click to toggle source

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

@param [String] host The ip address or host name

# File lib/orocos/name_service.rb, line 550
def ip=(host)
    reset(host)
end
name() click to toggle source

(see Orocos::NameServiceBase#name)

# File lib/orocos/name_service.rb, line 539
def name
    "CORBA:#{namespace}"
end
names() click to toggle source

(see Orocos::NameServiceBase#names)

# File lib/orocos/name_service.rb, line 596
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
namespace() click to toggle source
# File lib/orocos/name_service.rb, line 543
def namespace
    ip
end
port() click to toggle source

@return [String] The port where the client tries to reach the CORBA name service

# File lib/orocos/name_service.rb, line 560
def port
    do_port
end
register(task,name=task.name) click to toggle source

Registers the IOR of the given {Orocos::TaskContext} on the CORBA name service.

@param [Orocos::TaskContext] task The task. @param [String] name The name which is used to register the task.

# File lib/orocos/name_service.rb, line 625
def register(task,name=task.name)
    verify_same_namespace(name)
    do_bind(task,basename(name))
end
reset(ip=ip(),port=port()) click to toggle source

Resets the CORBA name service client.

@param [String] ip The ip address or host name where the CORBA name service is running @param [String] port The port of the CORBA name service

# File lib/orocos/name_service.rb, line 583
def reset(ip=ip(),port=port())
    do_reset(ip,port)
end
to_async(reconnect: true) click to toggle source

The async-access object for this name service @param (see Orocos::Async::CORBA::NameService#initialize) @return [Orocos::Async::CORBA::NameService]

# File lib/orocos/name_service.rb, line 575
def to_async(reconnect: true)
    Orocos::Async::CORBA::NameService.new(ip, reconnect: reconnect)
end
validate() click to toggle source

(see Orocos::NameServiceBase#validate)

# File lib/orocos/name_service.rb, line 646
def validate
    CORBA.refine_exceptions("corba naming service #{ip}") do
        do_validate
    end
end