class Orocos::Avahi::NameService
Name service to access Orocos Tasks which are publishing their IOR via Avahi
Public Class Methods
A new instance of NameService which is listening on the given search domain. The serach domain must have a ._tcp or ._udp at the end for a protocol type.
@param [String] searchdomain The search domain the name service is listening to (_myrobot._tcp / _myrobot._udp)
# File lib/orocos/name_service.rb, line 684 def initialize(searchdomain) raise ArgumentError,"no serachdomain is given" unless searchdomain @registered_tasks = Hash.new @searchdomain = searchdomain begin require 'servicediscovery' @avahi_nameserver = ::Avahi::ServiceDiscovery.new rescue LoadError raise LoadError, "NameService: 'distributed_nameserver' needs to be installed for Avahi nameservice support" end # Start listening on the given domains (this does refer to the _myservice._tcp service domain and not(!) the .local domain) begin @avahi_nameserver.listen_on(Array(@searchdomain)) rescue RuntimeError raise ArgumentError, "given search domain #{searchdomain} is invalid. Use '_myservice._tcp'." end end
Public Instance Methods
Deregisters the given name or task from the name service.
@param [String,TaskContext] task The name or task @note This only works for tasks which were registered by the same ruby instance.
# File lib/orocos/name_service.rb, line 735 def deregister(task) name = if task.respond_to? :name task.name else task end @registered_tasks.delete name end
(see Orocos::NameServiceBase#get)
# File lib/orocos/name_service.rb, line 760 def get(name,options = Hash.new) options = Kernel.validate_options options,:name,:namespace,:process ns,_ = Namespace.split_name(name) options[:namespace] ||= ns Orocos::TaskContext.new(ior(name),options) rescue Orocos::CORBA::ComError => e raise Orocos::NotFound, "task context #{name} is registered but cannot be reached." end
(see Orocos::NameServiceBase#ior)
# File lib/orocos/name_service.rb, line 745 def ior(name) services = @avahi_nameserver.find_services(name) if services.empty? raise Orocos::NotFound, "Avahi nameservice could not find a task named '#{name}'" elsif services.size > 1 warn "Avahi: '#{name}' found multiple times. Possibly due to publishing on IPv4 and IPv6, or on multiple interfaces -- picking first one in list" end ior = services.first.get_description("IOR") if !ior || ior.empty? raise Orocos::NotFound, "Avahi nameservice could not retrieve an ior for task #{name}" end ior end
(see Orocos::NameServiceBase#names)
# File lib/orocos/name_service.rb, line 706 def names @avahi_nameserver.get_all_services.uniq end
Registers the IOR of the given {Orocos::TaskContext} on the Avahi 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 718 def register(task,name=task.name) existing_service = @registered_tasks[name] service = existing_service || ::Avahi::ServiceDiscovery.new service.set_description("IOR",task.ior) if existing_service service.update else @registered_tasks[name] = service service.publish(name, @searchdomain) end service end
# File lib/orocos/name_service.rb, line 710 def same_namespace?(name) true end