diff --git a/rcl/include/rcl/client.h b/rcl/include/rcl/client.h index 978c479c97..abf19a2593 100644 --- a/rcl/include/rcl/client.h +++ b/rcl/include/rcl/client.h @@ -441,6 +441,32 @@ rcl_client_set_on_new_response_callback( rcl_event_callback_t callback, const void * user_data); +/// Get the actual qos settings of the client. +/** + * Used to get the actual qos settings of the client. + * The actual configuration applied when using RMW_*_SYSTEM_DEFAULT + * can only be resolved after the creation of the client, and it + * depends on the underlying rmw implementation. + * If the underlying setting in use can't be represented in ROS terms, + * it will be set to RMW_*_UNKNOWN. + * The returned struct is only valid as long as the rcl_client_t is valid. + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | No + * Thread-Safe | Yes + * Uses Atomics | No + * Lock-Free | Yes + * + * \param[in] client pointer to the rcl client + * \return qos struct if successful, otherwise `NULL` + */ +RCL_PUBLIC +RCL_WARN_UNUSED +const rmw_qos_profile_t * +rcl_client_get_actual_qos(const rcl_client_t * client); + #ifdef __cplusplus } #endif diff --git a/rcl/include/rcl/service.h b/rcl/include/rcl/service.h index e14f62d26e..9b5b1113d2 100644 --- a/rcl/include/rcl/service.h +++ b/rcl/include/rcl/service.h @@ -472,6 +472,32 @@ rcl_service_set_on_new_request_callback( rcl_event_callback_t callback, const void * user_data); +/// Get the actual qos settings of the service. +/** + * Used to get the actual qos settings of the service. + * The actual configuration applied when using RMW_*_SYSTEM_DEFAULT + * can only be resolved after the creation of the service, and it + * depends on the underlying rmw implementation. + * If the underlying setting in use can't be represented in ROS terms, + * it will be set to RMW_*_UNKNOWN. + * The returned struct is only valid as long as the rcl_service_t is valid. + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | No + * Thread-Safe | Yes + * Uses Atomics | No + * Lock-Free | Yes + * + * \param[in] service pointer to the rcl service + * \return qos struct if successful, otherwise `NULL` + */ +RCL_PUBLIC +RCL_WARN_UNUSED +const rmw_qos_profile_t * +rcl_service_get_actual_qos(const rcl_service_t * service); + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/client.c b/rcl/src/rcl/client.c index 7cf54b35d5..1561caf639 100644 --- a/rcl/src/rcl/client.c +++ b/rcl/src/rcl/client.c @@ -36,6 +36,7 @@ extern "C" typedef struct rcl_client_impl_t { rcl_client_options_t options; + rmw_qos_profile_t actual_qos; rmw_client_t * rmw_handle; atomic_int_least64_t sequence_number; } rcl_client_impl_t; @@ -111,6 +112,14 @@ rcl_client_init( RCL_SET_ERROR_MSG(rmw_get_error_string().str); goto fail; } + // get actual qos, and store it + rmw_ret_t rmw_ret = rmw_client_get_actual_qos( + client->impl->rmw_handle, + &client->impl->actual_qos); + if (RMW_RET_OK != rmw_ret) { + RCL_SET_ERROR_MSG(rmw_get_error_string().str); + goto fail; + } // options client->impl->options = *options; atomic_init(&client->impl->sequence_number, 0); @@ -298,6 +307,15 @@ rcl_client_set_on_new_response_callback( user_data); } +const rmw_qos_profile_t * +rcl_client_get_actual_qos(const rcl_client_t * client) +{ + if (!rcl_client_is_valid(client)) { + return NULL; + } + return &client->impl->actual_qos; +} + #ifdef __cplusplus } #endif diff --git a/rcl/src/rcl/service.c b/rcl/src/rcl/service.c index 926a4437ca..5d00238d65 100644 --- a/rcl/src/rcl/service.c +++ b/rcl/src/rcl/service.c @@ -33,6 +33,7 @@ extern "C" typedef struct rcl_service_impl_t { rcl_service_options_t options; + rmw_qos_profile_t actual_qos; rmw_service_t * rmw_handle; } rcl_service_impl_t; @@ -122,6 +123,14 @@ rcl_service_init( RCL_SET_ERROR_MSG(rmw_get_error_string().str); goto fail; } + // get actual qos, and store it + rmw_ret_t rmw_ret = rmw_service_get_actual_qos( + service->impl->rmw_handle, + &service->impl->actual_qos); + if (RMW_RET_OK != rmw_ret) { + RCL_SET_ERROR_MSG(rmw_get_error_string().str); + goto fail; + } // options service->impl->options = *options; RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Service initialized"); @@ -318,6 +327,15 @@ rcl_service_set_on_new_request_callback( user_data); } +const rmw_qos_profile_t * +rcl_service_get_actual_qos(const rcl_service_t * service) +{ + if (!rcl_service_is_valid(service)) { + return NULL; + } + return &service->impl->actual_qos; +} + #ifdef __cplusplus }