Skip to content

Commit cf8c162

Browse files
committed
Centralise the generation of the default DataSharing domain ID
The code to generate the default DataSharing domain ID has been extracted to a common place to avoid code duplication and maintenance. Signed-off-by: Iker Luengo <[email protected]>
1 parent c270b67 commit cf8c162

File tree

8 files changed

+92
-34
lines changed

8 files changed

+92
-34
lines changed

include/fastdds/dds/core/policy/QosPolicies.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <fastrtps/types/TypeObject.h>
3737
#include <fastrtps/utils/collections/ResourceLimitedVector.hpp>
3838

39-
4039
namespace eprosima {
4140
namespace fastdds {
4241
namespace dds {

src/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ set(${PROJECT_NAME}_source_files
161161
fastdds/core/condition/StatusCondition.cpp
162162
fastdds/core/condition/WaitSet.cpp
163163
fastdds/core/policy/ParameterList.cpp
164+
fastdds/core/policy/QosPolicyUtils.cpp
164165
fastdds/publisher/qos/WriterQos.cpp
165166
fastdds/subscriber/qos/ReaderQos.cpp
166167
rtps/builtin/BuiltinProtocols.cpp
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file QosPolicyUtils.cpp
17+
*
18+
*/
19+
20+
#include <fastdds/core/policy/QosPolicyUtils.hpp>
21+
22+
#include <utils/Host.hpp>
23+
24+
namespace eprosima {
25+
namespace fastdds {
26+
namespace dds {
27+
namespace utils {
28+
29+
// Compute the default DataSharing domain ID
30+
uint64_t default_domain_id()
31+
{
32+
uint64_t id = 0;
33+
Host::uint48 mac_id = Host::instance().mac_id();
34+
for (size_t i = 0; i < Host::mac_id_length; ++i)
35+
{
36+
id |= static_cast<uint64_t>(mac_id.value[i]) << (56 - (i * 8));
37+
}
38+
return id;
39+
}
40+
41+
} // namespace utils
42+
} // namespace dds
43+
} // namespace fastdds
44+
} // namespace eprosima
45+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file QosPolicyUtils.hpp
17+
*
18+
*/
19+
20+
#ifndef _FASTDDS_DDS_QOS_QOSPOLICYUTILS_HPP_
21+
#define _FASTDDS_DDS_QOS_QOSPOLICYUTILS_HPP_
22+
23+
#include <stdint.h>
24+
25+
namespace eprosima {
26+
namespace fastdds {
27+
namespace dds {
28+
namespace utils {
29+
30+
// Compute the default DataSharing domain ID
31+
uint64_t default_domain_id();
32+
33+
} // namespace utils
34+
} // namespace dds
35+
} // namespace fastdds
36+
} // namespace eprosima
37+
38+
#endif // _FASTDDS_DDS_QOS_QOSPOLICYUTILS_HPP_

src/cpp/fastdds/publisher/DataWriterImpl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535

3636
#include <fastdds/dds/log/Log.hpp>
3737
#include <fastrtps/utils/TimeConversion.h>
38-
#include <utils/Host.hpp>
3938
#include <fastdds/rtps/resources/ResourceEvent.h>
4039
#include <fastdds/rtps/resources/TimedEvent.h>
4140
#include <fastdds/rtps/builtin/liveliness/WLP.h>
4241
#include <fastdds/core/policy/ParameterSerializer.hpp>
42+
#include <fastdds/core/policy/QosPolicyUtils.hpp>
4343

4444
#include <rtps/history/TopicPayloadPoolRegistry.hpp>
4545
#include <rtps/DataSharing/DataSharingPayloadPool.hpp>
@@ -205,13 +205,7 @@ ReturnCode_t DataWriterImpl::enable()
205205
DataSharingQosPolicy datasharing(qos_.data_sharing());
206206
if (datasharing.domain_ids().empty())
207207
{
208-
uint64_t id = 0;
209-
Host::uint48 mac_id = Host::instance().mac_id();
210-
for (size_t i = 0; i < Host::mac_id_length; ++i)
211-
{
212-
id |= mac_id.value[i] << (64 - i);
213-
}
214-
datasharing.add_domain_id(id);
208+
datasharing.add_domain_id(utils::default_domain_id());
215209
}
216210
w_att.endpoint.set_data_sharing_configuration(datasharing);
217211
}

src/cpp/fastdds/publisher/qos/DataWriterQos.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
21-
#include <utils/Host.hpp>
21+
#include <fastdds/core/policy/QosPolicyUtils.hpp>
2222

2323
using namespace eprosima::fastdds::dds;
2424

@@ -58,13 +58,7 @@ WriterQos DataWriterQos::get_writerqos(
5858
if (qos.data_sharing.kind() != OFF &&
5959
qos.data_sharing.domain_ids().empty())
6060
{
61-
uint64_t id = 0;
62-
Host::uint48 mac_id = Host::instance().mac_id();
63-
for (size_t i = 0; i < Host::mac_id_length; ++i)
64-
{
65-
id |= static_cast<uint64_t>(mac_id.value[i]) << (56 - (i * 8));
66-
}
67-
qos.data_sharing.add_domain_id(id);
61+
qos.data_sharing.add_domain_id(utils::default_domain_id());
6862
}
6963

7064
return qos;

src/cpp/fastdds/subscriber/DataReaderImpl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
#include <fastdds/rtps/reader/RTPSReader.h>
3737
#include <fastdds/rtps/resources/ResourceEvent.h>
3838
#include <fastdds/rtps/resources/TimedEvent.h>
39+
#include <fastdds/core/policy/QosPolicyUtils.hpp>
3940

4041
#include <fastdds/subscriber/SubscriberImpl.hpp>
4142
#include <fastdds/subscriber/DataReaderImpl/ReadTakeCommand.hpp>
4243
#include <fastdds/subscriber/DataReaderImpl/StateFilter.hpp>
4344

4445
#include <fastrtps/utils/TimeConversion.h>
45-
#include <utils/Host.hpp>
4646
#include <fastrtps/subscriber/SampleInfo.h>
4747

4848
#include <rtps/history/TopicPayloadPoolRegistry.hpp>
@@ -202,13 +202,7 @@ ReturnCode_t DataReaderImpl::enable()
202202
DataSharingQosPolicy datasharing(qos_.data_sharing());
203203
if (datasharing.domain_ids().empty())
204204
{
205-
uint64_t id = 0;
206-
Host::uint48 mac_id = Host::instance().mac_id();
207-
for (size_t i = 0; i < Host::mac_id_length; ++i)
208-
{
209-
id |= mac_id.value[i] << (64 - i);
210-
}
211-
datasharing.add_domain_id(id);
205+
datasharing.add_domain_id(utils::default_domain_id());
212206
}
213207
att.endpoint.set_data_sharing_configuration(datasharing);
214208
}

src/cpp/fastdds/subscriber/qos/DataReaderQos.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919

2020
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
21-
#include <utils/Host.hpp>
22-
#include <fastdds/dds/log/Log.hpp>
21+
#include <fastdds/core/policy/QosPolicyUtils.hpp>
2322

2423
namespace eprosima {
2524
namespace fastdds {
@@ -54,13 +53,7 @@ ReaderQos DataReaderQos::get_readerqos(
5453
if (qos.data_sharing.kind() != OFF &&
5554
qos.data_sharing.domain_ids().empty())
5655
{
57-
uint64_t id = 0;
58-
Host::uint48 mac_id = Host::instance().mac_id();
59-
for (size_t i = 0; i < Host::mac_id_length; ++i)
60-
{
61-
id |= static_cast<uint64_t>(mac_id.value[i]) << (56 - (i * 8));
62-
}
63-
qos.data_sharing.add_domain_id(id);
56+
qos.data_sharing.add_domain_id(utils::default_domain_id());
6457
}
6558

6659
return qos;

0 commit comments

Comments
 (0)