Skip to content

Commit 42366bd

Browse files
author
Mauro Passerino
committed
Add apis to retrieve service/client QoS
Signed-off-by: Mauro Passerino <mpasserino@irobot.com>
1 parent edfd0ac commit 42366bd

4 files changed

Lines changed: 88 additions & 0 deletions

File tree

rcl/include/rcl/client.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,32 @@ rcl_client_set_on_new_response_callback(
441441
rcl_event_callback_t callback,
442442
const void * user_data);
443443

444+
/// Get the actual qos settings of the client.
445+
/**
446+
* Used to get the actual qos settings of the client.
447+
* The actual configuration applied when using RMW_*_SYSTEM_DEFAULT
448+
* can only be resolved after the creation of the client, and it
449+
* depends on the underlying rmw implementation.
450+
* If the underlying setting in use can't be represented in ROS terms,
451+
* it will be set to RMW_*_UNKNOWN.
452+
* The returned struct is only valid as long as the rcl_client_t is valid.
453+
*
454+
* <hr>
455+
* Attribute | Adherence
456+
* ------------------ | -------------
457+
* Allocates Memory | No
458+
* Thread-Safe | Yes
459+
* Uses Atomics | No
460+
* Lock-Free | Yes
461+
*
462+
* \param[in] client pointer to the rcl client
463+
* \return qos struct if successful, otherwise `NULL`
464+
*/
465+
RCL_PUBLIC
466+
RCL_WARN_UNUSED
467+
const rmw_qos_profile_t *
468+
rcl_client_get_actual_qos(const rcl_client_t * client);
469+
444470
#ifdef __cplusplus
445471
}
446472
#endif

rcl/include/rcl/service.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,32 @@ rcl_service_set_on_new_request_callback(
472472
rcl_event_callback_t callback,
473473
const void * user_data);
474474

475+
/// Get the actual qos settings of the service.
476+
/**
477+
* Used to get the actual qos settings of the service.
478+
* The actual configuration applied when using RMW_*_SYSTEM_DEFAULT
479+
* can only be resolved after the creation of the service, and it
480+
* depends on the underlying rmw implementation.
481+
* If the underlying setting in use can't be represented in ROS terms,
482+
* it will be set to RMW_*_UNKNOWN.
483+
* The returned struct is only valid as long as the rcl_service_t is valid.
484+
*
485+
* <hr>
486+
* Attribute | Adherence
487+
* ------------------ | -------------
488+
* Allocates Memory | No
489+
* Thread-Safe | Yes
490+
* Uses Atomics | No
491+
* Lock-Free | Yes
492+
*
493+
* \param[in] service pointer to the rcl service
494+
* \return qos struct if successful, otherwise `NULL`
495+
*/
496+
RCL_PUBLIC
497+
RCL_WARN_UNUSED
498+
const rmw_qos_profile_t *
499+
rcl_service_get_actual_qos(const rcl_service_t * service);
500+
475501
#ifdef __cplusplus
476502
}
477503
#endif

rcl/src/rcl/client.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern "C"
3636
typedef struct rcl_client_impl_t
3737
{
3838
rcl_client_options_t options;
39+
rmw_qos_profile_t actual_qos;
3940
rmw_client_t * rmw_handle;
4041
atomic_int_least64_t sequence_number;
4142
} rcl_client_impl_t;
@@ -111,6 +112,14 @@ rcl_client_init(
111112
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
112113
goto fail;
113114
}
115+
// get actual qos, and store it
116+
rmw_ret_t rmw_ret = rmw_client_get_actual_qos(
117+
client->impl->rmw_handle,
118+
&client->impl->actual_qos);
119+
if (RMW_RET_OK != rmw_ret) {
120+
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
121+
goto fail;
122+
}
114123
// options
115124
client->impl->options = *options;
116125
atomic_init(&client->impl->sequence_number, 0);
@@ -298,6 +307,15 @@ rcl_client_set_on_new_response_callback(
298307
user_data);
299308
}
300309

310+
const rmw_qos_profile_t *
311+
rcl_client_get_actual_qos(const rcl_client_t * client)
312+
{
313+
if (!rcl_client_is_valid(client)) {
314+
return NULL;
315+
}
316+
return &client->impl->actual_qos;
317+
}
318+
301319
#ifdef __cplusplus
302320
}
303321
#endif

rcl/src/rcl/service.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C"
3333
typedef struct rcl_service_impl_t
3434
{
3535
rcl_service_options_t options;
36+
rmw_qos_profile_t actual_qos;
3637
rmw_service_t * rmw_handle;
3738
} rcl_service_impl_t;
3839

@@ -122,6 +123,14 @@ rcl_service_init(
122123
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
123124
goto fail;
124125
}
126+
// get actual qos, and store it
127+
rmw_ret_t rmw_ret = rmw_service_get_actual_qos(
128+
service->impl->rmw_handle,
129+
&service->impl->actual_qos);
130+
if (RMW_RET_OK != rmw_ret) {
131+
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
132+
goto fail;
133+
}
125134
// options
126135
service->impl->options = *options;
127136
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Service initialized");
@@ -318,6 +327,15 @@ rcl_service_set_on_new_request_callback(
318327
user_data);
319328
}
320329

330+
const rmw_qos_profile_t *
331+
rcl_service_get_actual_qos(const rcl_service_t * service)
332+
{
333+
if (!rcl_service_is_valid(service)) {
334+
return NULL;
335+
}
336+
return &service->impl->actual_qos;
337+
}
338+
321339

322340
#ifdef __cplusplus
323341
}

0 commit comments

Comments
 (0)