Skip to content

Commit 78332f8

Browse files
authored
Merge pull request OpenDDS#3766 from jwillemsen/jwi-ddsxtypesextended
Test and fix for problem with appendable types and additional written fields
2 parents 700df73 + 7ee338d commit 78332f8

File tree

6 files changed

+108
-20
lines changed

6 files changed

+108
-20
lines changed

dds/idl/marshal_generator.cpp

+24-14
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,11 @@ namespace {
27772777
be_global->impl_ <<
27782778
" const Encoding& encoding = strm.encoding();\n"
27792779
" ACE_UNUSED_ARG(encoding);\n";
2780+
if (is_appendable) {
2781+
be_global->impl_ <<
2782+
" bool reached_end_of_struct = false;\n"
2783+
" ACE_UNUSED_ARG(reached_end_of_struct);\n";
2784+
}
27802785
marshal_generator::generate_dheader_code(
27812786
" if (!strm.read_delimiter(total_size)) {\n"
27822787
" return false;\n"
@@ -2805,16 +2810,14 @@ namespace {
28052810
* to read a non-existent member id.
28062811
*/
28072812
be_global->impl_ <<
2808-
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 &&\n"
2809-
" strm.rpos() >= end_of_struct) {\n"
2813+
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() >= end_of_struct) {\n"
28102814
" return true;\n"
28112815
" }\n"
28122816
" bool must_understand = false;\n"
28132817
" if (!strm.read_parameter_id(member_id, field_size, must_understand)) {\n"
28142818
" return false;\n"
28152819
" }\n"
2816-
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_1 &&\n"
2817-
" member_id == Serializer::pid_list_end) {\n"
2820+
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_1 && member_id == Serializer::pid_list_end) {\n"
28182821
" return true;\n"
28192822
" }\n"
28202823
" const size_t end_of_field = strm.rpos() + field_size;\n"
@@ -2930,14 +2933,9 @@ namespace {
29302933
if (expr.size() && exten != extensibilitykind_appendable) {
29312934
expr += "\n && ";
29322935
}
2933-
// TODO (sonndinh): Integrate with try-construct for when the stream
2934-
// ends before some fields on the reader side get their values.
29352936
if (is_appendable) {
29362937
expr +=
2937-
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 &&\n"
2938-
" strm.rpos() >= end_of_struct) {\n"
2939-
" return true;\n"
2940-
" }\n";
2938+
" reached_end_of_struct |= (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() >= end_of_struct);\n";
29412939
}
29422940
const string field_name = field->local_name()->get_string();
29432941
const string cond = rtpsCustom.getConditional(field_name);
@@ -2956,23 +2954,35 @@ namespace {
29562954
expr += prefix + "(!(" + cond + ") || ";
29572955
}
29582956
} else if (is_appendable) {
2959-
expr += " if (!";
2957+
AST_Type* const type = field->field_type();
2958+
string stru_field_name = "stru" + value_access + "." + field_name;
2959+
if (use_cxx11) {
2960+
stru_field_name += "()";
2961+
}
2962+
expr +=
2963+
" if (reached_end_of_struct) {\n" +
2964+
type_to_default(" ", type, stru_field_name, type->anonymous()) +
2965+
" } else {\n"
2966+
" if (!";
29602967
}
29612968
expr += generate_field_stream(
29622969
indent, field, ">> stru" + value_access, wrap_nested_key_only, intro);
29632970
if (is_appendable) {
29642971
expr += ") {\n"
2965-
" return false;\n"
2972+
" return false;\n"
2973+
" }\n";
2974+
if (cond.empty()) {
2975+
expr +=
29662976
" }\n";
2977+
}
29672978
} else if (!cond.empty()) {
29682979
expr += ")";
29692980
}
29702981
}
29712982
intro.join(be_global->impl_, indent);
29722983
if (is_appendable) {
29732984
expr +=
2974-
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 &&\n"
2975-
" strm.rpos() < end_of_struct) {\n"
2985+
" if (encoding.xcdr_version() == Encoding::XCDR_VERSION_2 && strm.rpos() < end_of_struct) {\n"
29762986
" strm.skip(end_of_struct - strm.rpos());\n"
29772987
" }\n"
29782988
" return true;\n";

tests/DCPS/XTypes/Publisher.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ void write_additional_prefix_field_struct(const DataWriter_var& dw)
9292
}
9393
}
9494

95+
void write_base_appendable_struct(const DataWriter_var& dw)
96+
{
97+
BaseAppendableStructDataWriter_var typed_dw = BaseAppendableStructDataWriter::_narrow(dw);
98+
99+
BaseAppendableStruct bas;
100+
bas.key_field = key_value;
101+
102+
const ReturnCode_t ret = typed_dw->write(bas, HANDLE_NIL);
103+
if (ret != RETCODE_OK) {
104+
ACE_ERROR((LM_ERROR, "ERROR: write_base_appendable_struct returned %C\n",
105+
OpenDDS::DCPS::retcode_to_string(ret)));
106+
}
107+
if (verbose) {
108+
ACE_DEBUG((LM_DEBUG, "writer: BaseAppendableStruct\n"));
109+
}
110+
}
111+
95112
void write_additional_postfix_field_struct(const DataWriter_var& dw)
96113
{
97114
AdditionalPostfixFieldStructDataWriter_var typed_dw = AdditionalPostfixFieldStructDataWriter::_narrow(dw);
@@ -307,6 +324,9 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
307324
} else if (type == "ModifiedFinalStruct") {
308325
ModifiedFinalStructTypeSupport_var ts = new ModifiedFinalStructTypeSupportImpl;
309326
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
327+
} else if (type == "BaseAppendableStruct") {
328+
BaseAppendableStructTypeSupport_var ts = new BaseAppendableStructTypeSupportImpl;
329+
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
310330
} else if (type == "AppendableStructNoXTypes") {
311331
AppendableStructNoXTypesTypeSupport_var ts = new AppendableStructNoXTypesTypeSupportImpl;
312332
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
@@ -484,6 +504,8 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
484504
write_final_struct(dw);
485505
} else if (type == "ModifiedFinalStruct") {
486506
write_modified_final_struct(dw);
507+
} else if (type == "BaseAppendableStruct") {
508+
write_base_appendable_struct(dw);
487509
} else if (type == "AppendableStructNoXTypes") {
488510
write_appendable_struct_no_xtypes(dw);
489511
} else if (type == "AdditionalPrefixFieldStruct") {

tests/DCPS/XTypes/Publisher.idl

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ struct ModifiedFinalStruct {
1515
};
1616

1717
// Appendable structures
18+
@topic
19+
@appendable
20+
struct BaseAppendableStruct {
21+
@key long key_field;
22+
};
23+
1824
@topic
1925
@appendable
2026
struct AdditionalPostfixFieldStruct {

tests/DCPS/XTypes/Subscriber.cpp

+43-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ template<typename T1, typename T2>
2222
ReturnCode_t read_tryconstruct_struct(const DataReader_var& dr, const T1& pdr, T2& data,
2323
const std::string& expected_value)
2424
{
25-
ReturnCode_t ret = RETCODE_OK;
26-
if ((ret = read_i(dr, pdr, data)) == RETCODE_OK) {
25+
ReturnCode_t ret = read_i(dr, pdr, data);
26+
if (ret == RETCODE_OK) {
2727
if (data.length() != 1) {
2828
ACE_ERROR((LM_ERROR, "ERROR: reader: unexpected data length: %d\n", data.length()));
2929
ret = RETCODE_ERROR;
@@ -45,8 +45,8 @@ ReturnCode_t read_tryconstruct_struct(const DataReader_var& dr, const T1& pdr, T
4545
template<typename T1, typename T2>
4646
ReturnCode_t read_struct(const DataReader_var& dr, const T1& pdr, T2& data)
4747
{
48-
ReturnCode_t ret = RETCODE_OK;
49-
if ((ret = read_i(dr, pdr, data)) == RETCODE_OK) {
48+
ReturnCode_t ret = read_i(dr, pdr, data);
49+
if (ret == RETCODE_OK) {
5050
if (data.length() != 1) {
5151
ACE_ERROR((LM_ERROR, "reader: unexpected data length: %d\n", data.length()));
5252
ret = RETCODE_ERROR;
@@ -64,11 +64,36 @@ ReturnCode_t read_struct(const DataReader_var& dr, const T1& pdr, T2& data)
6464
return ret;
6565
}
6666

67+
template<typename T1, typename T2>
68+
ReturnCode_t read_extended_struct(const DataReader_var& dr, const T1& pdr, T2& data)
69+
{
70+
ReturnCode_t ret = read_i(dr, pdr, data);
71+
if (ret == RETCODE_OK) {
72+
if (data.length() != 1) {
73+
ACE_ERROR((LM_ERROR, "reader: unexpected data length: %d\n", data.length()));
74+
ret = RETCODE_ERROR;
75+
} else if (data[0].key_field != key_value) {
76+
ACE_ERROR((LM_ERROR, "reader: expected key value: %d, received: %d\n", key_value, data[0].key_field));
77+
ret = RETCODE_ERROR;
78+
} else if (data[0].additional_field != 0) {
79+
ACE_ERROR((LM_ERROR, "reader: expected additional_field: %d, received: %d\n", 0, data[0].additional_field));
80+
ret = RETCODE_ERROR;
81+
} else if (verbose) {
82+
ACE_DEBUG((LM_DEBUG, "reader: %d additional_field: %d\n", data[0].key_field, data[0].additional_field));
83+
}
84+
} else {
85+
ACE_ERROR((LM_ERROR, "ERROR: Reader: read_i returned %C\n",
86+
OpenDDS::DCPS::retcode_to_string(ret)));
87+
}
88+
89+
return ret;
90+
}
91+
6792
template<typename T1, typename T2>
6893
ReturnCode_t read_union(const DataReader_var& dr, const T1& pdr, T2& data)
6994
{
70-
ReturnCode_t ret = RETCODE_OK;
71-
if ((ret = read_i(dr, pdr, data)) == RETCODE_OK) {
95+
ReturnCode_t ret = read_i(dr, pdr, data);
96+
if (ret == RETCODE_OK) {
7297
if (data.length() != 1) {
7398
ACE_ERROR((LM_ERROR, "reader: unexpected data length: %d\n", data.length()));
7499
ret = RETCODE_ERROR;
@@ -128,6 +153,13 @@ ReturnCode_t read_appendable_struct(const DataReader_var& dr)
128153
return read_struct(dr, pdr, data);
129154
}
130155

156+
ReturnCode_t read_extended_appendable_struct(const DataReader_var& dr)
157+
{
158+
ExtendedAppendableStructDataReader_var pdr = ExtendedAppendableStructDataReader::_narrow(dr);
159+
::ExtendedAppendableStructSeq data;
160+
return read_extended_struct(dr, pdr, data);
161+
}
162+
131163
ReturnCode_t read_appendable_struct_no_xtypes(const DataReader_var& dr)
132164
{
133165
AppendableStructNoXTypesDataReader_var pdr = AppendableStructNoXTypesDataReader::_narrow(dr);
@@ -250,6 +282,9 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
250282
} else if (type == "AppendableStruct") {
251283
AppendableStructTypeSupport_var ts = new AppendableStructTypeSupportImpl;
252284
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
285+
} else if (type == "ExtendedAppendableStruct") {
286+
ExtendedAppendableStructTypeSupport_var ts = new ExtendedAppendableStructTypeSupportImpl;
287+
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
253288
} else if (type == "AppendableStructNoXTypes") {
254289
AppendableStructNoXTypesTypeSupport_var ts = new AppendableStructNoXTypesTypeSupportImpl;
255290
failed = !get_topic(ts, dp, topic_name, topic, registered_type_name);
@@ -402,6 +437,8 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
402437
failed = (read_plain_cdr_struct(dr) != RETCODE_OK);
403438
} else if (type == "AppendableStruct") {
404439
failed = (read_appendable_struct(dr) != RETCODE_OK);
440+
} else if (type == "ExtendedAppendableStruct") {
441+
failed = (read_extended_appendable_struct(dr) != RETCODE_OK);
405442
} else if (type == "AppendableStructNoXTypes") {
406443
failed = (read_appendable_struct_no_xtypes(dr) != RETCODE_OK);
407444
} else if (type == "FinalStructSub") {

tests/DCPS/XTypes/Subscriber.idl

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ struct AppendableStruct {
1414
@key long key_field;
1515
};
1616

17+
@topic
18+
@appendable
19+
struct ExtendedAppendableStruct {
20+
@key long key_field;
21+
long additional_field;
22+
};
23+
24+
1725
// Mutable structures
1826
@topic
1927
@mutable

tests/DCPS/XTypes/run_test.pl

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@
120120
expect_inconsistent_topic => 0, topic => "AppendableStructT", key_val => 4,
121121
r_ini => "rtps_disc.ini", w_ini => "rtps_disc.ini",
122122
},
123+
"ExtendedAppendableMatch" => {
124+
reader_type => "ExtendedAppendableStruct", writer_type => "BaseAppendableStruct",
125+
expect_inconsistent_topic => 0, topic => "AppendableStructT", key_val => 4,
126+
r_ini => "rtps_disc.ini", w_ini => "rtps_disc.ini",
127+
},
123128
"AppendableNoMatch" => {
124129
reader_type => "AppendableStruct", writer_type => "AdditionalPrefixFieldStruct",
125130
expect_inconsistent_topic => 1, topic => "AppendableStructT_NoMatch", key_val => 5,

0 commit comments

Comments
 (0)