From 8d91408be41d4f69b052e28c589ae5b1f9fbd1d6 Mon Sep 17 00:00:00 2001 From: Antonio cuadros Date: Tue, 7 Sep 2021 16:41:09 +0200 Subject: [PATCH 1/2] Add binary entity creation to CED middleware --- .../agent/middleware/ced/CedMiddleware.hpp | 73 ++++++------ src/cpp/middleware/ced/CedMiddleware.cpp | 109 ++++++++++++++++++ 2 files changed, 145 insertions(+), 37 deletions(-) diff --git a/include/uxr/agent/middleware/ced/CedMiddleware.hpp b/include/uxr/agent/middleware/ced/CedMiddleware.hpp index ee289091b..df007b88d 100644 --- a/include/uxr/agent/middleware/ced/CedMiddleware.hpp +++ b/include/uxr/agent/middleware/ced/CedMiddleware.hpp @@ -64,13 +64,13 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_participant_by_bin( - uint16_t /* participant_id */, - const dds::xrce::OBJK_DomainParticipant_Binary& /* participant_xrce */) override { return false; }; + uint16_t participant_id, + const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) override; /** * @startuml @@ -109,14 +109,14 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_topic_by_bin( - uint16_t /* topic_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Topic_Binary& /* topic_xrce */) override { return false; }; + uint16_t topic_id, + uint16_t participant_id, + const dds::xrce::OBJK_Topic_Binary& topic_xrce) override; /** * @startuml @@ -134,14 +134,14 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_publisher_by_bin( - uint16_t /* publisher_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Publisher_Binary& /* publisher_xrce */) override { return false; }; + uint16_t publisher_id, + uint16_t participant_id, + const dds::xrce::OBJK_Publisher_Binary& publisher_xrce) override; /** * @startuml @@ -159,14 +159,14 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_subscriber_by_bin( - uint16_t /* subscriber_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Subscriber_Binary& /* subscriber_xrce */) override { return false; }; + uint16_t subscriber_id, + uint16_t participant_id, + const dds::xrce::OBJK_Subscriber_Binary& subscriber_xrce) override; /** * @startuml @@ -197,14 +197,14 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_datawriter_by_bin( - uint16_t /* datawriter_id */, - uint16_t /* publisher_id */, - const dds::xrce::OBJK_DataWriter_Binary& /* datawriter_xrce */) override { return false; }; + uint16_t datawriter_id, + uint16_t publisher_id, + const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) override; /** * @startuml @@ -235,14 +235,14 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief Not implemented. + * @brief TODO. * * @return false */ bool create_datareader_by_bin( - uint16_t /* datareader_id */, - uint16_t /* subscriber_id */, - const dds::xrce::OBJK_DataReader_Binary& /* datareader_xrce */) override { return false; }; + uint16_t datareader_id, + uint16_t subscriber_id, + const dds::xrce::OBJK_DataReader_Binary& datareader_xrce) override; /** * @brief Not implemented. @@ -467,12 +467,12 @@ class CedMiddleware : public Middleware /** - * @brief Not implemented. + * @brief TODO. */ 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; }; + uint16_t participant_id, + int16_t domain_id, + const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) const override; /** * @brief Checks whether an existing CedTopic, identified by the topic_id, matches with a new CedTopic that would @@ -501,11 +501,11 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief Not implemented. + * @brief TODO. */ bool matched_topic_from_bin( - uint16_t /* topic_id */, - const dds::xrce::OBJK_Topic_Binary& /* topic_xrce */) const override { return false; }; + uint16_t topic_id, + const dds::xrce::OBJK_Topic_Binary& topic_xrce) const override; /** * @brief Checks whether an existing CedDataWriter, identified by the datawriter_id, matches with the new @@ -534,11 +534,11 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief Not implemented. + * @brief TODO. */ bool matched_datawriter_from_bin( - uint16_t /* datawriter_id */, - const dds::xrce::OBJK_DataWriter_Binary& /* datawriter_xrce */) const override { return false; }; + uint16_t datawriter_id, + const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) const override; /** * @brief Checks whether an existing CedDataReader, identified by the datareader_id, matches with the new @@ -567,12 +567,11 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief Not implemented. + * @brief TODO. */ bool matched_datareader_from_bin( - uint16_t /* datareader_id */, - const dds::xrce::OBJK_DataReader_Binary& /* datareader_xrce */) const override { return false; }; - + uint16_t datareader_id , + const dds::xrce::OBJK_DataReader_Binary& datareader_xrce) const override; /** * @brief Not implemented. diff --git a/src/cpp/middleware/ced/CedMiddleware.cpp b/src/cpp/middleware/ced/CedMiddleware.cpp index de9ae2e10..4ac8037ae 100644 --- a/src/cpp/middleware/ced/CedMiddleware.cpp +++ b/src/cpp/middleware/ced/CedMiddleware.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include +#include namespace eprosima { namespace uxr { @@ -92,6 +93,13 @@ bool CedMiddleware::create_participant_by_xml( return create_participant_by_ref(participant_id, domain_id, xml); } +bool CedMiddleware::create_participant_by_bin( + uint16_t participant_id, + const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) +{ + return create_participant_by_ref(participant_id, participant_xrce.domain_id(), participant_xrce.domain_referente()); +} + static std::shared_ptr create_topic( std::shared_ptr& participant, @@ -142,6 +150,14 @@ bool CedMiddleware::create_topic_by_xml( return create_topic_by_ref(topic_id, participant_id, xml); } +bool CedMiddleware::create_topic_by_bin( + uint16_t topic_id, + uint16_t participant_id, + const dds::xrce::OBJK_Topic_Binary& topic_xrce) +{ + return create_topic_by_ref(topic_id, participant_id, topic_xrce.topic_name()); +} + bool CedMiddleware::create_publisher_by_xml( uint16_t publisher_id, uint16_t participant_id, @@ -161,6 +177,14 @@ bool CedMiddleware::create_publisher_by_xml( return rv; } +bool CedMiddleware::create_publisher_by_bin( + uint16_t publisher_id, + uint16_t participant_id, + const dds::xrce::OBJK_Publisher_Binary& publisher_xrce) +{ + return create_publisher_by_xml(publisher_id, participant_id, publisher_xrce.publisher_name()); +} + bool CedMiddleware::create_subscriber_by_xml( uint16_t subscirber_id, uint16_t participant_id, @@ -180,6 +204,14 @@ bool CedMiddleware::create_subscriber_by_xml( return rv; } +bool CedMiddleware::create_subscriber_by_bin( + uint16_t subscriber_id, + uint16_t participant_id, + const dds::xrce::OBJK_Subscriber_Binary& subscriber_xrce) +{ + return create_subscriber_by_xml(subscriber_id, participant_id, subscriber_xrce.subscriber_name()); +} + bool CedMiddleware::create_datawriter_by_ref( uint16_t datawriter_id, uint16_t publisher_id, @@ -215,6 +247,22 @@ bool CedMiddleware::create_datawriter_by_xml( return create_datawriter_by_ref(datawriter_id, publisher_id, xml); } +bool CedMiddleware::create_datawriter_by_bin( + uint16_t datawriter_id, + uint16_t publisher_id, + const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) +{ + bool rv = false; + auto it = topics_.find(eprosima::uxr::conversion::objectid_to_raw(datawriter_xrce.topic_id())); + + if (topics_.end() != it) + { + rv = create_datawriter_by_ref(datawriter_id, publisher_id, it->second->get_name()); + } + + return rv; +} + bool CedMiddleware::create_datareader_by_ref( uint16_t datareader_id, uint16_t subscriber_id, @@ -249,6 +297,22 @@ bool CedMiddleware::create_datareader_by_xml( return create_datareader_by_ref(datareader_id, subscriber_id, xml); } +bool CedMiddleware::create_datareader_by_bin( + uint16_t datareader_id, + uint16_t subscriber_id, + const dds::xrce::OBJK_DataReader_Binary& datareader_xrce) +{ + bool rv = false; + auto it = topics_.find(eprosima::uxr::conversion::objectid_to_raw(datareader_xrce.topic_id())); + + if (topics_.end() != it) + { + rv = create_datareader_by_ref(datareader_id, subscriber_id, it->second->get_name()); + } + + return rv; +} + /********************************************************************************************************************** * Delete functions. **********************************************************************************************************************/ @@ -339,6 +403,14 @@ bool CedMiddleware::matched_participant_from_xml( return matched_participant_from_ref(participant_id, domain_id, xml); } +bool CedMiddleware::matched_participant_from_bin( + uint16_t participant_id, + int16_t domain_id, + const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) const +{ + return matched_participant_from_ref(participant_id, domain_id, participant_xrce.domain_referente()); +} + bool CedMiddleware::matched_topic_from_ref( uint16_t topic_id, const std::string& ref) const @@ -359,6 +431,13 @@ bool CedMiddleware::matched_topic_from_xml( return matched_topic_from_ref(topic_id, xml); } +bool CedMiddleware::matched_topic_from_bin( + uint16_t topic_id, + const dds::xrce::OBJK_Topic_Binary& topic_xrce) const +{ + return matched_topic_from_ref(topic_id, topic_xrce.topic_name()); +} + bool CedMiddleware::matched_datawriter_from_ref( uint16_t datawriter_id, const std::string& ref) const @@ -379,6 +458,21 @@ bool CedMiddleware::matched_datawriter_from_xml( return matched_datawriter_from_ref(datawriter_id, xml); } +bool CedMiddleware::matched_datawriter_from_bin( + uint16_t datawriter_id, + const dds::xrce::OBJK_DataWriter_Binary& datawriter_xrce) const +{ + bool rv = false; + auto it = topics_.find(eprosima::uxr::conversion::objectid_to_raw(datawriter_xrce.topic_id())); + + if (topics_.end() != it) + { + rv = matched_datawriter_from_ref(datawriter_id, it->second->get_name()); + } + + return rv; +} + bool CedMiddleware::matched_datareader_from_ref( uint16_t datareader_id, const std::string& ref) const @@ -399,5 +493,20 @@ bool CedMiddleware::matched_datareader_from_xml( return matched_datareader_from_ref(datareader_id, xml); } +bool CedMiddleware::matched_datareader_from_bin( + uint16_t datareader_id, + const dds::xrce::OBJK_DataReader_Binary& datareader_xrce) const +{ + bool rv = false; + auto it = topics_.find(eprosima::uxr::conversion::objectid_to_raw(datareader_xrce.topic_id())); + + if (topics_.end() != it) + { + rv = matched_datareader_from_ref(datareader_id, it->second->get_name()); + } + + return rv; +} + } // namespace uxr } // namespace eprosima From 9ceea717c24bce768793676e5047bcf2a17a4311 Mon Sep 17 00:00:00 2001 From: Antonio cuadros Date: Wed, 8 Sep 2021 09:09:26 +0200 Subject: [PATCH 2/2] Update doc on CED binary creation --- .../agent/middleware/ced/CedMiddleware.hpp | 124 ++++++++++++------ src/cpp/middleware/ced/CedMiddleware.cpp | 14 +- 2 files changed, 89 insertions(+), 49 deletions(-) diff --git a/include/uxr/agent/middleware/ced/CedMiddleware.hpp b/include/uxr/agent/middleware/ced/CedMiddleware.hpp index df007b88d..4e2fad4fa 100644 --- a/include/uxr/agent/middleware/ced/CedMiddleware.hpp +++ b/include/uxr/agent/middleware/ced/CedMiddleware.hpp @@ -64,9 +64,11 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedParticipant from a binary reference. + * Currently, only the domain_id is taken into account for the creation. + * @param participant_id The CedParticipant identifier. + * @param participant_xrce XRCE Participant binary representation, NOT USED. + * @return true in case of creation and false in other case. */ bool create_participant_by_bin( uint16_t participant_id, @@ -109,9 +111,11 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedTopic associated to a CedParticipant from a binary reference. + * @param topic_id The CedTopic identifier. + * @param participant_id The CedParticipant identifier to which the CedTopic is associated. + * @param topic_xrce XRCE Topic binary representation. + * @return true in case of creation and false in other case. */ bool create_topic_by_bin( uint16_t topic_id, @@ -134,9 +138,11 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedPublisher associated to a CedParticipant using a binary reference. + * @param publisher_id The CedPublisher identifier. + * @param participant_id The CedParticipant identifier to which the CedPublisher is associated. + * @param publisher_xrce XRCE Publisher binary representation, NOT USED. + * @return true in case of creation and false in other case. */ bool create_publisher_by_bin( uint16_t publisher_id, @@ -159,9 +165,11 @@ class CedMiddleware : public Middleware const std::string&) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedSubscriber associated to a CedParticipant using a binary reference. + * @param subscirber_id The CedSubscriber identifier. + * @param participant_id The CedParticipant identifier to which the CedSubscriber is associated. + * @param subscriber_xrce XRCE Subscriber binary representation, NOT USED. + * @return true in case of creation and false in other case. */ bool create_subscriber_by_bin( uint16_t subscriber_id, @@ -197,9 +205,11 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedDataWriter associated to a CedPublisher from a binary reference. + * @param datawriter_id The CedDataWriter identifier. + * @param publisher_id The CedPublisher identifier. + * @param datawriter_xrce XRCE DataWriter binary representation. + * @return true in case of creation and false in other case. */ bool create_datawriter_by_bin( uint16_t datawriter_id, @@ -235,9 +245,11 @@ class CedMiddleware : public Middleware const std::string& xml) override; /** - * @brief TODO. - * - * @return false + * @brief Creates a CedDataReader associated to a CedSubscriber from a binary reference. + * @param datareader_id The CedDataReader identifier. + * @param subscriber_id The CedSubscriber identifier. + * @param datawriter_xrce XRCE DataReader binary representation. + * @return true in case of creation and false in other case. */ bool create_datareader_by_bin( uint16_t datareader_id, @@ -250,7 +262,6 @@ class CedMiddleware : public Middleware * @param requester_id * @param participant_id * @param ref - * @return true * @return false */ bool create_requester_by_ref( @@ -264,7 +275,6 @@ class CedMiddleware : public Middleware * @param requester_id * @param participant_id * @param xml - * @return true * @return false */ bool create_requester_by_xml( @@ -275,12 +285,15 @@ class CedMiddleware : public Middleware /** * @brief Not implemented. * + * @param requester_id + * @param participant_id + * @param requester_xrce * @return false */ bool create_requester_by_bin( - uint16_t /* requester_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Requester_Binary& /* requester_xrce */) override { return false; }; + uint16_t, + uint16_t, + const dds::xrce::OBJK_Requester_Binary&) override { return false; }; /** * @brief Not implemented. @@ -288,7 +301,6 @@ class CedMiddleware : public Middleware * @param replier_id * @param participant_id * @param ref - * @return true * @return false */ bool create_replier_by_ref( @@ -302,7 +314,6 @@ class CedMiddleware : public Middleware * @param replier_id * @param participant_id * @param xml - * @return true * @return false */ bool create_replier_by_xml( @@ -313,12 +324,15 @@ class CedMiddleware : public Middleware /** * @brief Not implemented. * + * @param replier_id + * @param participant_id + * @param replier_xrce * @return false */ bool create_replier_by_bin( - uint16_t /* replier_id */, - uint16_t /* participant_id */, - const dds::xrce::OBJK_Replier_Binary& /* replier_xrce */) override { return false; }; + uint16_t, + uint16_t, + const dds::xrce::OBJK_Replier_Binary&) override { return false; }; /** * @brief Removes a CedParticipant from the participants register. @@ -366,7 +380,6 @@ class CedMiddleware : public Middleware * @brief Not implemented. * * @param requester_id - * @return true * @return false */ bool delete_requester(uint16_t) override { return false; }; @@ -375,7 +388,6 @@ class CedMiddleware : public Middleware * @brief Not implemented * * @param replier_id - * @return true * @return false */ bool delete_replier(uint16_t) override { return false; }; @@ -467,7 +479,13 @@ class CedMiddleware : public Middleware /** - * @brief TODO. + * @brief Checks whether an existing CedParticipant, identified by the participant_id, matches with a new + * CedParticipant that would result from the creation of a new one using the domain_id and the binary reference. + * It is considered that the CedParticipants match if both have the same domain_id. + * @param participant_id The existing CedParticipant identifier. + * @param domain_id The Domain identifier of the new CedParticipant. + * @param xml XRCE Participant binary representation (unused). + * @return true if both CedParticipant have the same Domain identifier, and false in other case. */ bool matched_participant_from_bin( uint16_t participant_id, @@ -501,7 +519,13 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief TODO. + * @brief Checks whether an existing CedTopic, identified by the topic_id, matches with a new CedTopic that would + * result from the creation of a new one using the binary reference. + * It is considered that the CedTopics match if both have the same topic name. + * @param topic_id The existing CedTopic identifier. + * @param topic_xrce XRCE Topic binary representation. + * It defines the CedGlobalTopic name. + * @return true if both CedTopic have associated the same CedGlobalTopic, and false in other case. */ bool matched_topic_from_bin( uint16_t topic_id, @@ -534,7 +558,13 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief TODO. + * @brief Checks whether an existing CedDataWriter, identified by the datawriter_id, matches with the new + * CedDataWriter that would result from the creation of a new one using the binary reference. + * It is considered that the CedDataWriters match if both are associated to the same CedGlobalTopic. + * @param datawriter_id The existing CedDataWriter identifier. + * @param datawriter_xrce XRCE DataWriter binary representation. + * It defines the name of the associated CedGlobalTopic. + * @return true if both CedDataWriter have associated the same CedGlobalTopic name */ bool matched_datawriter_from_bin( uint16_t datawriter_id, @@ -567,7 +597,13 @@ class CedMiddleware : public Middleware const std::string& xml) const override; /** - * @brief TODO. + * @brief Checks whether an existing CedDataReader, identified by the datareader_id, matches with the new + * CedDataReader that would result from the creation of a new one using the binary reference. + * It is considered that the CedDataReaders match if both are associated to the same CedGlobalTopic. + * @param datareader_id The existing CedDataReader identifier. + * @param datawriter_xrce XRCE DataReader binary representation. + * It defines the name of the associated CedGlobalTopic. + * @return true if both CedDataReader have associated the same CedGlobalTopic name */ bool matched_datareader_from_bin( uint16_t datareader_id , @@ -578,7 +614,6 @@ class CedMiddleware : public Middleware * * @param participant_id * @param ref - * @return true * @return false */ bool matched_requester_from_ref( @@ -590,7 +625,6 @@ class CedMiddleware : public Middleware * * @param participant_id * @param xml - * @return true * @return false */ bool matched_requester_from_xml( @@ -599,17 +633,20 @@ class CedMiddleware : public Middleware /** * @brief Not implemented. + * + * @param requester_id + * @param requester_xrce + * @return false */ bool matched_requester_from_bin( - uint16_t /* requester_id */, - const dds::xrce::OBJK_Requester_Binary& /* requester_xrce */) const override { return false; }; + uint16_t, + const dds::xrce::OBJK_Requester_Binary&) const override { return false; }; /** * @brief Not implemented. * * @param participant_id * @param ref - * @return true * @return false */ bool matched_replier_from_ref( @@ -621,7 +658,6 @@ class CedMiddleware : public Middleware * * @param participant_id * @param xml - * @return true * @return false */ bool matched_replier_from_xml( @@ -630,10 +666,14 @@ class CedMiddleware : public Middleware /** * @brief Not implemented. + * + * @param replier_id + * @param replier_xrce + * @return false */ bool matched_replier_from_bin( - uint16_t /* replier_id */, - const dds::xrce::OBJK_Replier_Binary& /* replier_xrce */) const override { return false; }; + uint16_t, + const dds::xrce::OBJK_Replier_Binary&) const override { return false; }; private: std::unordered_map> participants_; diff --git a/src/cpp/middleware/ced/CedMiddleware.cpp b/src/cpp/middleware/ced/CedMiddleware.cpp index 4ac8037ae..50f5443e5 100644 --- a/src/cpp/middleware/ced/CedMiddleware.cpp +++ b/src/cpp/middleware/ced/CedMiddleware.cpp @@ -97,7 +97,7 @@ bool CedMiddleware::create_participant_by_bin( uint16_t participant_id, const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) { - return create_participant_by_ref(participant_id, participant_xrce.domain_id(), participant_xrce.domain_referente()); + return create_participant_by_ref(participant_id, (int16_t) participant_xrce.domain_id(), std::string()); } static @@ -180,9 +180,9 @@ bool CedMiddleware::create_publisher_by_xml( bool CedMiddleware::create_publisher_by_bin( uint16_t publisher_id, uint16_t participant_id, - const dds::xrce::OBJK_Publisher_Binary& publisher_xrce) + const dds::xrce::OBJK_Publisher_Binary& /* publisher_xrce */) { - return create_publisher_by_xml(publisher_id, participant_id, publisher_xrce.publisher_name()); + return create_publisher_by_xml(publisher_id, participant_id, std::string()); } bool CedMiddleware::create_subscriber_by_xml( @@ -207,9 +207,9 @@ bool CedMiddleware::create_subscriber_by_xml( bool CedMiddleware::create_subscriber_by_bin( uint16_t subscriber_id, uint16_t participant_id, - const dds::xrce::OBJK_Subscriber_Binary& subscriber_xrce) + const dds::xrce::OBJK_Subscriber_Binary& /* subscriber_xrce */) { - return create_subscriber_by_xml(subscriber_id, participant_id, subscriber_xrce.subscriber_name()); + return create_subscriber_by_xml(subscriber_id, participant_id, std::string()); } bool CedMiddleware::create_datawriter_by_ref( @@ -406,9 +406,9 @@ bool CedMiddleware::matched_participant_from_xml( bool CedMiddleware::matched_participant_from_bin( uint16_t participant_id, int16_t domain_id, - const dds::xrce::OBJK_DomainParticipant_Binary& participant_xrce) const + const dds::xrce::OBJK_DomainParticipant_Binary& /* participant_xrce */) const { - return matched_participant_from_ref(participant_id, domain_id, participant_xrce.domain_referente()); + return matched_participant_from_ref(participant_id, domain_id, std::string()); } bool CedMiddleware::matched_topic_from_ref(