Skip to content

Commit

Permalink
[#16] Distinguish RMW and Impl types
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Dec 21, 2024
1 parent b387856 commit af07f2c
Show file tree
Hide file tree
Showing 12 changed files with 512 additions and 504 deletions.
78 changes: 40 additions & 38 deletions rmw_iceoryx2_cxx/src/rmw/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

extern "C" {

rmw_client_t* rmw_create_client(const rmw_node_t* node,
rmw_client_t* rmw_create_client(const rmw_node_t* rmw_node,
const rosidl_service_type_support_t* type_support,
const char* service_name,
const rmw_qos_profile_t* qos) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(node, nullptr);
RMW_IOX2_ENSURE_IMPLEMENTATION(node->implementation_identifier, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node, nullptr);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_node->implementation_identifier, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(type_support, nullptr);
RMW_IOX2_ENSURE_VALID_SERVICE_TYPESUPPORT(type_support, nullptr);
RMW_IOX2_ENSURE_NOT_NULL(service_name, nullptr);
Expand All @@ -34,46 +34,46 @@ rmw_client_t* rmw_create_client(const rmw_node_t* node,
// Implementation -------------------------------------------------------------------------------
using ::rmw::iox2::allocate_copy;

auto client = rmw_client_allocate();
if (client == nullptr) {
auto rmw_client = rmw_client_allocate();
if (rmw_client == nullptr) {
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for rmw_client_t");
return nullptr;
}
client->implementation_identifier = rmw_get_implementation_identifier();
rmw_client->implementation_identifier = rmw_get_implementation_identifier();

if (auto ptr = allocate_copy(service_name); ptr.has_error()) {
rmw_client_free(client);
rmw_client_free(rmw_client);
RMW_IOX2_CHAIN_ERROR_MSG("failed to allocate memory for topic name");
return nullptr;
} else {
client->service_name = ptr.value();
rmw_client->service_name = ptr.value();
}

return client;
return rmw_client;
}

rmw_ret_t rmw_destroy_client(rmw_node_t* node, rmw_client_t* client) {
rmw_ret_t rmw_destroy_client(rmw_node_t* rmw_node, rmw_client_t* rmw_client) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);

// Implementation -------------------------------------------------------------------------------
using ::rmw::iox2::deallocate;

if (client->service_name != nullptr) {
deallocate(client->service_name);
if (rmw_client->service_name != nullptr) {
deallocate(rmw_client->service_name);
}
rmw_client_free(client);
rmw_client_free(rmw_client);

return RMW_RET_OK;
}

rmw_ret_t rmw_send_request(const rmw_client_t* client, const void* ros_request, int64_t* sequence_id) {
rmw_ret_t rmw_send_request(const rmw_client_t* rmw_client, const void* ros_request, int64_t* sequence_id) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(ros_request, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(sequence_id, RMW_RET_INVALID_ARGUMENT);

Expand All @@ -82,9 +82,9 @@ rmw_ret_t rmw_send_request(const rmw_client_t* client, const void* ros_request,
}

rmw_ret_t
rmw_take_response(const rmw_client_t* client, rmw_service_info_t* request_header, void* ros_response, bool* taken) {
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
rmw_take_response(const rmw_client_t* rmw_client, rmw_service_info_t* request_header, void* ros_response, bool* taken) {
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(request_header, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(ros_response, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(taken, RMW_RET_INVALID_ARGUMENT);
Expand All @@ -93,10 +93,10 @@ rmw_take_response(const rmw_client_t* client, rmw_service_info_t* request_header
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_client_request_publisher_get_actual_qos(const rmw_client_t* client, rmw_qos_profile_t* qos) {
rmw_ret_t rmw_client_request_publisher_get_actual_qos(const rmw_client_t* rmw_client, rmw_qos_profile_t* qos) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(qos, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
Expand All @@ -105,10 +105,10 @@ rmw_ret_t rmw_client_request_publisher_get_actual_qos(const rmw_client_t* client
return RMW_RET_OK;
}

rmw_ret_t rmw_client_response_subscription_get_actual_qos(const rmw_client_t* client, rmw_qos_profile_t* qos) {
rmw_ret_t rmw_client_response_subscription_get_actual_qos(const rmw_client_t* rmw_client, rmw_qos_profile_t* qos) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(qos, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
Expand All @@ -117,23 +117,25 @@ rmw_ret_t rmw_client_response_subscription_get_actual_qos(const rmw_client_t* cl
return RMW_RET_OK;
}

rmw_ret_t
rmw_client_set_on_new_response_callback(rmw_client_t* client, rmw_event_callback_t callback, const void* user_data) {
rmw_ret_t rmw_client_set_on_new_response_callback(rmw_client_t* rmw_client,
rmw_event_callback_t callback,
const void* user_data) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(user_data, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_service_server_is_available(const rmw_node_t* node, const rmw_client_t* client, bool* is_available) {
rmw_ret_t
rmw_service_server_is_available(const rmw_node_t* rmw_node, const rmw_client_t* rmw_client, bool* is_available) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_node, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_node->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(is_available, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
Expand Down
22 changes: 12 additions & 10 deletions rmw_iceoryx2_cxx/src/rmw/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,28 @@ extern "C" {
* Delayed as not required for minimal functionality.
*/

rmw_ret_t rmw_publisher_event_init(rmw_event_t* event, const rmw_publisher_t* publisher, rmw_event_type_t event_type) {
rmw_ret_t
rmw_publisher_event_init(rmw_event_t* rmw_event, const rmw_publisher_t* rmw_publisher, rmw_event_type_t event_type) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(publisher, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(publisher->implementation_identifier, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(rmw_publisher, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_publisher->implementation_identifier, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t
rmw_subscription_event_init(rmw_event_t* event, const rmw_subscription_t* subscription, rmw_event_type_t event_type) {
rmw_ret_t rmw_subscription_event_init(rmw_event_t* rmw_event,
const rmw_subscription_t* rmw_subscription,
rmw_event_type_t event_type) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(subscription, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(subscription->implementation_identifier, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(rmw_subscription, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_subscription->implementation_identifier, RMW_RET_INVALID_ARGUMENT);

// Implementation -------------------------------------------------------------------------------
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_take_event(const rmw_event_t* event, void* event_info, bool* taken) {
rmw_ret_t rmw_take_event(const rmw_event_t* rmw_event, void* event_info, bool* taken) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(event_info, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(taken, RMW_RET_INVALID_ARGUMENT);
Expand All @@ -46,14 +48,14 @@ rmw_ret_t rmw_take_event(const rmw_event_t* event, void* event_info, bool* taken
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_event_fini(rmw_event_t* event) {
rmw_ret_t rmw_event_fini(rmw_event_t* rmw_event) {
// Invariants ----------------------------------------------------------------------------------

// Implementation -------------------------------------------------------------------------------
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_event_set_callback(rmw_event_t* event, rmw_event_callback_t callback, const void* user_data) {
rmw_ret_t rmw_event_set_callback(rmw_event_t* rmw_event, rmw_event_callback_t callback, const void* user_data) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(user_data, RMW_RET_INVALID_ARGUMENT);

Expand Down
4 changes: 2 additions & 2 deletions rmw_iceoryx2_cxx/src/rmw/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "rmw/features.h"

bool rmw_feature_supported(rmw_feature_t feature) {
static_cast<void>(feature);
bool rmw_feature_supported(rmw_feature_t rmw_feature) {
static_cast<void>(rmw_feature);
return false;
}
20 changes: 10 additions & 10 deletions rmw_iceoryx2_cxx/src/rmw/gid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ rmw_ret_t rmw_get_gid_for_publisher(const rmw_publisher_t* rmw_publisher, rmw_gi
return RMW_RET_ERROR;
}

rmw_ret_t rmw_get_gid_for_client(const rmw_client_t* client, rmw_gid_t* gid) {
rmw_ret_t rmw_get_gid_for_client(const rmw_client_t* rmw_client, rmw_gid_t* rmw_gid) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(gid, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(rmw_client, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(rmw_client->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_NOT_NULL(rmw_gid, RMW_RET_INVALID_ARGUMENT);

// ementation -------------------------------------------------------------------------------
return RMW_RET_UNSUPPORTED;
}

rmw_ret_t rmw_compare_gids_equal(const rmw_gid_t* gid1, const rmw_gid_t* gid2, bool* result) {
rmw_ret_t rmw_compare_gids_equal(const rmw_gid_t* lhs, const rmw_gid_t* rhs, bool* result) {
// Invariants ----------------------------------------------------------------------------------
RMW_IOX2_ENSURE_NOT_NULL(gid1, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(gid2, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(lhs, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(rhs, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_NOT_NULL(result, RMW_RET_INVALID_ARGUMENT);
RMW_IOX2_ENSURE_IMPLEMENTATION(gid1->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_IMPLEMENTATION(gid2->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_IMPLEMENTATION(lhs->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
RMW_IOX2_ENSURE_IMPLEMENTATION(rhs->implementation_identifier, RMW_RET_INCORRECT_RMW_IMPLEMENTATION);

// ementation -------------------------------------------------------------------------------
// NOTE: In iceoryx2, GIDs for different entities (Publishers, Notifiers, etc.) have unique types.
// Thus, these IDs may have the same value but the type system prevents them from being considered equal.
// In C, only the raw value is worked with. This might cause problems.

*result = std::equal(gid1->data, gid1->data + RMW_GID_STORAGE_SIZE, gid2->data);
*result = std::equal(lhs->data, lhs->data + RMW_GID_STORAGE_SIZE, rhs->data);
return RMW_RET_OK;
}
Loading

0 comments on commit af07f2c

Please sign in to comment.