Skip to content

Commit

Permalink
Update graph API return codes. (#243)
Browse files Browse the repository at this point in the history
This patch affects:
- rmw_get_node_names()
- rmw_get_node_names_with_enclaves()
- rmw_get_topic_names_and_types()
- rmw_get_service_names_and_types()
- rmw_get_publishers_info_by_topic()
- rmw_get_subscriptions_info_by_topic()
- rmw_get_subscriber_names_and_types_by_node()
- rmw_get_publisher_names_and_types_by_node()
- rmw_get_service_names_and_types_by_node()
- rmw_get_client_names_and_types_by_node()
- rmw_count_publishers()
- rmw_count_subscribers()

Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic authored and ahcorde committed Oct 8, 2020
1 parent 4f843e1 commit fba2730
Showing 1 changed file with 144 additions and 34 deletions.
178 changes: 144 additions & 34 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4060,12 +4060,17 @@ extern "C" rmw_ret_t rmw_get_node_names(
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names) ||
RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces))
{
return RMW_RET_ERROR;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names)) {
return RMW_RET_INVALID_ARGUMENT;
}
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = &node->context->impl->common;
Expand All @@ -4083,12 +4088,20 @@ extern "C" rmw_ret_t rmw_get_node_names_with_enclaves(
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * enclaves)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names) ||
RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces))
{
return RMW_RET_ERROR;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names)) {
return RMW_RET_INVALID_ARGUMENT;
}
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) {
return RMW_RET_INVALID_ARGUMENT;
}
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(enclaves)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = &node->context->impl->common;
Expand All @@ -4105,12 +4118,16 @@ extern "C" rmw_ret_t rmw_get_topic_names_and_types(
rcutils_allocator_t * allocator,
bool no_demangle, rmw_names_and_types_t * tptyp)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(allocator);
rmw_ret_t ret = rmw_names_and_types_check_zero(tptyp);
if (ret != RMW_RET_OK) {
return ret;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "allocator argument is invalid", return RMW_RET_INVALID_ARGUMENT);
if (RMW_RET_OK != rmw_names_and_types_check_zero(tptyp)) {
return RMW_RET_INVALID_ARGUMENT;
}

DemangleFunction demangle_topic = _demangle_ros_topic_from_topic;
Expand All @@ -4132,6 +4149,18 @@ extern "C" rmw_ret_t rmw_get_service_names_and_types(
rcutils_allocator_t * allocator,
rmw_names_and_types_t * sntyp)
{
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "allocator argument is invalid", return RMW_RET_INVALID_ARGUMENT);
if (RMW_RET_OK != rmw_names_and_types_check_zero(sntyp)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = &node->context->impl->common;
return common_context->graph_cache.get_names_and_types(
_demangle_service_from_topic,
Expand Down Expand Up @@ -4242,6 +4271,25 @@ extern "C" rmw_ret_t rmw_count_publishers(
const rmw_node_t * node, const char * topic_name,
size_t * count)
{
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_name, RMW_RET_INVALID_ARGUMENT);
int validation_result = RMW_TOPIC_VALID;
rmw_ret_t ret = rmw_validate_full_topic_name(topic_name, &validation_result, nullptr);
if (RMW_RET_OK != ret) {
return ret;
}
if (RMW_TOPIC_VALID != validation_result) {
const char * reason = rmw_full_topic_name_validation_result_string(validation_result);
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("topic_name argument is invalid: %s", reason);
return RMW_RET_INVALID_ARGUMENT;
}
RMW_CHECK_ARGUMENT_FOR_NULL(count, RMW_RET_INVALID_ARGUMENT);

auto common_context = &node->context->impl->common;
const std::string mangled_topic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", false);
return common_context->graph_cache.get_writer_count(mangled_topic_name, count);
Expand All @@ -4251,6 +4299,25 @@ extern "C" rmw_ret_t rmw_count_subscribers(
const rmw_node_t * node, const char * topic_name,
size_t * count)
{
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_name, RMW_RET_INVALID_ARGUMENT);
int validation_result = RMW_TOPIC_VALID;
rmw_ret_t ret = rmw_validate_full_topic_name(topic_name, &validation_result, nullptr);
if (RMW_RET_OK != ret) {
return ret;
}
if (RMW_TOPIC_VALID != validation_result) {
const char * reason = rmw_full_topic_name_validation_result_string(validation_result);
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("topic_name argument is invalid: %s", reason);
return RMW_RET_INVALID_ARGUMENT;
}
RMW_CHECK_ARGUMENT_FOR_NULL(count, RMW_RET_INVALID_ARGUMENT);

auto common_context = &node->context->impl->common;
const std::string mangled_topic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", false);
return common_context->graph_cache.get_reader_count(mangled_topic_name, count);
Expand All @@ -4276,12 +4343,39 @@ static rmw_ret_t get_topic_names_and_types_by_node(
GetNamesAndTypesByNodeFunction get_names_and_types_by_node,
rmw_names_and_types_t * topic_names_and_types)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(allocator);
RET_NULL(node_name);
RET_NULL(node_namespace);
RET_NULL(topic_names_and_types);
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "allocator argument is invalid", return RMW_RET_INVALID_ARGUMENT);
int validation_result = RMW_NODE_NAME_VALID;
rmw_ret_t ret = rmw_validate_node_name(node_name, &validation_result, nullptr);
if (RMW_RET_OK != ret) {
return ret;
}
if (RMW_NODE_NAME_VALID != validation_result) {
const char * reason = rmw_node_name_validation_result_string(validation_result);
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("node_name argument is invalid: %s", reason);
return RMW_RET_INVALID_ARGUMENT;
}
validation_result = RMW_NAMESPACE_VALID;
ret = rmw_validate_namespace(node_namespace, &validation_result, nullptr);
if (RMW_RET_OK != ret) {
return ret;
}
if (RMW_NAMESPACE_VALID != validation_result) {
const char * reason = rmw_namespace_validation_result_string(validation_result);
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING("node_namespace argument is invalid: %s", reason);
return RMW_RET_INVALID_ARGUMENT;
}
ret = rmw_names_and_types_check_zero(topic_names_and_types);
if (RMW_RET_OK != ret) {
return ret;
}

auto common_context = &node->context->impl->common;
if (no_demangle) {
demangle_topic = _identity_demangle;
Expand Down Expand Up @@ -4406,11 +4500,19 @@ extern "C" rmw_ret_t rmw_get_publishers_info_by_topic(
bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(allocator);
RET_NULL(topic_name);
RET_NULL(publishers_info);
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "allocator argument is invalid", return RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_name, RMW_RET_INVALID_ARGUMENT);
if (RMW_RET_OK != rmw_topic_endpoint_info_array_check_zero(publishers_info)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = &node->context->impl->common;
std::string mangled_topic_name = topic_name;
DemangleFunction demangle_type = _identity_demangle;
Expand All @@ -4432,11 +4534,19 @@ extern "C" rmw_ret_t rmw_get_subscriptions_info_by_topic(
bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(allocator);
RET_NULL(topic_name);
RET_NULL(subscriptions_info);
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
eclipse_cyclonedds_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
allocator, "allocator argument is invalid", return RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_ARGUMENT_FOR_NULL(topic_name, RMW_RET_INVALID_ARGUMENT);
if (RMW_RET_OK != rmw_topic_endpoint_info_array_check_zero(subscriptions_info)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = &node->context->impl->common;
std::string mangled_topic_name = topic_name;
DemangleFunction demangle_type = _identity_demangle;
Expand Down

0 comments on commit fba2730

Please sign in to comment.