Skip to content

Commit

Permalink
Refs #21094: Change example name and fix interval parsing
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 3, 2024
1 parent 6e36fe4 commit f946f6e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
29 changes: 25 additions & 4 deletions examples/cpp/custom_payload_pool/CLIParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CLIParser
static void print_help(
uint8_t return_code)
{
std::cout << "Usage: hello_world <entity> [options]" << std::endl;
std::cout << "Usage: custom_payload_pool <entity> [options]" << std::endl;
std::cout << "" << std::endl;
std::cout << "Entities:" << std::endl;
std::cout << " publisher Run a publisher entity" << std::endl;
Expand Down Expand Up @@ -186,13 +186,34 @@ class CLIParser
}
else if (arg == "-i" || arg == "--interval")
{
if (config.entity == CLIParser::EntityKind::PUBLISHER)
if (i + 1 < argc)
{
config.pub_config.interval = true;
try
{
if (config.entity == CLIParser::EntityKind::PUBLISHER)
{
config.pub_config.interval = std::stoi(argv[++i]);
}
else
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "interval can only be used with the publisher entity");
print_help(EXIT_FAILURE);
}
}
catch (const std::invalid_argument& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid interval argument for " + arg + ": " + e.what());
print_help(EXIT_FAILURE);
}
catch (const std::out_of_range& e)
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "interval argument out of range for " + arg + ": " + e.what());
print_help(EXIT_FAILURE);
}
}
else
{
EPROSIMA_LOG_ERROR(CLI_PARSER, "interval can only be used with the publisher entity");
EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg);
print_help(EXIT_FAILURE);
}
}
Expand Down
12 changes: 6 additions & 6 deletions examples/cpp/custom_payload_pool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

cmake_minimum_required(VERSION 3.20)

project(CustomPayloadPoolExample VERSION 1 LANGUAGES CXX)
project(custom_payload_pool VERSION 1 LANGUAGES CXX)

# Find requirements
if(NOT fastcdr_FOUND)
Expand All @@ -38,11 +38,11 @@ message(STATUS "Configuring custom payload pool example...")
file(GLOB CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CPP "*.cpp")

add_executable(CustomPayloadPoolExample ${CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CXX} ${CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CPP})
target_compile_definitions(CustomPayloadPoolExample PRIVATE
add_executable(custom_payload_pool ${CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CXX} ${CUSTOM_PAYLOAD_POOL_DATA_EXAMPLE_SOURCES_CPP})
target_compile_definitions(custom_payload_pool PRIVATE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_link_libraries(CustomPayloadPoolExample fastdds fastcdr fastdds::optionparser)
install(TARGETS CustomPayloadPoolExample
RUNTIME DESTINATION examples/cpp/dds/CustomPayloadPoolExample/${BIN_INSTALL_DIR})
target_link_libraries(custom_payload_pool fastdds fastcdr fastdds::optionparser)
install(TARGETS custom_payload_pool
RUNTIME DESTINATION examples/cpp/dds/custom_payload_pool/${BIN_INSTALL_DIR})

0 comments on commit f946f6e

Please sign in to comment.