Skip to content

Commit

Permalink
Refs #21185: Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
  • Loading branch information
elianalf committed Jul 3, 2024
1 parent cc43795 commit d89d2eb
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 100 deletions.
47 changes: 23 additions & 24 deletions examples/cpp/flow_control/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,43 +226,42 @@ class CLIParser
}
else if (arg == "--period")
{
if (config.entity == CLIParser::EntityKind::PUBLISHER)
if (config.entity != CLIParser::EntityKind::PUBLISHER)
{
if (++i < argc)
EPROSIMA_LOG_ERROR(CLI_PARSER, "period argument is only valid for publisher entity");
print_help(EXIT_FAILURE);
}

if (++i < argc)
{
try
{
try
{
uint64_t input = std::stoull(argv[i]);
if (input > std::numeric_limits<uint64_t>::max())
{
throw std::out_of_range("period argument " + std::string(
argv[i]) + " out of range.");
}
config.period = input;
}
catch (const std::invalid_argument& e)
uint64_t input = std::stoull(argv[i]);
if (input > std::numeric_limits<uint64_t>::max())
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid period argument " + std::string(
argv[i]) + ": " + std::string(e.what()));
print_help(EXIT_FAILURE);
}
catch (const std::out_of_range& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what()));
print_help(EXIT_FAILURE);
throw std::out_of_range("period argument " + std::string(
argv[i]) + " out of range.");
}
config.period = input;
}
else
catch (const std::invalid_argument& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing period argument");
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid period argument " + std::string(
argv[i]) + ": " + std::string(e.what()));
print_help(EXIT_FAILURE);
}
catch (const std::out_of_range& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what()));
print_help(EXIT_FAILURE);
}
}
else
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "period argument is only valid for publisher entity");
EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing period argument");
print_help(EXIT_FAILURE);
}

}
else if (arg == "--scheduler")
{
Expand Down
73 changes: 38 additions & 35 deletions examples/cpp/flow_control/FlowControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class FlowControl
eProsima_user_DllExport FlowControl(
const FlowControl& x)
{
m_message = x.m_message;
m_index = x.m_index;

m_index = x.m_index;
m_message = x.m_message;

}

Expand All @@ -92,8 +92,8 @@ class FlowControl
eProsima_user_DllExport FlowControl(
FlowControl&& x) noexcept
{
m_message = std::move(x.m_message);
m_index = x.m_index;
m_message = std::move(x.m_message);
}

/*!
Expand All @@ -104,9 +104,9 @@ class FlowControl
const FlowControl& x)
{

m_message = x.m_message;
m_index = x.m_index;

m_index = x.m_index;
m_message = x.m_message;

return *this;
}
Expand All @@ -119,8 +119,8 @@ class FlowControl
FlowControl&& x) noexcept
{

m_message = std::move(x.m_message);
m_index = x.m_index;
m_message = std::move(x.m_message);
return *this;
}

Expand All @@ -131,8 +131,8 @@ class FlowControl
eProsima_user_DllExport bool operator ==(
const FlowControl& x) const
{
return (m_message == x.m_message &&
m_index == x.m_index);
return (m_index == x.m_index &&
m_message == x.m_message);
}

/*!
Expand All @@ -145,6 +145,35 @@ class FlowControl
return !(*this == x);
}

/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}

/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}

/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}


/*!
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
Expand Down Expand Up @@ -183,38 +212,12 @@ class FlowControl
return m_message;
}

/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}

/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}

/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}

private:

std::array<char, 600000> m_message{0};
uint32_t m_index{0};
std::array<char, 600000> m_message{0};

};

Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/flow_control/FlowControl.idl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct FlowControl
{
char message[600000];
unsigned long index;
char message[600000];
};
12 changes: 6 additions & 6 deletions examples/cpp/flow_control/FlowControlCdrAux.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ eProsima_user_DllExport size_t calculate_serialized_size(


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

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


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

scdr
<< eprosima::fastcdr::MemberId(0) << data.message()
<< eprosima::fastcdr::MemberId(1) << data.index()
<< eprosima::fastcdr::MemberId(0) << data.index()
<< eprosima::fastcdr::MemberId(1) << data.message()
;
scdr.end_serialize_type(current_state);
}
Expand All @@ -94,11 +94,11 @@ eProsima_user_DllExport void deserialize(
switch (mid.id)
{
case 0:
dcdr >> data.message();
dcdr >> data.index();
break;

case 1:
dcdr >> data.index();
dcdr >> data.message();
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/flow_control/FlowControlPubSubTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FlowControlPubSubType : public eprosima::fastdds::dds::TopicDataType
}

eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
Expand Down
62 changes: 31 additions & 31 deletions examples/cpp/flow_control/FlowControlTypeObjectSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ void register_FlowControl_type_identifier(
CompleteStructHeader header_FlowControl;
header_FlowControl = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_FlowControl);
CompleteStructMemberSeq member_seq_FlowControl;
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);

if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000000;
bool common_index_ec {false};
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))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_FlowControl.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_FlowControl);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_index);
}
{
TypeIdentifierPair type_ids_message;
ReturnCode_t return_code_message {eprosima::fastdds::dds::RETCODE_OK};
Expand Down Expand Up @@ -107,7 +137,7 @@ void register_FlowControl_type_identifier(
}
StructMemberFlag member_flags_message = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_message = 0x00000000;
MemberId member_id_message = 0x00000001;
bool common_message_ec {false};
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))};
if (!common_message_ec)
Expand All @@ -122,36 +152,6 @@ void register_FlowControl_type_identifier(
CompleteStructMember member_message = TypeObjectUtils::build_complete_struct_member(common_message, detail_message);
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_message);
}
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);

if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000001;
bool common_index_ec {false};
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))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_FlowControl.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_FlowControl);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_FlowControl, member_index);
}
CompleteStructType struct_type_FlowControl = TypeObjectUtils::build_complete_struct_type(struct_flags_FlowControl, header_FlowControl, member_seq_FlowControl);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_FlowControl, type_name_FlowControl.to_string(), type_ids_FlowControl))
Expand Down
Loading

0 comments on commit d89d2eb

Please sign in to comment.