Class: Orocos::NameServiceBase

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/name_service.rb,
ext/rorocos/corba.cc

Overview

Base class for all Orocos name services. An orocos name service is used to find local and remote Orocos Tasks based on their name and namespace.

Author:

  • Alexander Duda

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

return [String] the name of the name service


103
104
105
# File 'lib/orocos/name_service.rb', line 103

def name
  @name
end

Instance Method Details

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

Calls the given code block for all reachable TaskContext known by the name service.

Yields:

  • (TaskContext)

    code block which is called for each TaskContext


170
171
172
173
174
175
176
177
178
179
# File 'lib/orocos/name_service.rb', line 170

def each_task
    return enum_for(__method__) if !block_given?
    names.each do |name|
        task = begin
                   get(name)
               rescue Orocos::NotFound
               end
        yield(task) if task
    end
end

#find_one_running(*names) ⇒ Orocos::TaskContext

Find exactly one running tasks from the provided names.

Parameters:

  • names (String, Array<String>)

    the names

Returns:

Raises:

  • (RuntimeError)

    if none of the tasks are running, reachable or more than one of them is running.


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/orocos/name_service.rb', line 186

def find_one_running(*names)
    candidates = names.map do |name|
        begin get name
        rescue Orocos::NotFound
        end
    end.compact

    if candidates.empty?
        raise "cannot find any task in #{names.join(", ")}"
    end

    running_candidates = candidates.find_all(&:running?)
    if running_candidates.empty?
        raise "none of #{names.join(", ")} is running"
    elsif running_candidates.size > 1
        raise "multiple candidates are running: #{running_candidates.map(&:name)}"
    else
        running_candidates.first
    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:


98
99
100
# File 'lib/orocos/name_service.rb', line 98

def get(name,options=Hash.new)
    raise NotImplementedError
end

#get_provides(type) ⇒ Orocos::TaskContext

Returns an handle to the TaskContext which provides the type interface.

Parameters:

  • type (String)

    the type

Returns:

Raises:


153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/orocos/name_service.rb', line 153

def get_provides(type) # :nodoc:
    results = enum_for(:each_task).find_all do |task|
        task.implements?(type)
    end
    if results.empty?
        raise Orocos::NotFound, "no task implements #{type}"
    elsif results.size > 1
        candidates = results.map { |t| t.name }.join(", ")
        raise Orocos::NotFound, "more than one task implements #{type}: #{candidates}"
    end
    get(results.first.name)
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:


112
113
114
# File 'lib/orocos/name_service.rb', line 112

def ior(name)
    raise NotImplementedError
end

#namesArray<String>

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

Returns:

  • (Array<String>)

Raises:

  • (NotImplementedError)

120
121
122
# File 'lib/orocos/name_service.rb', line 120

def names
    raise NotImplementedError
end

#reachable?Boolean

Checks if the name service is reachable.

Returns:

  • (Boolean)

140
141
142
143
144
145
# File 'lib/orocos/name_service.rb', line 140

def reachable?
    validate
    true
rescue
    false
end

#same_namespace?(name) ⇒ Boolean

True if name is a valid name inside this service's namespace

Returns:

  • (Boolean)

125
126
127
# File 'lib/orocos/name_service.rb', line 125

def same_namespace?(name)
    true
end

#task_reachable?(name) ⇒ Boolean

Checks if a TaskContext with the given name is reachable.

Parameters:

  • name (String)

    the name if the TaskContext

Returns:

  • (Boolean)

80
81
82
83
84
85
# File 'lib/orocos/name_service.rb', line 80

def task_reachable?(name)
    get(name)
    true
rescue Orocos::NotFound
    false
end

#validatenil

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

Returns:

  • (nil)

Raises:


134
135
# File 'lib/orocos/name_service.rb', line 134

def validate
end