@@ -16,7 +16,7 @@ pub use self::{builder::*, graph::*, primitive_options::*};
16
16
use crate :: {
17
17
rcl_bindings:: * , Client , ClientBase , Clock , Context , ContextHandle , GuardCondition ,
18
18
ParameterBuilder , ParameterInterface , ParameterVariant , Parameters , Publisher , PublisherOptions ,
19
- RclrsError , Service , ServiceBase , Subscription , SubscriptionBase , SubscriptionCallback ,
19
+ RclrsError , Service , ServiceBase , ServiceOptions , Subscription , SubscriptionBase , SubscriptionCallback ,
20
20
SubscriptionOptions , TimeSource , ENTITY_LIFECYCLE_MUTEX ,
21
21
} ;
22
22
@@ -297,11 +297,49 @@ impl Node {
297
297
298
298
/// Creates a [`Service`][1].
299
299
///
300
+ /// Pass in only the service name for the `options` argument to use all default service options:
301
+ /// ```
302
+ /// # use rclrs::*;
303
+ /// # let context = Context::new([]).unwrap();
304
+ /// # let node = create_node(&context, "my_node").unwrap();
305
+ /// let service = node.create_service::<test_msgs::srv::Empty, _>(
306
+ /// "my_service",
307
+ /// |_info, _request| {
308
+ /// println!("Received request!");
309
+ /// test_msgs::srv::Empty_Response::default()
310
+ /// },
311
+ /// );
312
+ /// ```
313
+ ///
314
+ /// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
315
+ /// service options:
316
+ ///
317
+ /// ```
318
+ /// # use rclrs::*;
319
+ /// # let context = Context::new([]).unwrap();
320
+ /// # let node = create_node(&context, "my_node").unwrap();
321
+ /// let service = node.create_service::<test_msgs::srv::Empty, _>(
322
+ /// "my_service"
323
+ /// .keep_all()
324
+ /// .transient_local(),
325
+ /// |_info, _request| {
326
+ /// println!("Received request!");
327
+ /// test_msgs::srv::Empty_Response::default()
328
+ /// },
329
+ /// );
330
+ /// ```
331
+ ///
332
+ /// Any quality of service options that you explicitly specify will override
333
+ /// the default service options. Any that you do not explicitly specify will
334
+ /// remain the default service options. Note that services are generally
335
+ /// expected to use [reliable][2], so is best not to change the reliability
336
+ /// setting unless you know what you are doing.
337
+ ///
300
338
/// [1]: crate::Service
301
- // TODO: make service's lifetime depend on node's lifetime
302
- pub fn create_service < T , F > (
339
+ /// [2]: crate::QoSReliabilityPolicy::Reliable
340
+ pub fn create_service < ' a , T , F > (
303
341
& self ,
304
- topic : & str ,
342
+ options : impl Into < ServiceOptions < ' a > > ,
305
343
callback : F ,
306
344
) -> Result < Arc < Service < T > > , RclrsError >
307
345
where
@@ -310,7 +348,7 @@ impl Node {
310
348
{
311
349
let service = Arc :: new ( Service :: < T > :: new (
312
350
Arc :: clone ( & self . handle ) ,
313
- topic ,
351
+ options ,
314
352
callback,
315
353
) ?) ;
316
354
{ self . services_mtx . lock ( ) . unwrap ( ) }
@@ -327,22 +365,22 @@ impl Node {
327
365
/// # let context = Context::new([]).unwrap();
328
366
/// # let node = create_node(&context, "my_node").unwrap();
329
367
/// let subscription = node.create_subscription(
330
- /// "my_subscription ",
368
+ /// "my_topic ",
331
369
/// |_msg: test_msgs::msg::Empty| {
332
370
/// println!("Received message!");
333
371
/// },
334
372
/// );
335
373
/// ```
336
374
///
337
- /// Take advantage of [`IntoPrimitiveOptions`] to easily build up the
375
+ /// Take advantage of the [`IntoPrimitiveOptions`] API to easily build up the
338
376
/// subscription options:
339
377
///
340
378
/// ```
341
379
/// # use rclrs::*;
342
380
/// # let context = Context::new([]).unwrap();
343
381
/// # let node = create_node(&context, "my_node").unwrap();
344
382
/// let subscription = node.create_subscription(
345
- /// "my_subscription "
383
+ /// "my_topic "
346
384
/// .keep_last(100)
347
385
/// .transient_local(),
348
386
/// |_msg: test_msgs::msg::Empty| {
@@ -351,7 +389,7 @@ impl Node {
351
389
/// );
352
390
///
353
391
/// let reliable_subscription = node.create_subscription(
354
- /// "my_reliable_subscription "
392
+ /// "my_reliable_topic "
355
393
/// .reliable(),
356
394
/// |_msg: test_msgs::msg::Empty| {
357
395
/// println!("Received message!");
0 commit comments