Class: Orocos::NameService

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

Overview

This name service abstracts all underlying name services. By default there is one global instance accessible via name_service which has by default one CORBA::NameService instance as underlying name service.

See Also:

Author:

  • Alexander Duda

Constant Summary

Constants included from Namespace

Orocos::Namespace::DELIMATOR

Instance Attribute Summary collapse

Attributes inherited from NameServiceBase

#name

Instance Method Summary collapse

Methods included from Namespace

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

Methods inherited from NameServiceBase

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

Constructor Details

#initialize(*name_services) ⇒ NameService

Returns a new instance of NameService

Parameters:


229
230
231
# File 'lib/orocos/name_service.rb', line 229

def initialize(*name_services)
    @name_services = name_services
end

Instance Attribute Details

#name_servicesArray

Returns The array with all underlying name services.

Returns:

  • (Array)

    The array with all underlying name services

Raises:

  • Orocos::NotFound if no name service was added


223
224
225
# File 'lib/orocos/name_service.rb', line 223

def name_services
  @name_services
end

Instance Method Details

#<<(name_service) ⇒ Object

Adds a name service.

Parameters:


256
257
258
# File 'lib/orocos/name_service.rb', line 256

def <<(name_service)
    add(name_service)
end

#add(name_service) ⇒ Object

Adds a name service.

Parameters:


269
270
271
272
# File 'lib/orocos/name_service.rb', line 269

def add(name_service)
    return if @name_services.include? name_service
    @name_services << name_service
end

#add_front(name_service) ⇒ Object

Adds a name service to the top of #name_services

Parameters:


263
264
265
266
# File 'lib/orocos/name_service.rb', line 263

def add_front(name_service)
    return if @name_services.include? name_service
    @name_services.insert(0,name_service)
end

#cleanupObject

Calls cleanup on all underlying name services which support cleanup


352
353
354
355
356
# File 'lib/orocos/name_service.rb', line 352

def cleanup
    name_services.each do |service|
        service.cleanup
    end
end

#clearObject

Removes all underlying name services


364
365
366
# File 'lib/orocos/name_service.rb', line 364

def clear
    @name_services.clear
end

#delete(service) ⇒ Object

remove the service from the list of services


359
360
361
# File 'lib/orocos/name_service.rb', line 359

def delete service
    @name_services.delete service
end

#each {|TaskContext| ... } ⇒ Object

Enumerates the name services registered on this global name service

Yields:


243
244
245
# File 'lib/orocos/name_service.rb', line 243

def each(&block)
    @name_services.each(&block)
end

#find(klass) ⇒ Object

Finds an underlying name service of the given class

Parameters:

  • klass (class)

    the class


289
290
291
292
293
# File 'lib/orocos/name_service.rb', line 289

def find(klass)
    @name_services.find do |service|
        true if service.is_a? klass
    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.

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:


311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/orocos/name_service.rb', line 311

def get(name,options = Hash.new)
    name_services.each do |service|
        begin
            if service.same_namespace?(name)
                task_context = service.get(name,options)
			return task_context if task_context
            end
        rescue Orocos::NotFound
        end
    end
    raise Orocos::NotFound, error_message(name)
end

#include?(klass) ⇒ Boolean

Checks if an underlying name service is of the given class

Parameters:

  • klass (class)

    the class

Returns:

  • (Boolean)

299
300
301
# File 'lib/orocos/name_service.rb', line 299

def include?(klass)
    !!find(klass)
end

#initialized?Boolean

Checks if there is at least one underlying name service

Returns:

  • (Boolean)

306
307
308
# File 'lib/orocos/name_service.rb', line 306

def initialized?
    !@name_services.empty?
end

#ior(name) ⇒ String

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

Parameters:

  • name (String)

    the name of the TaskContext

Returns:

  • (String)

Raises:


325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/orocos/name_service.rb', line 325

def ior(name)
    verify_same_namespace(name)
    name_services.each do |service|
        next if !service.respond_to?(:ior)
        begin
            if service.same_namespace?(name)
                return service.ior(name)
            end
        rescue Orocos::NotFound
        end
    end
    raise Orocos::NotFound, error_message(name)
end

#namesArray<String>

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

Returns:

  • (Array<String>)

340
341
342
343
344
345
346
347
348
349
# File 'lib/orocos/name_service.rb', line 340

def names
    names = name_services.collect do |service|
        begin
            service.names
        rescue Orocos::CORBAError,Orocos::CORBA::ComError
            []
        end
    end
    names.flatten.uniq
end

#remove(name_service) ⇒ true, false

Remove a name service from the set of resolvants

Parameters:

Returns:

  • (true, false)

    true if the name service was registered, false otherwise


279
280
281
282
283
284
# File 'lib/orocos/name_service.rb', line 279

def remove(name_service)
    if @name_services.include? name_service
        @name_services.delete name_service
        true
    end
end

#same_namespace?(name) ⇒ Boolean

Checks if the given name is in the same namespace.

Parameters:

  • name (String)

    the name which shall be checked

Returns:

  • (Boolean)

234
235
236
237
238
# File 'lib/orocos/name_service.rb', line 234

def same_namespace?(name)
    name_services.any? do |service|
        service.same_namespace?(name)
    end
end