Change RET_WRONG_IMPLID() to return RMW_RET_INCORRECT_IMPLEMENTATION (#226)

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
Michel Hidalgo 2020-08-25 13:22:18 -03:00 committed by Alejandro Hernández Cordero
parent aa4ee36aff
commit ba077ce061

View file

@ -102,7 +102,6 @@ using namespace std::literals::chrono_literals;
#define RET_ALLOC_X(var, code) do {if (!var) {RET_ERR_X("failed to allocate " #var, code);} \
} while (0)
#define RET_WRONG_IMPLID_X(var, code) do { \
RET_NULL_X(var, code); \
if ((var)->implementation_identifier != eclipse_cyclonedds_identifier) { \
RET_ERR_X(#var " not from this implementation", code); \
} \
@ -115,7 +114,7 @@ using namespace std::literals::chrono_literals;
#define RET_ERR(msg) RET_ERR_X(msg, return RMW_RET_ERROR)
#define RET_NULL(var) RET_NULL_X(var, return RMW_RET_ERROR)
#define RET_ALLOC(var) RET_ALLOC_X(var, return RMW_RET_ERROR)
#define RET_WRONG_IMPLID(var) RET_WRONG_IMPLID_X(var, return RMW_RET_ERROR)
#define RET_WRONG_IMPLID(var) RET_WRONG_IMPLID_X(var, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION)
#define RET_NULL_OR_EMPTYSTR(var) RET_NULL_OR_EMPTYSTR_X(var, return RMW_RET_ERROR)
using rmw_dds_common::msg::ParticipantEntitiesInfo;
@ -1354,6 +1353,7 @@ extern "C" rmw_ret_t rmw_destroy_node(rmw_node_t * node)
extern "C" const rmw_guard_condition_t * rmw_node_get_graph_guard_condition(const rmw_node_t * node)
{
RET_NULL_X(node, return nullptr);
RET_WRONG_IMPLID_X(node, return nullptr);
auto node_impl = static_cast<CddsNode *>(node->data);
RET_NULL_X(node_impl, return nullptr);
@ -1505,6 +1505,7 @@ extern "C" rmw_ret_t rmw_publish(
rmw_publisher_allocation_t * allocation)
{
static_cast<void>(allocation); // unused
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
RET_NULL(ros_message);
auto pub = static_cast<CddsPublisher *>(publisher->data);
@ -1522,6 +1523,7 @@ extern "C" rmw_ret_t rmw_publish_serialized_message(
const rmw_serialized_message_t * serialized_message, rmw_publisher_allocation_t * allocation)
{
static_cast<void>(allocation); // unused
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
RET_NULL(serialized_message);
auto pub = static_cast<CddsPublisher *>(publisher->data);
@ -2019,6 +2021,7 @@ extern "C" rmw_publisher_t * rmw_create_publisher(
extern "C" rmw_ret_t rmw_get_gid_for_publisher(const rmw_publisher_t * publisher, rmw_gid_t * gid)
{
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
RET_NULL(gid);
auto pub = static_cast<const CddsPublisher *>(publisher->data);
@ -2034,7 +2037,9 @@ extern "C" rmw_ret_t rmw_compare_gids_equal(
const rmw_gid_t * gid1, const rmw_gid_t * gid2,
bool * result)
{
RET_NULL(gid1);
RET_WRONG_IMPLID(gid1);
RET_NULL(gid2);
RET_WRONG_IMPLID(gid2);
RET_NULL(result);
/* alignment is potentially lost because of the translation to an array of bytes, so use
@ -2047,6 +2052,7 @@ extern "C" rmw_ret_t rmw_publisher_count_matched_subscriptions(
const rmw_publisher_t * publisher,
size_t * subscription_count)
{
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
auto pub = static_cast<CddsPublisher *>(publisher->data);
dds_publication_matched_status_t status;
@ -2060,6 +2066,7 @@ extern "C" rmw_ret_t rmw_publisher_count_matched_subscriptions(
rmw_ret_t rmw_publisher_assert_liveliness(const rmw_publisher_t * publisher)
{
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
auto pub = static_cast<CddsPublisher *>(publisher->data);
if (dds_assert_liveliness(pub->enth) < 0) {
@ -2378,6 +2385,7 @@ extern "C" rmw_subscription_t * rmw_create_subscription(
extern "C" rmw_ret_t rmw_subscription_count_matched_publishers(
const rmw_subscription_t * subscription, size_t * publisher_count)
{
RET_NULL(subscription);
RET_WRONG_IMPLID(subscription);
auto sub = static_cast<CddsSubscription *>(subscription->data);
dds_subscription_matched_status_t status;
@ -2485,6 +2493,7 @@ static rmw_ret_t rmw_take_int(
{
RET_NULL(taken);
RET_NULL(ros_message);
RET_NULL(subscription);
RET_WRONG_IMPLID(subscription);
CddsSubscription * sub = static_cast<CddsSubscription *>(subscription->data);
RET_NULL(sub);
@ -2527,6 +2536,7 @@ static rmw_ret_t rmw_take_seq(
RET_NULL(taken);
RET_NULL(message_sequence);
RET_NULL(message_info_sequence);
RET_NULL(subscription);
RET_WRONG_IMPLID(subscription);
if (count > message_sequence->capacity) {
@ -2606,6 +2616,7 @@ static rmw_ret_t rmw_take_ser_int(
{
RET_NULL(taken);
RET_NULL(serialized_message);
RET_NULL(subscription);
RET_WRONG_IMPLID(subscription);
CddsSubscription * sub = static_cast<CddsSubscription *>(subscription->data);
RET_NULL(sub);
@ -2773,7 +2784,8 @@ static rmw_ret_t init_rmw_event(
extern "C" rmw_ret_t rmw_publisher_event_init(
rmw_event_t * rmw_event, const rmw_publisher_t * publisher, rmw_event_type_t event_type)
{
RET_WRONG_IMPLID_X(publisher, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RET_NULL(publisher);
RET_WRONG_IMPLID(publisher);
return init_rmw_event(
rmw_event,
publisher->implementation_identifier,
@ -2784,7 +2796,8 @@ extern "C" rmw_ret_t rmw_publisher_event_init(
extern "C" rmw_ret_t rmw_subscription_event_init(
rmw_event_t * rmw_event, const rmw_subscription_t * subscription, rmw_event_type_t event_type)
{
RET_WRONG_IMPLID_X(subscription, return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RET_NULL(subscription);
RET_WRONG_IMPLID(subscription);
return init_rmw_event(
rmw_event,
subscription->implementation_identifier,
@ -2796,6 +2809,7 @@ extern "C" rmw_ret_t rmw_take_event(
const rmw_event_t * event_handle, void * event_info,
bool * taken)
{
RET_NULL(event_handle);
RET_WRONG_IMPLID(event_handle);
RET_NULL(taken);
RET_NULL(event_info);
@ -2956,6 +2970,7 @@ extern "C" rmw_ret_t rmw_destroy_guard_condition(rmw_guard_condition_t * guard_c
extern "C" rmw_ret_t rmw_trigger_guard_condition(
const rmw_guard_condition_t * guard_condition_handle)
{
RET_NULL(guard_condition_handle);
RET_WRONG_IMPLID(guard_condition_handle);
auto * gcond_impl = static_cast<CddsGuardCondition *>(guard_condition_handle->data);
dds_set_guardcondition(gcond_impl->gcondh, true);
@ -3024,6 +3039,7 @@ fail_alloc_wait_set:
extern "C" rmw_ret_t rmw_destroy_wait_set(rmw_wait_set_t * wait_set)
{
RET_NULL(wait_set);
RET_WRONG_IMPLID(wait_set);
auto result = RMW_RET_OK;
auto ws = static_cast<CddsWaitset *>(wait_set->data);
@ -3409,6 +3425,7 @@ extern "C" rmw_ret_t rmw_take_response(
rmw_service_info_t * request_header, void * ros_response,
bool * taken)
{
RET_NULL(client);
RET_WRONG_IMPLID(client);
auto info = static_cast<CddsClient *>(client->data);
dds_time_t source_timestamp;
@ -3456,6 +3473,7 @@ extern "C" rmw_ret_t rmw_take_request(
rmw_service_info_t * request_header, void * ros_request,
bool * taken)
{
RET_NULL(service);
RET_WRONG_IMPLID(service);
auto info = static_cast<CddsService *>(service->data);
return rmw_take_response_request(
@ -3530,6 +3548,7 @@ extern "C" rmw_ret_t rmw_send_response(
const rmw_service_t * service,
rmw_request_id_t * request_header, void * ros_response)
{
RET_NULL(service);
RET_WRONG_IMPLID(service);
RET_NULL(request_header);
RET_NULL(ros_response);
@ -3579,6 +3598,7 @@ extern "C" rmw_ret_t rmw_send_request(
int64_t * sequence_id)
{
static std::atomic_uint next_request_id;
RET_NULL(client);
RET_WRONG_IMPLID(client);
RET_NULL(ros_request);
RET_NULL(sequence_id);
@ -3650,6 +3670,7 @@ static rmw_ret_t rmw_init_cs(
const char * service_name, const rmw_qos_profile_t * qos_policies,
bool is_service)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL_OR_EMPTYSTR(service_name);
RET_NULL(qos_policies);
@ -3783,7 +3804,9 @@ static void rmw_fini_cs(CddsCS * cs)
static rmw_ret_t destroy_client(const rmw_node_t * node, rmw_client_t * client)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(client);
RET_WRONG_IMPLID(client);
auto info = static_cast<CddsClient *>(client->data);
clean_waitset_caches();
@ -3875,7 +3898,9 @@ extern "C" rmw_ret_t rmw_destroy_client(rmw_node_t * node, rmw_client_t * client
static rmw_ret_t destroy_service(const rmw_node_t * node, rmw_service_t * service)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(service);
RET_WRONG_IMPLID(service);
auto info = static_cast<CddsService *>(service->data);
clean_waitset_caches();
@ -3974,6 +3999,7 @@ 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))
@ -3996,6 +4022,7 @@ 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))
@ -4017,6 +4044,7 @@ 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);
@ -4116,7 +4144,9 @@ extern "C" rmw_ret_t rmw_service_server_is_available(
const rmw_client_t * client,
bool * is_available)
{
RET_NULL(node);
RET_WRONG_IMPLID(node);
RET_NULL(client);
RET_WRONG_IMPLID(client);
RET_NULL(is_available);
*is_available = false;
@ -4185,6 +4215,7 @@ 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);
@ -4314,6 +4345,7 @@ 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);
@ -4339,6 +4371,7 @@ 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);