Class: ROS::ServiceServer
Overview
server of ROS Service. Node#advertise_service return a instance of this class. Service can be shutdown by #shutdown. This class uses TCPROS::ServiceServer for data transfer.
Instance Attribute Summary collapse
-
#num_request ⇒ Integer
readonly
How many times this service called.
Attributes inherited from Service
#caller_id, #service_name, #service_type
Instance Method Summary collapse
-
#call(request, response) ⇒ Boolean
execute the service callback.
-
#close ⇒ Object
user should not call this method.
-
#get_connection_data ⇒ Array
Connection data.
-
#initialize(caller_id, service_name, service_type, callback) ⇒ ServiceServer
constructor
A new instance of ServiceServer.
-
#service_uri ⇒ String
URI of this service (rosrpc://**).
-
#set_manager(manager) ⇒ Object
set GraphManager for shutdown.
-
#shutdown ⇒ Object
shutdown the service connection.
Constructor Details
#initialize(caller_id, service_name, service_type, callback) ⇒ ServiceServer
Returns a new instance of ServiceServer.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ros/service_server.rb', line 36 def initialize(caller_id, service_name, service_type, callback) super(caller_id, service_name, service_type) @callback = callback @server = TCPROS::ServiceServer.new(@caller_id, @service_name, @service_type, self) @server.start @num_request = 0 end |
Instance Attribute Details
#num_request ⇒ Integer (readonly)
Returns how many times this service called.
90 91 92 |
# File 'lib/ros/service_server.rb', line 90 def num_request @num_request end |
Instance Method Details
#call(request, response) ⇒ Boolean
execute the service callback. User should not call this directly.
53 54 55 56 |
# File 'lib/ros/service_server.rb', line 53 def call(request, response) @num_request += 1 @callback.call(request, response) end |
#close ⇒ Object
user should not call this method. Please use shutdown method.
67 68 69 |
# File 'lib/ros/service_server.rb', line 67 def close #:nodoc: @server.shutdown end |
#get_connection_data ⇒ Array
Returns connection data.
85 86 87 |
# File 'lib/ros/service_server.rb', line 85 def get_connection_data [@num_request, @server.byte_received, @server.byte_sent] end |
#service_uri ⇒ String
URI of this service (rosrpc://**)
60 61 62 |
# File 'lib/ros/service_server.rb', line 60 def service_uri 'rosrpc://' + @server.host + ':' + @server.port.to_s end |
#set_manager(manager) ⇒ Object
set GraphManager for shutdown
80 81 82 |
# File 'lib/ros/service_server.rb', line 80 def set_manager(manager) #:nodoc: @manager = manager end |
#shutdown ⇒ Object
shutdown the service connection
74 75 76 |
# File 'lib/ros/service_server.rb', line 74 def shutdown @manager.shutdow_service_server(self) end |