30
30
31
31
#include < string>
32
32
#include " ros/common.h"
33
+ #include " ros/duration.h"
33
34
#include " ros/message.h"
34
35
#include " ros/forwards.h"
35
36
#include " ros/node_handle.h"
@@ -62,11 +63,11 @@ namespace service
62
63
* @return true on success, false otherwise.
63
64
*/
64
65
template <class MReq , class MRes >
65
- bool call (const std::string& service_name, MReq& req, MRes& res)
66
+ bool call (const std::string& service_name, MReq& req, MRes& res, const ros::Duration& timeout = ros::Duration(- 1.0 ) )
66
67
{
67
68
namespace st = service_traits;
68
69
NodeHandle nh;
69
- ServiceClientOptions ops (ros::names::resolve (service_name), st::md5sum (req), false , M_string ());
70
+ ServiceClientOptions ops (ros::names::resolve (service_name), st::md5sum (req), false , M_string (), timeout );
70
71
ServiceClient client = nh.serviceClient (ops);
71
72
return client.call (req, res);
72
73
}
@@ -82,12 +83,12 @@ bool call(const std::string& service_name, MReq& req, MRes& res)
82
83
* @return true on success, false otherwise.
83
84
*/
84
85
template <class Service >
85
- bool call (const std::string& service_name, Service& service)
86
+ bool call (const std::string& service_name, Service& service, const ros::Duration& timeout = ros::Duration(- 1.0 ) )
86
87
{
87
88
namespace st = service_traits;
88
89
89
90
NodeHandle nh;
90
- ServiceClientOptions ops (ros::names::resolve (service_name), st::md5sum (service), false , M_string ());
91
+ ServiceClientOptions ops (ros::names::resolve (service_name), st::md5sum (service), false , M_string (), timeout );
91
92
ServiceClient client = nh.serviceClient (ops);
92
93
return client.call (service.request , service.response );
93
94
}
@@ -131,10 +132,10 @@ ROSCPP_DECL bool exists(const std::string& service_name, bool print_failure_reas
131
132
* @param header_values Key/value pairs you'd like to send along in the connection handshake
132
133
*/
133
134
template <class MReq , class MRes >
134
- ServiceClient createClient (const std::string& service_name, bool persistent = false , const M_string& header_values = M_string())
135
+ ServiceClient createClient (const std::string& service_name, bool persistent = false , const M_string& header_values = M_string(), const ros::Duration& timeout = ros::Duration(- 1.0 ) )
135
136
{
136
137
NodeHandle nh;
137
- ServiceClient client = nh.template serviceClient <MReq, MRes>(ros::names::resolve (service_name), persistent, header_values);
138
+ ServiceClient client = nh.template serviceClient <MReq, MRes>(ros::names::resolve (service_name), persistent, header_values, timeout );
138
139
return client;
139
140
}
140
141
@@ -149,10 +150,10 @@ ServiceClient createClient(const std::string& service_name, bool persistent = fa
149
150
* @param header_values Key/value pairs you'd like to send along in the connection handshake
150
151
*/
151
152
template <class Service >
152
- ServiceClient createClient (const std::string& service_name, bool persistent = false , const M_string& header_values = M_string())
153
+ ServiceClient createClient (const std::string& service_name, bool persistent = false , const M_string& header_values = M_string(), const ros::Duration& timeout = ros::Duration(- 1.0 ) )
153
154
{
154
155
NodeHandle nh;
155
- ServiceClient client = nh.template serviceClient <Service>(ros::names::resolve (service_name), persistent, header_values);
156
+ ServiceClient client = nh.template serviceClient <Service>(ros::names::resolve (service_name), persistent, header_values, timeout );
156
157
return client;
157
158
}
158
159
0 commit comments