Skip to content

Commit

Permalink
Add support for dynamic allocations
Browse files Browse the repository at this point in the history
See:
* ros2/rmw#349
* ros2/rcl#1038

Signed-off-by: Arjo Chakravarty <[email protected]>
  • Loading branch information
arjo129 authored and wjwwood committed Mar 21, 2023
1 parent eee29f0 commit 76201c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ class ParticipantListener
for (const auto &a : peer_aliases) {
result.insert(a);
}
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp", "Got static peer: %s", hostname);
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp", "Got static peer: %s", hostname.c_str());
}
start = end + delimiter.length();
}
if (start < static_peers_string.length() - 1) {
auto peer = static_peers_string.substr(start);
result.insert(peer);
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp", "Got last static peer: %s", peer);
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp", "Got last static peer: %s", peer.c_str());
}
}

Expand Down Expand Up @@ -341,13 +341,13 @@ class ParticipantListener
// Check if the host is a static peer on our list
auto aliases = utils::get_peer_aliases(hostname);
for (size_t ii = 0; ii < discovery_params_.static_peers_count; ++ii) {
if (hostname == discovery_params_.static_peers[ii]) {
if (hostname == discovery_params_.static_peers[ii].peer_address) {
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp",
"Matching host in our static peer list");
return true;
}

if (aliases.count(discovery_params_.static_peers[ii]) > 0)
if (aliases.count(discovery_params_.static_peers[ii].peer_address) > 0)
{
RCUTILS_LOG_DEBUG_NAMED("rmw_fastrtps_shared_cpp",
"Matching host in our static peer list");
Expand Down
13 changes: 7 additions & 6 deletions rmw_fastrtps_shared_cpp/src/participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ CustomParticipantInfo *rmw_fastrtps_shared_cpp::create_participant(
user_data << "staticpeers=";
for (size_t ii = 0; ii < discovery_params->static_peers_count; ++ii) {
eprosima::fastrtps::rtps::Locator_t peer;
if (ip_version(discovery_params->static_peers[ii]) == 4) {
if (ip_version(discovery_params->static_peers[ii].peer_address) == 4) {
eprosima::fastrtps::rtps::IPLocator::setIPv4(
peer, discovery_params->static_peers[ii]);
peer, discovery_params->static_peers[ii].peer_address);
}
else if (ip_version(discovery_params->static_peers[ii]) == 6) {
else if (ip_version(discovery_params->static_peers[ii].peer_address) == 6) {
eprosima::fastrtps::rtps::IPLocator::setIPv6(
peer, discovery_params->static_peers[ii]);
peer, discovery_params->static_peers[ii].peer_address);
}
// Not specifying the port of the peer means FastDDS will try all
// possible participant ports according to the port calculation equation
Expand All @@ -273,10 +273,11 @@ CustomParticipantInfo *rmw_fastrtps_shared_cpp::create_participant(
domainParticipantQos.wire_protocol().builtin.initialPeersList.push_back(
peer);

user_data << discovery_params->static_peers[ii] << ',';
user_data << discovery_params->static_peers[ii].peer_address << ',';

// Add any aliases (IPs for hostnames, hostnames for IPs)
auto aliases = utils::get_peer_aliases(discovery_params->static_peers[ii]);
auto aliases = utils::get_peer_aliases(
discovery_params->static_peers[ii].peer_address);
for (const auto &alias : aliases) {
user_data << alias << ',';
}
Expand Down
10 changes: 9 additions & 1 deletion rmw_fastrtps_shared_cpp/src/rmw_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ rmw_init_options_copy(
}
const rcutils_allocator_t * allocator = &src->allocator;
RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT);

rmw_init_options_t tmp = *src;
tmp.enclave = rcutils_strdup(tmp.enclave, *allocator);
if (NULL != src->enclave && NULL == tmp.enclave) {
Expand All @@ -82,6 +81,11 @@ rmw_init_options_copy(
allocator->deallocate(tmp.enclave, allocator->state);
return ret;
}
tmp.discovery_params = rmw_get_zero_initialized_discovery_params();
ret = rmw_discovery_params_copy(
&src->discovery_params,
allocator,
&tmp.discovery_params);
*dst = tmp;
return RMW_RET_OK;
}
Expand All @@ -105,6 +109,10 @@ rmw_init_options_fini(const char * identifier, rmw_init_options_t * init_options

allocator->deallocate(init_options->enclave, allocator->state);
rmw_ret_t ret = rmw_security_options_fini(&init_options->security_options, allocator);
if (ret != RMW_RET_OK)
return ret;

ret = rmw_discovery_params_fini(&init_options->discovery_params, allocator);
*init_options = rmw_get_zero_initialized_init_options();
return ret;
}
Expand Down

0 comments on commit 76201c8

Please sign in to comment.