Skip to content

Commit

Permalink
Refs #20575: Refactor configuration example
Browse files Browse the repository at this point in the history
Signed-off-by: JesusPoderoso <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Mar 21, 2024
1 parent 30d4fcd commit b83c0ac
Show file tree
Hide file tree
Showing 34 changed files with 2,240 additions and 2,462 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
set(fastdds_FOUND TRUE)
add_subdirectory(cpp/dds)
add_subdirectory(cpp/rtps)
add_subdirectory(cpp/configuration)
57 changes: 57 additions & 0 deletions examples/cpp/configuration/Application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file Application.cpp
*
*/

#include "Application.hpp"

#include "CLIParser.hpp"
#include "PublisherApp.hpp"
#include "SubscriberApp.hpp"

using namespace eprosima::fastdds::dds;

namespace eprosima {
namespace fastdds {
namespace examples {
namespace configuration {

//! Factory method to create a publisher or subscriber
std::shared_ptr<Application> Application::make_app(
const CLIParser::configuration_config& config)
{
std::shared_ptr<Application> entity;
switch (config.entity)
{
case CLIParser::EntityKind::PUBLISHER:
entity = std::make_shared<PublisherApp>(config.pub_config);
break;
case CLIParser::EntityKind::SUBSCRIBER:
entity = std::make_shared<SubscriberApp>(config.sub_config);
break;
case CLIParser::EntityKind::UNDEFINED:
default:
throw std::runtime_error("Entity initialization failed");
break;
}
return entity;
}

} // namespace configuration
} // namespace examples
} // namespace fastdds
} // namespace eprosima
52 changes: 52 additions & 0 deletions examples/cpp/configuration/Application.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file Application.hpp
*
*/

#ifndef _FASTDDS_CONFIGURATION_APPLICATION_HPP_
#define _FASTDDS_CONFIGURATION_APPLICATION_HPP_

#include <atomic>

#include "CLIParser.hpp"

namespace eprosima {
namespace fastdds {
namespace examples {
namespace configuration {

class Application
{
public:

//! Run application
virtual void run() = 0;

//! Trigger the end of execution
virtual void stop() = 0;

//! Factory method to create applications based on configuration
static std::shared_ptr<Application> make_app(
const CLIParser::configuration_config& config);
};

} // namespace configuration
} // namespace examples
} // namespace fastdds
} // namespace eprosima

#endif /* _FASTDDS_CONFIGURATION_APPLICATION_HPP_ */
959 changes: 959 additions & 0 deletions examples/cpp/configuration/CLIParser.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

cmake_minimum_required(VERSION 3.20)

project(AdvancedConfigurationExample VERSION 1 LANGUAGES CXX)
project(fastdds_configuration_example VERSION 1 LANGUAGES CXX)

# Find requirements
if(NOT fastcdr_FOUND)
Expand All @@ -35,19 +35,32 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
endif()
endif()

message(STATUS "Configuring AdvancedConfiguration example...")
file(GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB ADVANCED_CONFIG_EXAMPLE_SOURCES_CPP "*.cpp")
message(STATUS "Configuring configuration example...")
file(GLOB CONFIGURATION_SOURCES_CXX "*.cxx")
file(GLOB CONFIGURATION_SOURCES_CPP "*.cpp")

add_executable(${PROJECT_NAME} ${ADVANCED_CONFIG_EXAMPLE_SOURCES_CXX} ${ADVANCED_CONFIG_EXAMPLE_SOURCES_CPP})
target_compile_definitions(${PROJECT_NAME} PRIVATE
add_executable(configuration ${CONFIGURATION_SOURCES_CXX} ${CONFIGURATION_SOURCES_CPP})
target_compile_definitions(configuration PRIVATE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
$<$<BOOL:${SHM_TRANSPORT_DEFAULT}>:SHM_TRANSPORT_BUILTIN> # Enable SHM as built-in transport
)

target_link_libraries(${PROJECT_NAME} fastdds fastcdr fastdds::optionparser)
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION examples/cpp/dds/${PROJECT_NAME}/${BIN_INSTALL_DIR})
target_link_libraries(configuration fastdds fastcdr)
install(TARGETS configuration
RUNTIME DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/configuration/${BIN_INSTALL_DIR})

file(COPY shm_off.xml DESTINATION ${PROJECT_BINARY_DIR})
# Copy the XML files over to the build directory
file(GLOB_RECURSE XML_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.xml)
# for each xml file detected
foreach(XML_FILE_COMPLETE_PATH ${XML_FILES})
# obtain the file name
get_filename_component(XML_FILE ${XML_FILE_COMPLETE_PATH} NAME_WE)
# copy the file from src to build folders
configure_file(
${XML_FILE_COMPLETE_PATH} # from full src path
${CMAKE_CURRENT_BINARY_DIR}/${XML_FILE}.xml # to relative build path
COPYONLY)
install(FILES ${XML_FILE_COMPLETE_PATH}
DESTINATION ${DATA_INSTALL_DIR}/fastdds/examples/cpp/configuration/${BIN_INSTALL_DIR})
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

/*!
* @file AdvancedConfiguration.cpp
* @file Configuration.cpp
* This source file contains the implementation of the described types in the IDL file.
*
* This file was generated by the tool fastddsgen.
Expand All @@ -26,9 +26,7 @@ char dummy;
} // namespace
#endif // _WIN32

#include "AdvancedConfiguration.h"

#if FASTCDR_VERSION_MAJOR > 1
#include "Configuration.h"

#include <fastcdr/Cdr.h>

Expand All @@ -43,32 +41,32 @@ using namespace eprosima::fastcdr::exception;



AdvancedConfiguration::AdvancedConfiguration()
Configuration::Configuration()
{
}

AdvancedConfiguration::~AdvancedConfiguration()
Configuration::~Configuration()
{
}

AdvancedConfiguration::AdvancedConfiguration(
const AdvancedConfiguration& x)
Configuration::Configuration(
const Configuration& x)
{
m_index = x.m_index;
m_message = x.m_message;
m_data = x.m_data;
}

AdvancedConfiguration::AdvancedConfiguration(
AdvancedConfiguration&& x) noexcept
Configuration::Configuration(
Configuration&& x) noexcept
{
m_index = x.m_index;
m_message = std::move(x.m_message);
m_data = std::move(x.m_data);
}

AdvancedConfiguration& AdvancedConfiguration::operator =(
const AdvancedConfiguration& x)
Configuration& Configuration::operator =(
const Configuration& x)
{

m_index = x.m_index;
Expand All @@ -77,8 +75,8 @@ AdvancedConfiguration& AdvancedConfiguration::operator =(
return *this;
}

AdvancedConfiguration& AdvancedConfiguration::operator =(
AdvancedConfiguration&& x) noexcept
Configuration& Configuration::operator =(
Configuration&& x) noexcept
{

m_index = x.m_index;
Expand All @@ -87,16 +85,16 @@ AdvancedConfiguration& AdvancedConfiguration::operator =(
return *this;
}

bool AdvancedConfiguration::operator ==(
const AdvancedConfiguration& x) const
bool Configuration::operator ==(
const Configuration& x) const
{
return (m_index == x.m_index &&
m_message == x.m_message &&
m_data == x.m_data);
}

bool AdvancedConfiguration::operator !=(
const AdvancedConfiguration& x) const
bool Configuration::operator !=(
const Configuration& x) const
{
return !(*this == x);
}
Expand All @@ -105,7 +103,7 @@ bool AdvancedConfiguration::operator !=(
* @brief This function sets a value in member index
* @param _index New value for member index
*/
void AdvancedConfiguration::index(
void Configuration::index(
uint32_t _index)
{
m_index = _index;
Expand All @@ -115,7 +113,7 @@ void AdvancedConfiguration::index(
* @brief This function returns the value of member index
* @return Value of member index
*/
uint32_t AdvancedConfiguration::index() const
uint32_t Configuration::index() const
{
return m_index;
}
Expand All @@ -124,7 +122,7 @@ uint32_t AdvancedConfiguration::index() const
* @brief This function returns a reference to member index
* @return Reference to member index
*/
uint32_t& AdvancedConfiguration::index()
uint32_t& Configuration::index()
{
return m_index;
}
Expand All @@ -134,7 +132,7 @@ uint32_t& AdvancedConfiguration::index()
* @brief This function copies the value in member message
* @param _message New value to be copied in member message
*/
void AdvancedConfiguration::message(
void Configuration::message(
const std::array<char, 20>& _message)
{
m_message = _message;
Expand All @@ -144,7 +142,7 @@ void AdvancedConfiguration::message(
* @brief This function moves the value in member message
* @param _message New value to be moved in member message
*/
void AdvancedConfiguration::message(
void Configuration::message(
std::array<char, 20>&& _message)
{
m_message = std::move(_message);
Expand All @@ -154,7 +152,7 @@ void AdvancedConfiguration::message(
* @brief This function returns a constant reference to member message
* @return Constant reference to member message
*/
const std::array<char, 20>& AdvancedConfiguration::message() const
const std::array<char, 20>& Configuration::message() const
{
return m_message;
}
Expand All @@ -163,7 +161,7 @@ const std::array<char, 20>& AdvancedConfiguration::message() const
* @brief This function returns a reference to member message
* @return Reference to member message
*/
std::array<char, 20>& AdvancedConfiguration::message()
std::array<char, 20>& Configuration::message()
{
return m_message;
}
Expand All @@ -173,7 +171,7 @@ std::array<char, 20>& AdvancedConfiguration::message()
* @brief This function copies the value in member data
* @param _data New value to be copied in member data
*/
void AdvancedConfiguration::data(
void Configuration::data(
const std::vector<uint8_t>& _data)
{
m_data = _data;
Expand All @@ -183,7 +181,7 @@ void AdvancedConfiguration::data(
* @brief This function moves the value in member data
* @param _data New value to be moved in member data
*/
void AdvancedConfiguration::data(
void Configuration::data(
std::vector<uint8_t>&& _data)
{
m_data = std::move(_data);
Expand All @@ -193,7 +191,7 @@ void AdvancedConfiguration::data(
* @brief This function returns a constant reference to member data
* @return Constant reference to member data
*/
const std::vector<uint8_t>& AdvancedConfiguration::data() const
const std::vector<uint8_t>& Configuration::data() const
{
return m_data;
}
Expand All @@ -202,13 +200,12 @@ const std::vector<uint8_t>& AdvancedConfiguration::data() const
* @brief This function returns a reference to member data
* @return Reference to member data
*/
std::vector<uint8_t>& AdvancedConfiguration::data()
std::vector<uint8_t>& Configuration::data()
{
return m_data;
}


// Include auxiliary functions like for serializing/deserializing.
#include "AdvancedConfigurationCdrAux.ipp"
#include "ConfigurationCdrAux.ipp"

#endif // FASTCDR_VERSION_MAJOR > 1
Loading

0 comments on commit b83c0ac

Please sign in to comment.