Skip to content

Commit d89d2eb

Browse files
committed
Refs #21185: Apply suggestions
Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
1 parent cc43795 commit d89d2eb

11 files changed

Lines changed: 142 additions & 100 deletions

examples/cpp/flow_control/CLIParser.hpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,43 +226,42 @@ class CLIParser
226226
}
227227
else if (arg == "--period")
228228
{
229-
if (config.entity == CLIParser::EntityKind::PUBLISHER)
229+
if (config.entity != CLIParser::EntityKind::PUBLISHER)
230230
{
231-
if (++i < argc)
231+
EPROSIMA_LOG_ERROR(CLI_PARSER, "period argument is only valid for publisher entity");
232+
print_help(EXIT_FAILURE);
233+
}
234+
235+
if (++i < argc)
236+
{
237+
try
232238
{
233-
try
234-
{
235-
uint64_t input = std::stoull(argv[i]);
236-
if (input > std::numeric_limits<uint64_t>::max())
237-
{
238-
throw std::out_of_range("period argument " + std::string(
239-
argv[i]) + " out of range.");
240-
}
241-
config.period = input;
242-
}
243-
catch (const std::invalid_argument& e)
239+
uint64_t input = std::stoull(argv[i]);
240+
if (input > std::numeric_limits<uint64_t>::max())
244241
{
245-
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid period argument " + std::string(
246-
argv[i]) + ": " + std::string(e.what()));
247-
print_help(EXIT_FAILURE);
248-
}
249-
catch (const std::out_of_range& e)
250-
{
251-
EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what()));
252-
print_help(EXIT_FAILURE);
242+
throw std::out_of_range("period argument " + std::string(
243+
argv[i]) + " out of range.");
253244
}
245+
config.period = input;
254246
}
255-
else
247+
catch (const std::invalid_argument& e)
256248
{
257-
EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing period argument");
249+
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid period argument " + std::string(
250+
argv[i]) + ": " + std::string(e.what()));
251+
print_help(EXIT_FAILURE);
252+
}
253+
catch (const std::out_of_range& e)
254+
{
255+
EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what()));
258256
print_help(EXIT_FAILURE);
259257
}
260258
}
261259
else
262260
{
263-
EPROSIMA_LOG_ERROR(CLI_PARSER, "period argument is only valid for publisher entity");
261+
EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing period argument");
264262
print_help(EXIT_FAILURE);
265263
}
264+
266265
}
267266
else if (arg == "--scheduler")
268267
{

examples/cpp/flow_control/FlowControl.hpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class FlowControl
7979
eProsima_user_DllExport FlowControl(
8080
const FlowControl& x)
8181
{
82-
m_message = x.m_message;
82+
m_index = x.m_index;
8383

84-
m_index = x.m_index;
84+
m_message = x.m_message;
8585

8686
}
8787

@@ -92,8 +92,8 @@ class FlowControl
9292
eProsima_user_DllExport FlowControl(
9393
FlowControl&& x) noexcept
9494
{
95-
m_message = std::move(x.m_message);
9695
m_index = x.m_index;
96+
m_message = std::move(x.m_message);
9797
}
9898

9999
/*!
@@ -104,9 +104,9 @@ class FlowControl
104104
const FlowControl& x)
105105
{
106106

107-
m_message = x.m_message;
107+
m_index = x.m_index;
108108

109-
m_index = x.m_index;
109+
m_message = x.m_message;
110110

111111
return *this;
112112
}
@@ -119,8 +119,8 @@ class FlowControl
119119
FlowControl&& x) noexcept
120120
{
121121

122-
m_message = std::move(x.m_message);
123122
m_index = x.m_index;
123+
m_message = std::move(x.m_message);
124124
return *this;
125125
}
126126

@@ -131,8 +131,8 @@ class FlowControl
131131
eProsima_user_DllExport bool operator ==(
132132
const FlowControl& x) const
133133
{
134-
return (m_message == x.m_message &&
135-
m_index == x.m_index);
134+
return (m_index == x.m_index &&
135+
m_message == x.m_message);
136136
}
137137

138138
/*!
@@ -145,6 +145,35 @@ class FlowControl
145145
return !(*this == x);
146146
}
147147

148+
/*!
149+
* @brief This function sets a value in member index
150+
* @param _index New value for member index
151+
*/
152+
eProsima_user_DllExport void index(
153+
uint32_t _index)
154+
{
155+
m_index = _index;
156+
}
157+
158+
/*!
159+
* @brief This function returns the value of member index
160+
* @return Value of member index
161+
*/
162+
eProsima_user_DllExport uint32_t index() const
163+
{
164+
return m_index;
165+
}
166+
167+
/*!
168+
* @brief This function returns a reference to member index
169+
* @return Reference to member index
170+
*/
171+
eProsima_user_DllExport uint32_t& index()
172+
{
173+
return m_index;
174+
}
175+
176+
148177
/*!
149178
* @brief This function copies the value in member message
150179
* @param _message New value to be copied in member message
@@ -183,38 +212,12 @@ class FlowControl
183212
return m_message;
184213
}
185214

186-
/*!
187-
* @brief This function sets a value in member index
188-
* @param _index New value for member index
189-
*/
190-
eProsima_user_DllExport void index(
191-
uint32_t _index)
192-
{
193-
m_index = _index;
194-
}
195215

196-
/*!
197-
* @brief This function returns the value of member index
198-
* @return Value of member index
199-
*/
200-
eProsima_user_DllExport uint32_t index() const
201-
{
202-
return m_index;
203-
}
204-
205-
/*!
206-
* @brief This function returns a reference to member index
207-
* @return Reference to member index
208-
*/
209-
eProsima_user_DllExport uint32_t& index()
210-
{
211-
return m_index;
212-
}
213216

214217
private:
215218

216-
std::array<char, 600000> m_message{0};
217219
uint32_t m_index{0};
220+
std::array<char, 600000> m_message{0};
218221

219222
};
220223

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct FlowControl
22
{
3-
char message[600000];
43
unsigned long index;
4+
char message[600000];
55
};

examples/cpp/flow_control/FlowControlCdrAux.ipp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ eProsima_user_DllExport size_t calculate_serialized_size(
5151

5252

5353
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
54-
data.message(), current_alignment);
54+
data.index(), current_alignment);
5555

5656
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
57-
data.index(), current_alignment);
57+
data.message(), current_alignment);
5858

5959

6060
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
@@ -74,8 +74,8 @@ eProsima_user_DllExport void serialize(
7474
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
7575

7676
scdr
77-
<< eprosima::fastcdr::MemberId(0) << data.message()
78-
<< eprosima::fastcdr::MemberId(1) << data.index()
77+
<< eprosima::fastcdr::MemberId(0) << data.index()
78+
<< eprosima::fastcdr::MemberId(1) << data.message()
7979
;
8080
scdr.end_serialize_type(current_state);
8181
}
@@ -94,11 +94,11 @@ eProsima_user_DllExport void deserialize(
9494
switch (mid.id)
9595
{
9696
case 0:
97-
dcdr >> data.message();
97+
dcdr >> data.index();
9898
break;
9999

100100
case 1:
101-
dcdr >> data.index();
101+
dcdr >> data.message();
102102
break;
103103

104104
default:

examples/cpp/flow_control/FlowControlPubSubTypes.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class FlowControlPubSubType : public eprosima::fastdds::dds::TopicDataType
106106
}
107107

108108
eProsima_user_DllExport inline bool is_plain(
109-
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
109+
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
110110
{
111111
static_cast<void>(data_representation);
112112
return false;

examples/cpp/flow_control/FlowControlTypeObjectSupport.cxx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@ void register_FlowControl_type_identifier(
5858
CompleteStructHeader header_FlowControl;
5959
header_FlowControl = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_FlowControl);
6060
CompleteStructMemberSeq member_seq_FlowControl;
61+
{
62+
TypeIdentifierPair type_ids_index;
63+
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
64+
return_code_index =
65+
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
66+
"_uint32_t", type_ids_index);
67+
68+
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
69+
{
70+
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
71+
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
72+
return;
73+
}
74+
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
75+
false, false, false, false);
76+
MemberId member_id_index = 0x00000000;
77+
bool common_index_ec {false};
78+
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
79+
if (!common_index_ec)
80+
{
81+
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
82+
return;
83+
}
84+
MemberName name_index = "index";
85+
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
86+
ann_custom_FlowControl.reset();
87+
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_FlowControl);
88+
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
89+
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_index);
90+
}
6191
{
6292
TypeIdentifierPair type_ids_message;
6393
ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK};
@@ -107,7 +137,7 @@ void register_FlowControl_type_identifier(
107137
}
108138
StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
109139
false, false, false, false);
110-
MemberId member_id_message = 0x00000000;
140+
MemberId member_id_message = 0x00000001;
111141
bool common_message_ec {false};
112142
CommonStructMember common_message {TypeObjectUtils::build_common_struct_member(member_id_message, member_flags_message, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_message, common_message_ec))};
113143
if (!common_message_ec)
@@ -122,36 +152,6 @@ void register_FlowControl_type_identifier(
122152
CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message);
123153
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_message);
124154
}
125-
{
126-
TypeIdentifierPair type_ids_index;
127-
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
128-
return_code_index =
129-
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
130-
"_uint32_t", type_ids_index);
131-
132-
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
133-
{
134-
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
135-
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
136-
return;
137-
}
138-
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
139-
false, false, false, false);
140-
MemberId member_id_index = 0x00000001;
141-
bool common_index_ec {false};
142-
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
143-
if (!common_index_ec)
144-
{
145-
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
146-
return;
147-
}
148-
MemberName name_index = "index";
149-
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
150-
ann_custom_FlowControl.reset();
151-
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_FlowControl);
152-
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
153-
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_index);
154-
}
155155
CompleteStructType struct_type_FlowControl = TypeObjectUtils::build_complete_struct_type(struct_flags_FlowControl, header_FlowControl, member_seq_FlowControl);
156156
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
157157
TypeObjectUtils::build_and_register_struct_type_object(struct_type_FlowControl, type_name_FlowControl.to_string(), type_ids_FlowControl))

0 commit comments

Comments
 (0)