diff --git a/CMakeLists.txt b/CMakeLists.txt index 10f9c591c..486da704a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,8 @@ option(UAGENT_SECURITY_PROFILE "Build security profile." OFF) option(UAGENT_BUILD_EXECUTABLE "Build Micro XRCE-DDS Agent provided executable." ON) option(UAGENT_BUILD_USAGE_EXAMPLES "Build Micro XRCE-DDS Agent built-in usage examples" OFF) -set(UAGENT_P2P_CLIENT_VERSION 2.4.3 CACHE STRING "Sets Micro XRCE-DDS client version for P2P") -set(UAGENT_P2P_CLIENT_TAG v2.4.3 CACHE STRING "Sets Micro XRCE-DDS client tag for P2P") +set(UAGENT_P2P_CLIENT_VERSION 3.0.0 CACHE STRING "Sets Micro XRCE-DDS client version for P2P") +set(UAGENT_P2P_CLIENT_TAG v3.0.0 CACHE STRING "Sets Micro XRCE-DDS client tag for P2P") option(UAGENT_BUILD_CI_TESTS "Build CI test cases.") if(UAGENT_BUILD_CI_TESTS) @@ -80,7 +80,7 @@ set(_deps "") if(UAGENT_USE_SYSTEM_FASTCDR) set(_fastcdr_version 2) else() - set(_fastcdr_version 2.2.0) + set(_fastcdr_version 2.2.4) set(_fastcdr_tag 2.2.x) endif() list(APPEND _deps "fastcdr\;${_fastcdr_version}") @@ -93,13 +93,13 @@ endif() if(UAGENT_FAST_PROFILE) if(UAGENT_USE_SYSTEM_FASTDDS) - set(_fastdds_version 2) + set(_fastdds_version 3) else() - set(_fastdds_version 2.14) - set(_fastdds_tag 2.14.x) + set(_fastdds_version 3.1) + set(_fastdds_tag 3.x) set(_foonathan_memory_tag v0.7-3) # This tag should be updated every time it gets updated in foonathan_memory_vendor eProsima's package endif() - list(APPEND _deps "fastrtps\;${_fastdds_version}") + list(APPEND _deps "fastdds\;${_fastdds_version}") endif() if(UAGENT_LOGGER_PROFILE) @@ -117,7 +117,7 @@ endif() ############################################################################### set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT UAGENT_SUPERBUILD) - project(microxrcedds_agent VERSION "2.4.3" LANGUAGES C CXX) + project(microxrcedds_agent VERSION "3.0.0" LANGUAGES C CXX) else() project(uagent_superbuild NONE) include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake) @@ -210,9 +210,6 @@ set(SRCS ${TRANSPORT_SRCS} $<$:src/cpp/transport/discovery/DiscoveryServer.cpp> $<$:src/cpp/types/TopicPubSubType.cpp> - $<$:src/cpp/xmlobjects/xmlobjects.cpp> - $<$:src/cpp/middleware/fast/FastEntities.cpp> - $<$:src/cpp/middleware/fast/FastMiddleware.cpp> $<$:src/cpp/middleware/fastdds/FastDDSEntities.cpp> $<$:src/cpp/middleware/fastdds/FastDDSMiddleware.cpp> $<$:src/cpp/middleware/ced/CedEntities.cpp> @@ -300,7 +297,7 @@ target_link_libraries(${PROJECT_NAME} $<$:iphlpapi> $<$:spdlog::spdlog> PRIVATE - $<$:fastrtps> + $<$:fastdds> $<$:microxrcedds_client> $<$:microcdr> $<$:pthread> @@ -314,7 +311,7 @@ target_include_directories(${PROJECT_NAME} BEFORE $ PRIVATE $ - $<$:$> + $<$:$> $<$:$> $<$:$> $<$:$> diff --git a/ci/linux/CMakeLists.txt b/ci/linux/CMakeLists.txt index 262959f75..dad2799f0 100644 --- a/ci/linux/CMakeLists.txt +++ b/ci/linux/CMakeLists.txt @@ -50,7 +50,6 @@ ExternalProject_Add(microxrcedds_agent_isolated TEST_COMMAND COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Test COMMAND ${CMAKE_CTEST_COMMAND} -VV -T MemCheck -E "test-case*" - COMMAND ${CMAKE_CTEST_COMMAND} -VV -T Coverage -E "test-case*" CMAKE_CACHE_ARGS -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER} diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index 0d4c86299..f6aaddbf2 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -117,8 +117,8 @@ if(UAGENT_FAST_PROFILE AND NOT UAGENT_USE_SYSTEM_FASTDDS) # Fast DDS. unset(fastdds_DIR CACHE) - find_package(fastrtps ${_fastdds_version} EXACT QUIET) - if(NOT fastrtps_FOUND) + find_package(fastdds ${_fastdds_version} EXACT QUIET) + if(NOT fastdds_FOUND) ExternalProject_Add(fastdds GIT_REPOSITORY https://github.com/eProsima/Fast-DDS.git @@ -127,7 +127,7 @@ if(UAGENT_FAST_PROFILE AND NOT UAGENT_USE_SYSTEM_FASTDDS) PREFIX ${PROJECT_BINARY_DIR}/fastdds INSTALL_DIR - ${PROJECT_BINARY_DIR}/temp_install/fastrtps-${_fastdds_version} + ${PROJECT_BINARY_DIR}/temp_install/fastdds-${_fastdds_version} CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH};${PROJECT_BINARY_DIR}/temp_install diff --git a/colcon.pkg b/colcon.pkg index 62843e442..06f55d015 100644 --- a/colcon.pkg +++ b/colcon.pkg @@ -3,7 +3,7 @@ "type": "cmake", "dependencies":[ "fastcdr", - "fastrtps" + "fastdds" ], "cmake-args":[ "-DUAGENT_ISOLATED_INSTALL=OFF", diff --git a/include/uxr/agent/middleware/Middleware.hpp b/include/uxr/agent/middleware/Middleware.hpp index d3b89786e..6f2fd3b55 100644 --- a/include/uxr/agent/middleware/Middleware.hpp +++ b/include/uxr/agent/middleware/Middleware.hpp @@ -38,7 +38,6 @@ class Middleware { NONE, #ifdef UAGENT_FAST_PROFILE - FASTRTPS, FASTDDS, #endif diff --git a/include/uxr/agent/middleware/fast/FastEntities.hpp b/include/uxr/agent/middleware/fast/FastEntities.hpp deleted file mode 100644 index c1b3e2b7a..000000000 --- a/include/uxr/agent/middleware/fast/FastEntities.hpp +++ /dev/null @@ -1,334 +0,0 @@ -// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef UXR_AGENT_MIDDLEWARE_FAST_FAST_ENTITIES_HPP_ -#define UXR_AGENT_MIDDLEWARE_FAST_FAST_ENTITIES_HPP_ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace eprosima { -namespace fastrtps { - -class ParticipantAttributes; -class PublisherAttributes; -class SubscriberAttributes; -class RequesterAttributes; -class ReplierAttributes; -class SampleInfo_t; - -} // namespace fastrtps -} // namespace eprosima - -namespace eprosima { -namespace uxr { - -class FastType; -class FastTopic; - -/********************************************************************************************************************** - * Listeners - **********************************************************************************************************************/ -class FastListener : public fastrtps::ParticipantListener - , public fastrtps::PublisherListener - , public fastrtps::SubscriberListener -{ -public: - void onParticipantDiscovery( - fastrtps::Participant*, - fastrtps::rtps::ParticipantDiscoveryInfo&& info) final; - - void onPublicationMatched( - fastrtps::Publisher*, - fastrtps::rtps::MatchingInfo& info) final; - - void onSubscriptionMatched( - fastrtps::Subscriber*, - fastrtps::rtps::MatchingInfo& info) final; -}; - -/********************************************************************************************************************** - * FastParticipant - **********************************************************************************************************************/ -class FastParticipant -{ -public: - FastParticipant(fastrtps::Participant* impl); - - ~FastParticipant(); - - bool match( - const fastrtps::ParticipantAttributes& attrs) const; - - fastrtps::Participant* get_ptr() const { return impl_; } - - bool register_type( - const std::shared_ptr& type); - - bool unregister_type( - const std::string& type_name); - - std::shared_ptr find_type( - const std::string& type_name) const; - - bool register_topic( - const std::shared_ptr& topic); - - bool unregister_topic( - const std::string& topic_name); - - std::shared_ptr find_topic( - const std::string& topic_name) const; - - int16_t domain_id() const; - - const fastrtps::rtps::GUID_t& get_guid() const; - -private: - fastrtps::Participant* impl_; - std::unordered_map> type_register_; - std::unordered_map> topic_register_; -}; - -/********************************************************************************************************************** - * FastTopic - **********************************************************************************************************************/ -class FastType : public TopicPubSubType -{ -public: - FastType( - const std::shared_ptr& participant); - - ~FastType(); - -private: - std::shared_ptr participant_; -}; - -class FastTopic -{ -public: - FastTopic( - const std::string& name, - const std::shared_ptr& type, - const std::shared_ptr& participant); - - ~FastTopic(); - - const std::string& get_name() const { return name_; } - - const std::shared_ptr& get_type() const { return type_; } - - bool match( - const fastrtps::TopicAttributes& attrs) const; - -private: - std::string name_; - std::shared_ptr type_; - std::shared_ptr participant_; -}; - -/********************************************************************************************************************** - * FastPublisher - **********************************************************************************************************************/ -class FastPublisher -{ -public: - FastPublisher( - const std::shared_ptr& participant) - : participant_(participant) - {} - - ~FastPublisher() = default; - - const std::shared_ptr& get_participant() const { return participant_; } - -private: - std::shared_ptr participant_; -}; - -/********************************************************************************************************************** - * FastSubscriber - **********************************************************************************************************************/ -class FastSubscriber -{ -public: - FastSubscriber( - const std::shared_ptr& participant) - : participant_(participant) - {} - - ~FastSubscriber() = default; - - const std::shared_ptr& get_participant() const { return participant_; } - -private: - std::shared_ptr participant_; -}; - -/********************************************************************************************************************** - * FastDataWriter - **********************************************************************************************************************/ -class FastDataWriter -{ -public: - FastDataWriter( - fastrtps::Publisher* impl_, - const std::shared_ptr& topic, - const std::shared_ptr& publisher); - - ~FastDataWriter(); - - bool match( - const fastrtps::PublisherAttributes& attrs) const; - - bool write( - const std::vector& data); - - bool write( - const std::vector& data, - fastrtps::rtps::WriteParams& wparams); - - const fastrtps::rtps::GUID_t& get_guid() const; - - const fastrtps::Participant* get_participant() const; - - const fastrtps::Publisher* get_ptr() const; - -private: - fastrtps::Publisher* impl_; - std::shared_ptr topic_; - std::shared_ptr publisher_; -}; - -/********************************************************************************************************************** - * FastDataReader - **********************************************************************************************************************/ -class FastDataReader -{ -public: - FastDataReader( - fastrtps::Subscriber* impl_, - const std::shared_ptr& topic, - const std::shared_ptr& Subscriber); - - ~FastDataReader(); - - bool match( - const fastrtps::SubscriberAttributes& attrs) const; - - bool read( - std::vector& data, - std::chrono::milliseconds timeout); - - bool read( - std::vector& data, - fastrtps::SampleInfo_t& info, - std::chrono::milliseconds timeout); - - const fastrtps::rtps::GUID_t& get_guid() const; - - const fastrtps::Participant* get_participant() const; - - const fastrtps::Subscriber* get_ptr() const; - -private: - fastrtps::Subscriber* impl_; - std::shared_ptr topic_; - std::shared_ptr subscriber_; -}; - - -/********************************************************************************************************************** - * FastRequester - **********************************************************************************************************************/ -class FastRequester -{ -public: - FastRequester( - const std::shared_ptr& datawriter, - const std::shared_ptr& datareader); - - ~FastRequester() = default; - - bool match( - const fastrtps::RequesterAttributes& attrs) const; - - bool write( - uint32_t sequence_number, - const std::vector& data); - - bool read( - uint32_t& sequence_number, - std::vector& data, - std::chrono::milliseconds timeout); - - const fastrtps::Participant* get_participant() const; - - const fastrtps::Publisher* get_request_datawriter() const; - - const fastrtps::Subscriber* get_reply_datareader() const; - -private: - std::shared_ptr datawriter_; - std::shared_ptr datareader_; - dds::GUID_t publisher_id_; - std::map sequence_to_sequence_; -}; - -/********************************************************************************************************************** - * FastReplier - **********************************************************************************************************************/ -class FastReplier -{ -public: - FastReplier( - const std::shared_ptr& datawriter, - const std::shared_ptr& datareader); - - ~FastReplier() = default; - - bool match( - const fastrtps::ReplierAttributes& attrs) const; - - bool write( - const std::vector& data); - - bool read( - std::vector& data, - std::chrono::milliseconds timeout); - - const fastrtps::Participant* get_participant() const; - - const fastrtps::Subscriber* get_request_datareader() const; - - const fastrtps::Publisher* get_reply_datawriter() const; - -private: - std::shared_ptr datawriter_; - std::shared_ptr datareader_; -}; - -} // namespace uxr -} // namespace eprosima - -#endif // UXR_AGENT_MIDDLEWARE_FAST_FAST_ENTITIES_HPP_ diff --git a/include/uxr/agent/middleware/fast/FastMiddleware.hpp b/include/uxr/agent/middleware/fast/FastMiddleware.hpp deleted file mode 100644 index e9e221f54..000000000 --- a/include/uxr/agent/middleware/fast/FastMiddleware.hpp +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#ifndef UXR_AGENT_MIDDLEWARE_FAST_FAST_MIDDLEWARE_HPP_ -#define UXR_AGENT_MIDDLEWARE_FAST_FAST_MIDDLEWARE_HPP_ - -#include -#include -#include - -#include -#include -#include -#include - -namespace eprosima { -namespace uxr { -namespace middleware { -class CallbackFactory; -} // namespace middleware - -class FastMiddleware : public Middleware -{ -public: - FastMiddleware(); - ~FastMiddleware() final = default; - -/********************************************************************************************************************** - * Create functions. - **********************************************************************************************************************/ - bool create_participant_by_ref( - uint16_t participant_id, - int16_t domain_id, - const std::string& ref) override; - - bool create_participant_by_xml( - uint16_t participant_id, - int16_t domain_id, - const std::string& xml) override; - - bool create_participant_by_bin( - uint16_t /* participant_id */, - const dds::xrce::OBJK_DomainParticipant_Binary& /* participant_xrce */) override { return false; }; - - bool create_topic_by_ref( - uint16_t topic_id, - uint16_t participant_id, - const std::string& ref) override; - - bool create_topic_by_xml( - uint16_t topic_id, - uint16_t participant_id, - const std::string& xml) override; - - bool create_topic_by_bin( - uint16_t /* topic_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Topic_Binary& /* topic_xrce */) override { return false; }; - - bool create_publisher_by_xml( - uint16_t publisher_id, - uint16_t participant_id, - const std::string&) override; - - bool create_publisher_by_bin( - uint16_t /* publisher_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Publisher_Binary& /* publisher_xrce */) override { return false; }; - - bool create_subscriber_by_xml( - uint16_t subscirber_id, - uint16_t participant_id, - const std::string&) override; - - bool create_subscriber_by_bin( - uint16_t /* subscriber_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Subscriber_Binary& /* subscriber_xrce */) override { return false; }; - - bool create_datawriter_by_ref( - uint16_t datawriter_id, - uint16_t publisher_id, - const std::string& ref) override; - - bool create_datawriter_by_xml( - uint16_t datawriter_id, - uint16_t publisher_id, - const std::string& xml) override; - - bool create_datawriter_by_bin( - uint16_t /* datawriter_id */, - uint16_t /* publisher_id */, - const dds::xrce::OBJK_DataWriter_Binary& /* datawriter_xrce */) override { return false; }; - - bool create_datareader_by_ref( - uint16_t datareader_id, - uint16_t subscriber_id, - const std::string& ref) override; - - bool create_datareader_by_xml( - uint16_t datareader_id, - uint16_t subscriber_id, - const std::string& xml) override; - - bool create_datareader_by_bin( - uint16_t /* datareader_id */, - uint16_t /* subscriber_id */, - const dds::xrce::OBJK_DataReader_Binary& /* datareader_xrce */) override { return false; }; - - bool create_requester_by_ref( - uint16_t requester_id, - uint16_t participant_id, - const std::string& ref) override; - - bool create_requester_by_xml( - uint16_t requester_id, - uint16_t participant_id, - const std::string& xml) override; - - bool create_requester_by_bin( - uint16_t /* requester_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Requester_Binary& /* requester_xrce */) override { return false; }; - - bool create_replier_by_ref( - uint16_t replier_id, - uint16_t participant_id, - const std::string& ref) override; - - bool create_replier_by_xml( - uint16_t replier_id, - uint16_t participant_id, - const std::string& xml) override; - - bool create_replier_by_bin( - uint16_t /* replier_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Replier_Binary& /* replier_xrce */) override { return false; }; - -/********************************************************************************************************************** - * Delete functions. - **********************************************************************************************************************/ - bool delete_participant(uint16_t participant_id) override; - - bool delete_topic(uint16_t topic_id) override; - - bool delete_publisher(uint16_t publisher_id) override; - - bool delete_subscriber(uint16_t subscriber_id) override; - - bool delete_datawriter(uint16_t datawriter_id) override; - - bool delete_datareader(uint16_t datareader_id) override; - - bool delete_requester(uint16_t requester_id) override; - - bool delete_replier(uint16_t replier_id) override; - -/********************************************************************************************************************** - * Write/Read functions. - **********************************************************************************************************************/ - bool write_data( - uint16_t datawriter_id, - const std::vector& data) override; - - bool write_request( - uint16_t requester_id, - uint32_t sequence_number, - const std::vector& data) override; - - bool write_reply( - uint16_t replier_id, - const std::vector& data) override; - - bool read_data( - uint16_t datareader_id, - std::vector& data, - std::chrono::milliseconds timeout) override; - - bool read_request( - uint16_t replier_id, - std::vector& data, - std::chrono::milliseconds timeout) override; - - bool read_reply( - uint16_t reply_id, - uint32_t& sequence_number, - std::vector& data, - std::chrono::milliseconds timeout) override; - -/********************************************************************************************************************** - * Matched functions. - **********************************************************************************************************************/ - bool matched_participant_from_ref( - uint16_t participant_id, - int16_t domain_id, - const std::string& ref) const override; - - bool matched_participant_from_xml( - uint16_t participant_id, - int16_t domain_id, - const std::string& xml) const override; - - bool matched_participant_from_bin( - uint16_t /* participant_id */, - int16_t /* domain_id */, - const dds::xrce::OBJK_DomainParticipant_Binary& /* participant_xrce */) const override { return false; }; - - bool matched_topic_from_ref( - uint16_t topic_id, - const std::string& ref) const override; - - bool matched_topic_from_xml( - uint16_t topic_id, - const std::string& xml) const override; - - bool matched_topic_from_bin( - uint16_t /* topic_id */, - const dds::xrce::OBJK_Topic_Binary& /* topic_xrce */) const override { return false; }; - - bool matched_datawriter_from_ref( - uint16_t datawriter_id, - const std::string& ref) const override; - - bool matched_datawriter_from_xml( - uint16_t datawriter_id, - const std::string& xml) const override; - - bool matched_datawriter_from_bin( - uint16_t /* datawriter_id */, - const dds::xrce::OBJK_DataWriter_Binary& /* datawriter_xrce */) const override { return false; }; - - bool matched_datareader_from_ref( - uint16_t datareader_id, - const std::string& ref) const override; - - bool matched_datareader_from_xml( - uint16_t datareader_id, - const std::string& xml) const override; - - bool matched_datareader_from_bin( - uint16_t /* datareader_id */, - const dds::xrce::OBJK_DataReader_Binary& /* datareader_xrce */) const override { return false; }; - - bool matched_requester_from_ref( - uint16_t participant_id, - const std::string& ref) const override; - - bool matched_requester_from_xml( - uint16_t participant_id, - const std::string& xml) const override; - - bool matched_requester_from_bin( - uint16_t /* requester_id */, - const dds::xrce::OBJK_Requester_Binary& /* requester_xrce */) const override { return false; }; - - bool matched_replier_from_ref( - uint16_t participant_id, - const std::string& ref) const override; - - bool matched_replier_from_xml( - uint16_t participant_id, - const std::string& xml) const override; - - bool matched_replier_from_bin( - uint16_t /* replier_id */, - const dds::xrce::OBJK_Replier_Binary& /* replier_xrce */) const override { return false; }; -private: - FastListener listener_; - std::unordered_map> participants_; - std::unordered_map> topics_; - std::unordered_map> publishers_; - std::unordered_map> subscribers_; - std::unordered_map> datawriters_; - std::unordered_map> datareaders_; - std::unordered_map> requesters_; - std::unordered_map> repliers_; - - middleware::CallbackFactory& callback_factory_; -}; - -} // namespace uxr -} // namespace eprosima - -#endif // UXR_AGENT_MIDDLEWARE_FAST_FAST_MIDDLEWARE_HPP_ diff --git a/include/uxr/agent/middleware/fastdds/FastDDSEntities.hpp b/include/uxr/agent/middleware/fastdds/FastDDSEntities.hpp index cc55d0a89..98e93ab04 100644 --- a/include/uxr/agent/middleware/fastdds/FastDDSEntities.hpp +++ b/include/uxr/agent/middleware/fastdds/FastDDSEntities.hpp @@ -15,14 +15,13 @@ #ifndef UXR__AGENT__MIDDLEWARE__FASTDDS__ENTITIES_HPP_ #define UXR__AGENT__MIDDLEWARE__FASTDDS__ENTITIES_HPP_ -//#include +#include #include #include #include #include #include #include -#include #include #include @@ -61,10 +60,10 @@ class FastDDSParticipant // Proxy methods int16_t domain_id() const { return domain_id_; } - fastrtps::rtps::GUID_t guid() const { return ptr_->guid(); } + fastdds::rtps::GUID_t guid() const { return ptr_->guid(); } fastdds::dds::DomainParticipant* get_ptr() const { return ptr_; } - ReturnCode_t unregister_type( + fastdds::dds::ReturnCode_t unregister_type( const std::string& typeName); fastdds::dds::Topic* create_topic( @@ -74,7 +73,7 @@ class FastDDSParticipant fastdds::dds::TopicListener* listener = nullptr, const fastdds::dds::StatusMask& mask = fastdds::dds::StatusMask::all()); - ReturnCode_t delete_topic( + fastdds::dds::ReturnCode_t delete_topic( fastdds::dds::Topic* topic); fastdds::dds::Publisher* create_publisher( @@ -82,7 +81,7 @@ class FastDDSParticipant fastdds::dds::PublisherListener* listener = nullptr, const fastdds::dds::StatusMask& mask = fastdds::dds::StatusMask::all()); - ReturnCode_t delete_publisher( + fastdds::dds::ReturnCode_t delete_publisher( fastdds::dds::Publisher* publisher); fastdds::dds::Subscriber* create_subscriber( @@ -90,7 +89,7 @@ class FastDDSParticipant fastdds::dds::SubscriberListener* listener = nullptr, const fastdds::dds::StatusMask& mask = fastdds::dds::StatusMask::all()); - ReturnCode_t delete_subscriber( + fastdds::dds::ReturnCode_t delete_subscriber( fastdds::dds::Subscriber* subscriber); // Types and topics registration @@ -159,22 +158,17 @@ class FastDDSTopic ~FastDDSTopic(); - bool create_by_ref(const std::string& ref); - bool create_by_xml(const std::string& xml); bool create_by_name_type(const std::string& name, - const std::shared_ptr& type); + const std::shared_ptr& type, + const fastdds::dds::TopicQos& qos); bool match_from_ref(const std::string& ref) const; bool match_from_xml(const std::string& xml) const; bool match_from_bin(const dds::xrce::OBJK_Topic_Binary& topic_xrce) const; - bool match(const fastrtps::TopicAttributes& attrs) const; const std::string& get_name() const { return ptr_->get_name(); } const std::shared_ptr& get_type() const { return type_; } fastdds::dds::Topic* get_ptr() const { return ptr_; } -private: - bool create_by_attributes(const fastrtps::TopicAttributes& attrs); - private: std::shared_ptr participant_; std::shared_ptr type_; @@ -198,13 +192,19 @@ class FastDDSPublisher bool create_by_xml(const std::string& xml); bool create_by_bin(const dds::xrce::OBJK_Publisher_Binary& publisher_xrce); + fastdds::dds::Publisher* get_ptr() const { return ptr_; } + fastdds::dds::DataWriter* create_datawriter( fastdds::dds::Topic* topic, const fastdds::dds::DataWriterQos& qos = fastdds::dds::DATAWRITER_QOS_DEFAULT, fastdds::dds::DataWriterListener* listener = nullptr, const fastdds::dds::StatusMask& mask = fastdds::dds::StatusMask::all()); - ReturnCode_t delete_datawriter( + fastdds::dds::DataWriter* create_datawriter_with_profile( + fastdds::dds::Topic* topic, + const std::string& profile_name); + + fastdds::dds::ReturnCode_t delete_datawriter( fastdds::dds::DataWriter* writer); std::shared_ptr get_participant() const { return participant_; } @@ -231,13 +231,19 @@ class FastDDSSubscriber bool create_by_xml(const std::string& xml); bool create_by_bin(const dds::xrce::OBJK_Subscriber_Binary& subscriber_xrce); + fastdds::dds::Subscriber* get_ptr() const { return ptr_; } + fastdds::dds::DataReader* create_datareader( fastdds::dds::TopicDescription* topic, const fastdds::dds::DataReaderQos& reader_qos, fastdds::dds::DataReaderListener* listener = nullptr, const fastdds::dds::StatusMask& mask = fastdds::dds::StatusMask::all()); - ReturnCode_t delete_datareader( + fastdds::dds::DataReader* create_datareader_with_profile( + fastdds::dds::TopicDescription* topic, + const std::string& profile_name); + + fastdds::dds::ReturnCode_t delete_datareader( fastdds::dds::DataReader* reader); @@ -263,14 +269,15 @@ class FastDDSDataWriter ~FastDDSDataWriter(); - fastrtps::rtps::GUID_t guid() const { return ptr_->guid(); } + fastdds::rtps::GUID_t guid() const { return ptr_->guid(); } bool create_by_ref(const std::string& ref); bool create_by_xml(const std::string& xml); bool create_by_bin( const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce, std::shared_ptr topic); - bool match(const fastrtps::PublisherAttributes& attrs) const; + bool match_from_ref(const std::string& ref) const; + bool match_from_xml(const std::string& xml) const; bool match_from_bin(const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) const; bool write(const std::vector& data); const fastdds::dds::DataWriter* ptr() const; @@ -295,7 +302,7 @@ class FastDDSDataReader ~FastDDSDataReader(); - fastrtps::rtps::GUID_t guid() const { return ptr_->guid(); } + fastdds::rtps::GUID_t guid() const { return ptr_->guid(); } bool create_by_ref(const std::string& ref); bool create_by_xml(const std::string& xml); @@ -339,11 +346,12 @@ class FastDDSRequester ~FastDDSRequester(); - fastrtps::rtps::GUID_t guid_datareader() const { return datareader_ptr_->guid(); } - fastrtps::rtps::GUID_t guid_datawriter() const { return datawriter_ptr_->guid(); } + bool create_by_qos( + const fastdds::dds::RequesterQos& qos); + + fastdds::rtps::GUID_t guid_datareader() const { return datareader_ptr_->guid(); } + fastdds::rtps::GUID_t guid_datawriter() const { return datawriter_ptr_->guid(); } - bool create_by_attributes( - const fastrtps::RequesterAttributes& attrs); bool match_from_ref(const std::string& ref) const; bool match_from_xml(const std::string& xml) const; bool match_from_bin(const dds::xrce::OBJK_Requester_Binary& requester_xrce) const; @@ -364,9 +372,6 @@ class FastDDSRequester const fastdds::dds::DataReader* get_reply_datareader() const; -private: - bool match(const fastrtps::RequesterAttributes& attrs) const; - private: std::shared_ptr participant_; @@ -405,11 +410,13 @@ class FastDDSReplier ~FastDDSReplier(); - fastrtps::rtps::GUID_t guid_datareader() const { return datareader_ptr_->guid(); } - fastrtps::rtps::GUID_t guid_datawriter() const { return datawriter_ptr_->guid(); } - bool create_by_attributes( - const fastrtps::ReplierAttributes& attrs); + bool create_by_qos( + const fastdds::dds::ReplierQos& qos); + + fastdds::rtps::GUID_t guid_datareader() const { return datareader_ptr_->guid(); } + fastdds::rtps::GUID_t guid_datawriter() const { return datawriter_ptr_->guid(); } + bool match_from_ref(const std::string& ref) const; bool match_from_xml(const std::string& xml) const; bool match_from_bin(const dds::xrce::OBJK_Replier_Binary& replier_xrce) const; @@ -426,13 +433,12 @@ class FastDDSReplier const fastdds::dds::DataWriter* get_reply_datawriter() const; private: - bool match(const fastrtps::ReplierAttributes& attrs) const; void transform_sample_identity( - const fastrtps::rtps::SampleIdentity& fast_identity, + const fastdds::rtps::SampleIdentity& fast_identity, dds::SampleIdentity& dds_identity); void transport_sample_identity( const dds::SampleIdentity& dds_identity, - fastrtps::rtps::SampleIdentity& fast_identity); + fastdds::rtps::SampleIdentity& fast_identity); private: std::shared_ptr participant_; diff --git a/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp b/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp index e69519378..9ee11c2d3 100644 --- a/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp +++ b/include/uxr/agent/middleware/fastdds/FastDDSMiddleware.hpp @@ -276,14 +276,6 @@ class FastDDSMiddleware : public Middleware uint16_t replier_id, const dds::xrce::OBJK_Replier_Binary& replier_xrce) const override; private: - std::shared_ptr create_requester( - std::shared_ptr& participant, - const fastrtps::RequesterAttributes& attrs); - - std::shared_ptr create_replier( - std::shared_ptr& participant, - const fastrtps::ReplierAttributes& attrs); - int16_t get_domain_id_from_env(); int16_t agent_domain_id_ = 0; diff --git a/include/uxr/agent/middleware/utils/Callbacks.hpp b/include/uxr/agent/middleware/utils/Callbacks.hpp index 4ac0f1bc1..046c677a8 100644 --- a/include/uxr/agent/middleware/utils/Callbacks.hpp +++ b/include/uxr/agent/middleware/utils/Callbacks.hpp @@ -18,9 +18,10 @@ #include #ifdef UAGENT_FAST_PROFILE -#include #include - +#include +#include +#include #endif // UAGENT_FAST_PROFILE #ifdef UAGENT_CED_PROFILE #include @@ -145,11 +146,6 @@ class CallbackFactory switch (middleware_kind) { #ifdef UAGENT_FAST_PROFILE - case Middleware::Kind::FASTRTPS: - { - fast_callback_factory_.add_callback(callback_kind, std::move(callback_function)); - break; - } case Middleware::Kind::FASTDDS: { fast_dds_callback_factory_.add_callback(callback_kind, std::move(callback_function)); @@ -185,11 +181,6 @@ class CallbackFactory switch (middleware_kind) { #ifdef UAGENT_FAST_PROFILE - case Middleware::Kind::FASTRTPS: - { - fast_callback_factory_.execute_callbacks(callback_kind, std::forward(args)...); - break; - } case Middleware::Kind::FASTDDS: { fast_dds_callback_factory_.execute_callbacks(callback_kind, std::forward(args)...); @@ -232,251 +223,6 @@ class CallbackFactory CallbackFactory &&) = delete; #ifdef UAGENT_FAST_PROFILE - /********************************************************************************************************************** - * FastCallbackFactory - **********************************************************************************************************************/ - class FastCallbackFactory - { - public: - /** - * @brief Default constructor. - */ - FastCallbackFactory() = default; - - /** - * @brief Default destructor. - */ - ~FastCallbackFactory() = default; - - /** - * @brief FastCallbackFactory shall not be copy constructible. - */ - FastCallbackFactory( - const FastCallbackFactory &) = delete; - - FastCallbackFactory( - FastCallbackFactory &&) = delete; - - /** - * @brief FastCallbackFactory shall not be copy assignable. - */ - FastCallbackFactory& operator = ( - const FastCallbackFactory &) = delete; - - FastCallbackFactory& operator = ( - FastCallbackFactory &&) = delete; - - /** - * @brief Adds a callback function to the database. - * @param callback_kind Enumerated element from class CallbackKind indicating which callback - * functions need to be executed. - * @param callback_function std::function rvalue variable implementing the callback method logic to be - * included in the callback database. - */ - template - void add_callback( - const CallbackKind& callback_kind, - std::function&& callback_function) - { - switch (callback_kind) - { - case CallbackKind::CREATE_PARTICIPANT: - { - on_create_participant_callbacks_.emplace_back(Callback(std::move(callback_function))); - break; - } - case CallbackKind::CREATE_DATAWRITER: - case CallbackKind::DELETE_DATAWRITER: - case CallbackKind::CREATE_DATAREADER: - case CallbackKind::DELETE_DATAREADER: - case CallbackKind::CREATE_REQUESTER: - case CallbackKind::DELETE_REQUESTER: - case CallbackKind::CREATE_REPLIER: - case CallbackKind::DELETE_REPLIER: - { - // Only implemented in template specialization - break; - } - case CallbackKind::DELETE_PARTICIPANT: - { - on_delete_participant_callbacks_.emplace_back(Callback(std::move(callback_function))); - break; - } - } - } - - /** - * @brief Executes a certain kind of callback functions. - * @param callback_kind Kind of callback functions to be executed. - */ - void execute_callbacks( - const CallbackKind callback_kind ...) const - { - va_list args; - va_start(args, callback_kind); - - switch (callback_kind) - { - case CallbackKind::CREATE_PARTICIPANT: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - for (const auto& on_create_participant_callback : on_create_participant_callbacks_) - { - on_create_participant_callback(participant); - } - break; - } - case CallbackKind::CREATE_DATAWRITER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* datawriter = va_arg(args, fastrtps::Publisher*); - for (const auto& on_create_datawriter_callback : on_create_datawriter_callbacks_) - { - on_create_datawriter_callback(participant, datawriter); - } - break; - } - case CallbackKind::CREATE_DATAREADER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Subscriber* datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_create_datareader_callback : on_create_datareader_callbacks_) - { - on_create_datareader_callback(participant, datareader); - } - break; - } - case CallbackKind::CREATE_REQUESTER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* req_datawriter = va_arg(args, fastrtps::Publisher*); - fastrtps::Subscriber* repl_datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_create_requester_callback : on_create_requester_callbacks_) - { - on_create_requester_callback(participant, req_datawriter, repl_datareader); - } - break; - } - case CallbackKind::CREATE_REPLIER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* repl_datawriter = va_arg(args, fastrtps::Publisher*); - fastrtps::Subscriber* req_datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_create_replier_callback : on_create_replier_callbacks_) - { - on_create_replier_callback(participant, repl_datawriter, req_datareader); - } - break; - } - case CallbackKind::DELETE_PARTICIPANT: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - for (const auto& on_delete_participant_callback : on_delete_participant_callbacks_) - { - on_delete_participant_callback(participant); - } - break; - } - case CallbackKind::DELETE_DATAWRITER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* datawriter = va_arg(args, fastrtps::Publisher*); - for (const auto& on_delete_datawriter_callback : on_delete_datawriter_callbacks_) - { - on_delete_datawriter_callback(participant, datawriter); - } - break; - } - case CallbackKind::DELETE_DATAREADER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Subscriber* datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_delete_datareader_callback : on_delete_datareader_callbacks_) - { - on_delete_datareader_callback(participant, datareader); - } - break; - } - case CallbackKind::DELETE_REQUESTER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* req_datawriter = va_arg(args, fastrtps::Publisher*); - fastrtps::Subscriber* repl_datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_delete_requester_callback : on_delete_requester_callbacks_) - { - on_delete_requester_callback(participant, req_datawriter, repl_datareader); - } - break; - } - case CallbackKind::DELETE_REPLIER: - { - fastrtps::Participant* participant = va_arg(args, fastrtps::Participant*); - fastrtps::Publisher* repl_datawriter = va_arg(args, fastrtps::Publisher*); - fastrtps::Subscriber* req_datareader = va_arg(args, fastrtps::Subscriber*); - for (const auto& on_delete_replier_callback : on_delete_replier_callbacks_) - { - on_delete_replier_callback(participant, repl_datawriter, req_datareader); - } - break; - } - } - va_end(args); - } - - private: - - using CreateParticipantCallback = Callback< - const fastrtps::Participant*>; - using DeleteParticipantCallback = Callback< - const fastrtps::Participant*>; - using CreateDataWriterCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*>; - - using DeleteDataWriterCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*>; - - using CreateDataReaderCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Subscriber*>; - - using DeleteDataReaderCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Subscriber*>; - - using CreateRequesterCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>; - - using DeleteRequesterCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>; - - using CreateReplierCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>; - - using DeleteReplierCallback = Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>; - - std::vector on_create_participant_callbacks_; - std::vector on_delete_participant_callbacks_; - std::vector on_create_datawriter_callbacks_; - std::vector on_delete_datawriter_callbacks_; - std::vector on_create_datareader_callbacks_; - std::vector on_delete_datareader_callbacks_; - std::vector on_create_requester_callbacks_; - std::vector on_delete_requester_callbacks_; - std::vector on_create_replier_callbacks_; - std::vector on_delete_replier_callbacks_; - }; - FastCallbackFactory fast_callback_factory_; /********************************************************************************************************************** * FastDDSCallbackFactory @@ -768,119 +514,6 @@ class CallbackFactory * Template specializations for callback methods **********************************************************************************************************************/ #ifdef UAGENT_FAST_PROFILE -template <> -inline void CallbackFactory::FastCallbackFactory::add_callback< - const fastrtps::Participant*, - const fastrtps::Publisher*>( - const CallbackKind& callback_kind, - std::function&& callback_function) -{ - switch (callback_kind) - { - case CallbackKind::CREATE_DATAWRITER: - { - on_create_datawriter_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*>(std::move(callback_function))); - break; - } - case CallbackKind::DELETE_DATAWRITER: - { - on_delete_datawriter_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*>(std::move(callback_function))); - break; - } - default: - { - break; - } - } -} - -template <> -inline void CallbackFactory::FastCallbackFactory::add_callback< - const fastrtps::Participant*, - const fastrtps::Subscriber*>( - const CallbackKind& callback_kind, - std::function&& callback_function) -{ - switch (callback_kind) - { - case CallbackKind::CREATE_DATAREADER: - { - on_create_datareader_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - case CallbackKind::DELETE_DATAREADER: - { - on_delete_datareader_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - default: - { - break; - } - } -} - -template <> -inline void CallbackFactory::FastCallbackFactory::add_callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>( - const CallbackKind& callback_kind, - std::function&& callback_function) -{ - switch (callback_kind) - { - case CallbackKind::CREATE_REQUESTER: - { - on_create_requester_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - case CallbackKind::CREATE_REPLIER: - { - on_create_replier_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - case CallbackKind::DELETE_REQUESTER: - { - on_delete_requester_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - case CallbackKind::DELETE_REPLIER: - { - on_delete_replier_callbacks_.emplace_back(Callback< - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*>(std::move(callback_function))); - break; - } - default: - { - break; - } - } -} - template <> inline void CallbackFactory::FastDDSCallbackFactory::add_callback< const fastdds::dds::DomainParticipant*, @@ -1017,25 +650,6 @@ inline void CallbackFactory::add_callback<__VA_ARGS__>( \ } #ifdef UAGENT_FAST_PROFILE -#define CALLBACK_FACTORY_ADD_FASTRTPS_CALLBACK(...) \ - CALLBACK_FACTORY_ADD_CALLBACK(Middleware::Kind::FASTRTPS, fast_callback_factory_, __VA_ARGS__) - -CALLBACK_FACTORY_ADD_FASTRTPS_CALLBACK( - const fastrtps::Participant*) - -CALLBACK_FACTORY_ADD_FASTRTPS_CALLBACK( - const fastrtps::Participant*, - const fastrtps::Publisher*) - -CALLBACK_FACTORY_ADD_FASTRTPS_CALLBACK( - const fastrtps::Participant*, - const fastrtps::Subscriber*) - -CALLBACK_FACTORY_ADD_FASTRTPS_CALLBACK( - const fastrtps::Participant*, - const fastrtps::Publisher*, - const fastrtps::Subscriber*) - #define CALLBACK_FACTORY_ADD_FASTDDS_CALLBACK(...) \ CALLBACK_FACTORY_ADD_CALLBACK(Middleware::Kind::FASTDDS, fast_dds_callback_factory_, __VA_ARGS__) diff --git a/include/uxr/agent/transport/custom/CustomAgent.hpp b/include/uxr/agent/transport/custom/CustomAgent.hpp index 14e33c2a8..b889f389b 100644 --- a/include/uxr/agent/transport/custom/CustomAgent.hpp +++ b/include/uxr/agent/transport/custom/CustomAgent.hpp @@ -89,7 +89,7 @@ class CustomAgent : public Server * @brief Constructor. * @param name Name of the middleware to be implemented by this CustomAgent. * @param middleware_kind The middleware selected to represent the XRCE entities - * in the DDS world (FastDDS, FastRTPS, CED...) + * in the DDS world (FastDDS, CED...) * @param framing Whether this agent transport shall use framing or not. * @param init_function Custom user-defined function, called during initialization. * @param fini_function Custom user-defined function, called upon agent's destruction. diff --git a/include/uxr/agent/types/TopicPubSubType.hpp b/include/uxr/agent/types/TopicPubSubType.hpp index bdf519fee..cc784a6ec 100644 --- a/include/uxr/agent/types/TopicPubSubType.hpp +++ b/include/uxr/agent/types/TopicPubSubType.hpp @@ -15,27 +15,40 @@ #ifndef _UXR_AGENT_TYPES_TOPICPUBSUBTYPES_HPP_ #define _UXR_AGENT_TYPES_TOPICPUBSUBTYPES_HPP_ -#include - +#include #include -using namespace eprosima::fastrtps; namespace eprosima { namespace uxr { -class TopicPubSubType: public TopicDataType +class TopicPubSubType: public fastdds::dds::TopicDataType { public: typedef std::vector type; explicit TopicPubSubType(bool with_key); ~TopicPubSubType() override = default; - bool serialize(void* data, rtps::SerializedPayload_t* payload) override; - bool deserialize(rtps::SerializedPayload_t* payload, void* data) override; - std::function getSerializedSizeProvider(void* data) override; - bool getKey(void* data, rtps::InstanceHandle_t* ihandle, bool force_md5 = false) override; - void* createData() override; - void deleteData(void* data) override; + bool serialize(const void* const data, fastdds::rtps::SerializedPayload_t& payload, fastdds::dds::DataRepresentationId_t data_representation) override; + bool deserialize(fastdds::rtps::SerializedPayload_t& payload, void* data) override; + + uint32_t calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t data_representation) override; + + void* create_data() override; + + void delete_data( + void* data) override; + + bool compute_key( + fastdds::rtps::SerializedPayload_t& payload, + fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5) override; + + bool compute_key( + const void* const data, + fastdds::rtps::InstanceHandle_t& ihandle, + bool force_md5) override; }; } // namespace uxr diff --git a/src/cpp/Agent.cpp b/src/cpp/Agent.cpp index 575d4e36b..cc612de28 100644 --- a/src/cpp/Agent.cpp +++ b/src/cpp/Agent.cpp @@ -657,22 +657,6 @@ UXR_AGENT_EXPORT void Agent::add_middleware_callback<__VA_ARGS__>( \ std::function &&); #ifdef UAGENT_FAST_PROFILE -AGENT_ADD_MW_CB( - const eprosima::fastrtps::Participant *) - -AGENT_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Publisher *) - -AGENT_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Subscriber *) - -AGENT_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Publisher *, - const eprosima::fastrtps::Subscriber *) - AGENT_ADD_MW_CB( const eprosima::fastdds::dds::DomainParticipant *) diff --git a/src/cpp/AgentInstance.cpp b/src/cpp/AgentInstance.cpp index df551dca8..52342ef06 100644 --- a/src/cpp/AgentInstance.cpp +++ b/src/cpp/AgentInstance.cpp @@ -117,7 +117,7 @@ void AgentInstance::stop() { exit_signal.notify_all(); agent_thread_.join(); - } + } } #endif @@ -139,22 +139,6 @@ UXR_AGENT_EXPORT void AgentInstance::add_middleware_callback<__VA_ARGS__>( \ std::function &&); #ifdef UAGENT_FAST_PROFILE -AGENTINSTANCE_ADD_MW_CB( - const eprosima::fastrtps::Participant *) - -AGENTINSTANCE_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Publisher *) - -AGENTINSTANCE_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Subscriber *) - -AGENTINSTANCE_ADD_MW_CB( - const eprosima::fastrtps::Participant *, - const eprosima::fastrtps::Publisher *, - const eprosima::fastrtps::Subscriber *) - AGENTINSTANCE_ADD_MW_CB( const eprosima::fastdds::dds::DomainParticipant *) diff --git a/src/cpp/Root.cpp b/src/cpp/Root.cpp index 23d07f216..a0292467c 100644 --- a/src/cpp/Root.cpp +++ b/src/cpp/Root.cpp @@ -17,10 +17,7 @@ #include #include -#ifdef UAGENT_FAST_PROFILE -// TODO (#5047): replace Fast RTPS dependency by XML parser library. -#include -#endif +#include #include #include @@ -86,7 +83,7 @@ dds::xrce::ResultStatus Root::create_client( std::unordered_map client_properties; if (client_representation.properties()) - { + { auto v = *client_representation.properties(); for (auto it_props = v.begin(); it_props != v.end(); ++it_props) { @@ -238,7 +235,7 @@ bool Root::get_next_client(std::shared_ptr& next_client) bool Root::load_config_file(const std::string& file_path) { #ifdef UAGENT_FAST_PROFILE - return fastrtps::xmlparser::XMLP_ret::XML_OK == fastrtps::xmlparser::XMLProfileManager::loadXMLFile(file_path); + return fastdds::dds::RETCODE_OK == fastdds::dds::DomainParticipantFactory::get_instance()->load_XML_profiles_file(file_path.c_str()); #else (void) file_path; return false; diff --git a/src/cpp/client/ProxyClient.cpp b/src/cpp/client/ProxyClient.cpp index 1d77ce09e..0fdad100b 100644 --- a/src/cpp/client/ProxyClient.cpp +++ b/src/cpp/client/ProxyClient.cpp @@ -23,7 +23,6 @@ #include #ifdef UAGENT_FAST_PROFILE -#include #include #endif @@ -57,11 +56,6 @@ ProxyClient::ProxyClient( conversion::clientkey_to_raw(representation.client_key())); } #ifdef UAGENT_FAST_PROFILE - case Middleware::Kind::FASTRTPS: - { - middleware_.reset(new FastMiddleware()); - break; - } case Middleware::Kind::FASTDDS: { bool intraprocess_enabled = diff --git a/src/cpp/middleware/fast/FastEntities.cpp b/src/cpp/middleware/fast/FastEntities.cpp deleted file mode 100644 index b3c14b3e1..000000000 --- a/src/cpp/middleware/fast/FastEntities.cpp +++ /dev/null @@ -1,579 +0,0 @@ -// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include "../../xmlobjects/xmlobjects.h" - -namespace eprosima { -namespace uxr { - -/********************************************************************************************************************** - * FastListener - **********************************************************************************************************************/ -void FastListener::onParticipantDiscovery( - fastrtps::Participant*, - fastrtps::rtps::ParticipantDiscoveryInfo&& info) -{ - if (info.status == eprosima::fastrtps::rtps::ParticipantDiscoveryInfo::DISCOVERED_PARTICIPANT) - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("matched"), - "entity_id: {}, guid_prefix: {}", - info.info.m_guid.entityId, - info.info.m_guid.guidPrefix); - } - else - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("unmatched"), - "entity_id: {}, guid_prefix: {}", - info.info.m_guid.entityId, - info.info.m_guid.guidPrefix); - } -} - -void FastListener::onPublicationMatched( - fastrtps::Publisher*, - fastrtps::rtps::MatchingInfo& info) -{ - if (info.status == fastrtps::rtps::MATCHED_MATCHING) - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("matched"), - "entity_id: {}, guid_prefix: {}", - info.remoteEndpointGuid.entityId, - info.remoteEndpointGuid.guidPrefix); - } - else - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("unmatched"), - "entity_id: {}, guid_prefix: {}", - info.remoteEndpointGuid.entityId, - info.remoteEndpointGuid.guidPrefix); - } -} - -void FastListener::onSubscriptionMatched( - fastrtps::Subscriber*, - fastrtps::rtps::MatchingInfo& info) -{ - if (info.status == fastrtps::rtps::MATCHED_MATCHING) - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("matched"), - "entity_id: {}, guid_prefix: {}", - info.remoteEndpointGuid.entityId, - info.remoteEndpointGuid.guidPrefix); - } - else - { - UXR_AGENT_LOG_TRACE( - UXR_DECORATE_WHITE("unmatched"), - "entity_id: {}, guid_prefix: {}", - info.remoteEndpointGuid.entityId, - info.remoteEndpointGuid.guidPrefix); - } -} - -/********************************************************************************************************************** - * FastParticipant - **********************************************************************************************************************/ -FastParticipant::FastParticipant( - fastrtps::Participant* impl) - : impl_{impl} - , type_register_{} - , topic_register_{} -{} - -FastParticipant::~FastParticipant() -{ - fastrtps::Domain::removeParticipant(impl_); -} - -bool FastParticipant::match( - const fastrtps::ParticipantAttributes& attrs) const -{ - return attrs == impl_->getAttributes(); -} - -bool FastParticipant::register_type( - const std::shared_ptr& type) -{ - return fastrtps::Domain::registerType(impl_, type.get()) - && type_register_.emplace(type->getName(), type).second; -} - -bool FastParticipant::unregister_type( - const std::string& type_name) -{ - return (1 == type_register_.erase(type_name)) - && fastrtps::Domain::unregisterType(impl_, type_name.c_str()); -} - -std::shared_ptr FastParticipant::find_type( - const std::string& type_name) const -{ - std::shared_ptr type; - auto it = type_register_.find(type_name); - if (it != type_register_.end()) - { - type = it->second.lock(); - } - return type; -} - -bool FastParticipant::register_topic( - const std::shared_ptr& topic) -{ - return topic_register_.emplace(topic->get_name(), topic).second; -} - -bool FastParticipant::unregister_topic( - const std::string& topic_name) -{ - return (1 == topic_register_.erase(topic_name)); -} - -std::shared_ptr FastParticipant::find_topic( - const std::string& topic_name) const -{ - std::shared_ptr topic; - auto it = topic_register_.find(topic_name); - if (it != topic_register_.end()) - { - topic = it->second.lock(); - } - return topic; -} - -int16_t FastParticipant::domain_id() const -{ - return (int16_t) impl_->getAttributes().domainId; -} - -const fastrtps::rtps::GUID_t& FastParticipant::get_guid() const -{ - return impl_->getGuid(); -} - -/********************************************************************************************************************** - * FastTopic - **********************************************************************************************************************/ -FastType::FastType( - const std::shared_ptr& participant) - : TopicPubSubType{false} - , participant_{participant} -{} - -FastType::~FastType() -{ - participant_->unregister_type(getName()); -} - -FastTopic::FastTopic( - const std::string& name, - const std::shared_ptr& type, - const std::shared_ptr& participant) - : name_{name} - , type_{type} - , participant_(participant) -{} - -FastTopic::~FastTopic() -{ - participant_->unregister_topic(name_); -} - -bool FastTopic::match(const fastrtps::TopicAttributes& attrs) const -{ - return (attrs.getTopicName() == name_) - && (0 == std::strcmp(type_->getName(), attrs.getTopicDataType().c_str())) - && (type_->m_isGetKeyDefined == (attrs.getTopicKind() == fastrtps::rtps::TopicKind_t::WITH_KEY)); -} - -/********************************************************************************************************************** - * FastDataWriter - **********************************************************************************************************************/ -FastDataWriter::FastDataWriter( - fastrtps::Publisher* impl, - const std::shared_ptr& topic, - const std::shared_ptr& publisher) - : impl_{impl} - , topic_{topic} - , publisher_{publisher} -{} - -FastDataWriter::~FastDataWriter() -{ - fastrtps::Domain::removePublisher(impl_); -} - -bool FastDataWriter::match( - const fastrtps::PublisherAttributes& attrs) const -{ - return (attrs == impl_->getAttributes()); -} - -bool FastDataWriter::write( - const std::vector& data) -{ - return impl_->write(&const_cast&>(data)); -} - -bool FastDataWriter::write( - const std::vector& data, - fastrtps::rtps::WriteParams& wparams) -{ - return impl_->write(&const_cast&>(data), wparams); -} - -const fastrtps::rtps::GUID_t& FastDataWriter::get_guid() const -{ - return impl_->getGuid(); -} - -const fastrtps::Participant* FastDataWriter::get_participant() const -{ - return publisher_->get_participant()->get_ptr(); -} - -const fastrtps::Publisher* FastDataWriter::get_ptr() const -{ - return impl_; -} - -/********************************************************************************************************************** - * FastDataReader - **********************************************************************************************************************/ -FastDataReader::FastDataReader( - fastrtps::Subscriber* impl, - const std::shared_ptr& topic, - const std::shared_ptr& subscriber) - : impl_{impl} - , topic_{topic} - , subscriber_{subscriber} -{} - -FastDataReader::~FastDataReader() -{ - fastrtps::Domain::removeSubscriber(impl_); -} - -bool FastDataReader::match( - const fastrtps::SubscriberAttributes& attrs) const -{ - return (attrs == impl_->getAttributes()); -} - -bool FastDataReader::read( - std::vector& data, - std::chrono::milliseconds timeout) -{ - bool rv = false; - eprosima::fastrtps::Duration_t tm = - {int32_t(timeout.count() / 1000), uint32_t(timeout.count() * 1000000)}; - if (impl_->wait_for_unread_samples(tm)) - { - fastrtps::SampleInfo_t info; - rv = impl_->takeNextData(&data, &info); - } - return rv; -} - -bool FastDataReader::read( - std::vector& data, - fastrtps::SampleInfo_t& info, - std::chrono::milliseconds timeout) -{ - bool rv = false; - eprosima::fastrtps::Duration_t tm = - {int32_t(timeout.count() / 1000), uint32_t(timeout.count() * 1000000)}; - if (impl_->wait_for_unread_samples(tm)) - { - rv = impl_->takeNextData(&data, &info); - } - return rv; -} - -const fastrtps::rtps::GUID_t& FastDataReader::get_guid() const -{ - return impl_->getGuid(); -} - -const fastrtps::Participant* FastDataReader::get_participant() const -{ - return subscriber_->get_participant()->get_ptr(); -} - -const fastrtps::Subscriber* FastDataReader::get_ptr() const -{ - return impl_; -} - -/********************************************************************************************************************** - * FastRequester - **********************************************************************************************************************/ -FastRequester::FastRequester( - const std::shared_ptr& datawriter, - const std::shared_ptr& datareader) - : datawriter_{datawriter} - , datareader_{datareader} - , publisher_id_{} - , sequence_to_sequence_{} -{ - std::copy( - std::begin(datawriter_->get_guid().guidPrefix.value), - std::end(datawriter_->get_guid().guidPrefix.value), - publisher_id_.guidPrefix().begin()); - std::copy( - std::begin(datawriter_->get_guid().entityId.value), - std::begin(datawriter_->get_guid().entityId.value) + 3, - publisher_id_.entityId().entityKey().begin()); - publisher_id_.entityId().entityKind() = datawriter_->get_guid().entityId.value[3]; -} - -bool FastRequester::match( - const fastrtps::RequesterAttributes& attrs) const -{ - return datawriter_->match(attrs.publisher) - && datareader_->match(attrs.subscriber); -} - -bool FastRequester::write( - uint32_t sequence_number, - const std::vector& data) -{ - bool rv = true; - try - { - fastrtps::rtps::WriteParams wparams; - rv = datawriter_->write(data, wparams); - if (rv) - { - int64_t sequence = (int64_t)wparams.sample_identity().sequence_number().high << 32; - sequence += wparams.sample_identity().sequence_number().low; - sequence_to_sequence_.emplace(sequence, sequence_number); - } - } - catch(const std::exception&) - { - rv = false; - } - return rv; -} - -bool FastRequester::read( - uint32_t& sequence_number, - std::vector& data, - std::chrono::milliseconds timeout) -{ - bool rv = false; - fastrtps::SampleInfo_t info; - datareader_->read(data, info, timeout); - - if (rv) - { - try - { - if (info.related_sample_identity.writer_guid() == datawriter_->get_guid()) - { - int64_t sequence = (int64_t)info.related_sample_identity.sequence_number().high << 32; - sequence += info.related_sample_identity.sequence_number().low; - auto it = sequence_to_sequence_.find(sequence); - if (it != sequence_to_sequence_.end()) - { - sequence_number = it->second; - sequence_to_sequence_.erase(it); - } - else - { - rv = false; - } - } - else - { - rv = false; - } - } - catch(const std::exception&) - { - rv = false; - } - } - - return rv; -} - -const fastrtps::Participant* FastRequester::get_participant() const -{ - const fastrtps::Participant* participant = datawriter_->get_participant(); - if (participant != datareader_->get_participant()) - { - participant = nullptr; - } - - return participant; -} - -const fastrtps::Publisher* FastRequester::get_request_datawriter() const -{ - return datawriter_->get_ptr(); -} - -const fastrtps::Subscriber* FastRequester::get_reply_datareader() const -{ - return datareader_->get_ptr(); -} - -/********************************************************************************************************************** - * FastReplier - **********************************************************************************************************************/ -FastReplier::FastReplier( - const std::shared_ptr& datawriter, - const std::shared_ptr& datareader) - : datawriter_{datawriter} - , datareader_{datareader} -{} - -bool FastReplier::match( - const fastrtps::ReplierAttributes& attrs) const -{ - return datawriter_->match(attrs.publisher) - && datareader_->match(attrs.subscriber); -} - -inline -void transform_sample_identity( - const fastrtps::rtps::SampleIdentity& fast_identity, - dds::SampleIdentity& dds_identity) -{ - std::copy( - std::begin(fast_identity.writer_guid().guidPrefix.value), - std::end(fast_identity.writer_guid().guidPrefix.value), - dds_identity.writer_guid().guidPrefix().begin()); - std::copy( - std::begin(fast_identity.writer_guid().entityId.value), - std::begin(fast_identity.writer_guid().entityId.value) + 3, - dds_identity.writer_guid().entityId().entityKey().begin()); - dds_identity.writer_guid().entityId().entityKind() = fast_identity.writer_guid().entityId.value[3]; - - dds_identity.sequence_number().high() = fast_identity.sequence_number().high; - dds_identity.sequence_number().low() = fast_identity.sequence_number().low; -} - -inline -void transport_sample_identity( - const dds::SampleIdentity& dds_identity, - fastrtps::rtps::SampleIdentity& fast_identity) -{ - std::copy( - dds_identity.writer_guid().guidPrefix().begin(), - dds_identity.writer_guid().guidPrefix().end(), - std::begin(fast_identity.writer_guid().guidPrefix.value)); - std::copy( - dds_identity.writer_guid().entityId().entityKey().begin(), - dds_identity.writer_guid().entityId().entityKey().end(), - std::begin(fast_identity.writer_guid().entityId.value)); - fast_identity.writer_guid().entityId.value[3] = dds_identity.writer_guid().entityId().entityKind(); - - fast_identity.sequence_number().high = dds_identity.sequence_number().high(); - fast_identity.sequence_number().low = dds_identity.sequence_number().low(); -} - -bool FastReplier::write( - const std::vector& data) -{ - fastcdr::FastBuffer fastbuffer{reinterpret_cast(const_cast(data.data())), data.size()}; - fastcdr::Cdr deserializer(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::CdrVersion::XCDRv1); - - dds::SampleIdentity sample_identity; - sample_identity.deserialize(deserializer); - - fastrtps::rtps::WriteParams wparams; - transport_sample_identity(sample_identity, wparams.related_sample_identity()); - - std::vector output_data(data.size() - deserializer.get_serialized_data_length()); - deserializer.deserialize_array(output_data.data(), output_data.size()); - - return datawriter_->write(output_data, wparams); -} - -bool FastReplier::read( - std::vector& data, - std::chrono::milliseconds timeout) -{ - std::vector temp_data; - bool rv = false; - fastrtps::SampleInfo_t info; - datareader_->read(temp_data, info, timeout); - - if (rv) - { - dds::SampleIdentity sample_identity; - transform_sample_identity(info.sample_identity, sample_identity); - - data.clear(); - data.resize(sample_identity.getCdrSerializedSize() + temp_data.size()); - - fastcdr::FastBuffer fastbuffer{reinterpret_cast(data.data()), data.size()}; - fastcdr::Cdr serializer(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN, eprosima::fastcdr::CdrVersion::XCDRv1); - - try - { - sample_identity.serialize(serializer); - serializer.serialize_array(temp_data.data(), temp_data.size()); - } - catch(const std::exception&) - { - rv = false; - } - } - - return rv; -} - -const fastrtps::Participant* FastReplier::get_participant() const -{ - const fastrtps::Participant* participant = datawriter_->get_participant(); - if (participant != datareader_->get_participant()) - { - participant = nullptr; - } - - return participant; -} - -const fastrtps::Subscriber* FastReplier::get_request_datareader() const -{ - return datareader_->get_ptr(); -} - -const fastrtps::Publisher* FastReplier::get_reply_datawriter() const -{ - return datawriter_->get_ptr(); -} - -} // namespace uxr -} // namespace eprosima diff --git a/src/cpp/middleware/fast/FastMiddleware.cpp b/src/cpp/middleware/fast/FastMiddleware.cpp deleted file mode 100644 index e8c4afd0a..000000000 --- a/src/cpp/middleware/fast/FastMiddleware.cpp +++ /dev/null @@ -1,977 +0,0 @@ -// Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include -#include -#include "../../xmlobjects/xmlobjects.h" - -namespace eprosima { -namespace uxr { - -using namespace fastrtps::xmlparser; - -FastMiddleware::FastMiddleware() - : participants_() - , topics_() - , publishers_() - , subscribers_() - , datawriters_() - , datareaders_() - , requesters_() - , repliers_() - , callback_factory_(callback_factory_.getInstance()) -{ -} - -/********************************************************************************************************************** - * Create functions. - **********************************************************************************************************************/ -bool FastMiddleware::create_participant_by_ref( - uint16_t participant_id, - int16_t domain_id, - const std::string& ref) -{ - bool rv = false; - fastrtps::ParticipantAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) - { - if(domain_id != UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF) { - attrs.domainId = domain_id; - } - fastrtps::Participant* impl = fastrtps::Domain::createParticipant(attrs, &listener_); - if (nullptr != impl) - { - std::shared_ptr participant(new FastParticipant(impl)); - auto emplace_res = participants_.emplace(participant_id, std::move(participant)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_PARTICIPANT, impl); - } - } - } - return rv; -} - -bool FastMiddleware::create_participant_by_xml( - uint16_t participant_id, - int16_t domain_id, - const std::string& xml) -{ - (void) domain_id; - bool rv = false; - fastrtps::ParticipantAttributes attrs; - if (xmlobjects::parse_participant(xml.data(), xml.size(), attrs)) - { - attrs.domainId = uint32_t(domain_id); - fastrtps::Participant* impl = fastrtps::Domain::createParticipant(attrs, &listener_); - if (nullptr != impl) - { - std::shared_ptr participant(new FastParticipant(impl)); - auto emplace_res = participants_.emplace(participant_id, std::move(participant)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_PARTICIPANT, impl); - } - } - } - return rv; -} - -static -std::shared_ptr create_topic( - std::shared_ptr& participant, - const fastrtps::TopicAttributes& attrs) -{ - std::shared_ptr topic = participant->find_topic(attrs.getTopicName().c_str()); - if (topic) - { - if (0 != std::strcmp(attrs.getTopicDataType().c_str(), topic->get_type()->getName())) - { - topic.reset(); - } - } - else - { - const char * type_name = attrs.getTopicDataType().c_str(); - std::shared_ptr type = participant->find_type(type_name); - if (!type) - { - type = std::make_shared(participant); - type->setName(type_name); - type->m_isGetKeyDefined = (attrs.getTopicKind() == fastrtps::rtps::TopicKind_t::WITH_KEY); - if (!participant->register_type(type)) - { - type.reset(); - } - } - - if (type) - { - topic = std::make_shared(attrs.getTopicName().c_str(), type, participant); - if (!participant->register_topic(topic)) - { - topic.reset(); - } - } - } - return topic; -} - -bool FastMiddleware::create_topic_by_ref( - uint16_t topic_id, - uint16_t participant_id, - const std::string& ref) -{ - bool rv = false; - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) - { - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr topic = create_topic(it_participant->second, attrs); - rv = topic && topics_.emplace(topic_id, std::move(topic)).second; - } - } - return rv; -} - -bool FastMiddleware::create_topic_by_xml( - uint16_t topic_id, - uint16_t participant_id, - const std::string& xml) -{ - bool rv = false; - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) - { - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr topic = create_topic(it_participant->second, attrs); - rv = topic && topics_.emplace(topic_id, std::move(topic)).second; - } - } - return rv; -} - -bool FastMiddleware::create_publisher_by_xml( - uint16_t publisher_id, - uint16_t participant_id, - const std::string&) -{ - bool rv = false; - auto it = participants_.find(participant_id); - if (it != participants_.end()) - { - std::shared_ptr publisher = std::make_shared(it->second); - rv = publishers_.emplace(publisher_id, std::move(publisher)).second; - } - return rv; -} - -bool FastMiddleware::create_subscriber_by_xml( - uint16_t subscriber_id, - uint16_t participant_id, - const std::string&) -{ - bool rv = false; - auto it = participants_.find(participant_id); - if (it != participants_.end()) - { - std::shared_ptr subscriber = std::make_shared(it->second); - rv = subscribers_.emplace(subscriber_id, std::move(subscriber)).second; - } - return rv; -} - -inline -std::shared_ptr create_datawriter( - const fastrtps::PublisherAttributes& attrs, - fastrtps::PublisherListener* listener, - const std::shared_ptr& publisher) -{ - std::shared_ptr datawriter; - const std::shared_ptr& participant = publisher->get_participant(); - std::shared_ptr topic = - participant->find_topic(attrs.topic.getTopicName().to_string()); - if (topic) - { - fastrtps::Publisher* impl = - fastrtps::Domain::createPublisher(participant->get_ptr(), attrs, listener); - if (nullptr != impl) - { - datawriter = std::make_shared(impl, topic, publisher); - } - } - return datawriter; -} - -bool FastMiddleware::create_datawriter_by_ref( - uint16_t datawriter_id, - uint16_t publisher_id, - const std::string& ref) -{ - bool rv = false; - auto it_publisher = publishers_.find(publisher_id); - if (publishers_.end() != it_publisher) - { - fastrtps::PublisherAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(ref, attrs)) - { - std::shared_ptr datawriter = - create_datawriter(attrs, &listener_, it_publisher->second); - if (nullptr == datawriter) - { - return false; - } - auto emplace_res = datawriters_.emplace(datawriter_id, std::move(datawriter)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_DATAWRITER, - emplace_res.first->second->get_participant(), - emplace_res.first->second->get_ptr()); - } - } - } - return rv; -} - -bool FastMiddleware::create_datawriter_by_xml( - uint16_t datawriter_id, - uint16_t publisher_id, - const std::string& xml) -{ - bool rv = false; - auto it_publisher = publishers_.find(publisher_id); - if (publishers_.end() != it_publisher) - { - fastrtps::PublisherAttributes attrs; - if (xmlobjects::parse_publisher(xml.data(), xml.size(), attrs)) - { - std::shared_ptr datawriter = - create_datawriter(attrs, &listener_, it_publisher->second); - if (nullptr == datawriter) - { - return false; - } - auto emplace_res = datawriters_.emplace(datawriter_id, std::move(datawriter)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_DATAWRITER, - emplace_res.first->second->get_participant(), - emplace_res.first->second->get_ptr()); - } - } - } - return rv; -} - -inline -std::shared_ptr create_datareader( - const fastrtps::SubscriberAttributes& attrs, - fastrtps::SubscriberListener* listener, - const std::shared_ptr& subscriber) -{ - std::shared_ptr datareader; - const std::shared_ptr& participant = subscriber->get_participant(); - std::shared_ptr topic = - participant->find_topic(attrs.topic.getTopicName().to_string()); - if (topic) - { - fastrtps::Subscriber* impl = - fastrtps::Domain::createSubscriber(participant->get_ptr(), attrs, listener); - if (nullptr != impl) - { - datareader = std::make_shared(impl, topic, subscriber); - } - } - return datareader; -} - -bool FastMiddleware::create_datareader_by_ref( - uint16_t datareader_id, - uint16_t subscriber_id, - const std::string& ref) -{ - bool rv = false; - auto it_subscriber = subscribers_.find(subscriber_id); - if (subscribers_.end() != it_subscriber) - { - fastrtps::SubscriberAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(ref, attrs)) - { - std::shared_ptr datareader = - create_datareader(attrs, &listener_, it_subscriber->second); - if (nullptr == datareader) - { - return false; - } - auto emplace_res = datareaders_.emplace(datareader_id, std::move(datareader)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_DATAREADER, - emplace_res.first->second->get_participant(), - emplace_res.first->second->get_ptr()); - } - } - } - return rv; -} - -bool FastMiddleware::create_datareader_by_xml( - uint16_t datareader_id, - uint16_t subscriber_id, - const std::string& xml) -{ - bool rv = false; - auto it_subscriber = subscribers_.find(subscriber_id); - if (subscribers_.end() != it_subscriber) - { - fastrtps::SubscriberAttributes attrs; - if (xmlobjects::parse_subscriber(xml.data(), xml.size(), attrs)) - { - std::shared_ptr datareader = - create_datareader(attrs, &listener_, it_subscriber->second); - if (nullptr == datareader) - { - return false; - } - auto emplace_res = datareaders_.emplace(datareader_id, std::move(datareader)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_DATAREADER, - emplace_res.first->second->get_participant(), - emplace_res.first->second->get_ptr()); - } - } - } - return rv; -} - -static -std::shared_ptr create_requester( - const fastrtps::RequesterAttributes& attrs, - FastListener* listener, - std::shared_ptr& participant) -{ - std::shared_ptr requester{}; - std::shared_ptr request_topic = create_topic(participant, attrs.publisher.topic); - std::shared_ptr reply_topic = create_topic(participant, attrs.subscriber.topic); - std::shared_ptr publisher = std::make_shared(participant); - std::shared_ptr datawriter = create_datawriter(attrs.publisher, listener, publisher); - std::shared_ptr subscriber = std::make_shared(participant); - std::shared_ptr datareader = create_datareader(attrs.subscriber, listener, subscriber); - if (datawriter && datareader) - { - requester = std::make_shared(datawriter, datareader); - } - return requester; -} - -bool FastMiddleware::create_requester_by_ref( - uint16_t requester_id, - uint16_t participant_id, - const std::string& ref) -{ - bool rv = false; - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr& participant = it_participant->second; - fastrtps::RequesterAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillRequesterAttributes(ref, attrs)) - { - std::shared_ptr requester = create_requester(attrs, &listener_, participant); - if (nullptr == requester) - { - return false; - } - auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_REQUESTER, - participant->get_ptr(), - emplace_res.first->second->get_request_datawriter(), - emplace_res.first->second->get_reply_datareader()); - } - } - } - return rv; -} - -bool FastMiddleware::create_requester_by_xml( - uint16_t requester_id, - uint16_t participant_id, - const std::string& xml) -{ - bool rv = false; - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr& participant = it_participant->second; - fastrtps::RequesterAttributes attrs; - if (xmlobjects::parse_requester(xml.data(), xml.size(), attrs)) - { - std::shared_ptr requester = create_requester(attrs, &listener_, participant); - if (nullptr == requester) - { - return false; - } - auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_REQUESTER, - participant->get_ptr(), - emplace_res.first->second->get_request_datawriter(), - emplace_res.first->second->get_reply_datareader()); - } - } - } - return rv; -} - -static -std::shared_ptr create_replier( - const fastrtps::ReplierAttributes& attrs, - FastListener* listener, - std::shared_ptr& participant) -{ - std::shared_ptr replier{}; - std::shared_ptr request_topic = create_topic(participant, attrs.subscriber.topic); - std::shared_ptr reply_topic = create_topic(participant, attrs.publisher.topic); - std::shared_ptr publisher = std::make_shared(participant); - std::shared_ptr datawriter = create_datawriter(attrs.publisher, listener, publisher); - std::shared_ptr subscriber = std::make_shared(participant); - std::shared_ptr datareader = create_datareader(attrs.subscriber, listener, subscriber); - if (datawriter && datareader) - { - replier = std::make_shared(datawriter, datareader); - } - return replier; -} - -bool FastMiddleware::create_replier_by_ref( - uint16_t replier_id, - uint16_t participant_id, - const std::string& ref) -{ - bool rv = false; - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr& participant = it_participant->second; - fastrtps::ReplierAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillReplierAttributes(ref, attrs)) - { - std::shared_ptr replier = create_replier(attrs, &listener_, participant); - if (nullptr == replier) - { - return false; - } - auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_REPLIER, - participant->get_ptr(), - emplace_res.first->second->get_reply_datawriter(), - emplace_res.first->second->get_request_datareader()); - } - } - } - return rv; -} - -bool FastMiddleware::create_replier_by_xml( - uint16_t replier_id, - uint16_t participant_id, - const std::string& xml) -{ - bool rv = false; - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) - { - std::shared_ptr& participant = it_participant->second; - fastrtps::ReplierAttributes attrs; - if (xmlobjects::parse_replier(xml.data(), xml.size(), attrs)) - { - std::shared_ptr replier = create_replier(attrs, &listener_, participant); - if (nullptr == replier) - { - return false; - } - auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_REPLIER, - participant->get_ptr(), - emplace_res.first->second->get_reply_datawriter(), - emplace_res.first->second->get_request_datareader()); - } - } - } - return rv; -} - -/********************************************************************************************************************** - * Delete functions. - **********************************************************************************************************************/ -bool FastMiddleware::delete_participant( - uint16_t participant_id) -{ - auto it = participants_.find(participant_id); - if (it == participants_.end()) - { - return false; - } - else - { - auto participant = it->second; - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_PARTICIPANT, - participant->get_ptr()); - - participants_.erase(participant_id); - return true; - } -} - -bool FastMiddleware::delete_topic( - uint16_t topic_id) -{ - return (0 != topics_.erase(topic_id)); -} - -bool FastMiddleware::delete_publisher( - uint16_t publisher_id) -{ - return (0 != publishers_.erase(publisher_id)); -} - -bool FastMiddleware::delete_subscriber( - uint16_t subscriber_id) -{ - return (0 != subscribers_.erase(subscriber_id)); -} - -bool FastMiddleware::delete_datawriter( - uint16_t datawriter_id) -{ - auto it = datawriters_.find(datawriter_id); - if (it == datawriters_.end()) - { - return false; - } - else - { - auto datawriter = it->second; - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_DATAWRITER, - datawriter->get_participant(), - datawriter->get_ptr()); - - datawriters_.erase(datawriter_id); - return true; - } -} - -bool FastMiddleware::delete_datareader( - uint16_t datareader_id) -{ - auto it = datareaders_.find(datareader_id); - if (it == datareaders_.end()) - { - return false; - } - else - { - auto datareader = it->second; - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_DATAREADER, - datareader->get_participant(), - datareader->get_ptr()); - - datareaders_.erase(datareader_id); - return true; - } -} - -bool FastMiddleware::delete_requester( - uint16_t requester_id) -{ - auto it = requesters_.find(requester_id); - if (it == requesters_.end()) - { - return false; - } - else - { - auto requester = it->second; - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_REQUESTER, - requester->get_participant(), - requester->get_request_datawriter(), - requester->get_reply_datareader()); - - requesters_.erase(requester_id); - return true; - } -} - -bool FastMiddleware::delete_replier( - uint16_t replier_id) -{ - auto it = repliers_.find(replier_id); - if (it == repliers_.end()) - { - return false; - } - else - { - auto replier = it->second; - callback_factory_.execute_callbacks(Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_REPLIER, - replier->get_participant(), - replier->get_reply_datawriter(), - replier->get_request_datareader()); - - repliers_.erase(replier_id); - return true; - } -} - -/********************************************************************************************************************** - * Write/Read functions. - **********************************************************************************************************************/ -bool FastMiddleware::write_data( - uint16_t datawriter_id, - const std::vector& data) -{ - bool rv = false; - auto it = datawriters_.find(datawriter_id); - if (datawriters_.end() != it) - { - rv = it->second->write(data); - } - return rv; -} - -bool FastMiddleware::write_request( - uint16_t requester_id, - uint32_t sequence_number, - const std::vector& data) -{ - bool rv = false; - auto it = requesters_.find(requester_id); - if (requesters_.end() != it) - { - rv = it->second->write(sequence_number, data); - } - return rv; -} - -bool FastMiddleware::write_reply( - uint16_t replier_id, - const std::vector& data) -{ - bool rv = false; - auto it = repliers_.find(replier_id); - if (repliers_.end() != it) - { - rv = it->second->write(data); - } - return rv; -} - -bool FastMiddleware::read_data( - uint16_t datareader_id, - std::vector& data, - std::chrono::milliseconds timeout) -{ - bool rv = false; - auto it = datareaders_.find(datareader_id); - if (datareaders_.end() != it) - { - rv = it->second->read(data, timeout); - } - return rv; -} - -bool FastMiddleware::read_request( - uint16_t replier_id, - std::vector& data, - std::chrono::milliseconds timeout) -{ - bool rv = false; - auto it = repliers_.find(replier_id); - if (repliers_.end() != it) - { - rv = it->second->read(data, timeout); - } - return rv; -} - -bool FastMiddleware::read_reply( - uint16_t requester_id, - uint32_t& sequence_number, - std::vector& data, - std::chrono::milliseconds timeout) -{ - bool rv = false; - auto it = requesters_.find(requester_id); - if (requesters_.end() != it) - { - rv = it->second->read(sequence_number, data, timeout); - } - return rv; -} - -/********************************************************************************************************************** - * Matched functions. - **********************************************************************************************************************/ -bool FastMiddleware::matched_participant_from_ref( - uint16_t participant_id, - int16_t domain_id, - const std::string& ref) const -{ - bool rv = false; - auto it = participants_.find(participant_id); - if (participants_.end() != it) - { - fastrtps::ParticipantAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) - { - if(domain_id != UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF) { - attrs.domainId = domain_id; - } - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_participant_from_xml( - uint16_t participant_id, - int16_t domain_id, - const std::string& xml) const -{ - bool rv = false; - auto it = participants_.find(participant_id); - if (participants_.end() != it) - { - fastrtps::ParticipantAttributes attrs; - if (xmlobjects::parse_participant(xml.data(), xml.size(), attrs)) - { - attrs.domainId = uint32_t(domain_id); - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_topic_from_ref( - uint16_t topic_id, - const std::string& ref) const -{ - bool rv = false; - auto it = topics_.find(topic_id); - if (topics_.end() != it) - { - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_topic_from_xml( - uint16_t topic_id, - const std::string& xml) const -{ - bool rv = false; - auto it = topics_.find(topic_id); - if (topics_.end() != it) - { - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_datawriter_from_ref( - uint16_t datawriter_id, - const std::string& ref) const -{ - bool rv = false; - auto it = datawriters_.find(datawriter_id); - if (datawriters_.end() != it) - { - fastrtps::PublisherAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_datawriter_from_xml( - uint16_t datawriter_id, - const std::string& xml) const -{ - bool rv = false; - auto it = datawriters_.find(datawriter_id); - if (datawriters_.end() != it) - { - fastrtps::PublisherAttributes attrs; - if (xmlobjects::parse_publisher(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_datareader_from_ref( - uint16_t datareader_id, - const std::string& ref) const -{ - bool rv = false; - auto it = datareaders_.find(datareader_id); - if (datareaders_.end() != it) - { - fastrtps::SubscriberAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_datareader_from_xml( - uint16_t datareader_id, - const std::string& xml) const -{ - bool rv = false; - auto it = datareaders_.find(datareader_id); - if (datareaders_.end() != it) - { - fastrtps::SubscriberAttributes attrs; - if (xmlobjects::parse_subscriber(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_requester_from_ref( - uint16_t requester_id, - const std::string& ref) const -{ - bool rv = false; - auto it = requesters_.find(requester_id); - if (requesters_.end() != it) - { - fastrtps::RequesterAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillRequesterAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_requester_from_xml( - uint16_t requester_id, - const std::string& xml) const -{ - bool rv = false; - auto it = requesters_.find(requester_id); - if (requesters_.end() != it) - { - fastrtps::RequesterAttributes attrs; - if (xmlobjects::parse_requester(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_replier_from_ref( - uint16_t requester_id, - const std::string& ref) const -{ - bool rv = false; - auto it = repliers_.find(requester_id); - if (repliers_.end() != it) - { - fastrtps::ReplierAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillReplierAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -bool FastMiddleware::matched_replier_from_xml( - uint16_t requester_id, - const std::string& xml) const -{ - bool rv = false; - auto it = repliers_.find(requester_id); - if (repliers_.end() != it) - { - fastrtps::ReplierAttributes attrs; - if (xmlobjects::parse_replier(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } - } - return rv; -} - -} // namespace uxr -} // namespace eprosima diff --git a/src/cpp/middleware/fastdds/FastDDSEntities.cpp b/src/cpp/middleware/fastdds/FastDDSEntities.cpp index 5a1fe7adf..652b509bd 100644 --- a/src/cpp/middleware/fastdds/FastDDSEntities.cpp +++ b/src/cpp/middleware/fastdds/FastDDSEntities.cpp @@ -13,132 +13,16 @@ // limitations under the License. #include -#include -#include #include #include #include +#include #include #include -#include "../../xmlobjects/xmlobjects.h" namespace eprosima { namespace uxr { -using namespace fastrtps::xmlparser; -using eprosima::fastrtps::types::ReturnCode_t; - -static void set_qos_from_attributes( - fastdds::dds::DomainParticipantQos& qos, - const fastrtps::rtps::RTPSParticipantAttributes& attr) -{ - qos.user_data().setValue(attr.userData); - qos.allocation() = attr.allocation; - qos.properties() = attr.properties; - qos.wire_protocol().prefix = attr.prefix; - qos.wire_protocol().participant_id = attr.participantID; - qos.wire_protocol().builtin = attr.builtin; - qos.wire_protocol().port = attr.port; - qos.wire_protocol().throughput_controller = attr.throughputController; - qos.wire_protocol().default_unicast_locator_list = attr.defaultUnicastLocatorList; - qos.wire_protocol().default_multicast_locator_list = attr.defaultMulticastLocatorList; - qos.transport().user_transports = attr.userTransports; - qos.transport().use_builtin_transports = attr.useBuiltinTransports; - qos.transport().send_socket_buffer_size = attr.sendSocketBufferSize; - qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize; - qos.name() = attr.getName(); -} - -static void set_qos_from_attributes( - fastdds::dds::TopicQos& qos, - const fastrtps::TopicAttributes& attr) -{ - qos.history() = attr.historyQos; - qos.resource_limits() = attr.resourceLimitsQos; -} - -static void set_qos_from_attributes( - fastdds::dds::SubscriberQos& qos, - const fastrtps::SubscriberAttributes& attr) -{ - qos.group_data().setValue(attr.qos.m_groupData); - qos.partition() = attr.qos.m_partition; - qos.presentation() = attr.qos.m_presentation; -} - -static void set_qos_from_attributes( - fastdds::dds::PublisherQos& qos, - const fastrtps::PublisherAttributes& attr) -{ - qos.group_data().setValue(attr.qos.m_groupData); - qos.partition() = attr.qos.m_partition; - qos.presentation() = attr.qos.m_presentation; -} - -static void set_qos_from_attributes( - fastdds::dds::DataWriterQos& qos, - const fastrtps::PublisherAttributes& attr) -{ - qos.writer_resource_limits().matched_subscriber_allocation = attr.matched_subscriber_allocation; - qos.properties() = attr.properties; - qos.throughput_controller() = attr.throughputController; - qos.endpoint().unicast_locator_list = attr.unicastLocatorList; - qos.endpoint().multicast_locator_list = attr.multicastLocatorList; - qos.endpoint().remote_locator_list = attr.remoteLocatorList; - qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; - qos.endpoint().user_defined_id = attr.getUserDefinedID(); - qos.endpoint().entity_id = attr.getEntityID(); - qos.reliable_writer_qos().times = attr.times; - qos.reliable_writer_qos().disable_positive_acks = attr.qos.m_disablePositiveACKs; - qos.durability() = attr.qos.m_durability; - qos.durability_service() = attr.qos.m_durabilityService; - qos.deadline() = attr.qos.m_deadline; - qos.latency_budget() = attr.qos.m_latencyBudget; - qos.liveliness() = attr.qos.m_liveliness; - qos.reliability() = attr.qos.m_reliability; - qos.lifespan() = attr.qos.m_lifespan; - qos.user_data().setValue(attr.qos.m_userData); - qos.ownership() = attr.qos.m_ownership; - qos.ownership_strength() = attr.qos.m_ownershipStrength; - qos.destination_order() = attr.qos.m_destinationOrder; - qos.representation() = attr.qos.representation; - qos.publish_mode() = attr.qos.m_publishMode; - qos.history() = attr.topic.historyQos; - qos.resource_limits() = attr.topic.resourceLimitsQos; -} - -static void set_qos_from_attributes( - fastdds::dds::DataReaderQos& qos, - const fastrtps::SubscriberAttributes& attr) -{ - qos.reader_resource_limits().matched_publisher_allocation = attr.matched_publisher_allocation; - qos.properties() = attr.properties; - qos.expects_inline_qos(attr.expectsInlineQos); - qos.endpoint().unicast_locator_list = attr.unicastLocatorList; - qos.endpoint().multicast_locator_list = attr.multicastLocatorList; - qos.endpoint().remote_locator_list = attr.remoteLocatorList; - qos.endpoint().history_memory_policy = attr.historyMemoryPolicy; - qos.endpoint().user_defined_id = attr.getUserDefinedID(); - qos.endpoint().entity_id = attr.getEntityID(); - qos.reliable_reader_qos().times = attr.times; - qos.reliable_reader_qos().disable_positive_ACKs = attr.qos.m_disablePositiveACKs; - qos.durability() = attr.qos.m_durability; - qos.durability_service() = attr.qos.m_durabilityService; - qos.deadline() = attr.qos.m_deadline; - qos.latency_budget() = attr.qos.m_latencyBudget; - qos.liveliness() = attr.qos.m_liveliness; - qos.reliability() = attr.qos.m_reliability; - qos.lifespan() = attr.qos.m_lifespan; - qos.user_data().setValue(attr.qos.m_userData); - qos.ownership() = attr.qos.m_ownership; - qos.destination_order() = attr.qos.m_destinationOrder; - qos.type_consistency().type_consistency = attr.qos.type_consistency; - qos.type_consistency().representation = attr.qos.representation; - qos.time_based_filter() = attr.qos.m_timeBasedFilter; - qos.history() = attr.topic.historyQos; - qos.resource_limits() = attr.topic.resourceLimitsQos; -} - static void set_qos_from_xrce_object( fastdds::dds::DomainParticipantQos& qos, const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) @@ -176,45 +60,45 @@ static void set_qos_from_xrce_object( const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) { qos.endpoint().history_memory_policy = - fastrtps::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + fastdds::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (datawriter_xrce.has_qos()) { - ReliabilityQosPolicy reliability; + fastdds::dds::ReliabilityQosPolicy reliability; reliability.kind = (datawriter_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_reliable) ? - ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : - ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; + fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : + fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; qos.reliability() = reliability; // TODO set is_ownership_exclusive // TODO set user data - DurabilityQosPolicy durability; + fastdds::dds::DurabilityQosPolicy durability; if (datawriter_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_transient_local) { - durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS; + durability.kind = fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS; } else if (datawriter_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_transient) { - durability.kind = TRANSIENT_DURABILITY_QOS; + durability.kind = fastdds::dds::TRANSIENT_DURABILITY_QOS; } else if (datawriter_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_persistent) { - durability.kind = PERSISTENT_DURABILITY_QOS; + durability.kind = fastdds::dds::PERSISTENT_DURABILITY_QOS; } else { - durability.kind = VOLATILE_DURABILITY_QOS; + durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS; } qos.durability() = durability; - HistoryQosPolicy history; + fastdds::dds::HistoryQosPolicy history; history.kind = (datawriter_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_history_keep_last) ? - HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS : - HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS : + fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; if (datawriter_xrce.qos().base().has_history_depth()) { @@ -224,21 +108,21 @@ static void set_qos_from_xrce_object( if (datawriter_xrce.qos().base().has_deadline_msec()) { - DeadlineQosPolicy deadline; + fastdds::dds::DeadlineQosPolicy deadline; deadline.period = Duration_t(static_cast(datawriter_xrce.qos().base().deadline_msec()/1000.0)); qos.deadline() = deadline; } if (datawriter_xrce.qos().base().has_lifespan_msec()) { - LifespanQosPolicy lifespan; + fastdds::dds::LifespanQosPolicy lifespan; lifespan.duration = Duration_t(static_cast(datawriter_xrce.qos().base().lifespan_msec()/1000.0)); qos.lifespan() = lifespan; } if (datawriter_xrce.qos().has_ownership_strength()) { - OwnershipStrengthQosPolicy ownership_strength; + fastdds::dds::OwnershipStrengthQosPolicy ownership_strength; ownership_strength.value = datawriter_xrce.qos().ownership_strength(); qos.ownership_strength() = ownership_strength; } @@ -250,45 +134,45 @@ static void set_qos_from_xrce_object( const dds::xrce::OBJK_DataReader_Binary& datareader_xrce) { qos.endpoint().history_memory_policy = - fastrtps::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + fastdds::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (datareader_xrce.has_qos()) { - ReliabilityQosPolicy reliability; + fastdds::dds::ReliabilityQosPolicy reliability; reliability.kind = (datareader_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_reliable) ? - ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : - ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; + fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS : + fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; qos.reliability() = reliability; // TODO set is_ownership_exclusive // TODO set user data // TODO set m_contentbased_filter - DurabilityQosPolicy durability; + fastdds::dds::DurabilityQosPolicy durability; if (datareader_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_transient_local) { - durability.kind = TRANSIENT_LOCAL_DURABILITY_QOS; + durability.kind = fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS; } else if (datareader_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_transient) { - durability.kind = TRANSIENT_DURABILITY_QOS; + durability.kind = fastdds::dds::TRANSIENT_DURABILITY_QOS; } else if (datareader_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_durability_persistent) { - durability.kind = PERSISTENT_DURABILITY_QOS; + durability.kind = fastdds::dds::PERSISTENT_DURABILITY_QOS; } else { - durability.kind = VOLATILE_DURABILITY_QOS; + durability.kind = fastdds::dds::VOLATILE_DURABILITY_QOS; } qos.durability() = durability; - HistoryQosPolicy history; + fastdds::dds::HistoryQosPolicy history; history.kind = (datareader_xrce.qos().base().qos_flags() & dds::xrce::EndpointQosFlags::is_history_keep_last) ? - HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS : - HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; + fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS : + fastdds::dds::HistoryQosPolicyKind::KEEP_ALL_HISTORY_QOS; if (datareader_xrce.qos().base().has_history_depth()) { @@ -298,21 +182,21 @@ static void set_qos_from_xrce_object( if (datareader_xrce.qos().base().has_deadline_msec()) { - DeadlineQosPolicy deadline; + fastdds::dds::DeadlineQosPolicy deadline; deadline.period = Duration_t(static_cast(datareader_xrce.qos().base().deadline_msec()/1000.0)); qos.deadline() = deadline; } if (datareader_xrce.qos().base().has_lifespan_msec()) { - LifespanQosPolicy lifespan; + fastdds::dds::LifespanQosPolicy lifespan; lifespan.duration = Duration_t(static_cast(datareader_xrce.qos().base().lifespan_msec()/1000.0)); qos.lifespan() = lifespan; } if (datareader_xrce.qos().has_timebasedfilter_msec()) { - TimeBasedFilterQosPolicy timebased_filter; + fastdds::dds::TimeBasedFilterQosPolicy timebased_filter; timebased_filter.minimum_separation = Duration_t(static_cast(datareader_xrce.qos().timebasedfilter_msec()/1000.0));; qos.time_based_filter() = timebased_filter; } @@ -362,10 +246,9 @@ FastDDSParticipant::~FastDDSParticipant() { if (ptr_) { - // TODO: Not available on foxy (Need FastDDS >= 2.2.0 for declaration and FastDDS >= 2.4.1 for implementation) - // if (ptr_->has_active_entities()) + if (ptr_->has_active_entities()) { - // ptr_->delete_contained_entities(); + ptr_->delete_contained_entities(); } factory_->delete_participant(ptr_); @@ -388,15 +271,10 @@ bool FastDDSParticipant::create_by_xml( const std::string& xml) { bool rv = false; - if (nullptr == ptr_) + fastdds::dds::DomainParticipantQos qos = factory_->get_default_participant_qos(); + if (nullptr == ptr_ && (xml.size() == 0 || fastdds::dds::RETCODE_OK == factory_->get_participant_qos_from_xml(xml, qos))) { - fastrtps::ParticipantAttributes attrs; - if (xmlobjects::parse_participant(xml.data(), xml.size(), attrs)) - { - fastdds::dds::DomainParticipantQos qos = factory_->get_default_participant_qos(); - set_qos_from_attributes(qos, attrs.rtps); - ptr_ = factory_->create_participant(domain_id_, qos); - } + ptr_ = factory_->create_participant(domain_id_, qos); rv = (nullptr != ptr_); } return rv; @@ -420,15 +298,10 @@ bool FastDDSParticipant::match_from_ref( const std::string& ref) const { bool rv = false; - if (nullptr != ptr_) + fastdds::dds::DomainParticipantQos qos = factory_->get_default_participant_qos(); + if (nullptr != ptr_ && fastdds::dds::RETCODE_OK == factory_->get_participant_qos_from_profile(ref, qos)) { - fastrtps::ParticipantAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) - { - fastdds::dds::DomainParticipantQos qos; - set_qos_from_attributes(qos, attrs.rtps); - rv = (ptr_->get_qos().name() == qos.name()); - } + rv = (ptr_->get_qos().name() == qos.name()); } return rv; } @@ -437,15 +310,10 @@ bool FastDDSParticipant::match_from_xml( const std::string& xml) const { bool rv = false; - if (nullptr != ptr_) + fastdds::dds::DomainParticipantQos qos = factory_->get_default_participant_qos(); + if (nullptr != ptr_ && (xml.size() == 0 || fastdds::dds::RETCODE_OK == factory_->get_participant_qos_from_xml(xml, qos))) { - fastrtps::ParticipantAttributes attrs; - if (xmlobjects::parse_participant(xml.data(), xml.size(), attrs)) - { - fastdds::dds::DomainParticipantQos qos; - set_qos_from_attributes(qos, attrs.rtps); - rv = (ptr_->get_qos().name() == qos.name()); - } + rv = (ptr_->get_qos().name() == qos.name()); } return rv; } @@ -465,7 +333,7 @@ bool FastDDSParticipant::match_from_bin( // Proxy methods -ReturnCode_t FastDDSParticipant::unregister_type( +fastdds::dds::ReturnCode_t FastDDSParticipant::unregister_type( const std::string& typeName) { return ptr_->unregister_type(typeName); @@ -481,7 +349,7 @@ fastdds::dds::Topic* FastDDSParticipant::create_topic( return ptr_->create_topic(topic_name, type_name, qos, listener, mask); } -ReturnCode_t FastDDSParticipant::delete_topic( +fastdds::dds::ReturnCode_t FastDDSParticipant::delete_topic( fastdds::dds::Topic* topic) { return ptr_->delete_topic(topic); @@ -495,22 +363,21 @@ fastdds::dds::Publisher* FastDDSParticipant::create_publisher( return ptr_->create_publisher(qos, listener, mask); } -ReturnCode_t FastDDSParticipant::delete_publisher( +fastdds::dds::ReturnCode_t FastDDSParticipant::delete_publisher( fastdds::dds::Publisher* publisher) { if (NULL == publisher) { - return ReturnCode_t::RETCODE_ALREADY_DELETED; + return fastdds::dds::RETCODE_ALREADY_DELETED; } if (publisher->has_datawriters()) { - ReturnCode_t ret = ReturnCode_t::RETCODE_OK; + fastdds::dds::ReturnCode_t ret = fastdds::dds::RETCODE_OK; - // TODO: Not available on foxy (Need FastDDS >= 2.2.0 for declaration and FastDDS >= 2.4.1 for implementation) - // ret = publisher->delete_contained_entities(); + ret = publisher->delete_contained_entities(); - //if (ReturnCode_t::RETCODE_UNSUPPORTED == ret) + if (fastdds::dds::RETCODE_UNSUPPORTED == ret) { std::vector writers; publisher->get_datawriters(writers); @@ -519,7 +386,7 @@ ReturnCode_t FastDDSParticipant::delete_publisher( { ret = publisher->delete_datawriter(datawriter); - if (ReturnCode_t::RETCODE_OK != ret) + if (fastdds::dds::RETCODE_OK != ret) { return ret; } @@ -538,22 +405,21 @@ fastdds::dds::Subscriber* FastDDSParticipant::create_subscriber( return ptr_->create_subscriber(qos, listener, mask); } -ReturnCode_t FastDDSParticipant::delete_subscriber( +fastdds::dds::ReturnCode_t FastDDSParticipant::delete_subscriber( fastdds::dds::Subscriber* subscriber) { if (NULL == subscriber) { - return ReturnCode_t::RETCODE_ALREADY_DELETED; + return fastdds::dds::RETCODE_ALREADY_DELETED; } if (subscriber->has_datareaders()) { - ReturnCode_t ret = ReturnCode_t::RETCODE_OK; + fastdds::dds::ReturnCode_t ret = fastdds::dds::RETCODE_OK; - // TODO: Not available on foxy (Need FastDDS >= 2.2.0 for declaration and FastDDS >= 2.4.1 for implementation) - // ret = subscriber->delete_contained_entities(); + ret = subscriber->delete_contained_entities(); - // if (ReturnCode_t::RETCODE_UNSUPPORTED == ret) + if (fastdds::dds::RETCODE_UNSUPPORTED == ret) { std::vector readers; subscriber->get_datareaders(readers); @@ -562,7 +428,7 @@ ReturnCode_t FastDDSParticipant::delete_subscriber( { ret = subscriber->delete_datareader(datareader); - if (ReturnCode_t::RETCODE_OK != ret) + if (fastdds::dds::RETCODE_OK != ret) { return ret; } @@ -579,8 +445,8 @@ bool FastDDSParticipant::register_local_type( const std::shared_ptr& type) { fastdds::dds::TypeSupport& type_support = type->get_type_support(); - return ReturnCode_t::RETCODE_OK == ptr_->register_type(type_support, type_support->getName()) - && type_register_.emplace(type_support->getName(), type).second; + return fastdds::dds::RETCODE_OK == ptr_->register_type(type_support, type_support->get_name()) + && type_register_.emplace(type_support->get_name(), type).second; } bool FastDDSParticipant::unregister_local_type( @@ -641,8 +507,8 @@ fastdds::dds::DomainParticipant* FastDDSParticipant::operator * () **********************************************************************************************************************/ FastDDSType::~FastDDSType() { - participant_->unregister_local_type(type_support_->getName()); - participant_->unregister_type(type_support_->getName()); + participant_->unregister_local_type(type_support_->get_name()); + participant_->unregister_type(type_support_->get_name()); } FastDDSTopic::~FastDDSTopic() @@ -651,54 +517,15 @@ FastDDSTopic::~FastDDSTopic() participant_->delete_topic(ptr_); } -bool FastDDSTopic::create_by_ref(const std::string& ref) -{ - bool rv = false; - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) - { - rv = create_by_attributes(attrs); - } - return rv; -} - -bool FastDDSTopic::create_by_xml(const std::string& xml) -{ - bool rv = false; - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) - { - rv = create_by_attributes(attrs); - } - return rv; -} - -bool FastDDSTopic::create_by_attributes(const fastrtps::TopicAttributes& attrs) -{ - bool rv = false; - if (nullptr == ptr_) - { - fastdds::dds::TopicQos qos; - set_qos_from_attributes(qos, attrs); - - ptr_ = participant_->create_topic(attrs.getTopicName().to_string(), - attrs.getTopicDataType().to_string(), qos); - - rv = (nullptr != ptr_); - } - return rv; -} - bool FastDDSTopic::create_by_name_type( const std::string& name, - const std::shared_ptr& type) + const std::shared_ptr& type, + const fastdds::dds::TopicQos& qos) { bool rv = false; if (nullptr == ptr_) { - fastdds::dds::TopicQos qos; - - ptr_ = participant_->create_topic(name, type->get_type_support()->getName(), qos); + ptr_ = participant_->create_topic(name, type->get_type_support()->get_name(), qos); rv = (nullptr != ptr_); @@ -714,16 +541,18 @@ bool FastDDSTopic::match_from_ref( const std::string& ref) const { bool rv = false; + if (nullptr != ptr_) { - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) + fastdds::dds::TopicQos qos; + std::string topic_name; + std::string type_name; + if (fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_topic_qos_from_profile(ref, qos, topic_name, type_name)) { - fastdds::dds::TopicQos qos; - set_qos_from_attributes(qos, attrs); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos() == qos) && (ptr_->get_name() == topic_name) && (type_->get_type_support()->get_name() == type_name); } } + return rv; } @@ -731,16 +560,18 @@ bool FastDDSTopic::match_from_xml( const std::string& xml) const { bool rv = false; + if (nullptr != ptr_) { - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) + fastdds::dds::TopicQos qos = participant_->get_ptr()->get_default_topic_qos(); + std::string topic_name; + std::string type_name; + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_topic_qos_from_xml(xml, qos, topic_name, type_name)) { - fastdds::dds::TopicQos qos; - set_qos_from_attributes(qos, attrs); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos() == qos) && (ptr_->get_name() == topic_name) && (type_->get_type_support()->get_name() == type_name); } } + return rv; } @@ -752,18 +583,11 @@ bool FastDDSTopic::match_from_bin( { fastdds::dds::TopicQos qos; set_qos_from_xrce_object(qos, topic_xrce); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos() == qos) && (ptr_->get_name() == topic_xrce.topic_name()) && (type_->get_type_support()->get_name() == topic_xrce.type_name()); } return rv; } -bool FastDDSTopic::match(const fastrtps::TopicAttributes& attrs) const -{ - return (attrs.getTopicName() == ptr_->get_name()) - && (0 == std::strcmp(type_->get_type_support()->getName(), attrs.getTopicDataType().c_str())) - && (type_->get_type_support()->m_isGetKeyDefined == (attrs.getTopicKind() == fastrtps::rtps::TopicKind_t::WITH_KEY)); -} - /********************************************************************************************************************** * FastDDSPublisher **********************************************************************************************************************/ @@ -781,14 +605,13 @@ bool FastDDSPublisher::create_by_xml( bool rv = false; if (nullptr == ptr_) { - fastdds::dds::PublisherQos qos; - fastrtps::PublisherAttributes attrs; - if (0 != xml.size() && xmlobjects::parse_publisher(xml.data(), xml.size(), attrs)) + fastdds::dds::PublisherQos qos = participant_->get_ptr()->get_default_publisher_qos(); + if(xml.size() == 0 || fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_publisher_qos_from_xml(xml, qos)) { - set_qos_from_attributes(qos, attrs); + ptr_ = participant_->create_publisher(qos); + rv = (nullptr != ptr_); } - ptr_ = participant_->create_publisher(qos); - rv = (nullptr != ptr_); } + } return rv; } @@ -814,12 +637,19 @@ fastdds::dds::DataWriter* FastDDSPublisher::create_datawriter( return ptr_->create_datawriter(topic, qos, listener, mask); } -ReturnCode_t FastDDSPublisher::delete_datawriter( +fastdds::dds::DataWriter* FastDDSPublisher::create_datawriter_with_profile( + fastdds::dds::Topic* topic, + const std::string& profile_name) +{ + return ptr_->create_datawriter_with_profile(topic, profile_name); +} + +fastdds::dds::ReturnCode_t FastDDSPublisher::delete_datawriter( fastdds::dds::DataWriter* writer) { if (NULL == writer) { - return ReturnCode_t::RETCODE_ALREADY_DELETED; + return fastdds::dds::RETCODE_ALREADY_DELETED; } return ptr_->delete_datawriter(writer); @@ -844,14 +674,12 @@ bool FastDDSSubscriber::create_by_xml( bool rv = false; if (nullptr == ptr_) { - fastrtps::SubscriberAttributes attrs; - fastdds::dds::SubscriberQos qos; - if (0 != xml.size() && xmlobjects::parse_subscriber(xml.data(), xml.size(), attrs)) + fastdds::dds::SubscriberQos qos = participant_->get_ptr()->get_default_subscriber_qos(); + if(xml.size() == 0 || fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_subscriber_qos_from_xml(xml, qos)) { - set_qos_from_attributes(qos, attrs); + ptr_ = participant_->create_subscriber(qos); + rv = (nullptr != ptr_); } - ptr_ = participant_->create_subscriber(qos); - rv = (nullptr != ptr_); } return rv; } @@ -878,12 +706,19 @@ fastdds::dds::DataReader* FastDDSSubscriber::create_datareader( return ptr_->create_datareader(topic, reader_qos, listener, mask); } -ReturnCode_t FastDDSSubscriber::delete_datareader( +fastdds::dds::DataReader* FastDDSSubscriber::create_datareader_with_profile( + fastdds::dds::TopicDescription* topic, + const std::string& profile_name) +{ + return ptr_->create_datareader_with_profile(topic, profile_name); +} + +fastdds::dds::ReturnCode_t FastDDSSubscriber::delete_datareader( fastdds::dds::DataReader* reader) { if (NULL == reader) { - return ReturnCode_t::RETCODE_ALREADY_DELETED; + return fastdds::dds::RETCODE_ALREADY_DELETED; } return ptr_->delete_datareader(reader); @@ -903,17 +738,18 @@ FastDDSDataWriter::~FastDDSDataWriter() bool FastDDSDataWriter::create_by_ref(const std::string& ref) { bool rv = false; - if (nullptr == ptr_){ - fastrtps::PublisherAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(ref, attrs)) + if (nullptr == ptr_) + { + fastdds::dds::DataWriterQos qos; + std::string topic_name; + if (fastdds::dds::RETCODE_OK == publisher_->get_ptr()->get_datawriter_qos_from_profile(ref, qos, topic_name)) { - topic_ = publisher_->get_participant()->find_local_topic(attrs.topic.topicName.c_str()); - if(topic_){ - fastdds::dds::DataWriterQos qos; - set_qos_from_attributes(qos, attrs); + topic_ = publisher_->get_participant()->find_local_topic(topic_name); - ptr_ = publisher_->create_datawriter(topic_->get_ptr(), qos); - rv = (nullptr != ptr_) && bool(topic_); + if (topic_) + { + ptr_ = publisher_->create_datawriter_with_profile(topic_->get_ptr(), ref); + rv = (nullptr != ptr_); } } } @@ -923,17 +759,19 @@ bool FastDDSDataWriter::create_by_ref(const std::string& ref) bool FastDDSDataWriter::create_by_xml(const std::string& xml) { bool rv = false; - if (nullptr == ptr_){ - fastrtps::PublisherAttributes attrs; - if (xmlobjects::parse_publisher(xml.data(), xml.size(), attrs)) + if (nullptr == ptr_) + { + std::string topic_name; + fastdds::dds::DataWriterQos qos = publisher_->get_ptr()->get_default_datawriter_qos(); + + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == publisher_->get_ptr()->get_datawriter_qos_from_xml(xml, qos, topic_name)) { - topic_ = publisher_->get_participant()->find_local_topic(attrs.topic.topicName.c_str()); - if(topic_){ - fastdds::dds::DataWriterQos qos; - set_qos_from_attributes(qos, attrs); + topic_ = publisher_->get_participant()->find_local_topic(topic_name); + if (topic_) + { ptr_ = publisher_->create_datawriter(topic_->get_ptr(), qos); - rv = (nullptr != ptr_) && bool(topic_); + rv = (nullptr != ptr_); } } } @@ -957,13 +795,39 @@ bool FastDDSDataWriter::create_by_bin( return rv; } -bool FastDDSDataWriter::match(const fastrtps::PublisherAttributes& attrs) const +bool FastDDSDataWriter::match_from_ref(const std::string& ref) const { - fastdds::dds::DataWriterQos qos; - set_qos_from_attributes(qos, attrs); - return (ptr_->get_qos() == qos); + bool rv = false; + + if (nullptr != ptr_) + { + fastdds::dds::DataWriterQos qos; + std::string topic_name; + if (fastdds::dds::RETCODE_OK == publisher_->get_ptr()->get_datawriter_qos_from_profile(ref, qos, topic_name)) + { + rv = (ptr_->get_qos() == qos) && (topic_->get_name() == topic_name); + } + } + + return rv; } +bool FastDDSDataWriter::match_from_xml(const std::string& xml) const +{ + bool rv = false; + + if (nullptr != ptr_) + { + fastdds::dds::DataWriterQos qos = publisher_->get_ptr()->get_default_datawriter_qos(); + std::string topic_name; + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == publisher_->get_ptr()->get_datawriter_qos_from_xml(xml, qos, topic_name)) + { + rv = (ptr_->get_qos() == qos) && (topic_->get_name() == topic_name); + } + } + + return rv; +} bool FastDDSDataWriter::match_from_bin(const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) const { @@ -1001,16 +865,19 @@ FastDDSDataReader::~FastDDSDataReader() bool FastDDSDataReader::create_by_ref(const std::string& ref) { bool rv = false; - if (nullptr == ptr_){ - fastrtps::SubscriberAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(ref, attrs)) + + if (nullptr == ptr_) + { + fastdds::dds::DataReaderQos qos; + std::string topic_name; + + if (fastdds::dds::RETCODE_OK == subscriber_->get_ptr()->get_datareader_qos_from_profile(ref, qos, topic_name)) { - topic_ = subscriber_->get_participant()->find_local_topic(attrs.topic.topicName.c_str()); - if(topic_){ - fastdds::dds::DataReaderQos qos; - set_qos_from_attributes(qos, attrs); + topic_ = subscriber_->get_participant()->find_local_topic(topic_name); - ptr_ = subscriber_->create_datareader(topic_->get_ptr(), qos); + if (topic_) + { + ptr_ = subscriber_->create_datareader_with_profile(topic_->get_ptr(), ref); rv = (nullptr != ptr_); } } @@ -1021,15 +888,17 @@ bool FastDDSDataReader::create_by_ref(const std::string& ref) bool FastDDSDataReader::create_by_xml(const std::string& xml) { bool rv = false; - if (nullptr == ptr_){ - fastrtps::SubscriberAttributes attrs; - if (xmlobjects::parse_subscriber(xml.data(), xml.size(), attrs)) + if (nullptr == ptr_) + { + std::string topic_name; + fastdds::dds::DataReaderQos qos = subscriber_->get_ptr()->get_default_datareader_qos(); + + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == subscriber_->get_ptr()->get_datareader_qos_from_xml(xml, qos, topic_name)) { - topic_ = subscriber_->get_participant()->find_local_topic(attrs.topic.topicName.c_str()); - if(topic_){ - fastdds::dds::DataReaderQos qos; - set_qos_from_attributes(qos, attrs); + topic_ = subscriber_->get_participant()->find_local_topic(topic_name); + if (topic_) + { ptr_ = subscriber_->create_datareader(topic_->get_ptr(), qos); rv = (nullptr != ptr_); } @@ -1059,16 +928,17 @@ bool FastDDSDataReader::match_from_ref( const std::string& ref) const { bool rv = false; + if (nullptr != ptr_) { - fastrtps::SubscriberAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillSubscriberAttributes(ref, attrs)) + fastdds::dds::DataReaderQos qos; + std::string topic_name; + if (fastdds::dds::RETCODE_OK == subscriber_->get_ptr()->get_datareader_qos_from_profile(ref, qos, topic_name)) { - fastdds::dds::DataReaderQos qos; - set_qos_from_attributes(qos, attrs); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos() == qos) && (topic_->get_name() == topic_name); } } + return rv; } @@ -1076,16 +946,17 @@ bool FastDDSDataReader::match_from_xml( const std::string& xml) const { bool rv = false; + if (nullptr != ptr_) { - fastrtps::SubscriberAttributes attrs; - if (xmlobjects::parse_subscriber(xml.data(), xml.size(), attrs)) + fastdds::dds::DataReaderQos qos = subscriber_->get_ptr()->get_default_datareader_qos(); + std::string topic_name; + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == subscriber_->get_ptr()->get_datareader_qos_from_xml(xml, qos, topic_name)) { - fastdds::dds::DataReaderQos qos; - set_qos_from_attributes(qos, attrs); - rv = (ptr_->get_qos() == qos); + rv = (ptr_->get_qos() == qos) && (topic_->get_name() == topic_name); } } + return rv; } @@ -1110,10 +981,10 @@ bool FastDDSDataReader::read( bool rv = false; - fastrtps::Duration_t d((long double) timeout.count()/1000.0); + fastdds::dds::Duration_t d((long double) timeout.count()/1000.0); if(ptr_->wait_for_unread_message(d)){ - rv = ReturnCode_t::RETCODE_OK == ptr_->take_next_sample(&data, &sample_info); + rv = fastdds::dds::RETCODE_OK == ptr_->take_next_sample(&data, &sample_info); } return rv; @@ -1144,28 +1015,15 @@ FastDDSRequester::~FastDDSRequester() } } -bool FastDDSRequester::create_by_attributes( - const fastrtps::RequesterAttributes& attrs) +bool FastDDSRequester::create_by_qos( + const fastdds::dds::RequesterQos& qos) { - bool rv = false; - - fastdds::dds::PublisherQos qos_publisher; - set_qos_from_attributes(qos_publisher, attrs.publisher); - publisher_ptr_ = participant_->create_publisher(qos_publisher); - - fastdds::dds::DataWriterQos qos_datawriter; - set_qos_from_attributes(qos_datawriter, attrs.publisher); - datawriter_ptr_ = publisher_ptr_->create_datawriter(request_topic_->get_ptr(), qos_datawriter); - - fastdds::dds::SubscriberQos qos_subscriber; - set_qos_from_attributes(qos_subscriber, attrs.subscriber); - subscriber_ptr_ = participant_->create_subscriber(qos_subscriber); - - fastdds::dds::DataReaderQos qos_datareader; - set_qos_from_attributes(qos_datareader, attrs.subscriber); - datareader_ptr_ = subscriber_ptr_->create_datareader(reply_topic_->get_ptr(), qos_datareader); + publisher_ptr_ = participant_->create_publisher(participant_->get_ptr()->get_default_publisher_qos()); + datawriter_ptr_ = publisher_ptr_->create_datawriter(request_topic_->get_ptr(), qos.writer_qos); + subscriber_ptr_ = participant_->create_subscriber(participant_->get_ptr()->get_default_subscriber_qos()); + datareader_ptr_ = subscriber_ptr_->create_datareader(reply_topic_->get_ptr(), qos.reader_qos); - rv = (nullptr != publisher_ptr_) && (nullptr != datawriter_ptr_) && + bool rv = (nullptr != publisher_ptr_) && (nullptr != datawriter_ptr_) && (nullptr != subscriber_ptr_) && (nullptr != datareader_ptr_); if (rv) @@ -1187,22 +1045,40 @@ bool FastDDSRequester::create_by_attributes( bool FastDDSRequester::match_from_ref(const std::string& ref) const { bool rv = false; - fastrtps::RequesterAttributes new_attributes; - if (XMLP_ret::XML_OK == XMLProfileManager::fillRequesterAttributes(ref, new_attributes)) + + fastdds::dds::RequesterQos qos; + + if(fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_requester_qos_from_profile(ref, qos)) { - rv = match(new_attributes); + rv = datawriter_ptr_->get_qos() == qos.writer_qos + && datareader_ptr_->get_qos() == qos.reader_qos + && reply_topic_->get_name() == qos.reply_topic_name + && request_topic_->get_name() == qos.request_topic_name + && reply_topic_->get_type()->get_type_support()->get_name() == qos.reply_type + && request_topic_->get_type()->get_type_support()->get_name() == qos.request_type; } + return rv; } bool FastDDSRequester::match_from_xml(const std::string& xml) const { bool rv = false; - fastrtps::RequesterAttributes new_attributes; - if (xmlobjects::parse_requester(xml.data(), xml.size(), new_attributes)) + + fastdds::dds::RequesterQos qos; + qos.writer_qos = publisher_ptr_->get_default_datawriter_qos(); + qos.reader_qos = subscriber_ptr_->get_default_datareader_qos(); + + if(xml.size() == 0 || fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_requester_qos_from_xml(xml, qos)) { - rv = match(new_attributes); + rv = datawriter_ptr_->get_qos() == qos.writer_qos + && datareader_ptr_->get_qos() == qos.reader_qos + && reply_topic_->get_name() == qos.reply_topic_name + && request_topic_->get_name() == qos.request_topic_name + && reply_topic_->get_type()->get_type_support()->get_name() == qos.reply_type + && request_topic_->get_type()->get_type_support()->get_name() == qos.request_type; } + return rv; } @@ -1214,21 +1090,11 @@ bool FastDDSRequester::match_from_bin(const dds::xrce::OBJK_Requester_Binary& re set_qos_from_xrce_object(qos_subscriber, requester_xrce); return publisher_ptr_->get_qos() == qos_publisher - && subscriber_ptr_->get_qos() == qos_subscriber; - // TODO Check topic names -} - -bool FastDDSRequester::match(const fastrtps::RequesterAttributes& attrs) const -{ - fastdds::dds::PublisherQos qos_publisher; - set_qos_from_attributes(qos_publisher, attrs.publisher); - fastdds::dds::SubscriberQos qos_subscriber; - set_qos_from_attributes(qos_subscriber, attrs.subscriber); - - return reply_topic_->match(attrs.subscriber.topic) - && request_topic_->match(attrs.publisher.topic) - && publisher_ptr_->get_qos() == qos_publisher - && subscriber_ptr_->get_qos() == qos_subscriber; + && subscriber_ptr_->get_qos() == qos_subscriber + && reply_topic_->get_name() == requester_xrce.reply_topic_name() + && request_topic_->get_name() == requester_xrce.request_topic_name() + && reply_topic_->get_type()->get_type_support()->get_name() == requester_xrce.reply_type() + && request_topic_->get_type()->get_type_support()->get_name() == requester_xrce.request_type(); } bool FastDDSRequester::write( @@ -1238,7 +1104,7 @@ bool FastDDSRequester::write( bool rv = true; try { - fastrtps::rtps::WriteParams wparams; + fastdds::rtps::WriteParams wparams; rv = datawriter_ptr_->write(&const_cast&>(data), wparams); if (rv) { @@ -1264,10 +1130,10 @@ bool FastDDSRequester::read( { bool rv = false; - fastrtps::Duration_t d((long double) timeout.count()/1000.0); + fastdds::dds::Duration_t d((long double) timeout.count()/1000.0); if(datareader_ptr_->wait_for_unread_message(d)){ - rv = ReturnCode_t::RETCODE_OK == datareader_ptr_->take_next_sample(&data, &info); + rv = fastdds::dds::RETCODE_OK == datareader_ptr_->take_next_sample(&data, &info); } if (rv) @@ -1333,26 +1199,14 @@ FastDDSReplier::~FastDDSReplier() } } -bool FastDDSReplier::create_by_attributes( - const fastrtps::ReplierAttributes& attrs) +bool FastDDSReplier::create_by_qos( + const fastdds::dds::ReplierQos& qos) { bool rv = false; - - fastdds::dds::PublisherQos qos_publisher; - set_qos_from_attributes(qos_publisher, attrs.publisher); - publisher_ptr_ = participant_->create_publisher(qos_publisher); - - fastdds::dds::DataWriterQos qos_datawriter; - set_qos_from_attributes(qos_datawriter, attrs.publisher); - datawriter_ptr_ = publisher_ptr_->create_datawriter(reply_topic_->get_ptr(), qos_datawriter); - - fastdds::dds::SubscriberQos qos_subscriber; - set_qos_from_attributes(qos_subscriber, attrs.subscriber); - subscriber_ptr_ = participant_->create_subscriber(qos_subscriber); - - fastdds::dds::DataReaderQos qos_datareader; - set_qos_from_attributes(qos_datareader, attrs.subscriber); - datareader_ptr_ = subscriber_ptr_->create_datareader(request_topic_->get_ptr(), qos_datareader); + publisher_ptr_ = participant_->create_publisher(participant_->get_ptr()->get_default_publisher_qos()); + datawriter_ptr_ = publisher_ptr_->create_datawriter(reply_topic_->get_ptr(), qos.writer_qos); + subscriber_ptr_ = participant_->create_subscriber(participant_->get_ptr()->get_default_subscriber_qos()); + datareader_ptr_ = subscriber_ptr_->create_datareader(request_topic_->get_ptr(), qos.reader_qos); rv = (nullptr != publisher_ptr_) && (nullptr != datawriter_ptr_) && (nullptr != subscriber_ptr_) && (nullptr != datareader_ptr_); @@ -1364,22 +1218,40 @@ bool FastDDSReplier::create_by_attributes( bool FastDDSReplier::match_from_ref(const std::string& ref) const { bool rv = false; - fastrtps::ReplierAttributes new_attributes; - if (XMLP_ret::XML_OK == XMLProfileManager::fillReplierAttributes(ref, new_attributes)) + + fastdds::dds::ReplierQos qos; + + if (fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_replier_qos_from_profile(ref, qos)) { - rv = match(new_attributes); + rv = datawriter_ptr_->get_qos() == qos.writer_qos + && datareader_ptr_->get_qos() == qos.reader_qos + && reply_topic_->get_name() == qos.reply_topic_name + && request_topic_->get_name() == qos.request_topic_name + && reply_topic_->get_type()->get_type_support()->get_name() == qos.reply_type + && request_topic_->get_type()->get_type_support()->get_name() == qos.request_type; } + return rv; } bool FastDDSReplier::match_from_xml(const std::string& xml) const { bool rv = false; - fastrtps::ReplierAttributes new_attributes; - if (xmlobjects::parse_replier(xml.data(), xml.size(), new_attributes)) + + fastdds::dds::ReplierQos qos; + qos.writer_qos = publisher_ptr_->get_default_datawriter_qos(); + qos.reader_qos = subscriber_ptr_->get_default_datareader_qos(); + + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == participant_->get_ptr()->get_replier_qos_from_xml(xml, qos)) { - rv = match(new_attributes); + rv = datawriter_ptr_->get_qos() == qos.writer_qos + && datareader_ptr_->get_qos() == qos.reader_qos + && reply_topic_->get_name() == qos.reply_topic_name + && request_topic_->get_name() == qos.request_topic_name + && reply_topic_->get_type()->get_type_support()->get_name() == qos.reply_type + && request_topic_->get_type()->get_type_support()->get_name() == qos.request_type; } + return rv; } @@ -1391,26 +1263,16 @@ bool FastDDSReplier::match_from_bin(const dds::xrce::OBJK_Replier_Binary& replie set_qos_from_xrce_object(qos_subscriber, replier_xrce); return publisher_ptr_->get_qos() == qos_publisher - && subscriber_ptr_->get_qos() == qos_subscriber; - // TODO Check topic names -} - -bool FastDDSReplier::match(const fastrtps::ReplierAttributes& attrs) const -{ - fastdds::dds::PublisherQos qos_publisher; - set_qos_from_attributes(qos_publisher, attrs.publisher); - fastdds::dds::SubscriberQos qos_subscriber; - set_qos_from_attributes(qos_subscriber, attrs.subscriber); - - return reply_topic_->match(attrs.publisher.topic) - && request_topic_->match(attrs.subscriber.topic) - && publisher_ptr_->get_qos() == qos_publisher - && subscriber_ptr_->get_qos() == qos_subscriber; + && subscriber_ptr_->get_qos() == qos_subscriber + && reply_topic_->get_name() == replier_xrce.reply_topic_name() + && request_topic_->get_name() == replier_xrce.request_topic_name() + && reply_topic_->get_type()->get_type_support()->get_name() == replier_xrce.reply_type() + && request_topic_->get_type()->get_type_support()->get_name() == replier_xrce.request_type(); } void FastDDSReplier::transport_sample_identity( const dds::SampleIdentity& dds_identity, - fastrtps::rtps::SampleIdentity& fast_identity) + fastdds::rtps::SampleIdentity& fast_identity) { std::copy( dds_identity.writer_guid().guidPrefix().begin(), @@ -1435,7 +1297,7 @@ bool FastDDSReplier::write( dds::SampleIdentity sample_identity; sample_identity.deserialize(deserializer); - fastrtps::rtps::WriteParams wparams; + fastdds::rtps::WriteParams wparams; transport_sample_identity(sample_identity, wparams.related_sample_identity()); std::vector output_data(data.size() - deserializer.get_serialized_data_length()); @@ -1445,7 +1307,7 @@ bool FastDDSReplier::write( } void FastDDSReplier::transform_sample_identity( - const fastrtps::rtps::SampleIdentity& fast_identity, + const fastdds::rtps::SampleIdentity& fast_identity, dds::SampleIdentity& dds_identity) { std::copy( @@ -1471,10 +1333,10 @@ bool FastDDSReplier::read( bool rv = false; - fastrtps::Duration_t d((long double) timeout.count()/1000.0); + fastdds::dds::Duration_t d((long double) timeout.count()/1000.0); if(datareader_ptr_->wait_for_unread_message(d)){ - rv = ReturnCode_t::RETCODE_OK == datareader_ptr_->take_next_sample(&temp_data, &info); + rv = fastdds::dds::RETCODE_OK == datareader_ptr_->take_next_sample(&temp_data, &info); } if (rv) diff --git a/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp b/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp index a383fb941..0d2c637d5 100644 --- a/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp +++ b/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp @@ -16,17 +16,12 @@ #include #include -#include #include -#include "../../xmlobjects/xmlobjects.h" - #include namespace eprosima { namespace uxr { -using namespace fastrtps::xmlparser; - FastDDSMiddleware::FastDDSMiddleware() : participants_() , topics_() @@ -79,12 +74,20 @@ bool FastDDSMiddleware::create_participant_by_ref( } bool rv = false; - fastrtps::ParticipantAttributes attrs; auto participant_domain_id = domain_id; - if(domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF && XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) + + if (domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF) { - participant_domain_id = static_cast(attrs.domainId); + fastdds::dds::DomainParticipantExtendedQos qos; + + auto factory = fastdds::dds::DomainParticipantFactory::get_instance(); + + if (fastdds::dds::RETCODE_OK == factory->get_participant_extended_qos_from_profile(ref, qos)) + { + participant_domain_id = static_cast(qos.domainId()); + } } + std::shared_ptr participant(new FastDDSParticipant(participant_domain_id)); if (participant->create_by_ref(ref)) { @@ -161,25 +164,28 @@ bool FastDDSMiddleware::create_participant_by_bin( static std::shared_ptr create_topic( std::shared_ptr& participant, - const fastrtps::TopicAttributes& attrs) + const fastdds::dds::TopicQos& qos, + const std::string& topic_name, + const std::string& type_name) { - std::shared_ptr topic = participant->find_local_topic(attrs.getTopicName().c_str()); + std::shared_ptr topic = participant->find_local_topic(topic_name); if (topic) { - if (0 != std::strcmp(attrs.getTopicDataType().c_str(), topic->get_type()->get_type_support()->getName())) + if (type_name == topic->get_type()->get_type_support()->get_name()) { - topic.reset(); + // TODO(pgarrido): Shall we reuse topics? + // topic.reset(); } } else { - const char * type_name = attrs.getTopicDataType().c_str(); std::shared_ptr type = participant->find_local_type(type_name); if (!type) { fastdds::dds::TypeSupport type_support(new TopicPubSubType{false}); - type_support->setName(type_name); - type_support->m_isGetKeyDefined = (attrs.getTopicKind() == fastrtps::rtps::TopicKind_t::WITH_KEY); + type_support->set_name(type_name); + // TODO(pgarrido): Handle topics with keys + type_support->is_compute_key_provided = false; type = std::make_shared(type_support, participant); if (!participant->register_local_type(type)) { @@ -190,7 +196,8 @@ std::shared_ptr create_topic( if (type) { topic = std::make_shared(participant); - topic->create_by_name_type(attrs.getTopicName().c_str(), type); + topic->create_by_name_type(topic_name, type, qos); + if (!participant->register_local_topic(topic)) { topic.reset(); @@ -206,16 +213,27 @@ bool FastDDSMiddleware::create_topic_by_ref( const std::string& ref) { bool rv = false; - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) + auto it_participant = participants_.find(participant_id); + + if (participants_.end() != it_participant) { - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) + fastdds::dds::TopicQos qos = fastdds::dds::TOPIC_QOS_DEFAULT; + std::string topic_name; + std::string type_name; + + auto & participant = it_participant->second; + + if (fastdds::dds::RETCODE_OK == participant->get_ptr()->get_topic_qos_from_profile(ref, qos, topic_name, type_name)) { - std::shared_ptr topic = create_topic(it_participant->second, attrs); - rv = topic && topics_.emplace(topic_id, std::move(topic)).second; + std::shared_ptr topic = create_topic(participant, qos, topic_name, type_name); + if (topic) + { + auto emplace_res = topics_.emplace(topic_id, std::move(topic)); + rv = emplace_res.second; + } } } + return rv; } @@ -225,16 +243,27 @@ bool FastDDSMiddleware::create_topic_by_xml( const std::string& xml) { bool rv = false; - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) + auto it_participant = participants_.find(participant_id); + + if (participants_.end() != it_participant) { - auto it_participant = participants_.find(participant_id); - if (participants_.end() != it_participant) + auto & participant = it_participant->second; + + fastdds::dds::TopicQos qos = participant->get_ptr()->get_default_topic_qos(); + std::string topic_name; + std::string type_name; + + if (xml.size() == 0 || fastdds::dds::RETCODE_OK == participant->get_ptr()->get_topic_qos_from_xml(xml, qos, topic_name, type_name)) { - std::shared_ptr topic = create_topic(it_participant->second, attrs); - rv = topic && topics_.emplace(topic_id, std::move(topic)).second; + std::shared_ptr topic = create_topic(participant, qos, topic_name, type_name); + if (topic) + { + auto emplace_res = topics_.emplace(topic_id, std::move(topic)); + rv = emplace_res.second; + } } } + return rv; } @@ -245,15 +274,26 @@ bool FastDDSMiddleware::create_topic_by_bin( { bool rv = false; auto it_participant = participants_.find(participant_id); + if (participants_.end() != it_participant) { - fastrtps::TopicAttributes attrs( - topic_xrce.topic_name().c_str(), - topic_xrce.type_name().c_str() - ); - std::shared_ptr topic = create_topic(it_participant->second, attrs); - rv = topic && topics_.emplace(topic_id, std::move(topic)).second; + fastdds::dds::TopicQos qos = fastdds::dds::TOPIC_QOS_DEFAULT; + std::string topic_name = topic_xrce.topic_name(); + std::string type_name = topic_xrce.type_name(); + + auto & participant = it_participant->second; + + // Nothing to fill in TopicQoS from binary representation + { + std::shared_ptr topic = create_topic(participant, qos, topic_name, type_name); + if (topic) + { + auto emplace_res = topics_.emplace(topic_id, std::move(topic)); + rv = emplace_res.second; + } + } } + return rv; } @@ -497,18 +537,19 @@ bool FastDDSMiddleware::create_datareader_by_bin( return rv; } -std::shared_ptr FastDDSMiddleware::create_requester( +static std::shared_ptr create_requester( std::shared_ptr& participant, - const fastrtps::RequesterAttributes& attrs) + const fastdds::dds::RequesterQos& qos) { std::shared_ptr requester{}; - std::shared_ptr request_topic = create_topic(participant, attrs.publisher.topic); - std::shared_ptr reply_topic = create_topic(participant, attrs.subscriber.topic); + std::shared_ptr request_topic = create_topic(participant, participant->get_ptr()->get_default_topic_qos(), qos.request_topic_name, qos.request_type); + std::shared_ptr reply_topic = create_topic(participant, participant->get_ptr()->get_default_topic_qos(), qos.reply_topic_name, qos.reply_type); + if (request_topic && reply_topic) { requester = std::make_shared(participant, request_topic, reply_topic); - if (!requester->create_by_attributes(attrs)) + if (!requester->create_by_qos(qos)) { requester.reset(); } @@ -526,17 +567,20 @@ bool FastDDSMiddleware::create_requester_by_ref( if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::RequesterAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillRequesterAttributes(ref, attrs)) + + fastdds::dds::RequesterQos qos; + if(fastdds::dds::RETCODE_OK == participant->get_ptr()->get_requester_qos_from_profile(ref, qos)) { - std::shared_ptr requester = create_requester(participant, attrs); + std::shared_ptr requester = create_requester(participant, qos); + if (nullptr == requester) { return false; } + auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); rv = emplace_res.second; - if (rv) + if(rv) { callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, middleware::CallbackKind::CREATE_REQUESTER, @@ -544,6 +588,7 @@ bool FastDDSMiddleware::create_requester_by_ref( emplace_res.first->second->get_request_datawriter(), emplace_res.first->second->get_reply_datareader()); } + } } return rv; @@ -559,17 +604,20 @@ bool FastDDSMiddleware::create_requester_by_xml( if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::RequesterAttributes attrs; - if (xmlobjects::parse_requester(xml.data(), xml.size(), attrs)) + + fastdds::dds::RequesterQos qos; + if(xml.size() == 0 || fastdds::dds::RETCODE_OK == participant->get_ptr()->get_requester_qos_from_xml(xml, qos)) { - std::shared_ptr requester = create_requester(participant, attrs); + std::shared_ptr requester = create_requester(participant, qos); + if (nullptr == requester) { return false; } + auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); rv = emplace_res.second; - if (rv) + if(rv) { callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, middleware::CallbackKind::CREATE_REQUESTER, @@ -577,6 +625,7 @@ bool FastDDSMiddleware::create_requester_by_xml( emplace_res.first->second->get_request_datawriter(), emplace_res.first->second->get_reply_datareader()); } + } } return rv; @@ -592,55 +641,55 @@ bool FastDDSMiddleware::create_requester_by_bin( if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::RequesterAttributes attrs; - attrs.service_name = requester_xrce.service_name(); - attrs.reply_topic_name = requester_xrce.reply_topic_name(); - attrs.request_topic_name = requester_xrce.request_topic_name(); - attrs.reply_type = requester_xrce.reply_type(); - attrs.request_type = requester_xrce.request_type(); + fastdds::dds::RequesterQos qos; + qos.reply_topic_name = requester_xrce.reply_topic_name(); + qos.request_topic_name = requester_xrce.request_topic_name(); + qos.reply_type = requester_xrce.reply_type(); + qos.request_type = requester_xrce.request_type(); - attrs.publisher.topic.topicName = requester_xrce.request_topic_name(); - attrs.publisher.topic.topicDataType = requester_xrce.request_type(); + qos.writer_qos.endpoint().history_memory_policy = fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + qos.reader_qos.endpoint().history_memory_policy = fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - attrs.subscriber.topic.topicName = requester_xrce.reply_topic_name(); - attrs.subscriber.topic.topicDataType = requester_xrce.reply_type(); + qos.reader_qos.reliability().kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; - attrs.publisher.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - attrs.subscriber.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - attrs.subscriber.qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; - - std::shared_ptr requester = create_requester(participant, attrs); - if (nullptr == requester) - { - return false; - } - auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); - rv = emplace_res.second; - if (rv) { - callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, - middleware::CallbackKind::CREATE_REQUESTER, - participant->get_ptr(), - emplace_res.first->second->get_request_datawriter(), - emplace_res.first->second->get_reply_datareader()); + std::shared_ptr requester = create_requester(participant, qos); + + if (nullptr == requester) + { + return false; + } + + auto emplace_res = requesters_.emplace(requester_id, std::move(requester)); + rv = emplace_res.second; + if(rv) + { + callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, + middleware::CallbackKind::CREATE_REQUESTER, + participant->get_ptr(), + emplace_res.first->second->get_request_datawriter(), + emplace_res.first->second->get_reply_datareader()); + } + } } return rv; } -std::shared_ptr FastDDSMiddleware::create_replier( +static std::shared_ptr create_replier( std::shared_ptr& participant, - const fastrtps::ReplierAttributes& attrs) + const fastdds::dds::ReplierQos& qos) { std::shared_ptr replier{}; - std::shared_ptr request_topic = create_topic(participant, attrs.subscriber.topic); - std::shared_ptr reply_topic = create_topic(participant, attrs.publisher.topic); + std::shared_ptr request_topic = create_topic(participant, participant->get_ptr()->get_default_topic_qos(), qos.request_topic_name, qos.request_type); + std::shared_ptr reply_topic = create_topic(participant, participant->get_ptr()->get_default_topic_qos(), qos.reply_topic_name, qos.reply_type); + if (request_topic && reply_topic) { replier = std::make_shared(participant, request_topic, reply_topic); - if (!replier->create_by_attributes(attrs)) + if (!replier->create_by_qos(qos)) { replier.reset(); } @@ -658,17 +707,20 @@ bool FastDDSMiddleware::create_replier_by_ref( if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::ReplierAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillReplierAttributes(ref, attrs)) + + fastdds::dds::ReplierQos qos; + if(fastdds::dds::RETCODE_OK == participant->get_ptr()->get_replier_qos_from_profile(ref, qos)) { - std::shared_ptr replier = create_replier(participant, attrs); + std::shared_ptr replier = create_replier(participant, qos); + if (nullptr == replier) { return false; } + auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); rv = emplace_res.second; - if (rv) + if(rv) { callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, middleware::CallbackKind::CREATE_REPLIER, @@ -676,6 +728,7 @@ bool FastDDSMiddleware::create_replier_by_ref( emplace_res.first->second->get_reply_datawriter(), emplace_res.first->second->get_request_datareader()); } + } } return rv; @@ -691,17 +744,20 @@ bool FastDDSMiddleware::create_replier_by_xml( if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::ReplierAttributes attrs; - if (xmlobjects::parse_replier(xml.data(), xml.size(), attrs)) + + fastdds::dds::ReplierQos qos; + if(xml.size() == 0 || fastdds::dds::RETCODE_OK == participant->get_ptr()->get_replier_qos_from_xml(xml, qos)) { - std::shared_ptr replier = create_replier(participant, attrs); + std::shared_ptr replier = create_replier(participant, qos); + if (nullptr == replier) { return false; } + auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); rv = emplace_res.second; - if (rv) + if(rv) { callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, middleware::CallbackKind::CREATE_REPLIER, @@ -709,6 +765,7 @@ bool FastDDSMiddleware::create_replier_by_xml( emplace_res.first->second->get_reply_datawriter(), emplace_res.first->second->get_request_datareader()); } + } } return rv; @@ -719,43 +776,41 @@ bool FastDDSMiddleware::create_replier_by_bin( uint16_t participant_id, const dds::xrce::OBJK_Replier_Binary& replier_xrce) { - bool rv = false; + bool rv = false; auto it_participant = participants_.find(participant_id); if (participants_.end() != it_participant) { std::shared_ptr& participant = it_participant->second; - fastrtps::ReplierAttributes attrs; - attrs.service_name = replier_xrce.service_name(); - attrs.reply_topic_name = replier_xrce.reply_topic_name(); - attrs.request_topic_name = replier_xrce.request_topic_name(); - attrs.reply_type = replier_xrce.reply_type(); - attrs.request_type = replier_xrce.request_type(); + fastdds::dds::ReplierQos qos; + qos.reply_topic_name = replier_xrce.reply_topic_name(); + qos.request_topic_name = replier_xrce.request_topic_name(); + qos.reply_type = replier_xrce.reply_type(); + qos.request_type = replier_xrce.request_type(); - attrs.subscriber.topic.topicName = replier_xrce.request_topic_name(); - attrs.subscriber.topic.topicDataType = replier_xrce.request_type(); + qos.writer_qos.endpoint().history_memory_policy = fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + qos.reader_qos.endpoint().history_memory_policy = fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + qos.reader_qos.reliability().kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; - attrs.publisher.topic.topicName = replier_xrce.reply_topic_name(); - attrs.publisher.topic.topicDataType = replier_xrce.reply_type(); + { + std::shared_ptr replier = create_replier(participant, qos); - attrs.publisher.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - attrs.subscriber.historyMemoryPolicy = fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - attrs.subscriber.qos.m_reliability.kind = fastdds::dds::RELIABLE_RELIABILITY_QOS; + if (nullptr == replier) + { + return false; + } + + auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); + rv = emplace_res.second; + if(rv) + { + callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, + middleware::CallbackKind::CREATE_REPLIER, + participant->get_ptr(), + emplace_res.first->second->get_reply_datawriter(), + emplace_res.first->second->get_request_datareader()); + } - std::shared_ptr replier = create_replier(participant, attrs); - if (nullptr == replier) - { - return false; - } - auto emplace_res = repliers_.emplace(replier_id, std::move(replier)); - rv = emplace_res.second; - if (rv) - { - callback_factory_.execute_callbacks(Middleware::Kind::FASTDDS, - middleware::CallbackKind::CREATE_REPLIER, - participant->get_ptr(), - emplace_res.first->second->get_reply_datawriter(), - emplace_res.first->second->get_request_datareader()); } } return rv; @@ -1026,11 +1081,12 @@ bool FastDDSMiddleware::matched_participant_from_ref( auto it = participants_.find(participant_id); if (participants_.end() != it) { - fastrtps::ParticipantAttributes attrs; + fastdds::dds::DomainParticipantExtendedQos qos; + auto factory = fastdds::dds::DomainParticipantFactory::get_instance(); auto participant_domain_id = domain_id; - if(domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF && XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(ref, attrs)) + if(domain_id == UXR_CLIENT_DOMAIN_ID_TO_USE_FROM_REF && fastdds::dds::RETCODE_OK == factory->get_participant_extended_qos_from_profile(ref, qos)) { - participant_domain_id = static_cast(attrs.domainId); + participant_domain_id = static_cast(qos.domainId()); } rv = (participant_domain_id== it->second->domain_id()) && (it->second->match_from_ref(ref)); } @@ -1073,11 +1129,7 @@ bool FastDDSMiddleware::matched_topic_from_ref( auto it = topics_.find(topic_id); if (topics_.end() != it) { - fastrtps::TopicAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillTopicAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } + rv = it->second->match_from_ref(ref); } return rv; } @@ -1090,11 +1142,7 @@ bool FastDDSMiddleware::matched_topic_from_xml( auto it = topics_.find(topic_id); if (topics_.end() != it) { - fastrtps::TopicAttributes attrs; - if (xmlobjects::parse_topic(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } + rv = it->second->match_from_xml(xml); } return rv; } @@ -1120,11 +1168,7 @@ bool FastDDSMiddleware::matched_datawriter_from_ref( auto it = datawriters_.find(datawriter_id); if (datawriters_.end() != it) { - fastrtps::PublisherAttributes attrs; - if (XMLP_ret::XML_OK == XMLProfileManager::fillPublisherAttributes(ref, attrs)) - { - rv = it->second->match(attrs); - } + rv = it->second->match_from_ref(ref); } return rv; } @@ -1137,11 +1181,7 @@ bool FastDDSMiddleware::matched_datawriter_from_xml( auto it = datawriters_.find(datawriter_id); if (datawriters_.end() != it) { - fastrtps::PublisherAttributes attrs; - if (xmlobjects::parse_publisher(xml.data(), xml.size(), attrs)) - { - rv = it->second->match(attrs); - } + rv = it->second->match_from_xml(xml); } return rv; } diff --git a/src/cpp/transport/stream_framing/StreamFramingProtocol.cpp b/src/cpp/transport/stream_framing/StreamFramingProtocol.cpp index 667d40898..9e242e341 100644 --- a/src/cpp/transport/stream_framing/StreamFramingProtocol.cpp +++ b/src/cpp/transport/stream_framing/StreamFramingProtocol.cpp @@ -442,7 +442,7 @@ size_t FramingIO::transport_read( TransportRc& transport_rc, size_t max_size) { - const auto time_init = std::chrono::system_clock::now(); + const auto time_init = std::chrono::steady_clock::now(); /** * Compute read-buffer available size. @@ -520,7 +520,7 @@ size_t FramingIO::transport_read( int time_elapsed = static_cast( std::chrono::duration_cast( - std::chrono::system_clock::now() - time_init) + std::chrono::steady_clock::now() - time_init) .count()); timeout -= (time_elapsed == 0) ? 1 : time_elapsed; diff --git a/src/cpp/types/TopicPubSubType.cpp b/src/cpp/types/TopicPubSubType.cpp index 3d64ef634..c715dd9b3 100644 --- a/src/cpp/types/TopicPubSubType.cpp +++ b/src/cpp/types/TopicPubSubType.cpp @@ -20,57 +20,79 @@ namespace eprosima { namespace uxr { TopicPubSubType::TopicPubSubType(bool with_key) { - m_typeSize = 1024 + 4 /*encapsulation*/; - m_isGetKeyDefined = with_key; + max_serialized_type_size = 1024 + 4 /*encapsulation*/; + is_compute_key_provided = with_key; } -bool TopicPubSubType::serialize(void *data, rtps::SerializedPayload_t *payload) +bool TopicPubSubType::serialize(const void* const data, fastdds::rtps::SerializedPayload_t &payload, fastdds::dds::DataRepresentationId_t /* data_representation */) { bool rv = false; - std::vector* buffer = reinterpret_cast*>(data); - payload->data[0] = 0; - payload->data[1] = 1; - payload->data[2] = 0; - payload->data[3] = 0; - if (buffer->size() <= (payload->max_size - 4)) + + // Reinterpret cast back to a std::vector from data pointer + void * non_const_data = const_cast(data); + std::vector* buffer = reinterpret_cast*>(non_const_data); + + // Representation header + payload.data[0] = 0; + payload.data[1] = 1; + payload.data[2] = 0; + payload.data[3] = 0; + + if (buffer->size() <= (payload.max_size - 4)) { - memcpy(&payload->data[4], buffer->data(), buffer->size()); - payload->length = uint32_t(buffer->size() + 4); //Get the serialized length + memcpy(&payload.data[4], buffer->data(), buffer->size()); + payload.length = uint32_t(buffer->size() + 4); //Get the serialized length rv = true; } + return rv; } -bool TopicPubSubType::deserialize(rtps::SerializedPayload_t* payload, void* data) +bool TopicPubSubType::deserialize(fastdds::rtps::SerializedPayload_t& payload, void* data) { std::vector* buffer = reinterpret_cast*>(data); - buffer->assign(payload->data + 4, payload->data + payload->length); + buffer->assign(payload.data + 4, payload.data + payload.length); return true; } -std::function TopicPubSubType::getSerializedSizeProvider(void* data) { - return [data]() -> uint32_t - { - return (uint32_t)reinterpret_cast*>(data)->size() + 4 /*encapsulation*/; - }; +uint32_t TopicPubSubType::calculate_serialized_size( + const void* const data, + eprosima::fastdds::dds::DataRepresentationId_t /* data_representation */) +{ + void * non_const_data = const_cast(data); + std::vector* buffer = reinterpret_cast*>(non_const_data); + + return static_cast(buffer->size() + 4); /*encapsulation*/ } -void* TopicPubSubType::createData() { +void* TopicPubSubType::create_data() +{ return (void*)new std::vector; } -void TopicPubSubType::deleteData(void* data) { +void TopicPubSubType::delete_data( + void* data) +{ delete((std::vector*)data); } -bool TopicPubSubType::getKey(void *data, rtps::InstanceHandle_t* handle, bool force_md5) +bool TopicPubSubType::compute_key( + fastdds::rtps::SerializedPayload_t& /* payload */, + fastdds::rtps::InstanceHandle_t& /* ihandle */, + bool /* force_md5 */) +{ + // TODO(pgarrido): Implement this function. + return false; +} + +bool TopicPubSubType::compute_key( + const void* const /* data */, + fastdds::rtps::InstanceHandle_t& /* ihandle */, + bool /* force_md5 */) { - // TODO. - (void) data; - (void) handle; - (void) force_md5; - return m_isGetKeyDefined; + // TODO(pgarrido): Implement this function. + return false; } } // namespace uxr diff --git a/src/cpp/utils/ArgumentParser.cpp b/src/cpp/utils/ArgumentParser.cpp index a34505ce8..49fff23a5 100644 --- a/src/cpp/utils/ArgumentParser.cpp +++ b/src/cpp/utils/ArgumentParser.cpp @@ -80,10 +80,6 @@ eprosima::uxr::Middleware::Kind eprosima::uxr::agent::parser::utils::get_mw_kind { return eprosima::uxr::Middleware::Kind::FASTDDS; } - if ("rtps" == kind) - { - return eprosima::uxr::Middleware::Kind::FASTRTPS; - } #endif #ifdef UAGENT_CED_PROFILE if ("ced" == kind) diff --git a/src/cpp/xmlobjects/xmlobjects.cpp b/src/cpp/xmlobjects/xmlobjects.cpp deleted file mode 100644 index 05e5bc063..000000000 --- a/src/cpp/xmlobjects/xmlobjects.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "xmlobjects.h" - -#include -#include -#include -#include -#include - -using eprosima::fastrtps::ParticipantAttributes; -using eprosima::fastrtps::PublisherAttributes; -using eprosima::fastrtps::SubscriberAttributes; -using eprosima::fastrtps::TopicAttributes; -using eprosima::fastrtps::RequesterAttributes; -using eprosima::fastrtps::ReplierAttributes; -using eprosima::fastrtps::xmlparser::BaseNode; -using eprosima::fastrtps::xmlparser::DataNode; -using eprosima::fastrtps::xmlparser::NodeType; -using eprosima::fastrtps::xmlparser::XMLP_ret; -using eprosima::fastrtps::xmlparser::XMLParser; - -bool eprosima::uxr::xmlobjects::parse_participant(const char* source, std::size_t source_size, - ParticipantAttributes& participant) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::PARTICIPANT) - { - participant = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} - -bool eprosima::uxr::xmlobjects::parse_publisher(const char* source, size_t source_size, - PublisherAttributes& publisher) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::PUBLISHER) - { - publisher = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} - -bool eprosima::uxr::xmlobjects::parse_subscriber(const char* source, size_t source_size, - SubscriberAttributes& subscriber) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::SUBSCRIBER) - { - subscriber = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} - -bool eprosima::uxr::xmlobjects::parse_topic(const char* source, std::size_t source_size, TopicAttributes& topic) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::TOPIC) - { - topic = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} - -bool eprosima::uxr::xmlobjects::parse_requester( - const char* source, - std::size_t source_size, - RequesterAttributes& requester) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::REQUESTER) - { - requester = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} - -bool eprosima::uxr::xmlobjects::parse_replier( - const char* source, - std::size_t source_size, - ReplierAttributes& replier) -{ - bool ret = false; - std::unique_ptr root; - if (XMLParser::loadXML(source, source_size, root) == XMLP_ret::XML_OK) - { - for (const auto& profile : root->getChildren()) - { - if (profile->getType() == NodeType::REPLIER) - { - replier = *(dynamic_cast*>(profile.get())->get()); - ret = true; - } - } - } - return ret; -} \ No newline at end of file diff --git a/src/cpp/xmlobjects/xmlobjects.h b/src/cpp/xmlobjects/xmlobjects.h deleted file mode 100644 index d02fc2dfb..000000000 --- a/src/cpp/xmlobjects/xmlobjects.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _XML_OBJECTS_H -#define _XML_OBJECTS_H - -#include -#include - -namespace eprosima { - -namespace fastrtps { -class ParticipantAttributes; -class PublisherAttributes; -class SubscriberAttributes; -class TopicAttributes; -class RequesterAttributes; -class ReplierAttributes; -} // namespace fastrtps -namespace uxr { -namespace xmlobjects { - -bool parse_participant( - const char* source, - std::size_t source_size, - eprosima::fastrtps::ParticipantAttributes& participant); - -bool parse_publisher( - const char* source, - std::size_t source_size, - eprosima::fastrtps::PublisherAttributes& publisher); - -bool parse_subscriber( - const char* source, - std::size_t source_size, - eprosima::fastrtps::SubscriberAttributes& subscriber); - -bool parse_topic( - const char* source, - std::size_t source_size, - eprosima::fastrtps::TopicAttributes& topic); - -bool parse_requester( - const char* source, - std::size_t source_size, - eprosima::fastrtps::RequesterAttributes& requester); - -bool parse_replier( - const char* source, - std::size_t source_size, - eprosima::fastrtps::ReplierAttributes& replier); - -} // namespace xmlobjects -} // namespace uxr -} // namespace eprosima - -#endif // !_XML_OBJECTS_H diff --git a/test/blackbox/tree/CMakeLists.txt b/test/blackbox/tree/CMakeLists.txt index eddbd10c2..4a6096add 100644 --- a/test/blackbox/tree/CMakeLists.txt +++ b/test/blackbox/tree/CMakeLists.txt @@ -30,9 +30,6 @@ if(GMOCK_FOUND) ${PROJECT_SOURCE_DIR}/src/cpp/replier/Replier.cpp ${PROJECT_SOURCE_DIR}/src/cpp/object/XRCEObject.cpp ${PROJECT_SOURCE_DIR}/src/cpp/types/TopicPubSubType.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/xmlobjects/xmlobjects.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/middleware/fast/FastEntities.cpp - ${PROJECT_SOURCE_DIR}/src/cpp/middleware/fast/FastMiddleware.cpp ${PROJECT_SOURCE_DIR}/src/cpp/middleware/fastdds/FastDDSEntities.cpp ${PROJECT_SOURCE_DIR}/src/cpp/middleware/fastdds/FastDDSMiddleware.cpp ${PROJECT_SOURCE_DIR}/src/cpp/middleware/ced/CedEntities.cpp @@ -44,7 +41,7 @@ if(GMOCK_FOUND) SOURCES ${SRCS} DEPENDENCIES - fastrtps + fastdds fastcdr ) target_include_directories(tree_test PRIVATE @@ -56,7 +53,7 @@ if(GMOCK_FOUND) ) target_link_libraries(tree_test PRIVATE - fastrtps + fastdds fastcdr $<$:spdlog::spdlog> ${GTEST_LIBRARIES} diff --git a/test/blackbox/tree/TreeTests.cpp b/test/blackbox/tree/TreeTests.cpp index 3488b7502..b0e865cc5 100644 --- a/test/blackbox/tree/TreeTests.cpp +++ b/test/blackbox/tree/TreeTests.cpp @@ -51,7 +51,7 @@ TEST_F(TreeTests, XMLTree) dds::xrce::ResultStatus response = root_.create_client( client_representation, agent_representation, - Middleware::Kind::FASTRTPS); + Middleware::Kind::FASTDDS); std::shared_ptr client = root_.get_client(client_representation.client_key()); /* Common creation mode. */ @@ -260,7 +260,7 @@ TEST_F(TreeTests, REFTree) dds::xrce::ResultStatus response = root_.create_client( client_representation, agent_representation, - Middleware::Kind::FASTRTPS); + Middleware::Kind::FASTDDS); std::shared_ptr client = root_.get_client(client_representation.client_key()); /* Common creation mode. */ @@ -515,7 +515,7 @@ TEST_F(TreeTests, CreationModeXMLTree) dds::xrce::ResultStatus response = root_.create_client( client_representation, agent_representation, - eprosima::uxr::Middleware::Kind::FASTRTPS); + eprosima::uxr::Middleware::Kind::FASTDDS); std::shared_ptr client = root_.get_client(client_representation.client_key()); /* Common creation mode. */ @@ -801,7 +801,7 @@ TEST_F(TreeTests, CreationModeREFTree) dds::xrce::ResultStatus response = root_.create_client( client_representation, agent_representation, - Middleware::Kind::FASTRTPS); + Middleware::Kind::FASTDDS); std::shared_ptr client = root_.get_client(client_representation.client_key()); /* Common creation mode. */ diff --git a/test/cmake/CMakeLists.txt b/test/cmake/CMakeLists.txt index 2e892ac54..96fd94c6c 100644 --- a/test/cmake/CMakeLists.txt +++ b/test/cmake/CMakeLists.txt @@ -22,7 +22,7 @@ project(PackagingTest) # Find package. find_package(fastcdr REQUIRED) -find_package(fastrtps REQUIRED) +find_package(fastdds REQUIRED) find_package(microxrcedds_agent REQUIRED) add_executable(${PROJECT_NAME} main.cpp) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index baaf68f49..104506c1d 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -31,7 +31,7 @@ add_gtest(test-root SOURCES ${SRCS} DEPENDENCIES - fastrtps + fastdds fastcdr ) target_include_directories(test-root @@ -46,7 +46,7 @@ target_include_directories(test-root target_link_libraries(test-root PRIVATE - fastrtps + fastdds fastcdr $<$:spdlog::spdlog> ${GTEST_LIBRARIES} diff --git a/test/unittest/agent/AgentUnitTests.cpp b/test/unittest/agent/AgentUnitTests.cpp index a21dc632a..dcaaf48f7 100644 --- a/test/unittest/agent/AgentUnitTests.cpp +++ b/test/unittest/agent/AgentUnitTests.cpp @@ -998,33 +998,6 @@ TEST_P(AgentUnitTests, RegisterCallbackFunctions) switch (GetParam()) { - case Middleware::Kind::FASTRTPS: - { - std::function on_create_participant - ([&]( - const fastrtps::Participant* /*participant*/) -> void - { - participant_callback_flag = true; - }); - agent_.add_middleware_callback( - Middleware::Kind::FASTRTPS, - middleware::CallbackKind::CREATE_PARTICIPANT, - std::move(on_create_participant)); - - std::function on_delete_participant - ([&]( - const fastrtps::Participant* /*participant*/) -> void - { - participant_callback_flag = false; - }); - agent_.add_middleware_callback( - Middleware::Kind::FASTRTPS, - middleware::CallbackKind::DELETE_PARTICIPANT, - std::move(on_delete_participant)); - break; - } case Middleware::Kind::FASTDDS: { std::function namespace eprosima {