Skip to content

Commit

Permalink
Add apis to retrieve service/client QoS
Browse files Browse the repository at this point in the history
Signed-off-by: Mauro Passerino <mpasserino@irobot.com>
  • Loading branch information
Mauro Passerino committed Sep 20, 2021
1 parent edfd0ac commit 42366bd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rcl/include/rcl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <hr>
* 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
Expand Down
26 changes: 26 additions & 0 deletions rcl/include/rcl/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <hr>
* 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
Expand Down
18 changes: 18 additions & 0 deletions rcl/src/rcl/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
18 changes: 18 additions & 0 deletions rcl/src/rcl/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 42366bd

Please sign in to comment.