| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,28 +89,22 @@ class GraphManager | |||
| 89 | 89 | ||
| 90 | 90 | /** | |
| 91 | 91 | * @brief Adds a DDS participant to the graph tree. | |
| 92 | - * @param participant Pointer to the participant to be added to the graph. | ||
| 93 | - */ | ||
| 94 | - void add_participant( | ||
| 95 | - const eprosima::fastdds::dds::DomainParticipant* participant); | ||
| 96 | - | ||
| 97 | - /** | ||
| 98 | - * @brief Adds a DDS participant to the graph tree. | ||
| 99 | - * @param guid rtps::GUID_t of the participant to be added. | ||
| 100 | - * @param node_name Name of the ROS 2 node associated to the given participant. | ||
| 92 | + * @param participant eprosima::fastdds::dds::DomainParticipant to be added. | ||
| 93 | + * @param from_microros if this participant has been added from micro-ROS. | ||
| 101 | 94 | * @param enclave ROS 2 enclave. | |
| 102 | 95 | */ | |
| 103 | 96 | void add_participant( | |
| 104 | - const eprosima::fastrtps::rtps::GUID_t& guid, | ||
| 105 | - const std::string& node_name, | ||
| 106 | - const std::string& enclave); | ||
| 97 | + const eprosima::fastdds::dds::DomainParticipant* participant, | ||
| 98 | + bool from_microros = true, | ||
| 99 | + const std::string& enclave = "/"); | ||
| 107 | 100 | ||
| 108 | 101 | /** | |
| 109 | 102 | * @brief Removes a DDS participant from the graph tree. | |
| 110 | - * @param guid rtps::GUID_t of the participant to be removed. | ||
| 103 | + * @param participant eprosima::fastdds::dds::DomainParticipant to be removed. | ||
| 111 | 104 | */ | |
| 112 | 105 | void remove_participant( | |
| 113 | - const eprosima::fastrtps::rtps::GUID_t& guid); | ||
| 106 | + const eprosima::fastdds::dds::DomainParticipant* participant, | ||
| 107 | + bool from_microros = true); | ||
| 114 | 108 | ||
| 115 | 109 | /** | |
| 116 | 110 | * @brief Adds a DDS datawriter to the graph tree. | |
@@ -277,11 +271,12 @@ class GraphManager | |||
| 277 | 271 | eprosima::fastdds::dds::DomainId_t domain_id_; | |
| 278 | 272 | bool graph_changed_; | |
| 279 | 273 | bool display_on_change_; | |
| 280 | - const char * enclave_; | ||
| 281 | 274 | std::thread microros_graph_publisher_; | |
| 282 | 275 | std::mutex mtx_; | |
| 283 | 276 | std::condition_variable cv_; | |
| 284 | 277 | ||
| 278 | + eprosima::fastdds::dds::DataWriterQos datawriter_qos_; | ||
| 279 | + | ||
| 285 | 280 | rmw_dds_common::GraphCache graphCache_; | |
| 286 | 281 | std::unique_ptr<ParticipantListener> participant_listener_; | |
| 287 | 282 | std::unique_ptr<DatareaderListener> datareader_listener_; | |
@@ -293,9 +288,14 @@ class GraphManager | |||
| 293 | 288 | std::unique_ptr<eprosima::fastdds::dds::Subscriber> subscriber_; | |
| 294 | 289 | std::unique_ptr<eprosima::fastdds::dds::Topic> ros_discovery_topic_; | |
| 295 | 290 | std::unique_ptr<eprosima::fastdds::dds::Topic> ros_to_microros_graph_topic_; | |
| 296 | - std::unique_ptr<eprosima::fastdds::dds::DataWriter> ros_discovery_datawriter_; | ||
| 297 | 291 | std::unique_ptr<eprosima::fastdds::dds::DataWriter> ros_to_microros_graph_datawriter_; | |
| 298 | 292 | std::unique_ptr<eprosima::fastdds::dds::DataReader> ros_discovery_datareader_; | |
| 293 | + | ||
| 294 | + // Store a auxiliary publishers and datawriter for each participant created in micro-ROS | ||
| 295 | + std::map< | ||
| 296 | + const eprosima::fastdds::dds::DomainParticipant*, | ||
| 297 | + std::unique_ptr<eprosima::fastdds::dds::DataWriter> | ||
| 298 | + > micro_ros_graph_datawriters_; | ||
| 299 | 299 | }; | |
| 300 | 300 | ||
| 301 | 301 | } // namespace graph_manager | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,12 +40,7 @@ bool Agent::create( | |||
| 40 | 40 | ([&]( | |
| 41 | 41 | const eprosima::fastdds::dds::DomainParticipant* participant) -> void | |
| 42 | 42 | { | |
| 43 | - auto graph_manager_ = | ||
| 44 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 45 | - participant->get_domain_id() | ||
| 46 | - ) | ||
| 47 | - ); | ||
| 48 | - | ||
| 43 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 49 | 44 | graph_manager_->add_participant(participant); | |
| 50 | 45 | }); | |
| 51 | 46 | xrce_dds_agent_instance_.add_middleware_callback( | |
@@ -61,13 +56,8 @@ bool Agent::create( | |||
| 61 | 56 | ([&]( | |
| 62 | 57 | const eprosima::fastdds::dds::DomainParticipant* participant) -> void | |
| 63 | 58 | { | |
| 64 | - auto graph_manager_ = | ||
| 65 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 66 | - participant->get_domain_id() | ||
| 67 | - ) | ||
| 68 | - ); | ||
| 69 | - | ||
| 70 | - graph_manager_->remove_participant(participant->guid()); | ||
| 59 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 60 | + graph_manager_->remove_participant(participant); | ||
| 71 | 61 | }); | |
| 72 | 62 | xrce_dds_agent_instance_.add_middleware_callback( | |
| 73 | 63 | eprosima::uxr::Middleware::Kind::FASTDDS, | |
@@ -84,11 +74,7 @@ bool Agent::create( | |||
| 84 | 74 | const eprosima::fastdds::dds::DomainParticipant* participant, | |
| 85 | 75 | const eprosima::fastdds::dds::DataWriter* datawriter) -> void | |
| 86 | 76 | { | |
| 87 | - auto graph_manager_ = | ||
| 88 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 89 | - participant->get_domain_id() | ||
| 90 | - ) | ||
| 91 | - ); | ||
| 77 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 92 | 78 | ||
| 93 | 79 | // TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed | |
| 94 | 80 | const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle = | |
@@ -115,11 +101,7 @@ bool Agent::create( | |||
| 115 | 101 | const eprosima::fastdds::dds::DataWriter* datawriter) -> void | |
| 116 | 102 | { | |
| 117 | 103 | ||
| 118 | - auto graph_manager_ = | ||
| 119 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 120 | - participant->get_domain_id() | ||
| 121 | - ) | ||
| 122 | - ); | ||
| 104 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 123 | 105 | ||
| 124 | 106 | // TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed | |
| 125 | 107 | const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle = | |
@@ -144,11 +126,7 @@ bool Agent::create( | |||
| 144 | 126 | const eprosima::fastdds::dds::DomainParticipant* participant, | |
| 145 | 127 | const eprosima::fastdds::dds::DataReader* datareader) -> void | |
| 146 | 128 | { | |
| 147 | - auto graph_manager_ = | ||
| 148 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 149 | - participant->get_domain_id() | ||
| 150 | - ) | ||
| 151 | - ); | ||
| 129 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 152 | 130 | ||
| 153 | 131 | // TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed | |
| 154 | 132 | const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle = | |
@@ -174,11 +152,7 @@ bool Agent::create( | |||
| 174 | 152 | const eprosima::fastdds::dds::DomainParticipant* participant, | |
| 175 | 153 | const eprosima::fastdds::dds::DataReader* datareader) -> void | |
| 176 | 154 | { | |
| 177 | - auto graph_manager_ = | ||
| 178 | - find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t( | ||
| 179 | - participant->get_domain_id() | ||
| 180 | - ) | ||
| 181 | - ); | ||
| 155 | + auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id()); | ||
| 182 | 156 | ||
| 183 | 157 | // TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed | |
| 184 | 158 | const eprosima::fastrtps::rtps::InstanceHandle_t instance_handle = | |
@@ -204,16 +178,14 @@ void Agent::run() | |||
| 204 | 178 | ||
| 205 | 179 | std::shared_ptr<graph_manager::GraphManager> Agent::find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id) | |
| 206 | 180 | { | |
| 207 | - auto it = graph_manager_map_.find(domain_id); | ||
| 181 | + | ||
| 182 | + auto it = graph_manager_map_.find(domain_id); | ||
| 208 | 183 | ||
| 209 | 184 | if (it != graph_manager_map_.end()) { | |
| 210 | 185 | return it->second; | |
| 211 | 186 | }else{ | |
| 212 | 187 | return graph_manager_map_.insert( | |
| 213 | - std::pair< | ||
| 214 | - eprosima::fastdds::dds::DomainId_t, | ||
| 215 | - std::shared_ptr<graph_manager::GraphManager> | ||
| 216 | - >( | ||
| 188 | + std::make_pair( | ||
| 217 | 189 | domain_id, | |
| 218 | 190 | std::make_shared<graph_manager::GraphManager>(domain_id) | |
| 219 | 191 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,11 +22,9 @@ namespace agent { | |||
| 22 | 22 | namespace graph_manager { | |
| 23 | 23 | ||
| 24 | 24 | GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id) | |
| 25 | - // : eprosima::fastrtps::ParticipantListener() | ||
| 26 | 25 | : domain_id_(domain_id) | |
| 27 | 26 | , graph_changed_(false) | |
| 28 | 27 | , display_on_change_(false) | |
| 29 | - , enclave_("/") | ||
| 30 | 28 | , mtx_() | |
| 31 | 29 | , cv_() | |
| 32 | 30 | , graphCache_() | |
@@ -43,12 +41,13 @@ GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id) | |||
| 43 | 41 | eprosima::fastdds::dds::DomainParticipantQos participant_qos = | |
| 44 | 42 | eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->get_default_participant_qos(); | |
| 45 | 43 | ||
| 46 | - size_t length = snprintf(nullptr, 0, "enclave=%s;", enclave_) + 1; | ||
| 44 | + const char * enclave = "/"; | ||
| 45 | + size_t length = snprintf(nullptr, 0, "enclave=%s;", enclave) + 1; | ||
| 47 | 46 | participant_qos.user_data().resize(length); | |
| 48 | 47 | snprintf(reinterpret_cast<char *>(participant_qos.user_data().data_vec().data()), | |
| 49 | - length, "enclave=%s;", enclave_); | ||
| 48 | + length, "enclave=%s;", enclave); | ||
| 50 | 49 | ||
| 51 | - participant_qos.name(enclave_); | ||
| 50 | + participant_qos.name(enclave); | ||
| 52 | 51 | participant_qos.wire_protocol().builtin.readerHistoryMemoryPolicy = | |
| 53 | 52 | eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; | |
| 54 | 53 | participant_qos.wire_protocol().builtin.writerHistoryMemoryPolicy = | |
@@ -80,28 +79,26 @@ GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id) | |||
| 80 | 79 | eprosima::fastdds::dds::TOPIC_QOS_DEFAULT)); | |
| 81 | 80 | ||
| 82 | 81 | // Create datawriters | |
| 83 | - eprosima::fastdds::dds::DataWriterQos datawriter_qos = | ||
| 82 | + datawriter_qos_ = | ||
| 84 | 83 | eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT; | |
| 85 | 84 | ||
| 86 | - datawriter_qos.history().kind = | ||
| 85 | + datawriter_qos_.history().kind = | ||
| 87 | 86 | eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS; | |
| 88 | - datawriter_qos.history().depth = 1; | ||
| 89 | - datawriter_qos.endpoint().history_memory_policy = | ||
| 87 | + datawriter_qos_.history().depth = 1; | ||
| 88 | + datawriter_qos_.endpoint().history_memory_policy = | ||
| 90 | 89 | eprosima::fastrtps::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; | |
| 91 | - datawriter_qos.publish_mode().kind = | ||
| 90 | + datawriter_qos_.publish_mode().kind = | ||
| 92 | 91 | eprosima::fastdds::dds::PublishModeQosPolicyKind::ASYNCHRONOUS_PUBLISH_MODE; | |
| 93 | - datawriter_qos.reliability().kind = | ||
| 92 | + datawriter_qos_.reliability().kind = | ||
| 94 | 93 | eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS; | |
| 95 | - datawriter_qos.durability().kind = | ||
| 94 | + datawriter_qos_.durability().kind = | ||
| 96 | 95 | eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS; | |
| 97 | 96 | ||
| 98 | - ros_discovery_datawriter_.reset( | ||
| 99 | - publisher_->create_datawriter(ros_discovery_topic_.get(), datawriter_qos)); | ||
| 100 | - | ||
| 101 | - datawriter_qos.history().kind = | ||
| 97 | + eprosima::fastdds::dds::DataWriterQos ros_to_microros_datawriter_qos_ = datawriter_qos_; | ||
| 98 | + ros_to_microros_datawriter_qos_.history().kind = | ||
| 102 | 99 | eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; | |
| 103 | 100 | ros_to_microros_graph_datawriter_.reset( | |
| 104 | - publisher_->create_datawriter(ros_to_microros_graph_topic_.get(), datawriter_qos)); | ||
| 101 | + publisher_->create_datawriter(ros_to_microros_graph_topic_.get(), ros_to_microros_datawriter_qos_)); | ||
| 105 | 102 | ||
| 106 | 103 | // Create datareaders | |
| 107 | 104 | ||
@@ -295,37 +292,55 @@ inline void GraphManager::publish_microros_graph() | |||
| 295 | 292 | } | |
| 296 | 293 | ||
| 297 | 294 | void GraphManager::add_participant( | |
| 298 | - const eprosima::fastdds::dds::DomainParticipant* participant) | ||
| 299 | - { | ||
| 300 | - const eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos(); | ||
| 301 | - this->add_participant(participant->guid(), qos.name().to_string(), enclave_); | ||
| 302 | - } | ||
| 303 | - | ||
| 304 | - void GraphManager::add_participant( | ||
| 305 | - const eprosima::fastrtps::rtps::GUID_t& guid, | ||
| 306 | - const std::string& node_name, | ||
| 295 | + const eprosima::fastdds::dds::DomainParticipant* participant, | ||
| 296 | + bool from_microros, | ||
| 307 | 297 | const std::string& enclave) | |
| 308 | 298 | { | |
| 309 | - const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", guid); | ||
| 299 | + const eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos(); | ||
| 300 | + const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid()); | ||
| 310 | 301 | ||
| 311 | 302 | graphCache_.add_participant(gid, enclave); | |
| 312 | 303 | ||
| 313 | - if (node_name != enclave) // Do not add root node | ||
| 304 | + // Do not add root node and | ||
| 305 | + // do not announce non-micro-ROS participants | ||
| 306 | + if (qos.name().to_string() != "/" && from_microros) | ||
| 314 | 307 | { | |
| 315 | 308 | std::string isolated_node_name, isolated_namespace; | |
| 316 | - get_name_and_namespace(node_name, isolated_node_name, isolated_namespace); | ||
| 309 | + get_name_and_namespace(qos.name().to_string(), isolated_node_name, isolated_namespace); | ||
| 317 | 310 | ||
| 318 | 311 | rmw_dds_common::msg::ParticipantEntitiesInfo info = | |
| 319 | 312 | graphCache_.add_node(gid, isolated_node_name, isolated_namespace); | |
| 320 | - ros_discovery_datawriter_->write(static_cast<void *>(&info)); | ||
| 313 | + | ||
| 314 | + auto it = micro_ros_graph_datawriters_.find(participant); | ||
| 315 | + if (it == micro_ros_graph_datawriters_.end()) | ||
| 316 | + { | ||
| 317 | + // Create datawriter | ||
| 318 | + std::unique_ptr<eprosima::fastdds::dds::DataWriter> datawriter; | ||
| 319 | + datawriter.reset(publisher_->create_datawriter(ros_discovery_topic_.get(), datawriter_qos_)); | ||
| 320 | + | ||
| 321 | + it = micro_ros_graph_datawriters_.insert( | ||
| 322 | + std::make_pair(participant, std::move(datawriter))).first; | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + it->second->write(static_cast<void *>(&info)); | ||
| 321 | 326 | } | |
| 322 | 327 | } | |
| 323 | 328 | ||
| 324 | 329 | void GraphManager::remove_participant( | |
| 325 | - const eprosima::fastrtps::rtps::GUID_t& guid) | ||
| 330 | + const eprosima::fastdds::dds::DomainParticipant* participant, | ||
| 331 | + bool from_microros) | ||
| 326 | 332 | { | |
| 327 | - const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", guid); | ||
| 333 | + const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid()); | ||
| 328 | 334 | graphCache_.remove_participant(gid); | |
| 335 | + | ||
| 336 | + if (from_microros) | ||
| 337 | + { | ||
| 338 | + rmw_dds_common::msg::ParticipantEntitiesInfo info; | ||
| 339 | + rmw_dds_common::convert_gid_to_msg(&gid, &info.gid); | ||
| 340 | + auto it = micro_ros_graph_datawriters_.find(participant); | ||
| 341 | + it->second->write(static_cast<void *>(&info)); | ||
| 342 | + } | ||
| 343 | + micro_ros_graph_datawriters_.erase(participant); | ||
| 329 | 344 | } | |
| 330 | 345 | ||
| 331 | 346 | void GraphManager::add_datawriter( | |
@@ -438,7 +453,9 @@ void GraphManager::associate_entity( | |||
| 438 | 453 | break; | |
| 439 | 454 | } | |
| 440 | 455 | } | |
| 441 | - ros_discovery_datawriter_->write(static_cast<void *>(&info)); | ||
| 456 | + | ||
| 457 | + auto it = micro_ros_graph_datawriters_.find(participant); | ||
| 458 | + it->second->write(static_cast<void *>(&info)); | ||
| 442 | 459 | } | |
| 443 | 460 | ||
| 444 | 461 | ||
@@ -592,13 +609,13 @@ void GraphManager::ParticipantListener::on_participant_discovery( | |||
| 592 | 609 | const std::string enclave = | |
| 593 | 610 | std::string(name_found->second.begin(), name_found->second.end()); | |
| 594 | 611 | ||
| 595 | - graphManager_from_->add_participant(participant->guid(), info.info.m_participantName.to_string(), enclave); | ||
| 612 | + graphManager_from_->add_participant(participant, false, enclave); | ||
| 596 | 613 | break; | |
| 597 | 614 | } | |
| 598 | 615 | case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::REMOVED_PARTICIPANT: | |
| 599 | 616 | case eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DROPPED_PARTICIPANT: | |
| 600 | 617 | { | |
| 601 | - graphManager_from_->remove_participant(info.info.m_guid); | ||
| 618 | + graphManager_from_->remove_participant(participant, false); | ||
| 602 | 619 | break; | |
| 603 | 620 | } | |
| 604 | 621 | default: | |
@@ -713,15 +730,13 @@ void GraphManager::ParticipantListener::on_subscriber_discovery( | |||
| 713 | 730 | eprosima::fastrtps::rtps::ReaderDiscoveryInfo&& info) | |
| 714 | 731 | { | |
| 715 | 732 | process_discovery_info<eprosima::fastrtps::rtps::ReaderDiscoveryInfo>(info); | |
| 716 | - // graphManager_from_->associate_entity(info.info.guid(), participant, dds::xrce::OBJK_DATAREADER); | ||
| 717 | 733 | } | |
| 718 | 734 | ||
| 719 | 735 | void GraphManager::ParticipantListener::on_publisher_discovery( | |
| 720 | 736 | eprosima::fastdds::dds::DomainParticipant* /*participant*/, | |
| 721 | 737 | eprosima::fastrtps::rtps::WriterDiscoveryInfo&& info) | |
| 722 | 738 | { | |
| 723 | 739 | process_discovery_info<eprosima::fastrtps::rtps::WriterDiscoveryInfo>(info); | |
| 724 | - // graphManager_from_->associate_entity(info.info.guid(), participant, dds::xrce::OBJK_DATAWRITER); | ||
| 725 | 740 | } | |
| 726 | 741 | ||
| 727 | 742 | GraphManager::DatareaderListener::DatareaderListener( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments