Class: URI::Orocos
- Inherits:
-
Generic
- Object
- Generic
- URI::Orocos
- Defined in:
- lib/orocos/uri.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#port_name ⇒ Object
readonly
Returns the value of attribute port_name.
-
#task_name ⇒ Object
readonly
Returns the value of attribute task_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser = DEFAULT_PARSER, arg_check = false) ⇒ Orocos
constructor
A new instance of Orocos.
- #port_proxy ⇒ Object
- #port_proxy? ⇒ Boolean
- #task_proxy ⇒ Object
- #task_proxy? ⇒ Boolean
Constructor Details
#initialize(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser = DEFAULT_PARSER, arg_check = false) ⇒ Orocos
Returns a new instance of Orocos
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/orocos/uri.rb', line 35 def initialize(scheme, userinfo, host, port, registry, path, opaque, query, fragment, parser = DEFAULT_PARSER, arg_check = false) super @hash = Orocos::from_query(query) if klass_match = Regexp.new("/(port)/(.+)").match(path) klass = klass_match [1] case klass when "port" if port_match = klass_match[2].match(/(.*)\.(\w+)$/) @task_name, @port_name = port_match[1], port_match[2] else raise ArgumentError, "expected task_name.port_name as path, but got #{klass_match[2]}" end end else raise ArgumentError, "#{uri} is not a valid path in an orocos URI" end end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash
33 34 35 |
# File 'lib/orocos/uri.rb', line 33 def hash @hash end |
#port_name ⇒ Object (readonly)
Returns the value of attribute port_name
33 34 35 |
# File 'lib/orocos/uri.rb', line 33 def port_name @port_name end |
#task_name ⇒ Object (readonly)
Returns the value of attribute task_name
33 34 35 |
# File 'lib/orocos/uri.rb', line 33 def task_name @task_name end |
Class Method Details
.from_port(port) ⇒ Object
5 6 7 8 |
# File 'lib/orocos/uri.rb', line 5 def from_port(port) hash = {:type_name => port.orocos_type_name} Orocos.new("OROCOS",nil,nil,nil,nil,"/port/#{port.full_name}",nil,to_query(hash),nil) end |
.from_query(str) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/orocos/uri.rb', line 19 def from_query(str) uri = str hash = Hash.new a = str.split("&") a << str if a.empty? a.each do |val| val =~ /(.*)=(.*)/ raise InvalidURIError,uri if !$1 || !$2 hash[$1.to_sym] = DEFAULT_PARSER.unescape $2 end hash end |
.to_query(hash) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/orocos/uri.rb', line 10 def to_query(hash) str = "" hash.each_pair do |key,value| value = DEFAULT_PARSER.escape(value) str += "#{key}=#{value}&" end str[0,str.size-1] end |
Instance Method Details
#port_proxy ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/orocos/uri.rb', line 68 def port_proxy raise ArgumentError,"URI does not point to a Port" unless port_proxy? type = if @hash.has_key? :type_name name = @hash[:type_name] begin ::Orocos.load_typekit_for name ::Orocos.registry.get name rescue Exception => e Vizkit.warn e nil end end task_proxy.port(port_name,:type => type) end |
#port_proxy? ⇒ Boolean
55 56 57 |
# File 'lib/orocos/uri.rb', line 55 def port_proxy? !!port_name end |
#task_proxy ⇒ Object
63 64 65 66 |
# File 'lib/orocos/uri.rb', line 63 def task_proxy raise ArgumentError,"URI does not point to a TaskContext" unless task_proxy? ::Orocos::Async.name_service.proxy(task_name) end |
#task_proxy? ⇒ Boolean
59 60 61 |
# File 'lib/orocos/uri.rb', line 59 def task_proxy? !!task_name end |