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

Update graph API return codes. #436

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 32 additions & 10 deletions rmw_fastrtps_shared_cpp/src/rmw_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include "rcutils/logging_macros.h"

#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"
#include "rmw/validate_full_topic_name.h"

#include "rmw_dds_common/context.hpp"

Expand All @@ -41,14 +43,24 @@ __rmw_count_publishers(
const char * topic_name,
size_t * count)
{
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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 (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
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 = static_cast<rmw_dds_common::Context *>(node->context->impl->common);
const std::string mangled_topic_name =
_mangle_topic_name(ros_topic_prefix, topic_name).to_string();
Expand All @@ -62,14 +74,24 @@ __rmw_count_subscribers(
const char * topic_name,
size_t * count)
{
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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 (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
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 = static_cast<rmw_dds_common::Context *>(node->context->impl->common);
const std::string mangled_topic_name =
_mangle_topic_name(ros_topic_prefix, topic_name).to_string();
Expand Down
50 changes: 15 additions & 35 deletions rmw_fastrtps_shared_cpp/src/rmw_get_topic_endpoint_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <tuple>
#include <vector>

#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/types.h"
#include "rmw/topic_endpoint_info_array.h"
Expand All @@ -35,49 +36,28 @@
namespace rmw_fastrtps_shared_cpp
{

rmw_ret_t
_validate_params(
static rmw_ret_t __validate_arguments(
const char * identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * topic_name,
rmw_topic_endpoint_info_array_t * participants_info)
{
if (!identifier) {
RMW_SET_ERROR_MSG("null implementation identifier provided");
return RMW_RET_ERROR;
}

if (!topic_name) {
RMW_SET_ERROR_MSG("null topic_name provided");
return RMW_RET_ERROR;
}

if (!allocator) {
RMW_SET_ERROR_MSG("null allocator provided");
return RMW_RET_ERROR;
}

if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_ERROR;
}

// Get participant pointer from node
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}

if (!participants_info) {
RMW_SET_ERROR_MSG("null participants_info provided");
return RMW_RET_ERROR;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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(participants_info)) {
return RMW_RET_INVALID_ARGUMENT;
}

return RMW_RET_OK;
}


rmw_ret_t
__rmw_get_publishers_info_by_topic(
const char * identifier,
Expand All @@ -87,7 +67,7 @@ __rmw_get_publishers_info_by_topic(
bool no_mangle,
rmw_topic_endpoint_info_array_t * publishers_info)
{
rmw_ret_t ret = _validate_params(
rmw_ret_t ret = __validate_arguments(
identifier,
node,
allocator,
Expand Down Expand Up @@ -120,7 +100,7 @@ __rmw_get_subscriptions_info_by_topic(
bool no_mangle,
rmw_topic_endpoint_info_array_t * subscriptions_info)
{
rmw_ret_t ret = _validate_params(
rmw_ret_t ret = __validate_arguments(
identifier,
node,
allocator,
Expand Down
84 changes: 33 additions & 51 deletions rmw_fastrtps_shared_cpp/src/rmw_node_info_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/names_and_types.h"
#include "rmw/rmw.h"
#include "rmw/validate_namespace.h"
#include "rmw/validate_node_name.h"

#include "rmw_dds_common/context.hpp"

Expand All @@ -45,53 +47,6 @@
namespace rmw_fastrtps_shared_cpp
{

/**
* Validate the input data of node_info_and_types functions.
*
* \return RMW_RET_INVALID_ARGUMENT for null input args
* \return RMW_RET_ERROR if identifier is not the same as the input node
* \return RMW_RET_OK if all input is valid
*/
rmw_ret_t __validate_input(
const char * identifier,
const rmw_node_t * node,
rcutils_allocator_t * allocator,
const char * node_name,
const char * node_namespace,
rmw_names_and_types_t * topic_names_and_types)
{
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null");
return RMW_RET_INVALID_ARGUMENT;
}
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
}

if (!node_name) {
RMW_SET_ERROR_MSG("null node name");
return RMW_RET_INVALID_ARGUMENT;
}

if (!node_namespace) {
RMW_SET_ERROR_MSG("null node namespace");
return RMW_RET_INVALID_ARGUMENT;
}

rmw_ret_t ret = rmw_names_and_types_check_zero(topic_names_and_types);
if (ret != RMW_RET_OK) {
return ret;
}

// Get participant pointer from node
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}
return RMW_RET_OK;
}

using GetNamesAndTypesByNodeFunction = rmw_ret_t (*)(
rmw_dds_common::Context *,
const std::string &,
Expand All @@ -114,10 +69,37 @@ __rmw_get_topic_names_and_types_by_node(
GetNamesAndTypesByNodeFunction get_names_and_types_by_node,
rmw_names_and_types_t * topic_names_and_types)
{
rmw_ret_t valid_input = __validate_input(
identifier, node, allocator, node_name, node_namespace, topic_names_and_types);
if (valid_input != RMW_RET_OK) {
return valid_input;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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 = static_cast<rmw_dds_common::Context *>(node->context->impl->common);

Expand Down
49 changes: 23 additions & 26 deletions rmw_fastrtps_shared_cpp/src/rmw_node_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rmw/allocators.h"
#include "rmw/convert_rcutils_ret_to_rmw_ret.h"
#include "rmw/error_handling.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/rmw.h"
#include "rmw/sanity_checks.h"

Expand All @@ -44,19 +45,17 @@ __rmw_get_node_names(
rcutils_string_array_t * node_names,
rcutils_string_array_t * node_namespaces)
{
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_ERROR;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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_check_zero_rmw_string_array(node_names) != RMW_RET_OK) {
return RMW_RET_ERROR;
}
if (rmw_check_zero_rmw_string_array(node_namespaces) != RMW_RET_OK) {
return RMW_RET_ERROR;
}
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = static_cast<rmw_dds_common::Context *>(node->context->impl->common);
Expand All @@ -76,22 +75,20 @@ __rmw_get_node_names_with_enclaves(
rcutils_string_array_t * node_namespaces,
rcutils_string_array_t * enclaves)
{
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_ERROR;
}
if (rmw_check_zero_rmw_string_array(node_names) != RMW_RET_OK) {
return RMW_RET_ERROR;
}
if (rmw_check_zero_rmw_string_array(node_namespaces) != RMW_RET_OK) {
return RMW_RET_ERROR;
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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_check_zero_rmw_string_array(enclaves) != RMW_RET_OK) {
return RMW_RET_ERROR;
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(node_namespaces)) {
return RMW_RET_INVALID_ARGUMENT;
}
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
if (RMW_RET_OK != rmw_check_zero_rmw_string_array(enclaves)) {
return RMW_RET_INVALID_ARGUMENT;
}

auto common_context = static_cast<rmw_dds_common::Context *>(node->context->impl->common);
Expand Down
24 changes: 10 additions & 14 deletions rmw_fastrtps_shared_cpp/src/rmw_service_names_and_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "rmw/allocators.h"
#include "rmw/error_handling.h"
#include "rmw/get_service_names_and_types.h"
#include "rmw/impl/cpp/macros.hpp"
#include "rmw/names_and_types.h"
#include "rmw/types.h"

Expand All @@ -40,22 +41,17 @@ __rmw_get_service_names_and_types(
rcutils_allocator_t * allocator,
rmw_names_and_types_t * service_names_and_types)
{
if (!allocator) {
RMW_SET_ERROR_MSG("allocator is null");
RMW_CHECK_ARGUMENT_FOR_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_CHECK_TYPE_IDENTIFIERS_MATCH(
node,
node->implementation_identifier,
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(service_names_and_types)) {
return RMW_RET_INVALID_ARGUMENT;
}
if (!node) {
RMW_SET_ERROR_MSG("null node handle");
return RMW_RET_INVALID_ARGUMENT;
}
rmw_ret_t ret = rmw_names_and_types_check_zero(service_names_and_types);
if (ret != RMW_RET_OK) {
return ret;
}
if (node->implementation_identifier != identifier) {
RMW_SET_ERROR_MSG("node handle not from this implementation");
return RMW_RET_ERROR;
}

auto common_context = static_cast<rmw_dds_common::Context *>(node->context->impl->common);

Expand Down
Loading