Skip to content

Commit

Permalink
Make more flexible EDP::valid_matching with TypeInformation (#5000)
Browse files Browse the repository at this point in the history
* Refs #21259. Improve TypeInformation valid_matching

Signed-off-by: Ricardo González Moreno <[email protected]>

* Refs #21259. Apply suggestion

Signed-off-by: Ricardo González Moreno <[email protected]>

---------

Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware authored Jul 10, 2024
1 parent e5b26c7 commit 6e287f4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/cpp/rtps/builtin/discovery/endpoint/EDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ static bool is_partition_empty(
return partition.size() <= 1 && 0 == strlen(partition.name());
}

static bool is_same_type(
const dds::xtypes::TypeInformation& t1,
const dds::xtypes::TypeInformation& t2)
{
return (dds::xtypes::TK_NONE != t1.complete().typeid_with_size().type_id()._d()
&& t1.complete().typeid_with_size() == t2.complete().typeid_with_size())
|| (dds::xtypes::TK_NONE != t1.minimal().typeid_with_size().type_id()._d()
&& t1.minimal().typeid_with_size() == t2.minimal().typeid_with_size());
}

EDP::EDP(
PDP* p,
RTPSParticipantImpl* part)
Expand Down Expand Up @@ -515,7 +525,7 @@ bool EDP::valid_matching(
if ((wdata->has_type_information() && wdata->type_information().assigned()) &&
(rdata->has_type_information() && rdata->type_information().assigned()))
{
if (wdata->type_information().type_information != rdata->type_information().type_information)
if (!is_same_type(wdata->type_information().type_information, rdata->type_information().type_information))
{
reason.set(MatchingFailureMask::different_typeinfo);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ class ReaderProxyData

bool has_type_information () const
{
return false;
return has_type_info_;
}

void type_information(
const fastdds::dds::xtypes::TypeInformationParameter& other_type_info)
{
has_type_info_ = true;
type_info_ = other_type_info;
}

Expand All @@ -231,6 +232,7 @@ class ReaderProxyData

fastdds::dds::xtypes::TypeInformationParameter& type_information()
{
has_type_info_ = true;
return type_info_;
}

Expand Down Expand Up @@ -349,6 +351,7 @@ class ReaderProxyData
InstanceHandle_t m_RTPSParticipantKey;
uint16_t m_userDefinedId;
fastdds::rtps::ContentFilterProperty content_filter_;
bool has_type_info_ {false};

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ class WriterProxyData

bool has_type_information () const
{
return false;
return has_type_info_;
}

void type_information(
const fastdds::dds::xtypes::TypeInformationParameter& other_type_info)
{
has_type_info_ = true;
type_info_ = other_type_info;
}

Expand All @@ -210,6 +211,7 @@ class WriterProxyData

fastdds::dds::xtypes::TypeInformationParameter& type_information()
{
has_type_info_ = true;
return type_info_;
}

Expand Down Expand Up @@ -321,6 +323,7 @@ class WriterProxyData
InstanceHandle_t m_key;
InstanceHandle_t m_RTPSParticipantKey;
uint16_t m_userDefinedId;
bool has_type_info_ {false};
};

} // namespace rtps
Expand Down
55 changes: 55 additions & 0 deletions test/unittest/rtps/discovery/EdpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,61 @@ TEST(MatchingFailureMask, matching_failure_mask_overflow)
EXPECT_TRUE(mask.test(EDP::MatchingFailureMask::different_typeinfo));
}

TEST_F(EdpTests, CheckTypeIdentifierComparation)
{
dds::xtypes::TypeIdentifier minimal;
minimal.equivalence_hash({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14});
minimal._d(dds::xtypes::EK_MINIMAL);
dds::xtypes::TypeIdentifier complete;
complete.equivalence_hash({2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
complete._d(dds::xtypes::EK_COMPLETE);

wdata->type_information().assigned(true);
rdata->type_information().assigned(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
wdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
rdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
rdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
check_expectations(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
wdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
rdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
rdata->type_information().type_information.minimal().typeid_with_size().type_id().no_value({});
check_expectations(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
wdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
rdata->type_information().type_information.complete().typeid_with_size().type_id().no_value({});
rdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
check_expectations(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
wdata->type_information().type_information.minimal().typeid_with_size().type_id().no_value({});
rdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
rdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
check_expectations(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id().no_value({});
wdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
rdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
rdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
check_expectations(true);

wdata->type_information().type_information.complete().typeid_with_size().type_id().no_value({});
wdata->type_information().type_information.minimal().typeid_with_size().type_id().no_value({});
rdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
rdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
check_expectations(false);

wdata->type_information().type_information.complete().typeid_with_size().type_id(complete);
wdata->type_information().type_information.minimal().typeid_with_size().type_id(minimal);
rdata->type_information().type_information.complete().typeid_with_size().type_id().no_value({});
rdata->type_information().type_information.minimal().typeid_with_size().type_id().no_value({});
check_expectations(false);
}


} // namespace rtps
} // namespace fastdds
Expand Down

0 comments on commit 6e287f4

Please sign in to comment.