Class: Orocos::NameServiceBase
- Inherits:
-
Object
- Object
- Orocos::NameServiceBase
- 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.
Direct Known Subclasses
Avahi::NameService, CORBA::NameService, CORBANameService, Local::NameService, NameService, ROS::NameService
Instance Attribute Summary collapse
-
#name ⇒ Object
return [String] the name of the name service.
Instance Method Summary collapse
-
#each_task {|TaskContext| ... } ⇒ Object
Calls the given code block for all reachable TaskContext known by the name service.
-
#find_one_running(*names) ⇒ Orocos::TaskContext
Find exactly one running tasks from the provided names.
-
#get(name, options = Hash.new) ⇒ Orocos::TaskContext, Orocos::Log::TaskContext
Gets an handle to a local/remote Orocos Task having the given name.
-
#get_provides(type) ⇒ Orocos::TaskContext
Returns an handle to the TaskContext which provides the
type
interface. -
#ior(name) ⇒ String
Gets the IOR for the given Orocos Task having the given name.
-
#names ⇒ Array<String>
Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.
-
#reachable? ⇒ Boolean
Checks if the name service is reachable.
-
#same_namespace?(name) ⇒ Boolean
True if
name
is a valid name inside this service's namespace. -
#task_reachable?(name) ⇒ Boolean
Checks if a TaskContext with the given name is reachable.
-
#validate ⇒ nil
Checks if the name service is reachable if not it raises a ComError.
Instance Attribute Details
#name ⇒ Object
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.
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.
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 Orocos::NotFound, "cannot find any tasks matching #{names.join(", ")}" end running_candidates = candidates.find_all(&:running?) if running_candidates.empty? raise Orocos::NotFound, "none of #{names.join(", ")} are running" elsif running_candidates.size > 1 raise Orocos::NotFound, "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.
98 99 100 |
# File 'lib/orocos/name_service.rb', line 98 def get(name,=Hash.new) raise NotImplementedError end |
#get_provides(type) ⇒ Orocos::TaskContext
Returns an handle to the TaskContext which provides the type
interface.
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.
112 113 114 |
# File 'lib/orocos/name_service.rb', line 112 def ior(name) raise NotImplementedError end |
#names ⇒ Array<String>
Returns all Orocos Task names known by the name service inclusive the namespace of the NameService instance.
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.
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
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.
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 |
#validate ⇒ nil
Checks if the name service is reachable if not it raises a ComError.
134 135 |
# File 'lib/orocos/name_service.rb', line 134 def validate end |