Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve X-Types interoperability #4985

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ constexpr uint32_t eprosima_fastdds_dds_xtypes_CompleteEnumeratedHeader_max_key_
constexpr uint32_t eprosima_fastdds_dds_xtypes_CompleteBitsetHeader_max_cdr_typesize {653UL};
constexpr uint32_t eprosima_fastdds_dds_xtypes_CompleteBitsetHeader_max_key_cdr_typesize {0UL};

constexpr uint32_t eprosima_fastdds_dds_xtypes_Dummy_max_cdr_typesize {0UL};
constexpr uint32_t eprosima_fastdds_dds_xtypes_Dummy_max_key_cdr_typesize {0UL};

constexpr uint32_t eprosima_fastdds_dds_xtypes_CompleteBitfield_max_cdr_typesize {1408UL};
constexpr uint32_t eprosima_fastdds_dds_xtypes_CompleteBitfield_max_key_cdr_typesize {0UL};

Expand Down Expand Up @@ -426,6 +429,10 @@ eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const eprosima::fastdds::dds::xtypes::ExtendedTypeDefn& data);

eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const eprosima::fastdds::dds::xtypes::Dummy& data);




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,115 @@ class ExtendedTypeDefnPubSubType : public eprosima::fastdds::dds::TopicDataType

};

/*!
* @brief This class represents the TopicDataType of the type Dummy defined by the user in the IDL file.
* @ingroup dds_xtypes_typeobject
*/
class DummyPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:

typedef Dummy type;

eProsima_user_DllExport DummyPubSubType();

eProsima_user_DllExport ~DummyPubSubType() override;

eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t* payload) override
{
return serialize(data, payload, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION);
}

eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t* payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;

eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t* payload,
void* data) override;

eProsima_user_DllExport std::function<uint32_t()> getSerializedSizeProvider(
const void* const data) override
{
return getSerializedSizeProvider(data, eprosima::fastdds::dds::DEFAULT_DATA_REPRESENTATION);
}

eProsima_user_DllExport std::function<uint32_t()> getSerializedSizeProvider(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;

eProsima_user_DllExport bool getKey(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t* ihandle,
bool force_md5 = false) override;

eProsima_user_DllExport void* createData() override;

eProsima_user_DllExport void deleteData(
void* data) override;

//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return true;
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED

#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain() const override
{
return is_plain_xcdrv1_impl();
}

eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
if (data_representation == eprosima::fastdds::dds::DataRepresentationId_t::XCDR2_DATA_REPRESENTATION)
{
return is_plain_xcdrv2_impl();
}
else
{
return is_plain_xcdrv1_impl();
}
}

#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN

#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
new (memory) Dummy();
return true;
}

#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE

eprosima::fastdds::MD5 m_md5;
unsigned char* m_keyBuffer;

private:

static constexpr bool is_plain_xcdrv1_impl()
{
return true;
}

static constexpr bool is_plain_xcdrv2_impl()
{
return true;
}

};

typedef std::vector<eprosima::fastdds::dds::xtypes::TypeIdentifier> TypeIdentifierSeq;
typedef uint32_t MemberId;

Expand Down
1 change: 1 addition & 0 deletions include/fastdds/rtps/common/VendorId_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using VendorId_t = std::array<uint8_t, 2>;
const VendorId_t c_VendorId_Unknown = {0x00, 0x00};
const VendorId_t c_VendorId_eProsima = {0x01, 0x0F};
const VendorId_t c_VendorId_rti_connext = {0x01, 0x01};
const VendorId_t c_VendorId_opendds = {0x01, 0x03};

} // namespace rtps
} // namespace fastdds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,28 @@ void TypeLookupRequestListener::process_requests()

if (!requests_queue_.empty())
{
TypeLookup_Request& request = requests_queue_.front();
std::pair<TypeLookup_Request, rtps::VendorId_t>& request = requests_queue_.front();
{
// Process the TypeLookup_Request based on its type
switch (request.data()._d())
switch (request.first.data()._d())
{
case TypeLookup_getTypes_HashId:
{
check_get_types_request(request.header().requestId(), request.data().getTypes());
check_get_types_request(request.first.header().requestId(),
request.first.data().getTypes(), request.second);
break;
}
case TypeLookup_getDependencies_HashId:
{
check_get_type_dependencies_request(request.header().requestId(),
request.data().getTypeDependencies());
check_get_type_dependencies_request(request.first.header().requestId(),
request.first.data().getTypeDependencies());
break;
}
default:
// If the type of request is not known, log an error and answer with an exception
EPROSIMA_LOG_WARNING(TYPELOOKUP_SERVICE_REQUEST_LISTENER,
"Received unknown request in type lookup service.");
answer_request(request.header().requestId(),
answer_request(request.first.header().requestId(),
rpc::RemoteExceptionCode_t::REMOTE_EX_UNKNOWN_OPERATION);
break;
}
Expand All @@ -185,7 +186,8 @@ void TypeLookupRequestListener::process_requests()

void TypeLookupRequestListener::check_get_types_request(
SampleIdentity request_id,
const TypeLookup_getTypes_In& request)
const TypeLookup_getTypes_In& request,
const rtps::VendorId_t& vendor_id)
{
// Always Sends EK_COMPLETE
// TODO: Add a property to the participant to configure this behavior. Allowing it to respond with EK_MINIMAL when possible.
Expand All @@ -198,7 +200,7 @@ void TypeLookupRequestListener::check_get_types_request(
for (const xtypes::TypeIdentifier& type_id : request.type_ids())
{
// If TypeIdentifier is EK_MINIMAL add complete_to_minimal to answer
if (type_id._d() == xtypes::EK_MINIMAL)
if (type_id._d() == xtypes::EK_MINIMAL && rtps::c_VendorId_opendds != vendor_id)
{
minimal_id = type_id;
// Get complete TypeIdentifier from registry
Expand Down Expand Up @@ -438,7 +440,7 @@ void TypeLookupRequestListener::on_new_cache_change_added(
{
std::unique_lock<std::mutex> guard(request_processor_cv_mutex_);
// Add request to the processing queue
requests_queue_.push(request);
requests_queue_.push({request, change->vendor_id});
// Notify processor
request_processor_cv_.notify_all();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>

#include <fastdds/builtin/type_lookup_service/detail/TypeLookupTypes.hpp>
#include <fastdds/rtps/common/VendorId_t.hpp>
#include <fastdds/rtps/reader/ReaderListener.hpp>
#include <fastdds/rtps/writer/WriterListener.hpp>
#include <fastdds/xtypes/type_representation/TypeIdentifierWithSizeHashSpecialization.h>
Expand All @@ -36,8 +38,7 @@

namespace std {

template <>
struct hash<eprosima::fastdds::dds::xtypes::TypeIdentifierSeq>
template <> struct hash<eprosima::fastdds::dds::xtypes::TypeIdentifierSeq>
{
std::size_t operator ()(
const eprosima::fastdds::dds::xtypes::TypeIdentifierSeq& k) const
Expand All @@ -54,7 +55,7 @@ struct hash<eprosima::fastdds::dds::xtypes::TypeIdentifierSeq>

};

} // std
} // namespace std

namespace eprosima {
namespace fastdds {
Expand Down Expand Up @@ -111,10 +112,12 @@ class TypeLookupRequestListener : public fastdds::rtps::ReaderListener, public f
* @brief Gets TypeObject from TypeObjectRegistry, creates and sends reply.
* @param request_id[in] The SampleIdentity of the request.
* @param request[in] The request data.
* @param vendor_id[in] Vendor identifier that sent the request.
*/
void check_get_types_request(
SampleIdentity request_id,
const TypeLookup_getTypes_In& request);
const TypeLookup_getTypes_In& request,
const rtps::VendorId_t& vendor_id);

/**
* @brief Gets type dependencies from TypeObjectRegistry, creates and sends reply.
Expand All @@ -132,7 +135,8 @@ class TypeLookupRequestListener : public fastdds::rtps::ReaderListener, public f
* @param continuation_point[in] The continuation point of the previous request.
* @return The reply containing the dependent types.
*/
TypeLookup_getTypeDependencies_Out prepare_get_type_dependencies_response(
TypeLookup_getTypeDependencies_Out
prepare_get_type_dependencies_response(
const xtypes::TypeIdentifierSeq& id_seq,
const std::unordered_set<xtypes::TypeIdentfierWithSize>& type_dependencies,
const std::vector<uint8_t>& continuation_point);
Expand All @@ -147,7 +151,8 @@ class TypeLookupRequestListener : public fastdds::rtps::ReaderListener, public f
SampleIdentity request_id,
rpc::RemoteExceptionCode_t exception_code,
TypeLookup_getTypeDependencies_Out& out);
void answer_request(
void
answer_request(
SampleIdentity request_id,
rpc::RemoteExceptionCode_t exception_code,
TypeLookup_getTypes_Out& out);
Expand Down Expand Up @@ -175,11 +180,11 @@ class TypeLookupRequestListener : public fastdds::rtps::ReaderListener, public f
std::mutex requests_with_continuation_mutex_;

//! Collection of the requests that needed continuation points.
std::unordered_map <xtypes::TypeIdentifierSeq,
std::unordered_set<xtypes::TypeIdentfierWithSize>> requests_with_continuation_;
std::unordered_map<xtypes::TypeIdentifierSeq, std::unordered_set<xtypes::TypeIdentfierWithSize>>
requests_with_continuation_;

eprosima::thread request_processor_thread;
std::queue<TypeLookup_Request> requests_queue_;
std::queue<std::pair<TypeLookup_Request, rtps::VendorId_t>> requests_queue_;
std::mutex request_processor_cv_mutex_;
std::condition_variable request_processor_cv_;
bool processing_ = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class TypeLookup_getTypes_Result
}


int32_t m__d {1};
int32_t m__d {2147483647};

union
{
Expand Down Expand Up @@ -1270,7 +1270,7 @@ class TypeLookup_getTypeDependencies_Result
}


int32_t m__d {1};
int32_t m__d {2147483647};

union
{
Expand Down Expand Up @@ -1638,7 +1638,7 @@ class TypeLookup_Call
}


int32_t m__d {0};
int32_t m__d {2147483647};

union
{
Expand Down Expand Up @@ -2187,7 +2187,7 @@ class TypeLookup_Return
}


int32_t m__d {0};
int32_t m__d {2147483647};

union
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../../../../../../include/fastdds/dds/core/detail/DDSReturnCode.idl"
#include "../../../../../../include/fastdds/dds/xtypes/type_representation/detail/dds-xtypes_typeobject.idl"
#include "rpc_types.idl"

module dds {
module builtin {

Expand Down Expand Up @@ -59,6 +59,7 @@ module builtin {
};

// @RPCRequestType // Annotation not defined
@final
struct TypeLookup_Request {
rpc::RequestHeader header;
TypeLookup_Call data;
Expand All @@ -73,6 +74,7 @@ module builtin {
};

// @RPCReplyType // Annotation not defined
@final
struct TypeLookup_Reply {
rpc::ReplyHeader header;
TypeLookup_Return return_value; //This name was changed from "return" to "return_value" to avoid problems in c++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include "TypeLookupTypes.hpp"

constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Reply_max_cdr_typesize {140UL};
constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Reply_max_cdr_typesize {116UL};
constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Reply_max_key_cdr_typesize {0UL};


Expand Down Expand Up @@ -78,6 +78,7 @@ constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_getTypes_In_max_key_c






constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_getTypeDependencies_Out_max_cdr_typesize {72UL};
Expand Down Expand Up @@ -124,7 +125,7 @@ constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_getTypes_Out_max_key_



constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Request_max_cdr_typesize {388UL};
constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Request_max_cdr_typesize {364UL};
constexpr uint32_t eprosima_fastdds_dds_builtin_TypeLookup_Request_max_key_cdr_typesize {0UL};


Expand Down
Loading
Loading