Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client/service QoS getters #941

Merged
merged 6 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions rcl/include/rcl/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,32 @@ RCL_PUBLIC
bool
rcl_client_is_valid(const rcl_client_t * client);

/// 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 @@ -440,6 +440,32 @@ RCL_PUBLIC
bool
rcl_service_is_valid(const rcl_service_t * service);

/// 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"
struct rcl_client_impl_s
{
rcl_client_options_t options;
rmw_qos_profile_t actual_qos;
rmw_client_t * rmw_handle;
atomic_int_least64_t sequence_number;
};
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(
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -280,6 +289,15 @@ rcl_client_is_valid(const rcl_client_t * client)
client->impl->rmw_handle, "client's rmw handle is invalid", return false);
return true;
}

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"
struct rcl_service_impl_s
{
rcl_service_options_t options;
rmw_qos_profile_t actual_qos;
rmw_service_t * rmw_handle;
};

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(
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -301,6 +310,15 @@ rcl_service_is_valid(const rcl_service_t * service)
return true;
}

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
}
#endif