Class: ROS::ServiceClient
Overview
This is an interface of ROS Service. Node#service returns ServiceClient instance.
Instance Attribute Summary
Attributes inherited from Service
#caller_id, #service_name, #service_type
Instance Method Summary collapse
-
#call(srv_request, srv_response) ⇒ Boolean
call service.
-
#get_host_port_from_uri(uri) ⇒ Array<String, Integer>
get hostname and port from uri.
-
#initialize(master_uri, caller_id, service_name, service_type, persistent = false) ⇒ ServiceClient
constructor
A new instance of ServiceClient.
-
#shutdown ⇒ Object
shutdown this service client.
Constructor Details
#initialize(master_uri, caller_id, service_name, service_type, persistent = false) ⇒ ServiceClient
Returns a new instance of ServiceClient.
36 37 38 39 40 |
# File 'lib/ros/service_client.rb', line 36 def initialize(master_uri, caller_id, service_name, service_type, persistent=false) super(caller_id, service_name, service_type) @master_uri = master_uri @persistent = persistent end |
Instance Method Details
#call(srv_request, srv_response) ⇒ Boolean
call service
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ros/service_client.rb', line 55 def call(srv_request, srv_response) if @persistent and @connection # not connect else master = XMLRPC::Client.new2(@master_uri) code, , uri = master.call('lookupService', @caller_id, @service_name) case code when 1 host, port = get_host_port_from_uri(uri) @connection = TCPROS::ServiceClient.new(host, port, @caller_id, @service_name, @service_type, @persistent) return @connection.call(srv_request, srv_response) when -1 raise "master error ${message}" else puts "fail to lookup" nil end end end |
#get_host_port_from_uri(uri) ⇒ Array<String, Integer>
get hostname and port from uri
46 47 48 49 |
# File 'lib/ros/service_client.rb', line 46 def get_host_port_from_uri(uri) #:nodoc: uri_data = URI.split(uri) [uri_data[2], uri_data[3]] end |
#shutdown ⇒ Object
shutdown this service client
78 79 80 |
# File 'lib/ros/service_client.rb', line 78 def shutdown @connection.close end |