Skip to content

Commit

Permalink
Refs #21094: 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 Jun 12, 2024
1 parent 6ac3274 commit dfecea5
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 16 deletions.
50 changes: 49 additions & 1 deletion examples/cpp/custom_payload_pool/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CLIParser
struct subscriber_config
{
uint16_t samples = 0;
uint16_t domain = 0;
};

//! Publisher application configuration structure
Expand Down Expand Up @@ -83,6 +84,8 @@ class CLIParser
std::cout << " -s <num>, --samples <num> Number of samples to send or receive" << std::endl;
std::cout << " [0 <= <num> <= 65535]" << std::endl;
std::cout << " (Default: 0 [unlimited])" << std::endl;
std::cout << " -d <num>, --domain <num> Domain ID number [0 <= <num> <= 232]" << std::endl;
std::cout << " (Default: 0)" << std::endl;
std::cout << "Publisher options:" << std::endl;
std::cout << " -i, --interval Time between samples in milliseconds " << std::endl;
std::cout << " (Default: 100)" << std::endl;
Expand Down Expand Up @@ -183,6 +186,51 @@ class CLIParser
EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg);
print_help(EXIT_FAILURE);
}
}
else if (arg == "-d" || arg == "--domain")
{
if (i + 1 < argc)
{
try
{
int input = std::stoi(argv[++i]);
if (input < 0 || input > 232)
{
throw std::out_of_range("domain argument out of range");
}
else
{
if (config.entity == CLIParser::EntityKind::PUBLISHER)
{
config.pub_config.domain = static_cast<uint16_t>(input);
}
else if (config.entity == CLIParser::EntityKind::SUBSCRIBER)
{
config.sub_config.domain = static_cast<uint16_t>(input);
}
else
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --domain argument");
print_help(EXIT_FAILURE);
}
}
}
catch (const std::invalid_argument& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid domain argument for " + arg + ": " + e.what());
print_help(EXIT_FAILURE);
}
catch (const std::out_of_range& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "domain argument out of range for " + arg + ": " + e.what());
print_help(EXIT_FAILURE);
}
}
else
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg);
print_help(EXIT_FAILURE);
}
}
else if (arg == "-i" || arg == "--interval")
{
Expand All @@ -192,7 +240,7 @@ class CLIParser
{
if (config.entity == CLIParser::EntityKind::PUBLISHER)
{
config.pub_config.interval = std::stoi(argv[++i]);
config.pub_config.interval = static_cast<uint16_t>(std::stoi(argv[++i]));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions examples/cpp/custom_payload_pool/CustomPayloadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* @file CustomPayloadPool.hpp
*/

#ifndef DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP
#define DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP
#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_
#define _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_

#include <assert.h>
#include <stdio.h>
Expand Down Expand Up @@ -97,4 +97,4 @@ class CustomPayloadPool : public eprosima::fastrtps::rtps::IPayloadPool

};

#endif // DDS_CUSTOM_PAYLOAD_POOL_DATA_HPP
#endif // _FASTDDS_CUSTOM_PAYLOAD_POOL_HPP_
5 changes: 3 additions & 2 deletions examples/cpp/custom_payload_pool/PublisherApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ PublisherApp::PublisherApp(
payload_pool_ = std::make_shared<CustomPayloadPool>();

// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
auto factory = DomainParticipantFactory::get_instance();
participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none());
participant_ = factory->create_participant(config.domain, pqos);
if (participant_ == nullptr)
{
throw std::runtime_error("Participant initialization failed");
Expand Down Expand Up @@ -176,4 +177,4 @@ void PublisherApp::stop()
} // namespace custom_payload_pool
} // namespace examples
} // namespace fastdds
} // namespace eprosima
} // namespace eprosima
6 changes: 3 additions & 3 deletions examples/cpp/custom_payload_pool/PublisherApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_HPP_
#define _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_HPP_
#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_
#define _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_HPP_

#include <condition_variable>
#include <mutex>
Expand Down Expand Up @@ -103,4 +103,4 @@ class PublisherApp : public Application, public DataWriterListener
} // namespace fastdds
} // namespace eprosima

#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_PUBLISHER_H_ */
#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_PUBLISHER_H_ */
5 changes: 3 additions & 2 deletions examples/cpp/custom_payload_pool/SubscriberApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ SubscriberApp::SubscriberApp(
payload_pool_ = std::make_shared<CustomPayloadPool>();

// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
auto factory = DomainParticipantFactory::get_instance();
participant_ = factory->create_participant_with_default_profile(nullptr, StatusMask::none());
participant_ = factory->create_participant(config.domain, pqos);
if (participant_ == nullptr)
{
throw std::runtime_error("Participant initialization failed");
Expand Down Expand Up @@ -160,4 +161,4 @@ void SubscriberApp::stop()
} // namespace custom_payload_pool
} // namespace examples
} // namespace fastdds
} // namespace eprosima
} // namespace eprosima
6 changes: 3 additions & 3 deletions examples/cpp/custom_payload_pool/SubscriberApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_
#define _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_
#ifndef _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_
#define _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_

#include <condition_variable>
#include <mutex>
Expand Down Expand Up @@ -101,4 +101,4 @@ class SubscriberApp : public Application, public DataReaderListener
} // namespace fastdds
} // namespace eprosima

#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_DATA_SUBSCRIBER_HPP_ */
#endif /* _FASTDDS_CUSTOM_PAYLOAD_POOL_SUBSCRIBER_HPP_ */
2 changes: 1 addition & 1 deletion test/examples/custom_payload_pool.compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ services:
EXAMPLE_DIR: @PROJECT_BINARY_DIR@/examples/cpp/custom_payload_pool
command: @SHELL_EXECUTABLE@ -c "$${EXAMPLE_DIR}/custom_payload_pool@FILE_EXTENSION@ publisher --samples 10"
depends_on:
- subscriber
- subscriber
2 changes: 1 addition & 1 deletion versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Forthcoming
* Refactor examples:
* Hello world example with wait-sets and environment XML profiles.
* Configuration example that condenses multiple QoS examples. Multiple configurations allowed through argument parsing.
* Custom payload pool example.
* Custom payload pool example that uses a user-defined payload pool instead of the default
* Removed `TypeConsistencyQos` from DataReader, and included `TypeConsistencyEnforcementQosPolicy` and `DataRepresentationQosPolicy`
* Added new `flow_controller_descriptor_list` XML configuration, remove `ThroughtputController`.
* Migrate `#define`s within `BuiltinEndpoints.hpp` to namespaced `constexpr` variables.
Expand Down

0 comments on commit dfecea5

Please sign in to comment.