Update graph API return codes. (#243)

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 <michel@ekumenlabs.com>
This commit is contained in:
Michel Hidalgo 2020-09-22 16:54:32 -03:00 committed by Alejandro Hernández Cordero
parent c65c015682
commit 914037bd29

View file

@ -4060,12 +4060,17 @@ extern "C" rmw_ret_t rmw_get_node_names(
rcutils_string_array_t * node_names, rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces) rcutils_string_array_t * node_namespaces)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names) || node,
RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) node->implementation_identifier,
{ eclipse_cyclonedds_identifier,
return RMW_RET_ERROR; 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; auto common_context = &node->context->impl->common;
@ -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 * node_namespaces,
rcutils_string_array_t * enclaves) rcutils_string_array_t * enclaves)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_names) || node,
RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) node->implementation_identifier,
{ eclipse_cyclonedds_identifier,
return RMW_RET_ERROR; 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; auto common_context = &node->context->impl->common;
@ -4105,12 +4118,16 @@ extern "C" rmw_ret_t rmw_get_topic_names_and_types(
rcutils_allocator_t * allocator, rcutils_allocator_t * allocator,
bool no_demangle, rmw_names_and_types_t * tptyp) bool no_demangle, rmw_names_and_types_t * tptyp)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
RET_NULL(allocator); node,
rmw_ret_t ret = rmw_names_and_types_check_zero(tptyp); node->implementation_identifier,
if (ret != RMW_RET_OK) { eclipse_cyclonedds_identifier,
return ret; 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; DemangleFunction demangle_topic = _demangle_ros_topic_from_topic;
@ -4132,6 +4149,18 @@ extern "C" rmw_ret_t rmw_get_service_names_and_types(
rcutils_allocator_t * allocator, rcutils_allocator_t * allocator,
rmw_names_and_types_t * sntyp) 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; auto common_context = &node->context->impl->common;
return common_context->graph_cache.get_names_and_types( return common_context->graph_cache.get_names_and_types(
_demangle_service_from_topic, _demangle_service_from_topic,
@ -4242,6 +4271,25 @@ extern "C" rmw_ret_t rmw_count_publishers(
const rmw_node_t * node, const char * topic_name, const rmw_node_t * node, const char * topic_name,
size_t * count) 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; auto common_context = &node->context->impl->common;
const std::string mangled_topic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", false); 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); return common_context->graph_cache.get_writer_count(mangled_topic_name, count);
@ -4251,6 +4299,25 @@ extern "C" rmw_ret_t rmw_count_subscribers(
const rmw_node_t * node, const char * topic_name, const rmw_node_t * node, const char * topic_name,
size_t * count) 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; auto common_context = &node->context->impl->common;
const std::string mangled_topic_name = make_fqtopic(ROS_TOPIC_PREFIX, topic_name, "", false); 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); return common_context->graph_cache.get_reader_count(mangled_topic_name, count);
@ -4276,12 +4343,39 @@ static rmw_ret_t get_topic_names_and_types_by_node(
GetNamesAndTypesByNodeFunction get_names_and_types_by_node, GetNamesAndTypesByNodeFunction get_names_and_types_by_node,
rmw_names_and_types_t * topic_names_and_types) rmw_names_and_types_t * topic_names_and_types)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
RET_NULL(allocator); node,
RET_NULL(node_name); node->implementation_identifier,
RET_NULL(node_namespace); eclipse_cyclonedds_identifier,
RET_NULL(topic_names_and_types); 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; auto common_context = &node->context->impl->common;
if (no_demangle) { if (no_demangle) {
demangle_topic = _identity_demangle; demangle_topic = _identity_demangle;
@ -4406,11 +4500,19 @@ extern "C" rmw_ret_t rmw_get_publishers_info_by_topic(
bool no_mangle, bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info) rmw_topic_endpoint_info_array_t * publishers_info)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
RET_NULL(allocator); node,
RET_NULL(topic_name); node->implementation_identifier,
RET_NULL(publishers_info); 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; auto common_context = &node->context->impl->common;
std::string mangled_topic_name = topic_name; std::string mangled_topic_name = topic_name;
DemangleFunction demangle_type = _identity_demangle; DemangleFunction demangle_type = _identity_demangle;
@ -4432,11 +4534,19 @@ extern "C" rmw_ret_t rmw_get_subscriptions_info_by_topic(
bool no_mangle, bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info) rmw_topic_endpoint_info_array_t * subscriptions_info)
{ {
RET_NULL(node); RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RET_WRONG_IMPLID(node); RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
RET_NULL(allocator); node,
RET_NULL(topic_name); node->implementation_identifier,
RET_NULL(subscriptions_info); 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; auto common_context = &node->context->impl->common;
std::string mangled_topic_name = topic_name; std::string mangled_topic_name = topic_name;
DemangleFunction demangle_type = _identity_demangle; DemangleFunction demangle_type = _identity_demangle;