Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20575] Examples refactor: Configuration #4570

Merged
merged 10 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

set(fastdds_FOUND TRUE)
add_subdirectory(cpp/configuration)
add_subdirectory(cpp/dds)
add_subdirectory(cpp/rtps)
add_subdirectory(cpp/hello_world)
add_subdirectory(cpp/rtps)
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
55 changes: 55 additions & 0 deletions examples/cpp/configuration/Application.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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:

//! Virtual destructor
virtual ~Application() = default;

//! 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_ */
1,140 changes: 1,140 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
@@ -1,4 +1,4 @@
# Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
# 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.
Expand All @@ -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,14 +13,14 @@
// limitations under the License.

/*!
* @file AdvancedConfiguration.hpp
* @file Configuration.hpp
* This header file contains the declaration of the described types in the IDL file.
*
* This file was generated by the tool fastddsgen.
*/

#ifndef _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_HPP_
#define _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_HPP_
#ifndef _FAST_DDS_GENERATED_CONFIGURATION_HPP_
#define _FAST_DDS_GENERATED_CONFIGURATION_HPP_

#include <array>
#include <cstdint>
Expand All @@ -40,46 +40,46 @@

#if defined(_WIN32)
#if defined(EPROSIMA_USER_DLL_EXPORT)
#if defined(ADVANCEDCONFIGURATION_SOURCE)
#define ADVANCEDCONFIGURATION_DllAPI __declspec( dllexport )
#if defined(CONFIGURATION_SOURCE)
#define CONFIGURATION_DllAPI __declspec( dllexport )
#else
#define ADVANCEDCONFIGURATION_DllAPI __declspec( dllimport )
#endif // ADVANCEDCONFIGURATION_SOURCE
#define CONFIGURATION_DllAPI __declspec( dllimport )
#endif // CONFIGURATION_SOURCE
#else
#define ADVANCEDCONFIGURATION_DllAPI
#define CONFIGURATION_DllAPI
#endif // EPROSIMA_USER_DLL_EXPORT
#else
#define ADVANCEDCONFIGURATION_DllAPI
#define CONFIGURATION_DllAPI
#endif // _WIN32

/*!
* @brief This class represents the structure AdvancedConfiguration defined by the user in the IDL file.
* @ingroup AdvancedConfiguration
* @brief This class represents the structure Configuration defined by the user in the IDL file.
* @ingroup Configuration
*/
class AdvancedConfiguration
class Configuration
{
public:

/*!
* @brief Default constructor.
*/
eProsima_user_DllExport AdvancedConfiguration()
eProsima_user_DllExport Configuration()
{
}

/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~AdvancedConfiguration()
eProsima_user_DllExport ~Configuration()
{
}

/*!
* @brief Copy constructor.
* @param x Reference to the object AdvancedConfiguration that will be copied.
* @param x Reference to the object Configuration that will be copied.
*/
eProsima_user_DllExport AdvancedConfiguration(
const AdvancedConfiguration& x)
eProsima_user_DllExport Configuration(
const Configuration& x)
{
m_index = x.m_index;

Expand All @@ -91,10 +91,10 @@ class AdvancedConfiguration

/*!
* @brief Move constructor.
* @param x Reference to the object AdvancedConfiguration that will be copied.
* @param x Reference to the object Configuration that will be copied.
*/
eProsima_user_DllExport AdvancedConfiguration(
AdvancedConfiguration&& x) noexcept
eProsima_user_DllExport Configuration(
Configuration&& x) noexcept
{
m_index = x.m_index;
m_message = std::move(x.m_message);
Expand All @@ -103,10 +103,10 @@ class AdvancedConfiguration

/*!
* @brief Copy assignment.
* @param x Reference to the object AdvancedConfiguration that will be copied.
* @param x Reference to the object Configuration that will be copied.
*/
eProsima_user_DllExport AdvancedConfiguration& operator =(
const AdvancedConfiguration& x)
eProsima_user_DllExport Configuration& operator =(
const Configuration& x)
{

m_index = x.m_index;
Expand All @@ -120,10 +120,10 @@ class AdvancedConfiguration

/*!
* @brief Move assignment.
* @param x Reference to the object AdvancedConfiguration that will be copied.
* @param x Reference to the object Configuration that will be copied.
*/
eProsima_user_DllExport AdvancedConfiguration& operator =(
AdvancedConfiguration&& x) noexcept
eProsima_user_DllExport Configuration& operator =(
Configuration&& x) noexcept
{

m_index = x.m_index;
Expand All @@ -134,10 +134,10 @@ class AdvancedConfiguration

/*!
* @brief Comparison operator.
* @param x AdvancedConfiguration object to compare.
* @param x Configuration object to compare.
*/
eProsima_user_DllExport bool operator ==(
const AdvancedConfiguration& x) const
const Configuration& x) const
{
return (m_index == x.m_index &&
m_message == x.m_message &&
Expand All @@ -146,10 +146,10 @@ class AdvancedConfiguration

/*!
* @brief Comparison operator.
* @param x AdvancedConfiguration object to compare.
* @param x Configuration object to compare.
*/
eProsima_user_DllExport bool operator !=(
const AdvancedConfiguration& x) const
const Configuration& x) const
{
return !(*this == x);
}
Expand Down Expand Up @@ -270,6 +270,6 @@ class AdvancedConfiguration

};

#endif // _FAST_DDS_GENERATED_ADVANCEDCONFIGURATION_HPP_
#endif // _FAST_DDS_GENERATED_CONFIGURATION_HPP_


Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
struct AdvancedConfiguration
@extensibility(APPENDABLE)
struct Configuration
{
unsigned long index;
char message[20];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
// limitations under the License.

/*!
* @file sampleCdrAux.hpp
* @file ConfigurationCdrAux.hpp
* This source file contains some definitions of CDR related functions.
*
* This file was generated by the tool fastddsgen.
*/

#ifndef _FAST_DDS_GENERATED_SAMPLECDRAUX_HPP_
#define _FAST_DDS_GENERATED_SAMPLECDRAUX_HPP_
#ifndef _FAST_DDS_GENERATED_CONFIGURATIONCDRAUX_HPP_
#define _FAST_DDS_GENERATED_CONFIGURATIONCDRAUX_HPP_

#include "sample.hpp"
#include "Configuration.hpp"

constexpr uint32_t sample_max_cdr_typesize {6UL};
constexpr uint32_t sample_max_key_cdr_typesize {1UL};
constexpr uint32_t Configuration_max_cdr_typesize {32UL};
constexpr uint32_t Configuration_max_key_cdr_typesize {0UL};


namespace eprosima {
Expand All @@ -36,11 +36,11 @@ class CdrSizeCalculator;

eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const sample& data);
const Configuration& data);


} // namespace fastcdr
} // namespace eprosima

#endif // _FAST_DDS_GENERATED_SAMPLECDRAUX_HPP_
#endif // _FAST_DDS_GENERATED_CONFIGURATIONCDRAUX_HPP_

Loading
Loading