Skip to content

Commit 5c71cde

Browse files
authored
Drop rmw_fastrtps_shared_cpp dependency (#287)
Signed-off-by: David Laseca Perez <davidlaseca@eprosima.com>
1 parent 8cf7741 commit 5c71cde

6 files changed

Lines changed: 66 additions & 21 deletions

File tree

‎micro_ros_agent/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ find_package(fastdds REQUIRED)
3838
find_package(rmw_dds_common REQUIRED)
3939
find_package(rmw REQUIRED)
4040
find_package(rcutils REQUIRED)
41-
find_package(rmw_fastrtps_shared_cpp REQUIRED)
41+
find_package(rcpputils REQUIRED)
4242

4343
find_package(ament_lint_auto REQUIRED)
4444

@@ -65,9 +65,9 @@ target_include_directories(${PROJECT_NAME}
6565
target_link_libraries(${PROJECT_NAME}
6666
${micro_ros_msgs_TARGETS}
6767
${rmw_dds_common_TARGETS}
68+
rcpputils::rcpputils
6869
rmw::rmw
6970
rmw_dds_common::rmw_dds_common_library
70-
rmw_fastrtps_shared_cpp::rmw_fastrtps_shared_cpp
7171
rosidl_runtime_cpp::rosidl_runtime_cpp
7272
rosidl_typesupport_cpp::rosidl_typesupport_cpp
7373
rosidl_typesupport_fastrtps_cpp::rosidl_typesupport_fastrtps_cpp

‎micro_ros_agent/include/agent/graph_manager/graph_manager.hpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737

3838
#include "rmw/types.h"
3939
#include "rmw/names_and_types.h"
40+
#include "rmw/qos_profiles.h"
4041
#include "rmw/impl/cpp/key_value.hpp"
4142
#include "rmw_dds_common/graph_cache.hpp"
42-
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
43-
#include "rmw_fastrtps_shared_cpp/qos.hpp"
4443

4544
#include "rcutils/types.h"
4645
#include "rcutils/types/string_array.h"

‎micro_ros_agent/include/agent/graph_manager/graph_typesupport.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "rmw/types.h"
3030
#include "rmw/impl/cpp/key_value.hpp"
3131
#include "rmw_dds_common/graph_cache.hpp"
32-
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
33-
#include "rmw_fastrtps_shared_cpp/qos.hpp"
3432

3533
#include "rcutils/types.h"
3634

‎micro_ros_agent/package.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<depend>rmw</depend>
1919
<depend>rcutils</depend>
20-
<depend>rmw_fastrtps_shared_cpp</depend>
20+
<depend>rcpputils</depend>
2121
<depend>rmw_dds_common</depend>
2222
<depend>micro_ros_msgs</depend>
2323
<depend>microxrcedds_agent</depend>

‎micro_ros_agent/src/agent/graph_manager/graph_manager.cpp‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.hpp>
2121
#include <fastdds/rtps/reader/ReaderDiscoveryStatus.hpp>
2222

23+
#include <cstring>
2324
#include <memory>
2425
#include <string>
2526
#include <utility>
@@ -29,6 +30,23 @@ namespace uros {
2930
namespace agent {
3031
namespace graph_manager {
3132

33+
// Builds a GID the way rmw_fastrtps_cpp does, the 16-byte GUID copied as is
34+
// Defined here since rmw_fastrtps_shared_cpp, which provided it, was removed upstream
35+
// (ros2/rmw_fastrtps#923)
36+
rmw_gid_t create_rmw_gid(
37+
const char* identifier,
38+
const eprosima::fastdds::rtps::GUID_t& guid)
39+
{
40+
static_assert(
41+
sizeof(guid) == sizeof(guid.guidPrefix.value) + sizeof(guid.entityId.value) &&
42+
sizeof(guid) <= RMW_GID_STORAGE_SIZE,
43+
"Fast DDS GUID_t must be a packed prefix + entity id that fits in rmw_gid_t");
44+
rmw_gid_t rmw_gid = {};
45+
rmw_gid.implementation_identifier = identifier;
46+
std::memcpy(rmw_gid.data, &guid, sizeof(guid));
47+
return rmw_gid;
48+
}
49+
3250
GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id)
3351
: domain_id_(domain_id)
3452
, graph_changed_(false)
@@ -307,7 +325,7 @@ void GraphManager::add_participant(
307325
const std::string& enclave)
308326
{
309327
const eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos();
310-
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
328+
const rmw_gid_t gid = create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
311329

312330
graphCache_.add_participant(gid, enclave);
313331

@@ -339,7 +357,7 @@ void GraphManager::remove_participant(
339357
const eprosima::fastdds::dds::DomainParticipant* participant,
340358
bool from_microros)
341359
{
342-
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
360+
const rmw_gid_t gid = create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
343361
graphCache_.remove_participant(gid);
344362

345363
if (from_microros)
@@ -371,9 +389,9 @@ void GraphManager::add_datawriter(
371389
const eprosima::fastdds::rtps::GUID_t& participant_guid,
372390
const eprosima::fastdds::dds::DataWriterQos& writer_qos)
373391
{
374-
const rmw_gid_t datawriter_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
392+
const rmw_gid_t datawriter_gid = create_rmw_gid(
375393
"rmw_fastrtps_cpp", datawriter_guid);
376-
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
394+
const rmw_gid_t participant_gid = create_rmw_gid(
377395
"rmw_fastrtps_cpp", participant_guid);
378396
const rmw_qos_profile_t qos_profile = fastdds_qos_to_rmw_qos(writer_qos);
379397

@@ -384,7 +402,7 @@ void GraphManager::add_datawriter(
384402
void GraphManager::remove_datawriter(
385403
const eprosima::fastdds::rtps::GUID_t& datawriter_guid)
386404
{
387-
const rmw_gid_t datawriter_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
405+
const rmw_gid_t datawriter_gid = create_rmw_gid(
388406
"rmw_fastrtps_cpp", datawriter_guid);
389407

390408
graphCache_.remove_entity(datawriter_gid, false);
@@ -408,9 +426,9 @@ void GraphManager::add_datareader(
408426
const eprosima::fastdds::rtps::GUID_t& participant_guid,
409427
const eprosima::fastdds::dds::DataReaderQos& reader_qos)
410428
{
411-
const rmw_gid_t datareader_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
429+
const rmw_gid_t datareader_gid = create_rmw_gid(
412430
"rmw_fastrtps_cpp", datareader_guid);
413-
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
431+
const rmw_gid_t participant_gid = create_rmw_gid(
414432
"rmw_fastrtps_cpp", participant_guid);
415433
const rmw_qos_profile_t qos_profile = fastdds_qos_to_rmw_qos(reader_qos);
416434

@@ -426,7 +444,7 @@ void GraphManager::add_datareader(
426444
void GraphManager::remove_datareader(
427445
const eprosima::fastdds::rtps::GUID_t& datareader_guid)
428446
{
429-
const rmw_gid_t datareader_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
447+
const rmw_gid_t datareader_gid = create_rmw_gid(
430448
"rmw_fastrtps_cpp", datareader_guid);
431449

432450
graphCache_.remove_entity(datareader_gid, true);
@@ -437,9 +455,9 @@ void GraphManager::associate_entity(
437455
const eprosima::fastdds::dds::DomainParticipant* participant,
438456
const dds::xrce::ObjectKind& entity_kind)
439457
{
440-
const rmw_gid_t entity_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
458+
const rmw_gid_t entity_gid = create_rmw_gid(
441459
"rmw_fastrtps_cpp", entity_guid);
442-
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
460+
const rmw_gid_t participant_gid = create_rmw_gid(
443461
"rmw_fastrtps_cpp", participant->guid());
444462

445463
eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos();
@@ -629,14 +647,14 @@ void GraphManager::ParticipantListener::on_participant_discovery(
629647
const std::string enclave =
630648
std::string(name_found->second.begin(), name_found->second.end());
631649

632-
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.guid);
650+
const rmw_gid_t gid = create_rmw_gid("rmw_fastrtps_cpp", info.guid);
633651
graphManager_from_->get_graph_cache().add_participant(gid, enclave);
634652
break;
635653
}
636654
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT:
637655
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT:
638656
{
639-
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.guid);
657+
const rmw_gid_t gid = create_rmw_gid("rmw_fastrtps_cpp", info.guid);
640658
graphManager_from_->get_graph_cache().remove_participant(gid);
641659
break;
642660
}

‎micro_ros_agent/src/agent/utils/demangle.cpp‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,44 @@
2323
#include <rcutils/logging_macros.h>
2424
#include <rcutils/types.h>
2525

26-
#include <rmw_fastrtps_shared_cpp/namespace_prefix.hpp>
27-
2826
#include <agent/utils/demangle.hpp>
2927

3028
namespace uros {
3129
namespace agent {
3230
namespace utils {
3331

32+
// ROS 2 name prefixes on DDS topics. Defined here since rmw_fastrtps_shared_cpp,
33+
// which provided them, was removed upstream (ros2/rmw_fastrtps#923)
34+
const char* const ros_topic_prefix = "rt";
35+
const char* const ros_service_requester_prefix = "rq";
36+
const char* const ros_service_response_prefix = "rr";
37+
38+
// Returns name without "<prefix>", or "" if name does not start with "<prefix>/".
39+
// Defined here for the same reason as the prefixes above
40+
std::string _resolve_prefix(
41+
const std::string& name,
42+
const std::string& prefix)
43+
{
44+
return (name.rfind(prefix + "/", 0) == 0) ? name.substr(prefix.length()) : "";
45+
}
46+
47+
// Returns topic_name without its ROS 2 prefix, if it has one.
48+
// Defined here for the same reason as the prefixes above
49+
std::string _strip_ros_prefix_if_exists(
50+
const std::string& topic_name)
51+
{
52+
for (const char* prefix :
53+
{ros_topic_prefix, ros_service_requester_prefix, ros_service_response_prefix})
54+
{
55+
const std::string stripped = _resolve_prefix(topic_name, prefix);
56+
if (!stripped.empty())
57+
{
58+
return stripped;
59+
}
60+
}
61+
return topic_name;
62+
}
63+
3464
std::string Demangle::demangle_if_ros_topic(
3565
const std::string& topic_name)
3666
{

0 commit comments

Comments
 (0)