From 39e902e65a26f9316bc164540d4aa51b30164960 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Mon, 2 Sep 2024 12:14:58 +0200 Subject: [PATCH] Refactor DDS CommonParticipant to handle InitializationException in create_writer and create_reader --- .../participant/dds/CommonParticipant.hpp | 2 ++ .../cpp/participant/dds/CommonParticipant.cpp | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp b/ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp index 8523e5f1..53d6112e 100644 --- a/ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp +++ b/ddspipe_participants/include/ddspipe_participants/participant/dds/CommonParticipant.hpp @@ -94,6 +94,7 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain * @brief Create a writer object * * Depending on the Topic QoS creates a Basic or Specific Writer. + * If it fails to create the writer it will return a blank one. */ DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_writer( @@ -103,6 +104,7 @@ class CommonParticipant : public core::IParticipant, public fastdds::dds::Domain * @brief Create a reader object * * Depending on the Topic QoS creates a Basic or Specific Reader. + * If it fails to create the reader it will return a blank one. */ DDSPIPE_PARTICIPANTS_DllAPI std::shared_ptr create_reader( diff --git a/ddspipe_participants/src/cpp/participant/dds/CommonParticipant.cpp b/ddspipe_participants/src/cpp/participant/dds/CommonParticipant.cpp index 4938252a..c5d360ef 100644 --- a/ddspipe_participants/src/cpp/participant/dds/CommonParticipant.cpp +++ b/ddspipe_participants/src/cpp/participant/dds/CommonParticipant.cpp @@ -254,8 +254,20 @@ std::shared_ptr CommonParticipant::create_writer( return std::make_shared(); } - // Get the DDS Topic associated (create it if it does not exist) - fastdds::dds::Topic* fastdds_topic = topic_related_(dds_topic); + fastdds::dds::Topic* fastdds_topic; + try + { + // Get the DDS Topic associated (create it if it does not exist) + fastdds_topic = topic_related_(dds_topic); + } + catch (const utils::InitializationException& e) + { + EPROSIMA_LOG_WARNING( + DDSPIPE_DDS_PARTICIPANT, + e.what() + << " Execution continue but this topic will not be published in Participant " << id() << "."); + return std::make_shared(); + } if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) { @@ -303,7 +315,20 @@ std::shared_ptr CommonParticipant::create_reader( } // Get the DDS Topic associated (create it if it does not exist) - fastdds::dds::Topic* fastdds_topic = topic_related_(dds_topic); + fastdds::dds::Topic* fastdds_topic; + try + { + // Get the DDS Topic associated (create it if it does not exist) + fastdds_topic = topic_related_(dds_topic); + } + catch (const utils::InitializationException& e) + { + EPROSIMA_LOG_WARNING( + DDSPIPE_DDS_PARTICIPANT, + e.what() + << ". Execution continue but this topic will not be subscribed in Participant " << id() << "."); + return std::make_shared(); + } if (dds_topic.topic_qos.has_partitions() || dds_topic.topic_qos.has_ownership()) {