File tree 3 files changed +26
-6
lines changed
examples/minimal_client_service/src
3 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ use std::env;
3
3
use anyhow:: { Error , Result } ;
4
4
5
5
fn handle_service (
6
- _request_header : & rclrs:: rmw_request_id_t ,
7
6
request : example_interfaces:: srv:: AddTwoInts_Request ,
8
7
) -> example_interfaces:: srv:: AddTwoInts_Response {
9
8
println ! ( "request: {} + {}" , request. a, request. b) ;
@@ -17,8 +16,8 @@ fn main() -> Result<(), Error> {
17
16
18
17
let node = rclrs:: create_node ( & context, "minimal_service" ) ?;
19
18
20
- let _server = node
21
- . create_service :: < example_interfaces:: srv:: AddTwoInts > ( "add_two_ints" , handle_service) ?;
19
+ let _server =
20
+ node . create_service :: < example_interfaces:: srv:: AddTwoInts > ( "add_two_ints" , handle_service) ?;
22
21
23
22
println ! ( "Starting server" ) ;
24
23
rclrs:: spin ( node) . map_err ( |err| err. into ( ) )
Original file line number Diff line number Diff line change @@ -264,6 +264,25 @@ impl Node {
264
264
/// [1]: crate::Service
265
265
// TODO: make service's lifetime depend on node's lifetime
266
266
pub fn create_service < T > (
267
+ & self ,
268
+ topic : & str ,
269
+ mut callback : impl FnMut ( T :: Request ) -> T :: Response + ' static + Send ,
270
+ ) -> Result < Arc < Service < T > > , RclrsError >
271
+ where
272
+ T : rosidl_runtime_rs:: Service ,
273
+ {
274
+ let callback =
275
+ move |_request_header : & rmw_request_id_t , request : T :: Request | callback ( request) ;
276
+ self . create_service_with_header ( topic, callback)
277
+ }
278
+
279
+ /// Creates a [`Service`][1]. Same as [`create_service`][2] but the callback
280
+ /// also has access to the ID of the service request.
281
+ ///
282
+ /// [1]: crate::Service
283
+ /// [2]: Self::create_service
284
+ // TODO: make service's lifetime depend on node's lifetime
285
+ pub fn create_service_with_header < T > (
267
286
& self ,
268
287
topic : & str ,
269
288
callback : impl FnMut ( & rmw_request_id_t , T :: Request ) -> T :: Response + ' static + Send ,
Original file line number Diff line number Diff line change @@ -51,11 +51,13 @@ type ServiceCallback<Request, Response> =
51
51
52
52
/// Main class responsible for responding to requests sent by ROS clients.
53
53
///
54
- /// The only available way to instantiate services is via [`Node::create_service()`][1], this is to
55
- /// ensure that [`Node`][2]s can track all the services that have been created.
54
+ /// The only available way to instantiate services is via [`Node::create_service()`][1] and
55
+ /// [`Node::create_service_with_header()`][2], this is to
56
+ /// ensure that [`Node`][3]s can track all the services that have been created.
56
57
///
57
58
/// [1]: crate::Node::create_service
58
- /// [2]: crate::Node
59
+ /// [2]: crate::Node::create_service_with_header
60
+ /// [3]: crate::Node
59
61
pub struct Service < T >
60
62
where
61
63
T : rosidl_runtime_rs:: Service ,
You can’t perform that action at this time.
0 commit comments