Skip to content

Commit 405fa95

Browse files
authored
Support both fastcdr v1 and v2 (#414)
* Regenerate types to make them compatible with both Fast-CDR v1 & v2 Signed-off-by: tempate <danieldiaz@eprosima.com> * Include the generated types in the CMakeLists Signed-off-by: tempate <danieldiaz@eprosima.com> * Update tests to use Fast-CDR v2 Signed-off-by: tempate <danieldiaz@eprosima.com> * Uncrustify Signed-off-by: tempate <danieldiaz@eprosima.com> --------- Signed-off-by: tempate <danieldiaz@eprosima.com>
1 parent 1f14040 commit 405fa95

21 files changed

Lines changed: 2022 additions & 453 deletions

ddsrouter_core/test/blackbox/ddsrouter_core/dds/WAN/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ set(TEST_NAME
2222
set(TEST_SOURCES
2323
DDSTestWAN.cpp
2424
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx
25+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldv1.cxx
26+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldCdrAux.ipp
2527
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx
2628
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx
29+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedv1.cxx
30+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedCdrAux.ipp
2731
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx)
2832

2933
set(TEST_LIST

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ set(TEST_NAME
2222
set(TEST_SOURCES
2323
DDSTestLocal.cpp
2424
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx
25+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldv1.cxx
26+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldCdrAux.ipp
2527
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx
2628
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx
29+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedv1.cxx
30+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedCdrAux.ipp
2731
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx)
2832

2933
set(TEST_LIST
@@ -62,8 +66,12 @@ set(TEST_NAME
6266
set(TEST_SOURCES
6367
DDSTestLocalDisposeKey.cpp
6468
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx
69+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldv1.cxx
70+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldCdrAux.ipp
6571
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx
6672
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx
73+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedv1.cxx
74+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedCdrAux.ipp
6775
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx)
6876

6977
set(TEST_LIST

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocal.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ DdsRouterConfiguration dds_test_simple_configuration(
111111
* The transient_local option changes the test behavior to verify that the communication is transient_local and all old data is sent
112112
* to Late Joiners.
113113
*/
114-
template <class MsgStruct>
114+
template <class MsgStruct, class MsgStructType>
115115
void test_local_communication(
116116
DdsRouterConfiguration ddsrouter_configuration,
117117
uint32_t samples_to_receive = DEFAULT_SAMPLES_TO_RECEIVE,
@@ -130,6 +130,8 @@ void test_local_communication(
130130

131131
// Create a message with size specified by repeating the same string
132132
MsgStruct msg;
133+
MsgStructType type;
134+
133135
std::string msg_str;
134136

135137
// Add this string as many times as the msg size requires
@@ -140,11 +142,11 @@ void test_local_communication(
140142
msg.message(msg_str);
141143

142144
// Create DDS Publisher in domain 0
143-
TestPublisher<MsgStruct> publisher(msg.isKeyDefined());
145+
TestPublisher<MsgStruct> publisher(type.m_isGetKeyDefined);
144146
ASSERT_TRUE(publisher.init(0));
145147

146148
// Create DDS Subscriber in domain 1
147-
TestSubscriber<MsgStruct> subscriber(msg.isKeyDefined(), transient_local);
149+
TestSubscriber<MsgStruct> subscriber(type.m_isGetKeyDefined, transient_local);
148150
ASSERT_TRUE(subscriber.init(1, &msg, &samples_received));
149151

150152
// Create DdsRouter entity
@@ -207,7 +209,7 @@ void test_local_communication(
207209
*/
208210
TEST(DDSTestLocal, end_to_end_local_communication)
209211
{
210-
test::test_local_communication<HelloWorld>(
212+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
211213
test::dds_test_simple_configuration());
212214
}
213215

@@ -217,7 +219,7 @@ TEST(DDSTestLocal, end_to_end_local_communication)
217219
*/
218220
TEST(DDSTestLocal, end_to_end_local_communication_keyed)
219221
{
220-
test::test_local_communication<HelloWorldKeyed>(
222+
test::test_local_communication<HelloWorldKeyed, HelloWorldKeyedPubSubType>(
221223
test::dds_test_simple_configuration());
222224
}
223225

@@ -228,13 +230,13 @@ TEST(DDSTestLocal, end_to_end_local_communication_keyed)
228230
*/
229231
TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery)
230232
{
231-
test::test_local_communication<HelloWorld>(
233+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
232234
test::dds_test_simple_configuration(true));
233235
}
234236

235237
TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keyed)
236238
{
237-
test::test_local_communication<HelloWorldKeyed>(
239+
test::test_local_communication<HelloWorldKeyed, HelloWorldKeyedPubSubType>(
238240
test::dds_test_simple_configuration(true));
239241
}
240242

@@ -247,7 +249,7 @@ TEST(DDSTestLocal, end_to_end_local_communication_disable_dynamic_discovery_keye
247249
*/
248250
TEST(DDSTestLocal, end_to_end_local_communication_high_frequency)
249251
{
250-
test::test_local_communication<HelloWorld>(
252+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
251253
test::dds_test_simple_configuration(),
252254
1000, // wait for 1000 samples received
253255
0); // send it without waiting from one sample to the other
@@ -262,7 +264,7 @@ TEST(DDSTestLocal, end_to_end_local_communication_high_frequency)
262264
*/
263265
TEST(DDSTestLocal, end_to_end_local_communication_high_size)
264266
{
265-
test::test_local_communication<HelloWorld>(
267+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
266268
test::dds_test_simple_configuration(),
267269
test::DEFAULT_SAMPLES_TO_RECEIVE,
268270
test::DEFAULT_MILLISECONDS_PUBLISH_LOOP,
@@ -280,7 +282,7 @@ TEST(DDSTestLocal, end_to_end_local_communication_high_size)
280282
*/
281283
TEST(DDSTestLocal, end_to_end_local_communication_high_throughput)
282284
{
283-
test::test_local_communication<HelloWorld>(
285+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
284286
test::dds_test_simple_configuration(),
285287
500,
286288
1,
@@ -293,7 +295,7 @@ TEST(DDSTestLocal, end_to_end_local_communication_high_throughput)
293295
*/
294296
TEST(DDSTestLocal, end_to_end_local_communication_transient_local)
295297
{
296-
test::test_local_communication<HelloWorld>(
298+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
297299
test::dds_test_simple_configuration(),
298300
test::DEFAULT_SAMPLES_TO_RECEIVE,
299301
test::DEFAULT_MILLISECONDS_PUBLISH_LOOP,
@@ -307,7 +309,7 @@ TEST(DDSTestLocal, end_to_end_local_communication_transient_local)
307309
*/
308310
TEST(DDSTestLocal, end_to_end_local_communication_transient_local_disable_dynamic_discovery)
309311
{
310-
test::test_local_communication<HelloWorld>(
312+
test::test_local_communication<HelloWorld, HelloWorldPubSubType>(
311313
test::dds_test_simple_configuration(true, true),
312314
test::DEFAULT_SAMPLES_TO_RECEIVE,
313315
test::DEFAULT_MILLISECONDS_PUBLISH_LOOP,

ddsrouter_core/test/blackbox/ddsrouter_core/dds/local/DDSTestLocalDisposeKey.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void test_local_communication_key_dispose(
9898

9999
// Create a message with size specified by repeating the same string
100100
HelloWorldKeyed msg;
101+
HelloWorldKeyedPubSubType type;
101102
std::string msg_str;
102103

103104
// Add this string as many times as the msg size requires
@@ -109,11 +110,11 @@ void test_local_communication_key_dispose(
109110
msg.id(666);
110111

111112
// Create DDS Publisher in domain 0
112-
TestPublisher<HelloWorldKeyed> publisher(msg.isKeyDefined());
113+
TestPublisher<HelloWorldKeyed> publisher(type.m_isGetKeyDefined);
113114
ASSERT_TRUE(publisher.init(0));
114115

115116
// Create DDS Subscriber in domain 1
116-
TestSubscriber<HelloWorldKeyed> subscriber(msg.isKeyDefined());
117+
TestSubscriber<HelloWorldKeyed> subscriber(type.m_isGetKeyDefined);
117118
ASSERT_TRUE(subscriber.init(1, &msg, &samples_received));
118119

119120
// Create DdsRouter entity

ddsrouter_core/test/blackbox/ddsrouter_core/dds/repeater/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ set(TEST_NAME
2222
set(TEST_SOURCES
2323
DDSTestRepeater.cpp
2424
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx
25+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldv1.cxx
26+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldCdrAux.ipp
2527
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorldPubSubTypes.cxx
2628
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyed.cxx
29+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedv1.cxx
30+
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedCdrAux.ipp
2731
${PROJECT_SOURCE_DIR}/test/blackbox/ddsrouter_core/dds/types/HelloWorldKeyed/HelloWorldKeyedPubSubTypes.cxx)
2832

2933
set(TEST_LIST

ddsrouter_core/test/blackbox/ddsrouter_core/dds/types/HelloWorld/HelloWorld.cxx

Lines changed: 40 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,119 +14,94 @@
1414

1515
/*!
1616
* @file HelloWorld.cpp
17-
* This source file contains the definition of the described types in the IDL file.
17+
* This source file contains the implementation of the described types in the IDL file.
1818
*
19-
* This file was generated by the tool gen.
19+
* This file was generated by the tool fastddsgen.
2020
*/
2121

2222
#ifdef _WIN32
2323
// Remove linker warning LNK4221 on Visual Studio
24-
namespace { char dummy; }
25-
#endif
24+
namespace {
25+
char dummy;
26+
} // namespace
27+
#endif // _WIN32
2628

2729
#include "HelloWorld.h"
30+
31+
#if FASTCDR_VERSION_MAJOR > 1
32+
2833
#include <fastcdr/Cdr.h>
2934

35+
3036
#include <fastcdr/exceptions/BadParamException.h>
3137
using namespace eprosima::fastcdr::exception;
3238

3339
#include <utility>
3440

41+
42+
43+
3544
HelloWorld::HelloWorld()
3645
{
37-
// m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@1622f1b
38-
m_index = 0;
39-
// m_message com.eprosima.idl.parser.typecode.StringTypeCode@70e8f8e
40-
m_message ="";
41-
4246
}
4347

4448
HelloWorld::~HelloWorld()
4549
{
46-
47-
4850
}
4951

50-
HelloWorld::HelloWorld(const HelloWorld &x)
52+
HelloWorld::HelloWorld(
53+
const HelloWorld& x)
5154
{
5255
m_index = x.m_index;
5356
m_message = x.m_message;
5457
}
5558

56-
HelloWorld::HelloWorld(HelloWorld &&x)
59+
HelloWorld::HelloWorld(
60+
HelloWorld&& x) noexcept
5761
{
5862
m_index = x.m_index;
5963
m_message = std::move(x.m_message);
6064
}
6165

62-
HelloWorld& HelloWorld::operator=(const HelloWorld &x)
66+
HelloWorld& HelloWorld::operator =(
67+
const HelloWorld& x)
6368
{
6469

6570
m_index = x.m_index;
6671
m_message = x.m_message;
67-
6872
return *this;
6973
}
7074

71-
HelloWorld& HelloWorld::operator=(HelloWorld &&x)
75+
HelloWorld& HelloWorld::operator =(
76+
HelloWorld&& x) noexcept
7277
{
7378

7479
m_index = x.m_index;
7580
m_message = std::move(x.m_message);
76-
7781
return *this;
7882
}
7983

80-
size_t HelloWorld::getMaxCdrSerializedSize(size_t current_alignment)
84+
bool HelloWorld::operator ==(
85+
const HelloWorld& x) const
8186
{
82-
size_t initial_alignment = current_alignment;
83-
84-
85-
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
86-
87-
88-
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;
89-
90-
91-
return current_alignment - initial_alignment;
87+
return (m_index == x.m_index &&
88+
m_message == x.m_message);
9289
}
9390

94-
size_t HelloWorld::getCdrSerializedSize(const HelloWorld& data, size_t current_alignment)
91+
bool HelloWorld::operator !=(
92+
const HelloWorld& x) const
9593
{
96-
(void)data;
97-
size_t initial_alignment = current_alignment;
98-
99-
100-
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
101-
102-
103-
current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.message().size() + 1;
104-
105-
106-
return current_alignment - initial_alignment;
107-
}
108-
109-
void HelloWorld::serialize(eprosima::fastcdr::Cdr &scdr) const
110-
{
111-
112-
scdr << m_index;
113-
scdr << m_message;
114-
}
115-
116-
void HelloWorld::deserialize(eprosima::fastcdr::Cdr &dcdr)
117-
{
118-
119-
dcdr >> m_index;
120-
dcdr >> m_message;
94+
return !(*this == x);
12195
}
12296

12397
/*!
12498
* @brief This function sets a value in member index
12599
* @param _index New value for member index
126100
*/
127-
void HelloWorld::index(uint32_t _index)
101+
void HelloWorld::index(
102+
uint32_t _index)
128103
{
129-
m_index = _index;
104+
m_index = _index;
130105
}
131106

132107
/*!
@@ -151,18 +126,20 @@ uint32_t& HelloWorld::index()
151126
* @brief This function copies the value in member message
152127
* @param _message New value to be copied in member message
153128
*/
154-
void HelloWorld::message(const std::string &_message)
129+
void HelloWorld::message(
130+
const std::string& _message)
155131
{
156-
m_message = _message;
132+
m_message = _message;
157133
}
158134

159135
/*!
160136
* @brief This function moves the value in member message
161137
* @param _message New value to be moved in member message
162138
*/
163-
void HelloWorld::message(std::string &&_message)
139+
void HelloWorld::message(
140+
std::string&& _message)
164141
{
165-
m_message = std::move(_message);
142+
m_message = std::move(_message);
166143
}
167144

168145
/*!
@@ -183,25 +160,7 @@ std::string& HelloWorld::message()
183160
return m_message;
184161
}
185162

186-
size_t HelloWorld::getKeyMaxCdrSerializedSize(size_t current_alignment)
187-
{
188-
size_t current_align = current_alignment;
189-
163+
// Include auxiliary functions like for serializing/deserializing.
164+
#include "HelloWorldCdrAux.ipp"
190165

191-
192-
193-
194-
return current_align;
195-
}
196-
197-
bool HelloWorld::isKeyDefined()
198-
{
199-
return false;
200-
}
201-
202-
void HelloWorld::serializeKey(eprosima::fastcdr::Cdr &scdr) const
203-
{
204-
(void) scdr;
205-
206-
207-
}
166+
#endif // FASTCDR_VERSION_MAJOR > 1

0 commit comments

Comments
 (0)