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

Fix InstanceHandle_t issues [13111] #2334

Merged
merged 4 commits into from
Dec 2, 2021
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
12 changes: 1 addition & 11 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,7 @@ class ParameterGuid_t : public Parameter_t
const fastrtps::rtps::InstanceHandle_t& iH)
: Parameter_t(pid, in_length)
{
for (uint8_t i = 0; i < 16; ++i)
{
if (i < 12)
{
guid.guidPrefix.value[i] = iH.value[i];
}
else
{
guid.entityId.value[i - 12] = iH.value[i];
}
}
fastrtps::rtps::iHandle2GUID(guid, iH);
}

};
Expand Down
17 changes: 15 additions & 2 deletions include/fastdds/rtps/common/InstanceHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ struct RTPS_DllAPI InstanceHandleValue_t
* @remark Do not use this method to check if this value has been set.
* Use method has_been_set() instead.
*/
template<typename T>
octet& operator [] (
size_t i) noexcept
T i) noexcept
{
has_been_set_ = true;
return value_[i];
Expand All @@ -62,8 +63,9 @@ struct RTPS_DllAPI InstanceHandleValue_t
* @remark Do not use this method to check if this value has been set.
* Use method has_been_set() instead.
*/
template<typename T>
octet operator [] (
size_t i) const noexcept
T i) const noexcept
{
return value_[i];
}
Expand Down Expand Up @@ -105,6 +107,12 @@ struct RTPS_DllAPI InstanceHandleValue_t
return has_been_set_;
}

void clear() noexcept
{
value_.fill(0);
has_been_set_ = false;
}

/**
* Equality comparison operator.
*/
Expand Down Expand Up @@ -185,6 +193,11 @@ struct RTPS_DllAPI InstanceHandle_t
return value.has_been_set();
}

void clear() noexcept
{
value.clear();
}

// TODO Review this conversion once InstanceHandle_t is implemented as DDS standard defines
explicit operator const GUID_t&() const noexcept
{
Expand Down
9 changes: 3 additions & 6 deletions src/cpp/rtps/builtin/data/ReaderProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,7 @@ bool ReaderProxyData::readFromCDRMessage(
return false;
}

memcpy(m_RTPSParticipantKey.value, p.guid.guidPrefix.value, 12);
memcpy(m_RTPSParticipantKey.value + 12, p.guid.entityId.value, 4);
m_RTPSParticipantKey = p.guid;
break;
}
case fastdds::dds::PID_ENDPOINT_GUID:
Expand All @@ -802,8 +801,7 @@ bool ReaderProxyData::readFromCDRMessage(
}

m_guid = p.guid;
memcpy(m_key.value, p.guid.guidPrefix.value, 12);
memcpy(m_key.value + 12, p.guid.entityId.value, 4);
m_key = p.guid;
break;
}
case fastdds::dds::PID_UNICAST_LOCATOR:
Expand Down Expand Up @@ -999,8 +997,7 @@ bool ReaderProxyData::readFromCDRMessage(
{
GUID_t tmp_guid = m_guid;
tmp_guid.entityId = c_EntityId_RTPSParticipant;
memcpy(m_RTPSParticipantKey.value, tmp_guid.guidPrefix.value, 12);
memcpy(m_RTPSParticipantKey.value + 12, tmp_guid.entityId.value, 4);
m_RTPSParticipantKey = tmp_guid;
}

return true;
Expand Down
9 changes: 3 additions & 6 deletions src/cpp/rtps/builtin/data/WriterProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,7 @@ bool WriterProxyData::readFromCDRMessage(
return false;
}

memcpy(m_RTPSParticipantKey.value, p.guid.guidPrefix.value, 12);
memcpy(m_RTPSParticipantKey.value + 12, p.guid.entityId.value, 4);
m_RTPSParticipantKey = p.guid;
break;
}
case fastdds::dds::PID_ENDPOINT_GUID:
Expand All @@ -817,8 +816,7 @@ bool WriterProxyData::readFromCDRMessage(
}

m_guid = p.guid;
memcpy(m_key.value, p.guid.guidPrefix.value, 12);
memcpy(m_key.value + 12, p.guid.entityId.value, 4);
m_key = p.guid;
break;
}
case fastdds::dds::PID_PERSISTENCE_GUID:
Expand Down Expand Up @@ -1009,8 +1007,7 @@ bool WriterProxyData::readFromCDRMessage(
{
GUID_t tmp_guid = m_guid;
tmp_guid.entityId = c_EntityId_RTPSParticipant;
memcpy(m_RTPSParticipantKey.value, tmp_guid.guidPrefix.value, 12);
memcpy(m_RTPSParticipantKey.value + 12, tmp_guid.entityId.value, 4);
m_RTPSParticipantKey = tmp_guid;
}

return true;
Expand Down
5 changes: 3 additions & 2 deletions src/cpp/rtps/builtin/liveliness/WLP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ WLP::WLP(
p->mp_participantImpl->getRTPSParticipantAttributes().allocation.locators.max_multicast_locators,
p->mp_participantImpl->getRTPSParticipantAttributes().allocation.data_limits)
{
automatic_instance_handle_ = p->mp_participantImpl->getGuid();
memset(&automatic_instance_handle_.value[12], 0, 3);
GUID_t tmp_guid = p->mp_participantImpl->getGuid();
tmp_guid.entityId = 0;
automatic_instance_handle_ = tmp_guid;
manual_by_participant_instance_handle_ = automatic_instance_handle_;

automatic_instance_handle_.value[15] = AUTOMATIC_LIVELINESS_QOS + 0x01;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/history/CacheChangePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CacheChangePool::return_cache_to_pool(
ch->sequenceNumber.high = 0;
ch->sequenceNumber.low = 0;
ch->writerGUID = c_Guid_Unknown;
memset(ch->instanceHandle.value, 0, 16);
ch->instanceHandle.clear();
ch->isRead = 0;
ch->sourceTimestamp.seconds(0);
ch->sourceTimestamp.fraction(0);
Expand Down
5 changes: 3 additions & 2 deletions test/unittest/rtps/history/BasicPoolsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ TEST_P(BasicPoolsTest, change_reset_on_release)
ASSERT_EQ(ch->writerGUID, c_Guid_Unknown);
ASSERT_EQ(ch->serializedPayload.length, 0U);
ASSERT_EQ(ch->serializedPayload.pos, 0U);
ASSERT_FALSE(ch->instanceHandle.isDefined());
for (uint8_t i = 0; i < 16; ++i)
{
ASSERT_EQ(ch->instanceHandle.value[i], 0U);
}

ASSERT_FALSE(ch->isRead);
ASSERT_EQ(ch->sourceTimestamp.seconds(), 0);
ASSERT_EQ(ch->sourceTimestamp.fraction(), 0U);
Expand All @@ -176,6 +176,7 @@ TEST_P(BasicPoolsTest, change_reset_on_release)
{
ch->instanceHandle.value[i] = 1;
}
ASSERT_TRUE(ch->instanceHandle.isDefined());
ch->isRead = true;
ch->sourceTimestamp.seconds(1);
ch->sourceTimestamp.fraction(1);
Expand All @@ -191,11 +192,11 @@ TEST_P(BasicPoolsTest, change_reset_on_release)
ASSERT_EQ(ch->writerGUID, c_Guid_Unknown);
ASSERT_EQ(ch->serializedPayload.length, 0U);
ASSERT_EQ(ch->serializedPayload.pos, 0U);
ASSERT_FALSE(ch->instanceHandle.isDefined());
for (uint8_t i = 0; i < 16; ++i)
{
ASSERT_EQ(ch->instanceHandle.value[i], 0U);
}

ASSERT_FALSE(ch->isRead);
ASSERT_EQ(ch->sourceTimestamp.seconds(), 0);
ASSERT_EQ(ch->sourceTimestamp.fraction(), 0U);
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/rtps/history/CacheChangePoolTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ TEST_P(CacheChangePoolTests, change_reset_on_release)
ASSERT_EQ(ch->sequenceNumber.high, 0);
ASSERT_EQ(ch->sequenceNumber.low, 0U);
ASSERT_EQ(ch->writerGUID, c_Guid_Unknown);
ASSERT_FALSE(ch->instanceHandle.isDefined());
for (uint8_t i = 0; i < 16; ++i)
{
ASSERT_EQ(ch->instanceHandle.value[i], 0U);
Expand All @@ -197,6 +198,7 @@ TEST_P(CacheChangePoolTests, change_reset_on_release)
{
ch->instanceHandle.value[i] = 1;
}
ASSERT_TRUE(ch->instanceHandle.isDefined());
ch->isRead = true;
ch->sourceTimestamp.seconds(1);
ch->sourceTimestamp.fraction(1);
Expand All @@ -210,6 +212,7 @@ TEST_P(CacheChangePoolTests, change_reset_on_release)
ASSERT_EQ(ch->sequenceNumber.high, 0);
ASSERT_EQ(ch->sequenceNumber.low, 0U);
ASSERT_EQ(ch->writerGUID, c_Guid_Unknown);
ASSERT_FALSE(ch->instanceHandle.isDefined());
for (uint8_t i = 0; i < 16; ++i)
{
ASSERT_EQ(ch->instanceHandle.value[i], 0U);
Expand Down