From 4cdce1ed1a07fd2be32a6dc6030a52864d34d0ea Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 26 May 2020 17:21:21 +0200 Subject: [PATCH 01/55] iox-#65 Added required files to be filled in. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds_gateway/CMakeLists.txt | 10 +++++++++- .../include/ioxdds/dds/cyclone_data_reader.hpp | 3 +++ iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp | 1 + .../include/ioxdds/gateway/dds_to_iox.hpp | 2 ++ .../include/ioxdds/internal/gateway/dds_to_iox.inl | 1 + iceoryx_dds_gateway/source/dds2iox_app/main.cpp | 8 ++++++++ .../source/ioxdds/dds/cyclone_data_reader.cpp | 0 7 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl create mode 100644 iceoryx_dds_gateway/source/dds2iox_app/main.cpp create mode 100644 iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp diff --git a/iceoryx_dds_gateway/CMakeLists.txt b/iceoryx_dds_gateway/CMakeLists.txt index 07755879f2..5fe43268f1 100644 --- a/iceoryx_dds_gateway/CMakeLists.txt +++ b/iceoryx_dds_gateway/CMakeLists.txt @@ -78,6 +78,14 @@ target_link_libraries(gateway_iox2dds ${PROJECT_NAMESPACE}::ioxdds ) +add_executable(gateway_dds2iox + source/dds2iox_app/main.cpp +) +target_link_libraries(gateway_dds2iox + iceoryx_posh::iceoryx_posh + ${PROJECT_NAMESPACE}::ioxdds +) + # ########## build test executables ########## # @@ -89,7 +97,7 @@ endif(BUILD_TESTS) ########## export library ########## # setup_install_directories_and_export_package( - TARGETS gateway_iox2dds + TARGETS gateway_iox2dds gateway_dds2iox INCLUDE_DIRECTORY include/ ) diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp new file mode 100644 index 0000000000..25f818e96b --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp @@ -0,0 +1,3 @@ + +#pragma once + diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp new file mode 100644 index 0000000000..6f70f09bee --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp new file mode 100644 index 0000000000..3f59c932d3 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -0,0 +1,2 @@ +#pragma once + diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl new file mode 100644 index 0000000000..6f70f09bee --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -0,0 +1 @@ +#pragma once diff --git a/iceoryx_dds_gateway/source/dds2iox_app/main.cpp b/iceoryx_dds_gateway/source/dds2iox_app/main.cpp new file mode 100644 index 0000000000..025a33c198 --- /dev/null +++ b/iceoryx_dds_gateway/source/dds2iox_app/main.cpp @@ -0,0 +1,8 @@ +#include + + +int main(int argc, char *argv[]) +{ + std::cout << "Hello." << std::endl; + return 0; +} diff --git a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp b/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp new file mode 100644 index 0000000000..e69de29bb2 From a0f38c71bb73d48dc8817c82557534734837f140 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 26 May 2020 17:48:26 +0200 Subject: [PATCH 02/55] iox-#65 Rename iox2dds to iox_to_dds to be consistent. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/{iox2dds.hpp => iox_to_dds.hpp} | 2 +- .../ioxdds/internal/gateway/{iox2dds.inl => iox_to_dds.inl} | 0 iceoryx_dds_gateway/source/iox2dds_app/main.cpp | 2 +- iceoryx_dds_gateway/test/CMakeLists.txt | 2 +- .../test/moduletests/{test_iox2dds.cpp => test_iox_to_dds.cpp} | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename iceoryx_dds_gateway/include/ioxdds/gateway/{iox2dds.hpp => iox_to_dds.hpp} (99%) rename iceoryx_dds_gateway/include/ioxdds/internal/gateway/{iox2dds.inl => iox_to_dds.inl} (100%) rename iceoryx_dds_gateway/test/moduletests/{test_iox2dds.cpp => test_iox_to_dds.cpp} (99%) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox2dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp similarity index 99% rename from iceoryx_dds_gateway/include/ioxdds/gateway/iox2dds.hpp rename to iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index ee188f2fe3..a5154f482c 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox2dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -146,4 +146,4 @@ class Iceoryx2DDSGateway : gateway_t } // dds } // iox -#include "ioxdds/internal/gateway/iox2dds.inl" +#include "ioxdds/internal/gateway/iox_to_dds.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox2dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox2dds.inl rename to iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl diff --git a/iceoryx_dds_gateway/source/iox2dds_app/main.cpp b/iceoryx_dds_gateway/source/iox2dds_app/main.cpp index 9095afad3b..97f896ae83 100644 --- a/iceoryx_dds_gateway/source/iox2dds_app/main.cpp +++ b/iceoryx_dds_gateway/source/iox2dds_app/main.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include class ShutdownManager { diff --git a/iceoryx_dds_gateway/test/CMakeLists.txt b/iceoryx_dds_gateway/test/CMakeLists.txt index fbfe579bb9..e7b6387cf9 100644 --- a/iceoryx_dds_gateway/test/CMakeLists.txt +++ b/iceoryx_dds_gateway/test/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(test_iox2dds VERSION ${test_iox2dds}) +project(test_iox_to_dds VERSION ${test_iox_to_dds}) find_package(iceoryx_utils_testing REQUIRED) find_package(GTest CONFIG REQUIRED) diff --git a/iceoryx_dds_gateway/test/moduletests/test_iox2dds.cpp b/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp similarity index 99% rename from iceoryx_dds_gateway/test/moduletests/test_iox2dds.cpp rename to iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp index 0153d69a8f..f72f970311 100644 --- a/iceoryx_dds_gateway/test/moduletests/test_iox2dds.cpp +++ b/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include "mocks/chunk_mock.hpp" #include "roudi_gtest.hpp" From 73f7931be97beb0b4a89f48a43eb00f1551a0030 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 27 May 2020 10:41:06 +0200 Subject: [PATCH 03/55] iox-#65 Added skeleton classes. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/dds/cyclone_data_reader.hpp | 13 ++++++++++++- .../include/ioxdds/dds/data_reader.hpp | 11 +++++++++++ .../include/ioxdds/dds/dds_types.hpp | 2 ++ .../include/ioxdds/gateway/dds_to_iox.hpp | 17 +++++++++++++++++ .../ioxdds/internal/gateway/dds_to_iox.inl | 1 - 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp index 25f818e96b..a37bc6acd2 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp @@ -1,3 +1,14 @@ - #pragma once +#include "ioxdds/dds/data_reader.hpp" + +namespace iox { +namespace dds { + +class CycloneDataReader : DataReader +{ + +}; + +} // namespace dds +} // namespace iox diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp index 6f70f09bee..a576a224fb 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp @@ -1 +1,12 @@ #pragma once + +namespace iox { +namespace dds { + +template +class DataReader{ + +}; + +} +} diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp index f40be7506e..056588b0df 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp @@ -17,6 +17,7 @@ #include "ioxdds/dds/data_writer.hpp" #ifdef USE_CYCLONE_DDS +#include "ioxdds/dds/cyclone_data_reader.hpp" #include "ioxdds/dds/cyclone_data_writer.hpp" #else #error "A DDS implementation must be provided." @@ -28,6 +29,7 @@ namespace dds { // DDS implementation defined with compiler flags #ifdef USE_CYCLONE_DDS +using data_reader_t = iox::dds::CycloneDataReader; using data_writer_t = iox::dds::CycloneDataWriter; #else #error "A DDS implementation must be set." diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 3f59c932d3..fa19840e66 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -1,2 +1,19 @@ #pragma once +#include +#include + +#include "ioxdds/dds/dds_types.hpp"; +namespace iox { +namespace dds { + +template +class DDS2IceoryxGateeway : gateway_t +{ + +}; + +} // namespace dds +} // namespace iox diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 6f70f09bee..e69de29bb2 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -1 +0,0 @@ -#pragma once From 5a60e82afd85929291ffaf7376963b3a8cf3143c Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 27 May 2020 12:55:34 +0200 Subject: [PATCH 04/55] iox-#65 Make skeleton buildable. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds_gateway/CMakeLists.txt | 1 + .../ioxdds/dds/cyclone_data_reader.hpp | 3 +- .../include/ioxdds/gateway/dds_to_iox.hpp | 30 ++++++++++++- .../ioxdds/internal/gateway/dds_to_iox.inl | 42 +++++++++++++++++++ .../ioxdds/internal/gateway/iox_to_dds.inl | 2 +- .../source/dds2iox_app/main.cpp | 33 +++++++++++++++ .../source/ioxdds/dds/cyclone_data_reader.cpp | 7 ++++ 7 files changed, 115 insertions(+), 3 deletions(-) diff --git a/iceoryx_dds_gateway/CMakeLists.txt b/iceoryx_dds_gateway/CMakeLists.txt index 5fe43268f1..392e43dfde 100644 --- a/iceoryx_dds_gateway/CMakeLists.txt +++ b/iceoryx_dds_gateway/CMakeLists.txt @@ -56,6 +56,7 @@ target_link_libraries(ioxdds if(USE_CYCLONE_DDS) target_sources(ioxdds PRIVATE + source/ioxdds/dds/cyclone_data_reader.cpp source/ioxdds/dds/cyclone_data_writer.cpp ) target_compile_definitions(ioxdds PUBLIC -DUSE_CYCLONE_DDS) diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp index a37bc6acd2..dd0eec420c 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp @@ -7,7 +7,8 @@ namespace dds { class CycloneDataReader : DataReader { - +public: + CycloneDataReader() noexcept; }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index fa19840e66..01aff5aa07 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -4,16 +4,44 @@ #include #include "ioxdds/dds/dds_types.hpp"; + namespace iox { namespace dds { template -class DDS2IceoryxGateeway : gateway_t +class DDS2IceoryxGateway : gateway_t { + public: + DDS2IceoryxGateway(); + ~DDS2IceoryxGateway(); + + DDS2IceoryxGateway(const DDS2IceoryxGateway&) = delete; + DDS2IceoryxGateway& operator=(const DDS2IceoryxGateway&) = delete; + DDS2IceoryxGateway(DDS2IceoryxGateway&&) = delete; + DDS2IceoryxGateway& operator=(DDS2IceoryxGateway&&) = delete; + + void runMultithreaded() noexcept; + void discover(const iox::capro::CaproMessage& msg) noexcept; + void forward() noexcept; + void shutdown() noexcept; + + private: + std::atomic_bool m_isRunning{false}; + std::atomic_bool m_runForwardingLoop{false}; + std::atomic_bool m_runDiscoveryLoop{false}; + + std::thread m_discoveryThread; + std::thread m_forwardingThread; + + void forwardingLoop() noexcept; + void discoveryLoop() noexcept; + }; } // namespace dds } // namespace iox + +#include "ioxdds/internal/gateway/dds_to_iox.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index e69de29bb2..961d8d2c51 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -0,0 +1,42 @@ + +#include "ioxdds/gateway/dds_to_iox.hpp" + +namespace iox { +namespace dds { + +template +inline DDS2IceoryxGateway::DDS2IceoryxGateway() + : gateway_t(iox::capro::Interfaces::DDS) +{ +} + +template +inline DDS2IceoryxGateway::~DDS2IceoryxGateway() +{ +} + +template +inline void DDS2IceoryxGateway::runMultithreaded() noexcept +{ +} + +template +inline void DDS2IceoryxGateway::discoveryLoop() noexcept +{ + +} + +template +inline void DDS2IceoryxGateway::forwardingLoop() noexcept +{ + +} + +template +inline void DDS2IceoryxGateway::shutdown() noexcept +{ + +} + +} // namespace dds +} // namespace iox diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index c78340eb8a..cce35b2081 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -30,7 +30,7 @@ inline Iceoryx2DDSGateway::Iceoryx2DDSGa : gateway_t(iox::capro::Interfaces::DDS) { m_channelFactory = Channel::create; -}; +} template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) diff --git a/iceoryx_dds_gateway/source/dds2iox_app/main.cpp b/iceoryx_dds_gateway/source/dds2iox_app/main.cpp index 025a33c198..0a3f0ea7b8 100644 --- a/iceoryx_dds_gateway/source/dds2iox_app/main.cpp +++ b/iceoryx_dds_gateway/source/dds2iox_app/main.cpp @@ -1,8 +1,41 @@ #include +#include +#include + +#include "ioxdds/gateway/dds_to_iox.hpp" + +class ShutdownManager +{ + public: + static void scheduleShutdown(int num) + { + char reason; + psignal(num, &reason); + s_semaphore.post(); + } + static void waitUntilShutdown() + { + s_semaphore.wait(); + } + + private: + static iox::posix::Semaphore s_semaphore; + ShutdownManager() = default; +}; +iox::posix::Semaphore ShutdownManager::s_semaphore = iox::posix::Semaphore::create(0u).get_value(); int main(int argc, char *argv[]) { + + iox::runtime::PoshRuntime::getInstance("/gateway_dds2iox"); + + iox::dds::DDS2IceoryxGateway<> gw; + gw.runMultithreaded(); + std::cout << "Hello." << std::endl; + + ShutdownManager::waitUntilShutdown(); + return 0; } diff --git a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp b/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp index e69de29bb2..1b4bf60a81 100644 --- a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp +++ b/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp @@ -0,0 +1,7 @@ + +#include "ioxdds/dds/cyclone_data_reader.hpp" + +iox::dds::CycloneDataReader::CycloneDataReader() noexcept +{ + +} From a95946a44805dab14d6bdbfed976f2683be88d79 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 27 May 2020 13:43:33 +0200 Subject: [PATCH 05/55] iox-#65 Rename Channel to OutputChannel since we require an InputChannel for the dds to iox direction. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/iox_to_dds.hpp | 8 ++++---- .../{channel.hpp => output_channel.hpp} | 14 +++++++------- .../ioxdds/internal/gateway/iox_to_dds.inl | 6 +++--- .../{channel.inl => output_channel.inl} | 18 +++++++++--------- .../test/moduletests/test_iox_to_dds.cpp | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) rename iceoryx_dds_gateway/include/ioxdds/gateway/{channel.hpp => output_channel.hpp} (86%) rename iceoryx_dds_gateway/include/ioxdds/internal/gateway/{channel.inl => output_channel.inl} (72%) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index a5154f482c..ff4c1de6c4 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -31,7 +31,7 @@ #include "ioxdds/dds/data_writer.hpp" #include "ioxdds/dds/dds_configs.hpp" #include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/channel.hpp" +#include "ioxdds/gateway/output_channel.hpp" namespace iox { @@ -47,8 +47,8 @@ template class Iceoryx2DDSGateway : gateway_t { - using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; - using ChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; + using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; + using ChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; using ConcurrentChannelVector = iox::concurrent::smart_lock; public: @@ -133,7 +133,7 @@ class Iceoryx2DDSGateway : gateway_t /// @param service The service for which a channel will be established. /// @return Channel object with subscriber and data writer for the given service. /// - Channel setupChannel(const iox::capro::ServiceDescription& service) noexcept; + OutputChannel setupChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief discardChannel Discards the channel for the given service. diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp similarity index 86% rename from iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp rename to iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp index 39dd05ebab..784d9271ef 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp @@ -29,15 +29,15 @@ namespace iox namespace dds { /// -/// @brief This data structure couples the subscriber and data writer components required to form a channel between -/// the POSH and DDS worlds. +/// @brief This data structure couples the subscriber and data writer components required to form an output channel +/// between the POSH and DDS worlds. /// The structure holds pointers to the related component instances. These instances can either be managed externally /// or by the class itself. /// Managed instances are placed in static ObjectPools which are fixed size according to /// MAX_CHANNEL_NUMBER and are automatically cleaned up when all references to them are discarded. /// template -class Channel +class OutputChannel { public: using SubscriberPtr = std::shared_ptr; @@ -52,18 +52,18 @@ class Channel /// @param subscriber An externally managed subscriber component. /// @param dataWriter An externally managed data writer component. /// - Channel(const iox::capro::ServiceDescription& m_service, + OutputChannel(const iox::capro::ServiceDescription& m_service, const SubscriberPtr m_subscriber, const DataWriterPtr m_dataWriter) noexcept; /// - /// @brief create Creates a channel whose components are instantiated in static object pools that will be + /// @brief create Creates an output channel whose components are instantiated in static object pools that will be /// automatically freed when all references are discarded. /// /// @param service The service that the channel is connecting. /// @return Channel A channel with internally managed endpoints. /// - static Channel create(const iox::capro::ServiceDescription& m_service) noexcept; + static OutputChannel create(const iox::capro::ServiceDescription& m_service) noexcept; iox::capro::ServiceDescription getService() const noexcept; SubscriberPtr getSubscriber() const noexcept; @@ -82,4 +82,4 @@ class Channel } // dds } // iox -#include "ioxdds/internal/gateway/channel.inl" +#include "ioxdds/internal/gateway/output_channel.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index cce35b2081..7b478fda67 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -29,7 +29,7 @@ template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() : gateway_t(iox::capro::Interfaces::DDS) { - m_channelFactory = Channel::create; + m_channelFactory = OutputChannel::create; } template @@ -176,7 +176,7 @@ inline void Iceoryx2DDSGateway::shutdown // ======================================== Private ======================================== // template -Channel Iceoryx2DDSGateway::setupChannel( +OutputChannel Iceoryx2DDSGateway::setupChannel( const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); @@ -193,7 +193,7 @@ void Iceoryx2DDSGateway::discardChannel( { auto guardedVector = m_channels.GetScopeGuard(); auto channel = std::find_if( - guardedVector->begin(), guardedVector->end(), [&service](const Channel& channel) { + guardedVector->begin(), guardedVector->end(), [&service](const OutputChannel& channel) { return channel.getService() == service; }); if (channel != guardedVector->end()) diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl similarity index 72% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl rename to iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl index eb3aa9c3c9..264e555016 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl @@ -24,12 +24,12 @@ using DataWriterPool = iox::cxx::ObjectPool; // Statics template -SubscriberPool Channel::s_subscriberPool = SubscriberPool(); +SubscriberPool OutputChannel::s_subscriberPool = SubscriberPool(); template -DataWriterPool Channel::s_dataWriterPool = DataWriterPool(); +DataWriterPool OutputChannel::s_dataWriterPool = DataWriterPool(); template -inline Channel::Channel(const iox::capro::ServiceDescription& service, +inline OutputChannel::OutputChannel(const iox::capro::ServiceDescription& service, const SubscriberPtr subscriber, const DataWriterPtr dataWriter) noexcept : m_service(service), @@ -39,8 +39,8 @@ inline Channel::Channel(const iox::capro::ServiceDe } template -inline Channel -Channel::create(const iox::capro::ServiceDescription& service) noexcept +inline OutputChannel +OutputChannel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. auto rawSubscriberPtr = s_subscriberPool.create(std::forward(service)); @@ -51,23 +51,23 @@ Channel::create(const iox::capro::ServiceDescriptio auto subscriberPtr = SubscriberPtr(rawSubscriberPtr, [](subscriber_t* p) { s_subscriberPool.free(p); }); auto dataWriterPtr = DataWriterPtr(rawDataWriterPtr, [](data_writer_t* p) { s_dataWriterPool.free(p); }); - return Channel(service, subscriberPtr, dataWriterPtr); + return OutputChannel(service, subscriberPtr, dataWriterPtr); } template -inline iox::capro::ServiceDescription Channel::getService() const noexcept +inline iox::capro::ServiceDescription OutputChannel::getService() const noexcept { return m_service; } template -inline std::shared_ptr Channel::getSubscriber() const noexcept +inline std::shared_ptr OutputChannel::getSubscriber() const noexcept { return m_subscriber; } template -inline std::shared_ptr Channel::getDataWriter() const noexcept +inline std::shared_ptr OutputChannel::getDataWriter() const noexcept { return m_dataWriter; } diff --git a/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp index f72f970311..bc11509aaa 100644 --- a/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp @@ -104,7 +104,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::dds::Channel mockChannelFactory(iox::capro::ServiceDescription sd) noexcept +static iox::dds::OutputChannel mockChannelFactory(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; @@ -130,7 +130,7 @@ static iox::dds::Channel mockChannelFactory(iox: mockDataWriter = createMockDataWriter(sd); } - return iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); + return iox::dds::OutputChannel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); } // ======================================== Fixture ======================================== // From 331e48b347f9b3565a66741e99256b3c29a6be82 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 27 May 2020 15:42:58 +0200 Subject: [PATCH 06/55] iox-#65 Set up input channels for all services in config. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../ioxdds/dds/cyclone_data_reader.hpp | 2 +- .../include/ioxdds/dds/data_reader.hpp | 4 + .../include/ioxdds/gateway/dds_to_iox.hpp | 12 ++ .../include/ioxdds/gateway/input_channel.hpp | 45 ++++++++ .../include/ioxdds/gateway/iox_to_dds.hpp | 2 - .../include/ioxdds/gateway/output_channel.hpp | 8 +- .../ioxdds/internal/gateway/dds_to_iox.inl | 103 ++++++++++++++++-- .../ioxdds/internal/gateway/input_channel.inl | 63 +++++++++++ .../include/ioxdds/internal/log/logging.hpp | 2 +- .../source/ioxdds/dds/cyclone_data_reader.cpp | 2 +- 10 files changed, 222 insertions(+), 21 deletions(-) create mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp index dd0eec420c..524d1e3ada 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp @@ -8,7 +8,7 @@ namespace dds { class CycloneDataReader : DataReader { public: - CycloneDataReader() noexcept; + CycloneDataReader(IdString serviceId, IdString instanceId, IdString eventId) noexcept; }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp index a576a224fb..1d8fe3eddb 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp @@ -1,8 +1,12 @@ #pragma once +#include + namespace iox { namespace dds { +using IdString = iox::cxx::string<100>; + template class DataReader{ diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 01aff5aa07..bfead334dd 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -4,6 +4,7 @@ #include #include "ioxdds/dds/dds_types.hpp"; +#include "ioxdds/gateway/input_channel.hpp" namespace iox { namespace dds { @@ -13,6 +14,9 @@ template class DDS2IceoryxGateway : gateway_t { + using InputChannelFactory = std::function(const iox::capro::ServiceDescription)>; + using InputChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; + using ConcurrentInputChannelVector = iox::concurrent::smart_lock; public: DDS2IceoryxGateway(); @@ -36,9 +40,17 @@ class DDS2IceoryxGateway : gateway_t std::thread m_discoveryThread; std::thread m_forwardingThread; + InputChannelFactory m_channelFactory; + ConcurrentInputChannelVector m_channels; + void forwardingLoop() noexcept; void discoveryLoop() noexcept; + void loadConfiguration() noexcept; + + InputChannel setupChannel(const iox::capro::ServiceDescription& service) noexcept; + void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp new file mode 100644 index 0000000000..8d3a3734a9 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +#include "ioxdds/dds/dds_configs.hpp" +#include "ioxdds/dds/dds_types.hpp" +#include "ioxdds/dds/data_reader.hpp" + +namespace iox { +namespace dds { + +template +class InputChannel +{ + public: + using PublisherPtr = std::shared_ptr; + using PublisherPool = iox::cxx::ObjectPool; + using DataReaderPtr = std::shared_ptr; + using DataReaderPool = iox::cxx::ObjectPool; + + InputChannel(const iox::capro::ServiceDescription& service, + const PublisherPtr publisher, + const DataReaderPtr dataReader) noexcept; + + static InputChannel create(const iox::capro::ServiceDescription& service) noexcept; + + iox::capro::ServiceDescription getService() const noexcept; + PublisherPtr getPublisher() const noexcept; + DataReaderPtr getDataReader() const noexcept; + + private: + // Store in data segment - too large to keep in stack. + static PublisherPool s_publisherPool; + static DataReaderPool s_dataReaderPool; + + iox::capro::ServiceDescription m_service; + PublisherPtr m_publisher; + DataReaderPtr m_dataReader; +}; + +} // dds +} // iox + +#include "ioxdds/internal/gateway/input_channel.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index ff4c1de6c4..ed95dc12e2 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -105,8 +105,6 @@ class Iceoryx2DDSGateway : gateway_t std::thread m_forwardingThread; ChannelFactory m_channelFactory; - - // This mutex is required for synchronized access to the channels list. ConcurrentChannelVector m_channels; /// diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp index 784d9271ef..09cf9a04ce 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp @@ -52,9 +52,9 @@ class OutputChannel /// @param subscriber An externally managed subscriber component. /// @param dataWriter An externally managed data writer component. /// - OutputChannel(const iox::capro::ServiceDescription& m_service, - const SubscriberPtr m_subscriber, - const DataWriterPtr m_dataWriter) noexcept; + OutputChannel(const iox::capro::ServiceDescription& service, + const SubscriberPtr subscriber, + const DataWriterPtr dataWriter) noexcept; /// /// @brief create Creates an output channel whose components are instantiated in static object pools that will be @@ -63,7 +63,7 @@ class OutputChannel /// @param service The service that the channel is connecting. /// @return Channel A channel with internally managed endpoints. /// - static OutputChannel create(const iox::capro::ServiceDescription& m_service) noexcept; + static OutputChannel create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; SubscriberPtr getSubscriber() const noexcept; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 961d8d2c51..ba46482716 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -1,42 +1,121 @@ +#include + +#include +#include + +#include "ioxdds/gateway/input_channel.hpp" #include "ioxdds/gateway/dds_to_iox.hpp" +#include "ioxdds/internal/log/logging.hpp" namespace iox { namespace dds { -template -inline DDS2IceoryxGateway::DDS2IceoryxGateway() +template +inline DDS2IceoryxGateway::DDS2IceoryxGateway() : gateway_t(iox::capro::Interfaces::DDS) { + + m_channelFactory = InputChannel::create; + + // Initialize pre-configured DDS DataReaders + loadConfiguration(); + } -template -inline DDS2IceoryxGateway::~DDS2IceoryxGateway() +template +inline DDS2IceoryxGateway::~DDS2IceoryxGateway() { } -template -inline void DDS2IceoryxGateway::runMultithreaded() noexcept +template +inline void DDS2IceoryxGateway::runMultithreaded() noexcept { } -template -inline void DDS2IceoryxGateway::discoveryLoop() noexcept +template +inline void DDS2IceoryxGateway::discoveryLoop() noexcept { } -template -inline void DDS2IceoryxGateway::forwardingLoop() noexcept +template +inline void DDS2IceoryxGateway::forwardingLoop() noexcept { } -template -inline void DDS2IceoryxGateway::shutdown() noexcept +template +inline void DDS2IceoryxGateway::shutdown() noexcept { } +// ======================================== Private ======================================== // +template +inline void DDS2IceoryxGateway::loadConfiguration() noexcept +{ + + // Search for config passed as command line argument. + + + // Search for local config. + auto config = cpptoml::parse_file("config.toml"); + + // Search for local config. + + + // Setup data readers and publishers + auto configuredTopics = config->get_table_array("services"); + for(const auto& topic : *configuredTopics) + { + auto service = topic->get_as("service").value_or(""); + auto instance = topic->get_as("instance").value_or(""); + auto event = topic->get_as("event").value_or(""); + + setupChannel(iox::capro::ServiceDescription( + IdString(iox::cxx::TruncateToCapacity, service.c_str()), + IdString(iox::cxx::TruncateToCapacity, instance.c_str()), + IdString(iox::cxx::TruncateToCapacity, event.c_str()) + ) + ); + + LogDebug() << "Loaded topic from file: " + service + "/" + instance + "/" + event; + + } + +} + +template +InputChannel DDS2IceoryxGateway::setupChannel( + const iox::capro::ServiceDescription& service) noexcept +{ + auto channel = m_channelFactory(service); + iox::LogDebug() << "[DDS2IceoryxGateway] Input channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + m_channels->push_back(channel); + return channel; +} + +template +void DDS2IceoryxGateway::discardChannel( + const iox::capro::ServiceDescription& service) noexcept +{ + auto guardedVector = m_channels.GetScopeGuard(); + auto channel = std::find_if( + guardedVector->begin(), guardedVector->end(), [&service](const InputChannel& channel) { + return channel.getService() == service; + }); + if (channel != guardedVector->end()) + { + guardedVector->erase(channel); + iox::LogDebug() << "[DDS2IceoryxGateway] Input channel taken down for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + } +} + + } // namespace dds } // namespace iox diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl new file mode 100644 index 0000000000..1cf4de60c5 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl @@ -0,0 +1,63 @@ +#include "ioxdds/gateway/input_channel.hpp" + +namespace iox { +namespace dds { + +// Typedefs +template +using PublisherPool = iox::cxx::ObjectPool; +template +using DataReaderPool = iox::cxx::ObjectPool; + +// Statics +template +PublisherPool InputChannel::s_publisherPool = PublisherPool(); +template +DataReaderPool InputChannel::s_dataReaderPool = DataReaderPool(); + +template +inline InputChannel::InputChannel(const iox::capro::ServiceDescription& service, + const PublisherPtr publisher, + const DataReaderPtr dataReader) noexcept + : m_service(service), + m_publisher(publisher), + m_dataReader(dataReader) +{ +} + +template +inline InputChannel +InputChannel::create(const iox::capro::ServiceDescription& service) noexcept +{ + // Create objects in the pool. + auto rawPublisherPtr = s_publisherPool.create(service); + auto rawDataReaderPtr = s_dataReaderPool.create( + service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); + + // Wrap in smart pointer with custom deleter to ensure automatic cleanup. + auto publisherPtr = PublisherPtr(rawPublisherPtr, [](publisher_t* p) { s_publisherPool.free(p); }); + auto dataReaderPtr = DataReaderPtr(rawDataReaderPtr, [](data_reader_t* p) { s_dataReaderPool.free(p); }); + + return InputChannel(service, publisherPtr, dataReaderPtr); +} + +template +inline iox::capro::ServiceDescription InputChannel::getService() const noexcept +{ + return m_service; +} + +template +inline std::shared_ptr InputChannel::getPublisher() const noexcept +{ + return m_publisher; +} + +template +inline std::shared_ptr InputChannel::getDataReader() const noexcept +{ + return m_dataReader; +} + +} +} diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp b/iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp index 147a2cb1f4..7935d1717f 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp @@ -23,7 +23,7 @@ namespace dds struct DDSLoggingComponent { static constexpr char Ctx[] = "DDS"; - static constexpr char Description[] = "Log context of the DDS stack used by the dds gateway."; + static constexpr char Description[] = "Log context of the DDS module."; }; static constexpr auto LogFatal = iox::log::ffbb::LogFatal; diff --git a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp b/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp index 1b4bf60a81..3c5859f2a0 100644 --- a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp +++ b/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp @@ -1,7 +1,7 @@ #include "ioxdds/dds/cyclone_data_reader.hpp" -iox::dds::CycloneDataReader::CycloneDataReader() noexcept +iox::dds::CycloneDataReader::CycloneDataReader(IdString serviceId, IdString instanceId, IdString eventId) noexcept { } From 532cfd9f10dabf790e2f803f824e55e5e40dae54 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 27 May 2020 17:14:44 +0200 Subject: [PATCH 07/55] iox-#65 Begin refactoring common gateway logic into a base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/dds/dds_types.hpp | 2 - .../include/ioxdds/gateway/base_gateway.hpp | 25 ++++++++++++ .../include/ioxdds/gateway/channel.hpp | 6 +++ .../include/ioxdds/gateway/dds_to_iox.hpp | 14 +++---- .../ioxdds/internal/gateway/base_gateway.inl | 7 ++++ .../ioxdds/internal/gateway/dds_to_iox.inl | 40 +++++++++---------- 6 files changed, 64 insertions(+), 30 deletions(-) create mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp index 056588b0df..fa61c007fe 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp @@ -14,8 +14,6 @@ #pragma once -#include "ioxdds/dds/data_writer.hpp" - #ifdef USE_CYCLONE_DDS #include "ioxdds/dds/cyclone_data_reader.hpp" #include "ioxdds/dds/cyclone_data_writer.hpp" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp new file mode 100644 index 0000000000..df5aa411ee --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace iox { +namespace dds { + +template +class DDSGateway : public iox::popo::GatewayGeneric +{ + +protected: + + DDSGateway(); + + void loadConfiguration() noexcept; + channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; + void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + +}; + +} // namespace dds +} // namespace iox + +#include "ioxdds/internal/gateway/base_gateway.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp new file mode 100644 index 0000000000..25247e8baa --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp @@ -0,0 +1,6 @@ +#pragma once + +class Channel +{ + +}; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index bfead334dd..41350909df 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -1,24 +1,24 @@ #pragma once -#include #include -#include "ioxdds/dds/dds_types.hpp"; +#include "ioxdds/dds/dds_types.hpp" +#include "ioxdds/gateway/base_gateway.hpp" #include "ioxdds/gateway/input_channel.hpp" namespace iox { namespace dds { -template -class DDS2IceoryxGateway : gateway_t +class DDS2IceoryxGateway : public iox::dds::DDSGateway> { + using InputChannelFactory = std::function(const iox::capro::ServiceDescription)>; using InputChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; using ConcurrentInputChannelVector = iox::concurrent::smart_lock; - public: +public: DDS2IceoryxGateway(); ~DDS2IceoryxGateway(); @@ -32,7 +32,7 @@ class DDS2IceoryxGateway : gateway_t void forward() noexcept; void shutdown() noexcept; - private: +private: std::atomic_bool m_isRunning{false}; std::atomic_bool m_runForwardingLoop{false}; std::atomic_bool m_runDiscoveryLoop{false}; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl new file mode 100644 index 0000000000..9772501a12 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl @@ -0,0 +1,7 @@ +#include "ioxdds/gateway/base_gateway.hpp" + +template +iox::dds::DDSGateway::DDSGateway() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) +{ + +} diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index ba46482716..28a2ae2e29 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -4,56 +4,54 @@ #include #include -#include "ioxdds/gateway/input_channel.hpp" #include "ioxdds/gateway/dds_to_iox.hpp" #include "ioxdds/internal/log/logging.hpp" namespace iox { namespace dds { -template -inline DDS2IceoryxGateway::DDS2IceoryxGateway() - : gateway_t(iox::capro::Interfaces::DDS) +template +inline DDS2IceoryxGateway::DDS2IceoryxGateway() { m_channelFactory = InputChannel::create; - // Initialize pre-configured DDS DataReaders + // Initialize pre-configured services loadConfiguration(); } -template -inline DDS2IceoryxGateway::~DDS2IceoryxGateway() +template +inline DDS2IceoryxGateway::~DDS2IceoryxGateway() { } -template -inline void DDS2IceoryxGateway::runMultithreaded() noexcept +template +inline void DDS2IceoryxGateway::runMultithreaded() noexcept { } -template -inline void DDS2IceoryxGateway::discoveryLoop() noexcept +template +inline void DDS2IceoryxGateway::discoveryLoop() noexcept { } -template -inline void DDS2IceoryxGateway::forwardingLoop() noexcept +template +inline void DDS2IceoryxGateway::forwardingLoop() noexcept { } -template -inline void DDS2IceoryxGateway::shutdown() noexcept +template +inline void DDS2IceoryxGateway::shutdown() noexcept { } // ======================================== Private ======================================== // -template -inline void DDS2IceoryxGateway::loadConfiguration() noexcept +template +inline void DDS2IceoryxGateway::loadConfiguration() noexcept { // Search for config passed as command line argument. @@ -86,8 +84,8 @@ inline void DDS2IceoryxGateway::loadConfi } -template -InputChannel DDS2IceoryxGateway::setupChannel( +template +InputChannel DDS2IceoryxGateway::setupChannel( const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); @@ -98,8 +96,8 @@ InputChannel DDS2IceoryxGateway -void DDS2IceoryxGateway::discardChannel( +template +void DDS2IceoryxGateway::discardChannel( const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = m_channels.GetScopeGuard(); From de970d9afaa5c4a1126069f1541d0f35f5b4bd09 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 14:11:37 +0200 Subject: [PATCH 08/55] iox-#65 Moved common dds gateway logic to a base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/dds/data_reader.hpp | 1 - .../include/ioxdds/dds/dds_types.hpp | 4 + .../include/ioxdds/gateway/base_gateway.hpp | 25 ------- .../ioxdds/gateway/dds_gateway_generic.hpp | 38 ++++++++++ .../include/ioxdds/gateway/dds_to_iox.hpp | 16 +--- .../ioxdds/internal/gateway/base_gateway.inl | 7 -- .../internal/gateway/dds_gateway_generic.inl | 74 +++++++++++++++++++ .../ioxdds/internal/gateway/dds_to_iox.inl | 68 +---------------- 8 files changed, 119 insertions(+), 114 deletions(-) delete mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp create mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp delete mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl create mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp index 1d8fe3eddb..432c40f6a9 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp @@ -4,7 +4,6 @@ namespace iox { namespace dds { - using IdString = iox::cxx::string<100>; template diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp index fa61c007fe..6ef7b5ab44 100644 --- a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp @@ -25,6 +25,10 @@ namespace iox { namespace dds { + +// Fixed strings +using IdString = iox::cxx::string<100>; + // DDS implementation defined with compiler flags #ifdef USE_CYCLONE_DDS using data_reader_t = iox::dds::CycloneDataReader; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp deleted file mode 100644 index df5aa411ee..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/base_gateway.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -namespace iox { -namespace dds { - -template -class DDSGateway : public iox::popo::GatewayGeneric -{ - -protected: - - DDSGateway(); - - void loadConfiguration() noexcept; - channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; - void discardChannel(const iox::capro::ServiceDescription& service) noexcept; - -}; - -} // namespace dds -} // namespace iox - -#include "ioxdds/internal/gateway/base_gateway.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp new file mode 100644 index 0000000000..fd9f9e4be1 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include + +#include "ioxdds/dds/dds_configs.hpp" +namespace iox { +namespace dds { + +template +class DDSGatewayGeneric : public iox::popo::GatewayGeneric +{ + + using ChannelFactory = std::function; + using ChannelVector = iox::cxx::vector; + using ConcurrentChannelVector = iox::concurrent::smart_lock; + +protected: + + DDSGatewayGeneric(); + + void loadConfiguration() noexcept; + channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; + void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + +private: + + ChannelFactory m_channelFactory; + ConcurrentChannelVector m_channels; + +}; + +} // namespace dds +} // namespace iox + +#include "ioxdds/internal/gateway/dds_gateway_generic.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 41350909df..109ec245fa 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -3,7 +3,7 @@ #include #include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/base_gateway.hpp" +#include "ioxdds/gateway/dds_gateway_generic.hpp" #include "ioxdds/gateway/input_channel.hpp" namespace iox { @@ -11,13 +11,9 @@ namespace dds { template -class DDS2IceoryxGateway : public iox::dds::DDSGateway> +class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric> { - using InputChannelFactory = std::function(const iox::capro::ServiceDescription)>; - using InputChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; - using ConcurrentInputChannelVector = iox::concurrent::smart_lock; - public: DDS2IceoryxGateway(); ~DDS2IceoryxGateway(); @@ -40,17 +36,9 @@ class DDS2IceoryxGateway : public iox::dds::DDSGateway setupChannel(const iox::capro::ServiceDescription& service) noexcept; - void discardChannel(const iox::capro::ServiceDescription& service) noexcept; - }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl deleted file mode 100644 index 9772501a12..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/base_gateway.inl +++ /dev/null @@ -1,7 +0,0 @@ -#include "ioxdds/gateway/base_gateway.hpp" - -template -iox::dds::DDSGateway::DDSGateway() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) -{ - -} diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl new file mode 100644 index 0000000000..4e4aa85423 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -0,0 +1,74 @@ + +#include + +#include "ioxdds/internal/log/logging.hpp" + +#include "ioxdds/dds/dds_types.hpp" +#include "ioxdds/gateway/dds_gateway_generic.hpp" + +template +iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) +{ + m_channelFactory = channel_t::create; +} + +template +void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept +{ + // Search for config passed as command line argument. + + + // Search for local config. + auto config = cpptoml::parse_file("config.toml"); + + // Search for local config. + + + // Setup data readers and publishers + auto configuredTopics = config->get_table_array("services"); + for(const auto& topic : *configuredTopics) + { + auto service = topic->get_as("service").value_or(""); + auto instance = topic->get_as("instance").value_or(""); + auto event = topic->get_as("event").value_or(""); + + this->setupChannel(iox::capro::ServiceDescription( + IdString(iox::cxx::TruncateToCapacity, service.c_str()), + IdString(iox::cxx::TruncateToCapacity, instance.c_str()), + IdString(iox::cxx::TruncateToCapacity, event.c_str()) + ) + ); + + LogDebug() << "[DDSGatewayGeneric] Loaded topic from file: " + service + "/" + instance + "/" + event; + + } +} + + +template +channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept +{ + auto channel = m_channelFactory(service); + iox::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + m_channels->push_back(channel); + return channel; +} + +template +void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept +{ + auto guardedVector = m_channels.GetScopeGuard(); + auto channel = std::find_if( + guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { + return channel.getService() == service; + }); + if (channel != guardedVector->end()) + { + guardedVector->erase(channel); + iox::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + } +} diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 28a2ae2e29..cb4670b485 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -13,11 +13,8 @@ namespace dds { template inline DDS2IceoryxGateway::DDS2IceoryxGateway() { - - m_channelFactory = InputChannel::create; - // Initialize pre-configured services - loadConfiguration(); + this->loadConfiguration(); } @@ -50,69 +47,6 @@ inline void DDS2IceoryxGateway::shutdown() noexcept } // ======================================== Private ======================================== // -template -inline void DDS2IceoryxGateway::loadConfiguration() noexcept -{ - - // Search for config passed as command line argument. - - - // Search for local config. - auto config = cpptoml::parse_file("config.toml"); - - // Search for local config. - - - // Setup data readers and publishers - auto configuredTopics = config->get_table_array("services"); - for(const auto& topic : *configuredTopics) - { - auto service = topic->get_as("service").value_or(""); - auto instance = topic->get_as("instance").value_or(""); - auto event = topic->get_as("event").value_or(""); - - setupChannel(iox::capro::ServiceDescription( - IdString(iox::cxx::TruncateToCapacity, service.c_str()), - IdString(iox::cxx::TruncateToCapacity, instance.c_str()), - IdString(iox::cxx::TruncateToCapacity, event.c_str()) - ) - ); - - LogDebug() << "Loaded topic from file: " + service + "/" + instance + "/" + event; - - } - -} - -template -InputChannel DDS2IceoryxGateway::setupChannel( - const iox::capro::ServiceDescription& service) noexcept -{ - auto channel = m_channelFactory(service); - iox::LogDebug() << "[DDS2IceoryxGateway] Input channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - m_channels->push_back(channel); - return channel; -} - -template -void DDS2IceoryxGateway::discardChannel( - const iox::capro::ServiceDescription& service) noexcept -{ - auto guardedVector = m_channels.GetScopeGuard(); - auto channel = std::find_if( - guardedVector->begin(), guardedVector->end(), [&service](const InputChannel& channel) { - return channel.getService() == service; - }); - if (channel != guardedVector->end()) - { - guardedVector->erase(channel); - iox::LogDebug() << "[DDS2IceoryxGateway] Input channel taken down for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - } -} } // namespace dds From e4c2adcc1f219487b62cec799bce6bf63aadbdcd Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 15:26:35 +0200 Subject: [PATCH 09/55] iox-#65 Begin factoring out common channel logic. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/channel.hpp | 57 +++++++++++++++++++ .../ioxdds/internal/gateway/dds_to_iox.inl | 1 - .../ioxdds/internal/gateway/iox_to_dds.inl | 3 - 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp index 25247e8baa..c1e4b99b35 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp @@ -1,6 +1,63 @@ #pragma once +#include + +#include +#include +#include "ioxdds/dds/dds_configs.hpp" + +namespace iox { +namespace dds{ + +/// +/// @class Channel +/// @brief A data structure representing a channel between Iceoryx and DDS. +/// +/// The class couples related iceoryx and dds entities that communicate with eachother to form the communication +/// channel. +/// For example: An Iceoryx subscriber and its corresponding DDS data writer, which communicate eachother to form +/// an outbound communication channel. +/// +/// The structure holds pointers to the instances of the coupled entities. +/// The entites can be created and managed externally, in which case the structure only serves as a means of coupling +/// the two. +/// This can be achieved by simply calling the constructor with pointers to the instances. +/// +/// Alternatively, the class can manage the entities internally in a static object pool, automatically +/// cleaning them up when the channel is discarded. +/// This can be achieved via the Channel::create method. +/// +template class Channel { + using IoxInterfacePtr = std::shared_ptr; + using IoxInterfacePool = iox::cxx::ObjectPool; + using DDSInterfacePtr = std::shared_ptr; + using DDSInterfacePool = iox::cxx::ObjectPool; + +public: + + Channel(const iox::capro::ServiceDescription& service, + const IoxInterfacePtr ioxInterface, + const DDSInterfacePtr ddsInterface) noexcept; + + static Channel create(const iox::capro::ServiceDescription& service) noexcept; + + iox::capro::ServiceDescription getService() const noexcept; + IoxInterfacePtr getIceoryInterface() const noexcept; + DDSInterfacePtr getDDSInterface() const noexcept; + +private: + + static IoxInterfacePool s_ioxInterfacePool; + static DDSInterfacePool s_ddsInterfacePool; + + iox::capro::ServiceDescription m_service; + IoxInterfacePtr m_ioxInterface; + DDSInterfacePtr m_ddsInterface; }; + +} // namespace dds +} // namespace iox + diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index cb4670b485..26f1d1523a 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -15,7 +15,6 @@ inline DDS2IceoryxGateway::DDS2IceoryxGateway() { // Initialize pre-configured services this->loadConfiguration(); - } template diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index 7b478fda67..576dc1819b 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -129,8 +129,6 @@ inline void Iceoryx2DDSGateway::forwardi template inline void Iceoryx2DDSGateway::forward() noexcept { - uint64_t index{0}; - auto guardedVector = m_channels.GetScopeGuard(); for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) { @@ -146,7 +144,6 @@ inline void Iceoryx2DDSGateway::forward( } subscriber->releaseChunk(header); } - index++; } } From bc986bf2ee5dbfdd81a3415472e5eccd3d408366 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 16:09:36 +0200 Subject: [PATCH 10/55] iox-#65 Factored out common channel logic into base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/channel.hpp | 36 +++++---- .../include/ioxdds/gateway/dds_to_iox.hpp | 3 +- .../ioxdds/internal/gateway/channel.inl | 79 +++++++++++++++++++ 3 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp index c1e4b99b35..ca5b4ef370 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp @@ -17,47 +17,49 @@ namespace dds{ /// channel. /// For example: An Iceoryx subscriber and its corresponding DDS data writer, which communicate eachother to form /// an outbound communication channel. +/// These entites are conceptualized as channel "Terminals". /// -/// The structure holds pointers to the instances of the coupled entities. -/// The entites can be created and managed externally, in which case the structure only serves as a means of coupling +/// The structure holds pointers to the instances of the terminals. +/// The terminals can be created and managed externally, in which case the structure only serves as a means of coupling /// the two. -/// This can be achieved by simply calling the constructor with pointers to the instances. +/// This can be achieved by simply calling the constructor with pointers to them. /// -/// Alternatively, the class can manage the entities internally in a static object pool, automatically +/// Alternatively, the class can manage the terminals internally in a static object pool, automatically /// cleaning them up when the channel is discarded. /// This can be achieved via the Channel::create method. /// -template +template class Channel { - using IoxInterfacePtr = std::shared_ptr; - using IoxInterfacePool = iox::cxx::ObjectPool; - using DDSInterfacePtr = std::shared_ptr; - using DDSInterfacePool = iox::cxx::ObjectPool; + using IoxTerminalPtr = std::shared_ptr; + using IoxTerminalPool = iox::cxx::ObjectPool; + using DDSTerminalPtr = std::shared_ptr; + using DDSTerminalPool = iox::cxx::ObjectPool; public: Channel(const iox::capro::ServiceDescription& service, - const IoxInterfacePtr ioxInterface, - const DDSInterfacePtr ddsInterface) noexcept; + const IoxTerminalPtr ioxInterface, + const DDSTerminalPtr ddsInterface) noexcept; static Channel create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; - IoxInterfacePtr getIceoryInterface() const noexcept; - DDSInterfacePtr getDDSInterface() const noexcept; + IoxTerminalPtr getIceoryxTerminal() const noexcept; + DDSTerminalPtr getDDSTerminal() const noexcept; private: - static IoxInterfacePool s_ioxInterfacePool; - static DDSInterfacePool s_ddsInterfacePool; + static IoxTerminalPool s_ioxTerminals; + static DDSTerminalPool s_ddsTerminals; iox::capro::ServiceDescription m_service; - IoxInterfacePtr m_ioxInterface; - DDSInterfacePtr m_ddsInterface; + IoxTerminalPtr m_ioxTerminal; + DDSTerminalPtr m_ddsTerminal; }; } // namespace dds } // namespace iox +#include "ioxdds/internal/gateway/channel.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 109ec245fa..334964e012 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -4,6 +4,7 @@ #include "ioxdds/dds/dds_types.hpp" #include "ioxdds/gateway/dds_gateway_generic.hpp" +#include "ioxdds/gateway/channel.hpp" #include "ioxdds/gateway/input_channel.hpp" namespace iox { @@ -11,7 +12,7 @@ namespace dds { template -class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric> +class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric> { public: diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl new file mode 100644 index 0000000000..a84f3e8072 --- /dev/null +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl @@ -0,0 +1,79 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + +#include "ioxdds/gateway/channel.hpp" + +namespace iox +{ +namespace dds +{ + +// Typedefs +template +using IoxTerminalPool = iox::cxx::ObjectPool; +template +using DDSTerminalPool = iox::cxx::ObjectPool; + +// Statics +template +IoxTerminalPool Channel::s_ioxTerminals = IoxTerminalPool(); +template +DDSTerminalPool Channel::s_ddsTerminals = DDSTerminalPool(); + +template +inline Channel::Channel(const iox::capro::ServiceDescription& service, + const IoxTerminalPtr ioxTerminal, + const DDSTerminalPtr ddsTerminal) noexcept + : m_service(service), + m_ioxTerminal(ioxTerminal), + m_ddsTerminal(ddsTerminal) +{ +} + +template +inline Channel +Channel::create(const iox::capro::ServiceDescription& service) noexcept +{ + // Create objects in the pool. + auto rawIoxTerminalPtr = s_ioxTerminals.create(std::forward(service)); + auto rawDDSTerminalPtr = s_ddsTerminals.create( + service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); + + // Wrap in smart pointer with custom deleter to ensure automatic cleanup. + auto ioxTerminalPtr = IoxTerminalPtr(rawIoxTerminalPtr, [](IoxTerminal* p) { s_ioxTerminals.free(p); }); + auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* p) { s_ddsTerminals.free(p); }); + + return Channel(service, ioxTerminalPtr, ddsTerminalPtr); +} + +template +inline iox::capro::ServiceDescription Channel::getService() const noexcept +{ + return m_service; +} + +template +inline std::shared_ptr Channel::getIceoryxTerminal() const noexcept +{ + return m_ioxTerminal; +} + +template +inline std::shared_ptr Channel::getDDSTerminal() const noexcept +{ + return m_ddsTerminal; +} + +} // namespace dds +} // namespace iox From 8c8dd015200d7ad5477749472d239e82e798e6ee Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 16:31:58 +0200 Subject: [PATCH 11/55] iox-#65 Updated iox2dds gateway to use generic base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../ioxdds/gateway/dds_gateway_generic.hpp | 2 - .../include/ioxdds/gateway/iox_to_dds.hpp | 37 +------- .../ioxdds/internal/gateway/iox_to_dds.inl | 95 ++++++------------- 3 files changed, 31 insertions(+), 103 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp index fd9f9e4be1..8e37e4858c 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -25,8 +25,6 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; void discardChannel(const iox::capro::ServiceDescription& service) noexcept; -private: - ChannelFactory m_channelFactory; ConcurrentChannelVector m_channels; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index ed95dc12e2..89aeee0a54 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -21,17 +21,14 @@ #include #include -#include #include #include -#include -#include -#include #include "ioxdds/dds/data_writer.hpp" #include "ioxdds/dds/dds_configs.hpp" #include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/output_channel.hpp" +#include "ioxdds/gateway/dds_gateway_generic.hpp" +#include "ioxdds/gateway/channel.hpp" namespace iox { @@ -42,24 +39,15 @@ namespace dds /// /// Forwards data published in a local posh runtime to an attached DDS network. /// -template -class Iceoryx2DDSGateway : gateway_t +class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric> { - using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; - using ChannelVector = iox::cxx::vector, MAX_CHANNEL_NUMBER>; - using ConcurrentChannelVector = iox::concurrent::smart_lock; public: Iceoryx2DDSGateway(); ~Iceoryx2DDSGateway(); - /// - /// @brief Iceoryx2DDSGateway Enables injection of mocks during testing. - /// @param channelFactory Factory method to create channel instances containing mocks. - /// - Iceoryx2DDSGateway(ChannelFactory channelFactory); Iceoryx2DDSGateway(const Iceoryx2DDSGateway&) = delete; Iceoryx2DDSGateway& operator=(const Iceoryx2DDSGateway&) = delete; Iceoryx2DDSGateway(Iceoryx2DDSGateway&&) = delete; @@ -104,9 +92,6 @@ class Iceoryx2DDSGateway : gateway_t std::thread m_discoveryThread; std::thread m_forwardingThread; - ChannelFactory m_channelFactory; - ConcurrentChannelVector m_channels; - /// /// @brief Starts the data forwarding loop. /// @@ -125,20 +110,6 @@ class Iceoryx2DDSGateway : gateway_t /// void discoveryLoop() noexcept; - /// - /// @brief setupChannelUnsafe Creates a new channel for a service. - /// - /// @param service The service for which a channel will be established. - /// @return Channel object with subscriber and data writer for the given service. - /// - OutputChannel setupChannel(const iox::capro::ServiceDescription& service) noexcept; - - /// - /// @brief discardChannel Discards the channel for the given service. - /// - /// @param service The service for which a channel will be discarded. - /// - void discardChannel(const iox::capro::ServiceDescription& service) noexcept; }; } // dds diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index 576dc1819b..d642f04c1b 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -16,7 +16,6 @@ #include #include -#include #include "ioxdds/internal/log/logging.hpp" @@ -25,44 +24,35 @@ namespace iox namespace dds { // ======================================== Public ======================================== // -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() - : gateway_t(iox::capro::Interfaces::DDS) +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() { - m_channelFactory = OutputChannel::create; } -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) - : gateway_t(iox::capro::Interfaces::DDS) -{ - m_channelFactory = channelFactory; -} -template -inline Iceoryx2DDSGateway::~Iceoryx2DDSGateway() +template +inline Iceoryx2DDSGateway::~Iceoryx2DDSGateway() { shutdown(); - m_channels->clear(); } -template -inline void Iceoryx2DDSGateway::runMultithreaded() noexcept +template +inline void Iceoryx2DDSGateway::runMultithreaded() noexcept { m_discoveryThread = std::thread([this] { discoveryLoop(); }); m_forwardingThread = std::thread([this] { forwardingLoop(); }); m_isRunning.store(true, std::memory_order_relaxed); } -template -inline void Iceoryx2DDSGateway::discoveryLoop() noexcept +template +inline void Iceoryx2DDSGateway::discoveryLoop() noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] Starting discovery."; m_runDiscoveryLoop.store(true, std::memory_order_relaxed); while (m_runDiscoveryLoop.load(std::memory_order_relaxed)) { iox::capro::CaproMessage msg; - while (static_cast(this)->getCaProMessage(msg)) + while (this->getCaProMessage(msg)) { discover(msg); } @@ -72,9 +62,9 @@ inline void Iceoryx2DDSGateway::discover iox::LogDebug() << "[Iceoryx2DDSGateway] Stopped discovery."; } -template +template inline void -Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept +Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] " << iox::capro::CaproMessageTypeString[static_cast(msg.m_type)] @@ -95,14 +85,14 @@ Iceoryx2DDSGateway::discover(const iox:: { case iox::capro::CaproMessageType::OFFER: { - auto channel = setupChannel(msg.m_serviceDescription); - channel.getSubscriber()->subscribe(SUBSCRIBER_CACHE_SIZE); - channel.getDataWriter()->connect(); + auto channel = this->setupChannel(msg.m_serviceDescription); + channel.getIceoryxTerminal()->subscribe(SUBSCRIBER_CACHE_SIZE); + channel.getDDSTerminal()->connect(); break; } case iox::capro::CaproMessageType::STOP_OFFER: { - discardChannel(msg.m_serviceDescription); + this->discardChannel(msg.m_serviceDescription); break; } default: @@ -112,8 +102,8 @@ Iceoryx2DDSGateway::discover(const iox:: } } -template -inline void Iceoryx2DDSGateway::forwardingLoop() noexcept +template +inline void Iceoryx2DDSGateway::forwardingLoop() noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] Starting forwarding."; m_runForwardingLoop.store(true, std::memory_order_relaxed); @@ -126,14 +116,14 @@ inline void Iceoryx2DDSGateway::forwardi iox::LogDebug() << "[Iceoryx2DDSGateway] Stopped forwarding."; } -template -inline void Iceoryx2DDSGateway::forward() noexcept +template +inline void Iceoryx2DDSGateway::forward() noexcept { - auto guardedVector = m_channels.GetScopeGuard(); + auto guardedVector = this->m_channels.GetScopeGuard(); for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) { - auto subscriber = channel->getSubscriber(); - auto writer = channel->getDataWriter(); + auto subscriber = channel->getIceoryxTerminal(); + auto writer = channel->getDDSTerminal(); if (subscriber->hasNewChunks()) { const iox::mepoo::ChunkHeader* header; @@ -147,15 +137,15 @@ inline void Iceoryx2DDSGateway::forward( } } -template -inline uint64_t Iceoryx2DDSGateway::getNumberOfChannels() const noexcept +template +inline uint64_t Iceoryx2DDSGateway::getNumberOfChannels() const noexcept { - auto guardedVector = m_channels.GetScopeGuard(); + auto guardedVector = this->m_channels.GetScopeGuard(); return guardedVector->size(); } -template -inline void Iceoryx2DDSGateway::shutdown() noexcept +template +inline void Iceoryx2DDSGateway::shutdown() noexcept { if (m_isRunning.load(std::memory_order_relaxed)) { @@ -171,36 +161,5 @@ inline void Iceoryx2DDSGateway::shutdown } } -// ======================================== Private ======================================== // -template -OutputChannel Iceoryx2DDSGateway::setupChannel( - const iox::capro::ServiceDescription& service) noexcept -{ - auto channel = m_channelFactory(service); - iox::LogDebug() << "[Iceoryx2DDSGateway] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - m_channels->push_back(channel); - return channel; -} - -template -void Iceoryx2DDSGateway::discardChannel( - const iox::capro::ServiceDescription& service) noexcept -{ - auto guardedVector = m_channels.GetScopeGuard(); - auto channel = std::find_if( - guardedVector->begin(), guardedVector->end(), [&service](const OutputChannel& channel) { - return channel.getService() == service; - }); - if (channel != guardedVector->end()) - { - guardedVector->erase(channel); - iox::LogDebug() << "[Iceoryx2DDSGateway] Channel taken down for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - } -} - } // namespace dds } // namespace iox From 3f50767e95d72c7592959303c9369bceda2edc74 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 16:56:13 +0200 Subject: [PATCH 12/55] iox-#65 Factor out gateway running and shutdown logic to base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../ioxdds/gateway/dds_gateway_generic.hpp | 29 +++++++- .../include/ioxdds/gateway/dds_to_iox.hpp | 12 ---- .../include/ioxdds/gateway/iox_to_dds.hpp | 40 +---------- .../internal/gateway/dds_gateway_generic.inl | 70 +++++++++++++++++++ .../ioxdds/internal/gateway/dds_to_iox.inl | 19 +---- .../ioxdds/internal/gateway/iox_to_dds.inl | 69 ------------------ 6 files changed, 102 insertions(+), 137 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp index 8e37e4858c..805a4c002b 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -1,5 +1,8 @@ #pragma once +#include +#include + #include #include #include @@ -17,16 +20,38 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; +public: + + virtual ~DDSGatewayGeneric(); + + void runMultithreaded() noexcept; + void shutdown() noexcept; + + virtual void discover(const iox::capro::CaproMessage& msg) noexcept = 0; + virtual void forward() noexcept = 0; + protected: DDSGatewayGeneric(); + // These are made available to child classes for use in discover or forward methods. + ChannelFactory m_channelFactory; + ConcurrentChannelVector m_channels; + void loadConfiguration() noexcept; channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; void discardChannel(const iox::capro::ServiceDescription& service) noexcept; - ChannelFactory m_channelFactory; - ConcurrentChannelVector m_channels; +private: + std::atomic_bool m_isRunning{false}; + std::atomic_bool m_runForwardingLoop{false}; + std::atomic_bool m_runDiscoveryLoop{false}; + + std::thread m_discoveryThread; + std::thread m_forwardingThread; + + void forwardingLoop() noexcept; + void discoveryLoop() noexcept; }; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 334964e012..459a53758c 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -24,21 +24,9 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric +iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() +{ + shutdown(); +} + +template +void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept +{ + m_discoveryThread = std::thread([this] { discoveryLoop(); }); + m_forwardingThread = std::thread([this] { forwardingLoop(); }); + m_isRunning.store(true, std::memory_order_relaxed); +} + +template +void iox::dds::DDSGatewayGeneric::shutdown() noexcept +{ + if (m_isRunning.load(std::memory_order_relaxed)) + { + iox::LogDebug() << "[DDSGatewayGeneric] Shutting down Posh2DDSGateway."; + + m_runDiscoveryLoop.store(false, std::memory_order_relaxed); + m_runForwardingLoop.store(false, std::memory_order_relaxed); + + m_discoveryThread.join(); + m_forwardingThread.join(); + + m_isRunning.store(false, std::memory_order_relaxed); + } +} + +// ================================================== Protected ================================================== // + template iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) { @@ -72,3 +107,38 @@ void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::Se << service.getEventIDString(); } } + +// ================================================== Private ================================================== // + +template +void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept +{ + iox::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; + m_runDiscoveryLoop.store(true, std::memory_order_relaxed); + while (m_runDiscoveryLoop.load(std::memory_order_relaxed)) + { + iox::capro::CaproMessage msg; + while (this->getCaProMessage(msg)) + { + discover(msg); + } + std::this_thread::sleep_until(std::chrono::steady_clock::now() + + std::chrono::milliseconds(DISCOVERY_PERIOD.milliSeconds())); + } + iox::LogDebug() << "[DDSGatewayGeneric] Stopped discovery."; +} + +template +void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept +{ + iox::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; + m_runForwardingLoop.store(true, std::memory_order_relaxed); + while (m_runForwardingLoop.load(std::memory_order_relaxed)) + { + forward(); + std::this_thread::sleep_until(std::chrono::steady_clock::now() + + std::chrono::milliseconds(FORWARDING_PERIOD.milliSeconds())); + }; + iox::LogDebug() << "[DDSGatewayGeneric] Stopped forwarding."; +} + diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 26f1d1523a..491394f507 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -23,30 +23,17 @@ inline DDS2IceoryxGateway::~DDS2IceoryxGateway() } template -inline void DDS2IceoryxGateway::runMultithreaded() noexcept -{ -} - -template -inline void DDS2IceoryxGateway::discoveryLoop() noexcept +inline void +DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept { } template -inline void DDS2IceoryxGateway::forwardingLoop() noexcept +inline void DDS2IceoryxGateway::forward() noexcept { } -template -inline void DDS2IceoryxGateway::shutdown() noexcept -{ - -} - -// ======================================== Private ======================================== // - - } // namespace dds } // namespace iox diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index d642f04c1b..940ad47c10 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -24,44 +24,6 @@ namespace iox namespace dds { // ======================================== Public ======================================== // -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() -{ -} - - -template -inline Iceoryx2DDSGateway::~Iceoryx2DDSGateway() -{ - shutdown(); -} - -template -inline void Iceoryx2DDSGateway::runMultithreaded() noexcept -{ - m_discoveryThread = std::thread([this] { discoveryLoop(); }); - m_forwardingThread = std::thread([this] { forwardingLoop(); }); - m_isRunning.store(true, std::memory_order_relaxed); -} - -template -inline void Iceoryx2DDSGateway::discoveryLoop() noexcept -{ - iox::LogDebug() << "[Iceoryx2DDSGateway] Starting discovery."; - m_runDiscoveryLoop.store(true, std::memory_order_relaxed); - while (m_runDiscoveryLoop.load(std::memory_order_relaxed)) - { - iox::capro::CaproMessage msg; - while (this->getCaProMessage(msg)) - { - discover(msg); - } - std::this_thread::sleep_until(std::chrono::steady_clock::now() - + std::chrono::milliseconds(DISCOVERY_PERIOD.milliSeconds())); - } - iox::LogDebug() << "[Iceoryx2DDSGateway] Stopped discovery."; -} - template inline void Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept @@ -102,20 +64,6 @@ Iceoryx2DDSGateway::discover(const iox::capro::Capr } } -template -inline void Iceoryx2DDSGateway::forwardingLoop() noexcept -{ - iox::LogDebug() << "[Iceoryx2DDSGateway] Starting forwarding."; - m_runForwardingLoop.store(true, std::memory_order_relaxed); - while (m_runForwardingLoop.load(std::memory_order_relaxed)) - { - forward(); - std::this_thread::sleep_until(std::chrono::steady_clock::now() - + std::chrono::milliseconds(FORWARDING_PERIOD.milliSeconds())); - }; - iox::LogDebug() << "[Iceoryx2DDSGateway] Stopped forwarding."; -} - template inline void Iceoryx2DDSGateway::forward() noexcept { @@ -144,22 +92,5 @@ inline uint64_t Iceoryx2DDSGateway::getNumberOfChan return guardedVector->size(); } -template -inline void Iceoryx2DDSGateway::shutdown() noexcept -{ - if (m_isRunning.load(std::memory_order_relaxed)) - { - iox::LogDebug() << "[Iceoryx2DDSGateway] Shutting down Posh2DDSGateway."; - - m_runDiscoveryLoop.store(false, std::memory_order_relaxed); - m_runForwardingLoop.store(false, std::memory_order_relaxed); - - m_discoveryThread.join(); - m_forwardingThread.join(); - - m_isRunning.store(false, std::memory_order_relaxed); - } -} - } // namespace dds } // namespace iox From 436c61bd3d59fe4e169d2474578abf67ef036965 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 17:07:19 +0200 Subject: [PATCH 13/55] iox-#65 Factor out more gateway stuff into base class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../ioxdds/gateway/dds_gateway_generic.hpp | 9 +++++-- .../include/ioxdds/gateway/dds_to_iox.hpp | 10 ------- .../include/ioxdds/gateway/iox_to_dds.hpp | 27 ------------------- .../internal/gateway/dds_gateway_generic.inl | 25 ++++++++++------- .../ioxdds/internal/gateway/dds_to_iox.inl | 5 ---- .../ioxdds/internal/gateway/iox_to_dds.inl | 17 +++++------- 6 files changed, 29 insertions(+), 64 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp index 805a4c002b..db0fd173be 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -21,17 +21,22 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric using ConcurrentChannelVector = iox::concurrent::smart_lock; public: - virtual ~DDSGatewayGeneric(); + DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; + DDSGatewayGeneric& operator=(const DDSGatewayGeneric&) = delete; + DDSGatewayGeneric(DDSGatewayGeneric&&) = delete; + DDSGatewayGeneric& operator=(DDSGatewayGeneric&&) = delete; + void runMultithreaded() noexcept; void shutdown() noexcept; virtual void discover(const iox::capro::CaproMessage& msg) noexcept = 0; virtual void forward() noexcept = 0; -protected: + uint64_t getNumberOfChannels() const noexcept; +protected: DDSGatewayGeneric(); // These are made available to child classes for use in discover or forward methods. diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 459a53758c..7e523b0f9f 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -14,20 +14,10 @@ template class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric> { - public: DDS2IceoryxGateway(); - ~DDS2IceoryxGateway(); - - DDS2IceoryxGateway(const DDS2IceoryxGateway&) = delete; - DDS2IceoryxGateway& operator=(const DDS2IceoryxGateway&) = delete; - DDS2IceoryxGateway(DDS2IceoryxGateway&&) = delete; - DDS2IceoryxGateway& operator=(DDS2IceoryxGateway&&) = delete; - void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; - - }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index 58c9ec9215..891b518845 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -43,37 +43,10 @@ template class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric> { - public: Iceoryx2DDSGateway() = default; - ~Iceoryx2DDSGateway() = default; - - Iceoryx2DDSGateway(const Iceoryx2DDSGateway&) = delete; - Iceoryx2DDSGateway& operator=(const Iceoryx2DDSGateway&) = delete; - Iceoryx2DDSGateway(Iceoryx2DDSGateway&&) = delete; - Iceoryx2DDSGateway& operator=(Iceoryx2DDSGateway&&) = delete; - - /// - /// @brief discover Run discovery logic for the given CaproMessage. - /// Used for manual gateway management. - /// - /// @param msg - /// void discover(const iox::capro::CaproMessage& msg) noexcept; - - /// - /// @brief forward Forward newly received data to DDS network. - /// Used for manual gateway management. - /// - /// void forward() noexcept; - - /// - /// @brief getNumberOfChannels Get the number of active channels. - /// @return The number of active channels. - /// - uint64_t getNumberOfChannels() const noexcept; - }; } // dds diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl index 2e0fada426..c8d76d569c 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -9,13 +9,13 @@ // ================================================== Public ================================================== // template -iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() +inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() { shutdown(); } template -void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept +inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept { m_discoveryThread = std::thread([this] { discoveryLoop(); }); m_forwardingThread = std::thread([this] { forwardingLoop(); }); @@ -23,7 +23,7 @@ void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept } template -void iox::dds::DDSGatewayGeneric::shutdown() noexcept +inline void iox::dds::DDSGatewayGeneric::shutdown() noexcept { if (m_isRunning.load(std::memory_order_relaxed)) { @@ -39,16 +39,23 @@ void iox::dds::DDSGatewayGeneric::shutdown() noexcept } } +template +inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept +{ + auto guardedVector = m_channels.GetScopeGuard(); + return guardedVector->size(); +} + // ================================================== Protected ================================================== // template -iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) +inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) { m_channelFactory = channel_t::create; } template -void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept +inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept { // Search for config passed as command line argument. @@ -81,7 +88,7 @@ void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept template -channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept +inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); iox::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " @@ -92,7 +99,7 @@ channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro: } template -void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept +inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = m_channels.GetScopeGuard(); auto channel = std::find_if( @@ -111,7 +118,7 @@ void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::Se // ================================================== Private ================================================== // template -void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept +inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept { iox::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; m_runDiscoveryLoop.store(true, std::memory_order_relaxed); @@ -129,7 +136,7 @@ void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept } template -void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept +inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept { iox::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; m_runForwardingLoop.store(true, std::memory_order_relaxed); diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 491394f507..17c52261b0 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -17,11 +17,6 @@ inline DDS2IceoryxGateway::DDS2IceoryxGateway() this->loadConfiguration(); } -template -inline DDS2IceoryxGateway::~DDS2IceoryxGateway() -{ -} - template inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index 940ad47c10..e9ca3328d3 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -48,8 +48,10 @@ Iceoryx2DDSGateway::discover(const iox::capro::Capr case iox::capro::CaproMessageType::OFFER: { auto channel = this->setupChannel(msg.m_serviceDescription); - channel.getIceoryxTerminal()->subscribe(SUBSCRIBER_CACHE_SIZE); - channel.getDDSTerminal()->connect(); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); break; } case iox::capro::CaproMessageType::STOP_OFFER: @@ -71,26 +73,19 @@ inline void Iceoryx2DDSGateway::forward() noexcept for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) { auto subscriber = channel->getIceoryxTerminal(); - auto writer = channel->getDDSTerminal(); + auto dataWriter = channel->getDDSTerminal(); if (subscriber->hasNewChunks()) { const iox::mepoo::ChunkHeader* header; subscriber->getChunk(&header); if (header->m_info.m_payloadSize > 0) { - writer->write(static_cast(header->payload()), header->m_info.m_payloadSize); + dataWriter->write(static_cast(header->payload()), header->m_info.m_payloadSize); } subscriber->releaseChunk(header); } } } -template -inline uint64_t Iceoryx2DDSGateway::getNumberOfChannels() const noexcept -{ - auto guardedVector = this->m_channels.GetScopeGuard(); - return guardedVector->size(); -} - } // namespace dds } // namespace iox From 54bf1d5b220910d2e141fde616602aaa3f451942 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 28 May 2020 18:02:23 +0200 Subject: [PATCH 14/55] iox-#65 Reduced amount of gateway templates - specify channel instead of the terminals. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/dds_to_iox.hpp | 5 +-- .../include/ioxdds/gateway/iox_to_dds.hpp | 7 ++-- .../internal/gateway/dds_gateway_generic.inl | 9 ++--- .../ioxdds/internal/gateway/dds_to_iox.inl | 14 +++---- .../ioxdds/internal/gateway/iox_to_dds.inl | 39 ++++++++++++++----- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index 7e523b0f9f..be51c05e57 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -10,9 +10,8 @@ namespace iox { namespace dds { -template -class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric> +template > +class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric { public: DDS2IceoryxGateway(); diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index 891b518845..d9d129f385 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -39,12 +39,11 @@ namespace dds /// /// Forwards data published in a local posh runtime to an attached DDS network. /// -template -class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric> +template > +class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric { public: - Iceoryx2DDSGateway() = default; + Iceoryx2DDSGateway(); void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl index c8d76d569c..9896c8ea28 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -51,6 +51,7 @@ inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() co template inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) { + LogDebug() << "[DDSGatewayGeneric] Using default channel factory."; m_channelFactory = channel_t::create; } @@ -66,8 +67,9 @@ inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept // Search for local config. - // Setup data readers and publishers - auto configuredTopics = config->get_table_array("services"); + // Setup data readers and publishers + auto configuredTopics = config->get_table_array("services"); + LogDebug() << "[DDSGatewayGeneric] Setting up channels for pre-configured services."; for(const auto& topic : *configuredTopics) { auto service = topic->get_as("service").value_or(""); @@ -80,9 +82,6 @@ inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept IdString(iox::cxx::TruncateToCapacity, event.c_str()) ) ); - - LogDebug() << "[DDSGatewayGeneric] Loaded topic from file: " + service + "/" + instance + "/" + event; - } } diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index 17c52261b0..c2587f9911 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -10,22 +10,22 @@ namespace iox { namespace dds { -template -inline DDS2IceoryxGateway::DDS2IceoryxGateway() +template +inline DDS2IceoryxGateway::DDS2IceoryxGateway() + : iox::dds::DDSGatewayGeneric() { // Initialize pre-configured services this->loadConfiguration(); } -template -inline void -DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept +template +inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept { } -template -inline void DDS2IceoryxGateway::forward() noexcept +template +inline void DDS2IceoryxGateway::forward() noexcept { } diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index e9ca3328d3..b686ace5e2 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -19,14 +19,23 @@ #include "ioxdds/internal/log/logging.hpp" +#include "ioxdds/gateway/iox_to_dds.hpp" + namespace iox { namespace dds { // ======================================== Public ======================================== // -template +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() : iox::dds::DDSGatewayGeneric() +{ + // Initialize pre-configured services + this->loadConfiguration(); +} + +template inline void -Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept +Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] " << iox::capro::CaproMessageTypeString[static_cast(msg.m_type)] @@ -47,12 +56,22 @@ Iceoryx2DDSGateway::discover(const iox::capro::Capr { case iox::capro::CaproMessageType::OFFER: { - auto channel = this->setupChannel(msg.m_serviceDescription); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); - break; +// // Check if channel already exists using a predicate that checks the channel service desription. +// auto guardedVector = this->m_channels.GetScopeGuard(); +// if(std::find_if( +// guardedVector->begin(), +// guardedVector->end(), +// [&msg](const Channel& channel) { +// return channel.getService() == msg.m_serviceDescription; +// }) == guardedVector->end()) +// { +// auto channel = this->setupChannel(msg.m_serviceDescription); +// auto subscriber = channel.getIceoryxTerminal(); +// auto dataWriter = channel.getDDSTerminal(); +// subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); +// dataWriter->connect(); +// break; +// } } case iox::capro::CaproMessageType::STOP_OFFER: { @@ -66,8 +85,8 @@ Iceoryx2DDSGateway::discover(const iox::capro::Capr } } -template -inline void Iceoryx2DDSGateway::forward() noexcept +template +inline void Iceoryx2DDSGateway::forward() noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) From ce3f2b777268ab8e73314f99f4ab7ae06b2e999d Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 2 Jun 2020 12:58:07 +0200 Subject: [PATCH 15/55] iox-#65 Create channels for preconfigured services. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../internal/gateway/dds_gateway_generic.inl | 14 +++---- .../ioxdds/internal/gateway/iox_to_dds.inl | 42 +++++++++++-------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl index 9896c8ea28..a7b1a422f8 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -76,12 +76,11 @@ inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept auto instance = topic->get_as("instance").value_or(""); auto event = topic->get_as("event").value_or(""); - this->setupChannel(iox::capro::ServiceDescription( - IdString(iox::cxx::TruncateToCapacity, service.c_str()), - IdString(iox::cxx::TruncateToCapacity, instance.c_str()), - IdString(iox::cxx::TruncateToCapacity, event.c_str()) - ) - ); + auto channel = this->setupChannel(iox::capro::ServiceDescription( + IdString(iox::cxx::TruncateToCapacity, service.c_str()), + IdString(iox::cxx::TruncateToCapacity, instance.c_str()), + IdString(iox::cxx::TruncateToCapacity, event.c_str()) + )); } } @@ -93,7 +92,8 @@ inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox: iox::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - m_channels->push_back(channel); + auto guardedVector = m_channels.GetScopeGuard(); + guardedVector->push_back(channel); return channel; } diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index b686ace5e2..6249a25652 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -29,8 +29,17 @@ namespace dds template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() : iox::dds::DDSGatewayGeneric() { - // Initialize pre-configured services + // Create channels for all pre-configured services. this->loadConfiguration(); + + // Connect the terminals of the created channels. + for (auto channel = this->m_channels->begin(); channel != this->m_channels->end(); channel++) + { + auto subscriber = channel->getIceoryxTerminal(); + auto dataWriter = channel->getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); + } } template @@ -56,22 +65,21 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe { case iox::capro::CaproMessageType::OFFER: { -// // Check if channel already exists using a predicate that checks the channel service desription. -// auto guardedVector = this->m_channels.GetScopeGuard(); -// if(std::find_if( -// guardedVector->begin(), -// guardedVector->end(), -// [&msg](const Channel& channel) { -// return channel.getService() == msg.m_serviceDescription; -// }) == guardedVector->end()) -// { -// auto channel = this->setupChannel(msg.m_serviceDescription); -// auto subscriber = channel.getIceoryxTerminal(); -// auto dataWriter = channel.getDDSTerminal(); -// subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); -// dataWriter->connect(); -// break; -// } + // Check if channel already exists using a predicate that checks the channel service desription. + if(std::find_if( + this->m_channels->begin(), + this->m_channels->end(), + [&msg](const channel_t& channel) { + return channel.getService() == msg.m_serviceDescription; + }) == this->m_channels->end()) + { + auto channel = this->setupChannel(msg.m_serviceDescription); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); + } + break; } case iox::capro::CaproMessageType::STOP_OFFER: { From 620d668942bb930f7b7efc0d73b414bb5e1c4686 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 2 Jun 2020 13:02:29 +0200 Subject: [PATCH 16/55] iox-#65 Declare constructors as noexcept. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/dds_gateway_generic.hpp | 4 ++-- iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp | 2 +- iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp | 2 +- .../include/ioxdds/internal/gateway/dds_gateway_generic.inl | 4 ++-- .../include/ioxdds/internal/gateway/dds_to_iox.inl | 2 +- .../include/ioxdds/internal/gateway/iox_to_dds.inl | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp index db0fd173be..49551c6438 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -21,7 +21,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric using ConcurrentChannelVector = iox::concurrent::smart_lock; public: - virtual ~DDSGatewayGeneric(); + virtual ~DDSGatewayGeneric() noexcept; DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; DDSGatewayGeneric& operator=(const DDSGatewayGeneric&) = delete; @@ -37,7 +37,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric uint64_t getNumberOfChannels() const noexcept; protected: - DDSGatewayGeneric(); + DDSGatewayGeneric() noexcept; // These are made available to child classes for use in discover or forward methods. ChannelFactory m_channelFactory; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp index be51c05e57..ae8a3fe70f 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp @@ -14,7 +14,7 @@ template { public: - DDS2IceoryxGateway(); + DDS2IceoryxGateway() noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp index d9d129f385..50848643bb 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp @@ -43,7 +43,7 @@ template { public: - Iceoryx2DDSGateway(); + Iceoryx2DDSGateway() noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl index a7b1a422f8..d2a7cc7bf6 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -9,7 +9,7 @@ // ================================================== Public ================================================== // template -inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() +inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() noexcept { shutdown(); } @@ -49,7 +49,7 @@ inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() co // ================================================== Protected ================================================== // template -inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) +inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) { LogDebug() << "[DDSGatewayGeneric] Using default channel factory."; m_channelFactory = channel_t::create; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl index c2587f9911..bd88660f52 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl @@ -11,7 +11,7 @@ namespace iox { namespace dds { template -inline DDS2IceoryxGateway::DDS2IceoryxGateway() +inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept : iox::dds::DDSGatewayGeneric() { // Initialize pre-configured services diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index 6249a25652..dcf7f67f9b 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -27,7 +27,7 @@ namespace dds { // ======================================== Public ======================================== // template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() : iox::dds::DDSGatewayGeneric() +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds::DDSGatewayGeneric() { // Create channels for all pre-configured services. this->loadConfiguration(); From 0505fe9a935c715536e29e9102b6a2de4c3c0c50 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 2 Jun 2020 14:25:57 +0200 Subject: [PATCH 17/55] iox-#65 Remove unused classes. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/input_channel.hpp | 45 ---------- .../include/ioxdds/gateway/output_channel.hpp | 85 ------------------- .../ioxdds/internal/gateway/input_channel.inl | 63 -------------- .../internal/gateway/output_channel.inl | 76 ----------------- 4 files changed, 269 deletions(-) delete mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp delete mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp delete mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl delete mode 100644 iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp deleted file mode 100644 index 8d3a3734a9..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/input_channel.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include -#include - -#include "ioxdds/dds/dds_configs.hpp" -#include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/dds/data_reader.hpp" - -namespace iox { -namespace dds { - -template -class InputChannel -{ - public: - using PublisherPtr = std::shared_ptr; - using PublisherPool = iox::cxx::ObjectPool; - using DataReaderPtr = std::shared_ptr; - using DataReaderPool = iox::cxx::ObjectPool; - - InputChannel(const iox::capro::ServiceDescription& service, - const PublisherPtr publisher, - const DataReaderPtr dataReader) noexcept; - - static InputChannel create(const iox::capro::ServiceDescription& service) noexcept; - - iox::capro::ServiceDescription getService() const noexcept; - PublisherPtr getPublisher() const noexcept; - DataReaderPtr getDataReader() const noexcept; - - private: - // Store in data segment - too large to keep in stack. - static PublisherPool s_publisherPool; - static DataReaderPool s_dataReaderPool; - - iox::capro::ServiceDescription m_service; - PublisherPtr m_publisher; - DataReaderPtr m_dataReader; -}; - -} // dds -} // iox - -#include "ioxdds/internal/gateway/input_channel.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp deleted file mode 100644 index 09cf9a04ce..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/output_channel.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -#pragma once - -#include - -#include -#include -#include - -#include "ioxdds/dds/data_writer.hpp" -#include "ioxdds/dds/dds_configs.hpp" -#include "ioxdds/dds/dds_types.hpp" - -namespace iox -{ -namespace dds -{ -/// -/// @brief This data structure couples the subscriber and data writer components required to form an output channel -/// between the POSH and DDS worlds. -/// The structure holds pointers to the related component instances. These instances can either be managed externally -/// or by the class itself. -/// Managed instances are placed in static ObjectPools which are fixed size according to -/// MAX_CHANNEL_NUMBER and are automatically cleaned up when all references to them are discarded. -/// -template -class OutputChannel -{ - public: - using SubscriberPtr = std::shared_ptr; - using SubscriberPool = iox::cxx::ObjectPool; - using DataWriterPtr = std::shared_ptr; - using DataWriterPool = iox::cxx::ObjectPool; - - /// - /// @brief Channel Constructs a channel object with components that are externally managed. - /// - /// @param service The service that the channel is connecting. - /// @param subscriber An externally managed subscriber component. - /// @param dataWriter An externally managed data writer component. - /// - OutputChannel(const iox::capro::ServiceDescription& service, - const SubscriberPtr subscriber, - const DataWriterPtr dataWriter) noexcept; - - /// - /// @brief create Creates an output channel whose components are instantiated in static object pools that will be - /// automatically freed when all references are discarded. - /// - /// @param service The service that the channel is connecting. - /// @return Channel A channel with internally managed endpoints. - /// - static OutputChannel create(const iox::capro::ServiceDescription& service) noexcept; - - iox::capro::ServiceDescription getService() const noexcept; - SubscriberPtr getSubscriber() const noexcept; - DataWriterPtr getDataWriter() const noexcept; - - private: - // Store in data segment - too large to keep in stack. - static SubscriberPool s_subscriberPool; - static DataWriterPool s_dataWriterPool; - - iox::capro::ServiceDescription m_service; - SubscriberPtr m_subscriber; - DataWriterPtr m_dataWriter; -}; - -} // dds -} // iox - -#include "ioxdds/internal/gateway/output_channel.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl deleted file mode 100644 index 1cf4de60c5..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/input_channel.inl +++ /dev/null @@ -1,63 +0,0 @@ -#include "ioxdds/gateway/input_channel.hpp" - -namespace iox { -namespace dds { - -// Typedefs -template -using PublisherPool = iox::cxx::ObjectPool; -template -using DataReaderPool = iox::cxx::ObjectPool; - -// Statics -template -PublisherPool InputChannel::s_publisherPool = PublisherPool(); -template -DataReaderPool InputChannel::s_dataReaderPool = DataReaderPool(); - -template -inline InputChannel::InputChannel(const iox::capro::ServiceDescription& service, - const PublisherPtr publisher, - const DataReaderPtr dataReader) noexcept - : m_service(service), - m_publisher(publisher), - m_dataReader(dataReader) -{ -} - -template -inline InputChannel -InputChannel::create(const iox::capro::ServiceDescription& service) noexcept -{ - // Create objects in the pool. - auto rawPublisherPtr = s_publisherPool.create(service); - auto rawDataReaderPtr = s_dataReaderPool.create( - service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); - - // Wrap in smart pointer with custom deleter to ensure automatic cleanup. - auto publisherPtr = PublisherPtr(rawPublisherPtr, [](publisher_t* p) { s_publisherPool.free(p); }); - auto dataReaderPtr = DataReaderPtr(rawDataReaderPtr, [](data_reader_t* p) { s_dataReaderPool.free(p); }); - - return InputChannel(service, publisherPtr, dataReaderPtr); -} - -template -inline iox::capro::ServiceDescription InputChannel::getService() const noexcept -{ - return m_service; -} - -template -inline std::shared_ptr InputChannel::getPublisher() const noexcept -{ - return m_publisher; -} - -template -inline std::shared_ptr InputChannel::getDataReader() const noexcept -{ - return m_dataReader; -} - -} -} diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl deleted file mode 100644 index 264e555016..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/output_channel.inl +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -namespace iox -{ -namespace dds -{ -// Typedefs -template -using SubscriberPool = iox::cxx::ObjectPool; -template -using DataWriterPool = iox::cxx::ObjectPool; - -// Statics -template -SubscriberPool OutputChannel::s_subscriberPool = SubscriberPool(); -template -DataWriterPool OutputChannel::s_dataWriterPool = DataWriterPool(); - -template -inline OutputChannel::OutputChannel(const iox::capro::ServiceDescription& service, - const SubscriberPtr subscriber, - const DataWriterPtr dataWriter) noexcept - : m_service(service), - m_subscriber(subscriber), - m_dataWriter(dataWriter) -{ -} - -template -inline OutputChannel -OutputChannel::create(const iox::capro::ServiceDescription& service) noexcept -{ - // Create objects in the pool. - auto rawSubscriberPtr = s_subscriberPool.create(std::forward(service)); - auto rawDataWriterPtr = s_dataWriterPool.create( - service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); - - // Wrap in smart pointer with custom deleter to ensure automatic cleanup. - auto subscriberPtr = SubscriberPtr(rawSubscriberPtr, [](subscriber_t* p) { s_subscriberPool.free(p); }); - auto dataWriterPtr = DataWriterPtr(rawDataWriterPtr, [](data_writer_t* p) { s_dataWriterPool.free(p); }); - - return OutputChannel(service, subscriberPtr, dataWriterPtr); -} - -template -inline iox::capro::ServiceDescription OutputChannel::getService() const noexcept -{ - return m_service; -} - -template -inline std::shared_ptr OutputChannel::getSubscriber() const noexcept -{ - return m_subscriber; -} - -template -inline std::shared_ptr OutputChannel::getDataWriter() const noexcept -{ - return m_dataWriter; -} - -} // namespace dds -} // namespace iox From 871633efb3be588aae2b69d301ffec492174c932 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 2 Jun 2020 15:30:20 +0200 Subject: [PATCH 18/55] iox-#65 Fix deadlock with channel access. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../ioxdds/gateway/dds_gateway_generic.hpp | 1 + .../internal/gateway/dds_gateway_generic.inl | 26 +++++++++++++------ .../ioxdds/internal/gateway/iox_to_dds.inl | 18 ++++++------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp index 49551c6438..973bcea6ad 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp @@ -46,6 +46,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric void loadConfiguration() noexcept; channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + bool channelExists(const iox::capro::ServiceDescription& service) noexcept; private: std::atomic_bool m_isRunning{false}; diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl index d2a7cc7bf6..ffea971df8 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl @@ -76,11 +76,11 @@ inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept auto instance = topic->get_as("instance").value_or(""); auto event = topic->get_as("event").value_or(""); - auto channel = this->setupChannel(iox::capro::ServiceDescription( - IdString(iox::cxx::TruncateToCapacity, service.c_str()), - IdString(iox::cxx::TruncateToCapacity, instance.c_str()), - IdString(iox::cxx::TruncateToCapacity, event.c_str()) - )); + this->setupChannel(iox::capro::ServiceDescription( + IdString(iox::cxx::TruncateToCapacity, service.c_str()), + IdString(iox::cxx::TruncateToCapacity, instance.c_str()), + IdString(iox::cxx::TruncateToCapacity, event.c_str()) + )); } } @@ -89,18 +89,17 @@ template inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); + m_channels->push_back(channel); iox::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - auto guardedVector = m_channels.GetScopeGuard(); - guardedVector->push_back(channel); return channel; } template inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept { - auto guardedVector = m_channels.GetScopeGuard(); + auto guardedVector = this->m_channels.GetScopeGuard(); auto channel = std::find_if( guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { return channel.getService() == service; @@ -114,6 +113,17 @@ inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::ca } } +template +inline bool iox::dds::DDSGatewayGeneric::channelExists(const iox::capro::ServiceDescription& service) noexcept +{ + auto guardedVector = this->m_channels.GetScopeGuard(); + auto channel = std::find_if( + guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { + return channel.getService() == service; + }); + return channel != guardedVector->end(); +} + // ================================================== Private ================================================== // template diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl index dcf7f67f9b..9d9c3e3e65 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -33,7 +33,8 @@ inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds:: this->loadConfiguration(); // Connect the terminals of the created channels. - for (auto channel = this->m_channels->begin(); channel != this->m_channels->end(); channel++) + auto guardedVector = this->m_channels.GetScopeGuard(); + for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) { auto subscriber = channel->getIceoryxTerminal(); auto dataWriter = channel->getDDSTerminal(); @@ -65,13 +66,7 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe { case iox::capro::CaproMessageType::OFFER: { - // Check if channel already exists using a predicate that checks the channel service desription. - if(std::find_if( - this->m_channels->begin(), - this->m_channels->end(), - [&msg](const channel_t& channel) { - return channel.getService() == msg.m_serviceDescription; - }) == this->m_channels->end()) + if(!this->channelExists(msg.m_serviceDescription)) { auto channel = this->setupChannel(msg.m_serviceDescription); auto subscriber = channel.getIceoryxTerminal(); @@ -83,7 +78,10 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe } case iox::capro::CaproMessageType::STOP_OFFER: { - this->discardChannel(msg.m_serviceDescription); + if(this->channelExists(msg.m_serviceDescription)) + { + this->discardChannel(msg.m_serviceDescription); + } break; } default: @@ -100,13 +98,13 @@ inline void Iceoryx2DDSGateway::forward() noexcept for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) { auto subscriber = channel->getIceoryxTerminal(); - auto dataWriter = channel->getDDSTerminal(); if (subscriber->hasNewChunks()) { const iox::mepoo::ChunkHeader* header; subscriber->getChunk(&header); if (header->m_info.m_payloadSize > 0) { + auto dataWriter = channel->getDDSTerminal(); dataWriter->write(static_cast(header->payload()), header->m_info.m_payloadSize); } subscriber->releaseChunk(header); From dd56561012b2c87b3e8e6ab7608173ebab570eac Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 2 Jun 2020 15:38:07 +0200 Subject: [PATCH 19/55] iox-#65 Fix template name in Channel class. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/channel.hpp | 18 ++++---- .../ioxdds/internal/gateway/channel.inl | 46 +++++++++---------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp index ca5b4ef370..99912228dd 100644 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp +++ b/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp @@ -28,35 +28,33 @@ namespace dds{ /// cleaning them up when the channel is discarded. /// This can be achieved via the Channel::create method. /// -template +template class Channel { - using IoxTerminalPtr = std::shared_ptr; - using IoxTerminalPool = iox::cxx::ObjectPool; + using IceoryxTerminalPtr = std::shared_ptr; + using IceoryxTerminalPool = iox::cxx::ObjectPool; using DDSTerminalPtr = std::shared_ptr; using DDSTerminalPool = iox::cxx::ObjectPool; public: Channel(const iox::capro::ServiceDescription& service, - const IoxTerminalPtr ioxInterface, - const DDSTerminalPtr ddsInterface) noexcept; + const IceoryxTerminalPtr iceoryxTerminal, + const DDSTerminalPtr ddsTerminal) noexcept; static Channel create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; - IoxTerminalPtr getIceoryxTerminal() const noexcept; + IceoryxTerminalPtr getIceoryxTerminal() const noexcept; DDSTerminalPtr getDDSTerminal() const noexcept; private: - - static IoxTerminalPool s_ioxTerminals; + static IceoryxTerminalPool s_iceoryxTerminals; static DDSTerminalPool s_ddsTerminals; iox::capro::ServiceDescription m_service; - IoxTerminalPtr m_ioxTerminal; + IceoryxTerminalPtr m_iceoryxTerminal; DDSTerminalPtr m_ddsTerminal; - }; } // namespace dds diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl index a84f3e8072..80185de74a 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl +++ b/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl @@ -20,57 +20,57 @@ namespace dds { // Typedefs -template -using IoxTerminalPool = iox::cxx::ObjectPool; +template +using IceoryxTerminalPool = iox::cxx::ObjectPool; template using DDSTerminalPool = iox::cxx::ObjectPool; // Statics -template -IoxTerminalPool Channel::s_ioxTerminals = IoxTerminalPool(); -template -DDSTerminalPool Channel::s_ddsTerminals = DDSTerminalPool(); +template +IceoryxTerminalPool Channel::s_iceoryxTerminals = IceoryxTerminalPool(); +template +DDSTerminalPool Channel::s_ddsTerminals = DDSTerminalPool(); -template -inline Channel::Channel(const iox::capro::ServiceDescription& service, - const IoxTerminalPtr ioxTerminal, +template +inline Channel::Channel(const iox::capro::ServiceDescription& service, + const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept : m_service(service), - m_ioxTerminal(ioxTerminal), + m_iceoryxTerminal(iceoryxTerminal), m_ddsTerminal(ddsTerminal) { } -template -inline Channel -Channel::create(const iox::capro::ServiceDescription& service) noexcept +template +inline Channel +Channel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. - auto rawIoxTerminalPtr = s_ioxTerminals.create(std::forward(service)); + auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); auto rawDDSTerminalPtr = s_ddsTerminals.create( service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); // Wrap in smart pointer with custom deleter to ensure automatic cleanup. - auto ioxTerminalPtr = IoxTerminalPtr(rawIoxTerminalPtr, [](IoxTerminal* p) { s_ioxTerminals.free(p); }); + auto iceoryxTerminalPtr = IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* p) { s_iceoryxTerminals.free(p); }); auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* p) { s_ddsTerminals.free(p); }); - return Channel(service, ioxTerminalPtr, ddsTerminalPtr); + return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); } -template -inline iox::capro::ServiceDescription Channel::getService() const noexcept +template +inline iox::capro::ServiceDescription Channel::getService() const noexcept { return m_service; } -template -inline std::shared_ptr Channel::getIceoryxTerminal() const noexcept +template +inline std::shared_ptr Channel::getIceoryxTerminal() const noexcept { - return m_ioxTerminal; + return m_iceoryxTerminal; } -template -inline std::shared_ptr Channel::getDDSTerminal() const noexcept +template +inline std::shared_ptr Channel::getDDSTerminal() const noexcept { return m_ddsTerminal; } From 0ce1ad58c765f18b2e08bdb87718edee0beb8c9c Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 3 Jun 2020 09:59:52 +0200 Subject: [PATCH 20/55] iox-#65 Rename module to iceoryx_dds. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../CMakeLists.txt | 46 ++++++++-------- .../README.md | 0 .../cmake/Config.cmake.in | 0 .../ioxdds/dds/cyclone_data_reader.hpp | 0 .../ioxdds/dds/cyclone_data_writer.hpp | 0 .../include/ioxdds/dds/data_reader.hpp | 0 .../include/ioxdds/dds/data_writer.hpp | 0 .../include/ioxdds/dds/dds_configs.hpp | 0 .../include/ioxdds/dds/dds_types.hpp | 0 .../include/ioxdds/gateway/channel.hpp | 0 .../ioxdds/gateway/dds_gateway_generic.hpp | 0 .../include/ioxdds/gateway/dds_to_iox.hpp | 0 .../include/ioxdds/gateway/iox_to_dds.hpp | 54 +++++++++++++++++++ .../ioxdds/internal/dds/data_writer.inl | 0 .../ioxdds/internal/gateway/channel.inl | 0 .../internal/gateway/dds_gateway_generic.inl | 0 .../ioxdds/internal/gateway/dds_to_iox.inl | 0 .../ioxdds/internal/gateway/iox_to_dds.inl | 2 +- .../include/ioxdds/internal/log/logging.hpp | 0 .../msg/Mempool.idl | 0 .../scripts/build-for-cyclonedds.sh | 0 .../source/dds2iceoryx_app}/main.cpp | 0 .../source/iceoryx2dds_app}/main.cpp | 0 .../iceoryx_dds}/dds/cyclone_data_reader.cpp | 0 .../iceoryx_dds}/dds/cyclone_data_writer.cpp | 0 .../source/iceoryx_dds}/log/logging.cpp | 0 .../test/CMakeLists.txt | 0 .../test/mocks/chunk_mock.hpp | 0 .../test/moduletests/main.cpp | 0 .../test/moduletests/test_iox_to_dds.cpp | 0 .../test/test.hpp | 0 31 files changed, 78 insertions(+), 24 deletions(-) rename {iceoryx_dds_gateway => iceoryx_dds}/CMakeLists.txt (60%) rename {iceoryx_dds_gateway => iceoryx_dds}/README.md (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/cmake/Config.cmake.in (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/cyclone_data_reader.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/cyclone_data_writer.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/data_reader.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/data_writer.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/dds_configs.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/dds/dds_types.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/gateway/channel.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/gateway/dds_gateway_generic.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/gateway/dds_to_iox.hpp (100%) create mode 100644 iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/dds/data_writer.inl (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/gateway/channel.inl (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/gateway/dds_gateway_generic.inl (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/gateway/dds_to_iox.inl (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/gateway/iox_to_dds.inl (99%) rename {iceoryx_dds_gateway => iceoryx_dds}/include/ioxdds/internal/log/logging.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/msg/Mempool.idl (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/scripts/build-for-cyclonedds.sh (100%) rename {iceoryx_dds_gateway/source/dds2iox_app => iceoryx_dds/source/dds2iceoryx_app}/main.cpp (100%) rename {iceoryx_dds_gateway/source/iox2dds_app => iceoryx_dds/source/iceoryx2dds_app}/main.cpp (100%) rename {iceoryx_dds_gateway/source/ioxdds => iceoryx_dds/source/iceoryx_dds}/dds/cyclone_data_reader.cpp (100%) rename {iceoryx_dds_gateway/source/ioxdds => iceoryx_dds/source/iceoryx_dds}/dds/cyclone_data_writer.cpp (100%) rename {iceoryx_dds_gateway/source/ioxdds => iceoryx_dds/source/iceoryx_dds}/log/logging.cpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/test/CMakeLists.txt (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/test/mocks/chunk_mock.hpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/test/moduletests/main.cpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/test/moduletests/test_iox_to_dds.cpp (100%) rename {iceoryx_dds_gateway => iceoryx_dds}/test/test.hpp (100%) diff --git a/iceoryx_dds_gateway/CMakeLists.txt b/iceoryx_dds/CMakeLists.txt similarity index 60% rename from iceoryx_dds_gateway/CMakeLists.txt rename to iceoryx_dds/CMakeLists.txt index 392e43dfde..792de7ec42 100644 --- a/iceoryx_dds_gateway/CMakeLists.txt +++ b/iceoryx_dds/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) -set(iceoryx_dds_gateway_VERSION 0.1.0) -project(iceoryx_dds_gateway VERSION ${iceoryx_dds_gateway_VERSION}) +set(iceoryx_dds_VERSION 0.1.0) +project(iceoryx_dds VERSION ${iceoryx_dds_VERSION}) option(BUILD_TESTS "build test binaries") @@ -15,7 +15,7 @@ include(IceoryxPackageHelper) # setup_package_name_and_create_files( NAME ${PROJECT_NAME} - NAMESPACE iceoryx_dds_gateway + NAMESPACE iceoryx_dds PROJECT_PREFIX ${PREFIX} ) @@ -34,34 +34,34 @@ endif() # ########## build building-block library ########## # -add_library(ioxdds +add_library(iceoryx_dds STATIC - source/ioxdds/log/logging.cpp + source/iceoryx_dds/log/logging.cpp ) -add_library(${PROJECT_NAMESPACE}::ioxdds ALIAS ioxdds) +add_library(${PROJECT_NAMESPACE}::iceoryx_dds ALIAS iceoryx_dds) -target_compile_options(ioxdds PUBLIC -std=c++11) +target_compile_options(iceoryx_dds PUBLIC -std=c++11) -target_include_directories(ioxdds +target_include_directories(iceoryx_dds PUBLIC $ $ ) -target_link_libraries(ioxdds +target_link_libraries(iceoryx_dds PRIVATE iceoryx_posh::iceoryx_posh iceoryx_utils::iceoryx_utils ) if(USE_CYCLONE_DDS) - target_sources(ioxdds + target_sources(iceoryx_dds PRIVATE - source/ioxdds/dds/cyclone_data_reader.cpp - source/ioxdds/dds/cyclone_data_writer.cpp + source/iceoryx_dds/dds/cyclone_data_reader.cpp + source/iceoryx_dds/dds/cyclone_data_writer.cpp ) - target_compile_definitions(ioxdds PUBLIC -DUSE_CYCLONE_DDS) + target_compile_definitions(iceoryx_dds PUBLIC -DUSE_CYCLONE_DDS) idl_ddscxx_generate(mempoolMessages_lib "msg/Mempool.idl") - target_link_libraries(ioxdds + target_link_libraries(iceoryx_dds PUBLIC CycloneDDS_CXX_API::ddscxx mempoolMessages_lib @@ -71,20 +71,20 @@ endif() # ########## build gateway apps ########## # -add_executable(gateway_iox2dds - source/iox2dds_app/main.cpp +add_executable(gateway_iceoryx2dds + source/iceoryx2dds_app/main.cpp ) -target_link_libraries(gateway_iox2dds +target_link_libraries(gateway_iceoryx2dds iceoryx_posh::iceoryx_posh - ${PROJECT_NAMESPACE}::ioxdds + ${PROJECT_NAMESPACE}::iceoryx_dds ) -add_executable(gateway_dds2iox - source/dds2iox_app/main.cpp +add_executable(gateway_dds2iceoryx + source/dds2iceoryx_app/main.cpp ) -target_link_libraries(gateway_dds2iox +target_link_libraries(gateway_dds2iceoryx iceoryx_posh::iceoryx_posh - ${PROJECT_NAMESPACE}::ioxdds + ${PROJECT_NAMESPACE}::iceoryx_dds ) # @@ -98,7 +98,7 @@ endif(BUILD_TESTS) ########## export library ########## # setup_install_directories_and_export_package( - TARGETS gateway_iox2dds gateway_dds2iox + TARGETS gateway_iceoryx2dds gateway_dds2iceoryx INCLUDE_DIRECTORY include/ ) diff --git a/iceoryx_dds_gateway/README.md b/iceoryx_dds/README.md similarity index 100% rename from iceoryx_dds_gateway/README.md rename to iceoryx_dds/README.md diff --git a/iceoryx_dds_gateway/cmake/Config.cmake.in b/iceoryx_dds/cmake/Config.cmake.in similarity index 100% rename from iceoryx_dds_gateway/cmake/Config.cmake.in rename to iceoryx_dds/cmake/Config.cmake.in diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/ioxdds/dds/cyclone_data_reader.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_reader.hpp rename to iceoryx_dds/include/ioxdds/dds/cyclone_data_reader.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/ioxdds/dds/cyclone_data_writer.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/cyclone_data_writer.hpp rename to iceoryx_dds/include/ioxdds/dds/cyclone_data_writer.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds/include/ioxdds/dds/data_reader.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/data_reader.hpp rename to iceoryx_dds/include/ioxdds/dds/data_reader.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/data_writer.hpp b/iceoryx_dds/include/ioxdds/dds/data_writer.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/data_writer.hpp rename to iceoryx_dds/include/ioxdds/dds/data_writer.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/dds_configs.hpp b/iceoryx_dds/include/ioxdds/dds/dds_configs.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/dds_configs.hpp rename to iceoryx_dds/include/ioxdds/dds/dds_configs.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp b/iceoryx_dds/include/ioxdds/dds/dds_types.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/dds/dds_types.hpp rename to iceoryx_dds/include/ioxdds/dds/dds_types.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp b/iceoryx_dds/include/ioxdds/gateway/channel.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/gateway/channel.hpp rename to iceoryx_dds/include/ioxdds/gateway/channel.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/ioxdds/gateway/dds_gateway_generic.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/gateway/dds_gateway_generic.hpp rename to iceoryx_dds/include/ioxdds/gateway/dds_gateway_generic.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/ioxdds/gateway/dds_to_iox.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/gateway/dds_to_iox.hpp rename to iceoryx_dds/include/ioxdds/gateway/dds_to_iox.hpp diff --git a/iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp new file mode 100644 index 0000000000..50848643bb --- /dev/null +++ b/iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ioxdds/dds/data_writer.hpp" +#include "ioxdds/dds/dds_configs.hpp" +#include "ioxdds/dds/dds_types.hpp" +#include "ioxdds/gateway/dds_gateway_generic.hpp" +#include "ioxdds/gateway/channel.hpp" + +namespace iox +{ +namespace dds +{ +/// +/// @brief A Gateway to support internode communication between iceoryx nodes in a DDS network. +/// +/// Forwards data published in a local posh runtime to an attached DDS network. +/// +template > +class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric +{ + public: + Iceoryx2DDSGateway() noexcept; + void discover(const iox::capro::CaproMessage& msg) noexcept; + void forward() noexcept; +}; + +} // dds +} // iox + +#include "ioxdds/internal/gateway/iox_to_dds.inl" diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/dds/data_writer.inl b/iceoryx_dds/include/ioxdds/internal/dds/data_writer.inl similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/dds/data_writer.inl rename to iceoryx_dds/include/ioxdds/internal/dds/data_writer.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl b/iceoryx_dds/include/ioxdds/internal/gateway/channel.inl similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/channel.inl rename to iceoryx_dds/include/ioxdds/internal/gateway/channel.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/ioxdds/internal/gateway/dds_gateway_generic.inl similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_gateway_generic.inl rename to iceoryx_dds/include/ioxdds/internal/gateway/dds_gateway_generic.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/ioxdds/internal/gateway/dds_to_iox.inl similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/dds_to_iox.inl rename to iceoryx_dds/include/ioxdds/internal/gateway/dds_to_iox.inl diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl similarity index 99% rename from iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl rename to iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl index 9d9c3e3e65..3978a4340d 100644 --- a/iceoryx_dds_gateway/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl @@ -95,7 +95,7 @@ template inline void Iceoryx2DDSGateway::forward() noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); - for (auto channel = guardedVector->begin(); channel != guardedVector->end(); channel++) + for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) { auto subscriber = channel->getIceoryxTerminal(); if (subscriber->hasNewChunks()) diff --git a/iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp b/iceoryx_dds/include/ioxdds/internal/log/logging.hpp similarity index 100% rename from iceoryx_dds_gateway/include/ioxdds/internal/log/logging.hpp rename to iceoryx_dds/include/ioxdds/internal/log/logging.hpp diff --git a/iceoryx_dds_gateway/msg/Mempool.idl b/iceoryx_dds/msg/Mempool.idl similarity index 100% rename from iceoryx_dds_gateway/msg/Mempool.idl rename to iceoryx_dds/msg/Mempool.idl diff --git a/iceoryx_dds_gateway/scripts/build-for-cyclonedds.sh b/iceoryx_dds/scripts/build-for-cyclonedds.sh similarity index 100% rename from iceoryx_dds_gateway/scripts/build-for-cyclonedds.sh rename to iceoryx_dds/scripts/build-for-cyclonedds.sh diff --git a/iceoryx_dds_gateway/source/dds2iox_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp similarity index 100% rename from iceoryx_dds_gateway/source/dds2iox_app/main.cpp rename to iceoryx_dds/source/dds2iceoryx_app/main.cpp diff --git a/iceoryx_dds_gateway/source/iox2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp similarity index 100% rename from iceoryx_dds_gateway/source/iox2dds_app/main.cpp rename to iceoryx_dds/source/iceoryx2dds_app/main.cpp diff --git a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp similarity index 100% rename from iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_reader.cpp rename to iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp diff --git a/iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_writer.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp similarity index 100% rename from iceoryx_dds_gateway/source/ioxdds/dds/cyclone_data_writer.cpp rename to iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp diff --git a/iceoryx_dds_gateway/source/ioxdds/log/logging.cpp b/iceoryx_dds/source/iceoryx_dds/log/logging.cpp similarity index 100% rename from iceoryx_dds_gateway/source/ioxdds/log/logging.cpp rename to iceoryx_dds/source/iceoryx_dds/log/logging.cpp diff --git a/iceoryx_dds_gateway/test/CMakeLists.txt b/iceoryx_dds/test/CMakeLists.txt similarity index 100% rename from iceoryx_dds_gateway/test/CMakeLists.txt rename to iceoryx_dds/test/CMakeLists.txt diff --git a/iceoryx_dds_gateway/test/mocks/chunk_mock.hpp b/iceoryx_dds/test/mocks/chunk_mock.hpp similarity index 100% rename from iceoryx_dds_gateway/test/mocks/chunk_mock.hpp rename to iceoryx_dds/test/mocks/chunk_mock.hpp diff --git a/iceoryx_dds_gateway/test/moduletests/main.cpp b/iceoryx_dds/test/moduletests/main.cpp similarity index 100% rename from iceoryx_dds_gateway/test/moduletests/main.cpp rename to iceoryx_dds/test/moduletests/main.cpp diff --git a/iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp similarity index 100% rename from iceoryx_dds_gateway/test/moduletests/test_iox_to_dds.cpp rename to iceoryx_dds/test/moduletests/test_iox_to_dds.cpp diff --git a/iceoryx_dds_gateway/test/test.hpp b/iceoryx_dds/test/test.hpp similarity index 100% rename from iceoryx_dds_gateway/test/test.hpp rename to iceoryx_dds/test/test.hpp From 38b5f67497624e20c06693e815718fb7e6fe9450 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 3 Jun 2020 10:00:22 +0200 Subject: [PATCH 21/55] iox-#65 Rename module to iceoryx_dds. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/ioxdds/gateway/iox_to_dds.hpp | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp diff --git a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp deleted file mode 100644 index 50848643bb..0000000000 --- a/iceoryx_dds_gateway/include/ioxdds/gateway/iox_to_dds.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "ioxdds/dds/data_writer.hpp" -#include "ioxdds/dds/dds_configs.hpp" -#include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/dds_gateway_generic.hpp" -#include "ioxdds/gateway/channel.hpp" - -namespace iox -{ -namespace dds -{ -/// -/// @brief A Gateway to support internode communication between iceoryx nodes in a DDS network. -/// -/// Forwards data published in a local posh runtime to an attached DDS network. -/// -template > -class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric -{ - public: - Iceoryx2DDSGateway() noexcept; - void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward() noexcept; -}; - -} // dds -} // iox - -#include "ioxdds/internal/gateway/iox_to_dds.inl" From 4848f9c897cb24aab853116aca123a4819b510d6 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 3 Jun 2020 12:31:44 +0200 Subject: [PATCH 22/55] iox-#65 Update include namespace to iceoryx_dds. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../dds/cyclone_data_reader.hpp | 2 +- .../dds/cyclone_data_writer.hpp | 2 +- .../{ioxdds => iceoryx_dds}/dds/data_reader.hpp | 0 .../{ioxdds => iceoryx_dds}/dds/data_writer.hpp | 0 .../{ioxdds => iceoryx_dds}/dds/dds_configs.hpp | 0 .../{ioxdds => iceoryx_dds}/dds/dds_types.hpp | 4 ++-- .../{ioxdds => iceoryx_dds}/gateway/channel.hpp | 4 ++-- .../gateway/dds_gateway_generic.hpp | 4 ++-- .../{ioxdds => iceoryx_dds}/gateway/dds_to_iox.hpp | 9 ++++----- .../{ioxdds => iceoryx_dds}/gateway/iox_to_dds.hpp | 12 ++++++------ .../internal/dds/data_writer.inl | 0 .../internal/gateway/channel.inl | 2 +- .../internal/gateway/dds_gateway_generic.inl | 7 +++---- .../internal/gateway/dds_to_iox.inl | 4 ++-- .../internal/gateway/iox_to_dds.inl | 5 ++--- .../{ioxdds => iceoryx_dds}/internal/log/logging.hpp | 0 iceoryx_dds/source/dds2iceoryx_app/main.cpp | 2 +- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 2 +- .../source/iceoryx_dds/dds/cyclone_data_reader.cpp | 2 +- .../source/iceoryx_dds/dds/cyclone_data_writer.cpp | 4 ++-- iceoryx_dds/source/iceoryx_dds/log/logging.cpp | 2 +- 21 files changed, 32 insertions(+), 35 deletions(-) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/cyclone_data_reader.hpp (85%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/cyclone_data_writer.hpp (97%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/data_reader.hpp (100%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/data_writer.hpp (100%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/dds_configs.hpp (100%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/dds/dds_types.hpp (91%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/gateway/channel.hpp (95%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/gateway/dds_gateway_generic.hpp (94%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/gateway/dds_to_iox.hpp (67%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/gateway/iox_to_dds.hpp (83%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/dds/data_writer.inl (100%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/gateway/channel.inl (98%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/gateway/dds_gateway_generic.inl (97%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/gateway/dds_to_iox.inl (87%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/gateway/iox_to_dds.inl (97%) rename iceoryx_dds/include/{ioxdds => iceoryx_dds}/internal/log/logging.hpp (100%) diff --git a/iceoryx_dds/include/ioxdds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp similarity index 85% rename from iceoryx_dds/include/ioxdds/dds/cyclone_data_reader.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index 524d1e3ada..309c5e6c07 100644 --- a/iceoryx_dds/include/ioxdds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -1,6 +1,6 @@ #pragma once -#include "ioxdds/dds/data_reader.hpp" +#include "iceoryx_dds/dds/data_reader.hpp" namespace iox { namespace dds { diff --git a/iceoryx_dds/include/ioxdds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp similarity index 97% rename from iceoryx_dds/include/ioxdds/dds/cyclone_data_writer.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index 4230ab13cc..5bfdfbd4bc 100644 --- a/iceoryx_dds/include/ioxdds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -17,7 +17,7 @@ #include #include -#include "ioxdds/dds/data_writer.hpp" +#include "iceoryx_dds/dds/data_writer.hpp" namespace iox { diff --git a/iceoryx_dds/include/ioxdds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp similarity index 100% rename from iceoryx_dds/include/ioxdds/dds/data_reader.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp diff --git a/iceoryx_dds/include/ioxdds/dds/data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp similarity index 100% rename from iceoryx_dds/include/ioxdds/dds/data_writer.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp diff --git a/iceoryx_dds/include/ioxdds/dds/dds_configs.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_configs.hpp similarity index 100% rename from iceoryx_dds/include/ioxdds/dds/dds_configs.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/dds_configs.hpp diff --git a/iceoryx_dds/include/ioxdds/dds/dds_types.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp similarity index 91% rename from iceoryx_dds/include/ioxdds/dds/dds_types.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp index 6ef7b5ab44..5a1d21923b 100644 --- a/iceoryx_dds/include/ioxdds/dds/dds_types.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp @@ -15,8 +15,8 @@ #pragma once #ifdef USE_CYCLONE_DDS -#include "ioxdds/dds/cyclone_data_reader.hpp" -#include "ioxdds/dds/cyclone_data_writer.hpp" +#include "iceoryx_dds/dds/cyclone_data_reader.hpp" +#include "iceoryx_dds/dds/cyclone_data_writer.hpp" #else #error "A DDS implementation must be provided." #endif diff --git a/iceoryx_dds/include/ioxdds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp similarity index 95% rename from iceoryx_dds/include/ioxdds/gateway/channel.hpp rename to iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 99912228dd..ca4639bfbe 100644 --- a/iceoryx_dds/include/ioxdds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -4,7 +4,7 @@ #include #include -#include "ioxdds/dds/dds_configs.hpp" +#include "iceoryx_dds/dds/dds_configs.hpp" namespace iox { namespace dds{ @@ -60,4 +60,4 @@ class Channel } // namespace dds } // namespace iox -#include "ioxdds/internal/gateway/channel.inl" +#include "iceoryx_dds/internal/gateway/channel.inl" diff --git a/iceoryx_dds/include/ioxdds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp similarity index 94% rename from iceoryx_dds/include/ioxdds/gateway/dds_gateway_generic.hpp rename to iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 973bcea6ad..4d54515452 100644 --- a/iceoryx_dds/include/ioxdds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -8,7 +8,7 @@ #include #include -#include "ioxdds/dds/dds_configs.hpp" +#include "iceoryx_dds/dds/dds_configs.hpp" namespace iox { namespace dds { @@ -64,4 +64,4 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric } // namespace dds } // namespace iox -#include "ioxdds/internal/gateway/dds_gateway_generic.inl" +#include "iceoryx_dds/internal/gateway/dds_gateway_generic.inl" diff --git a/iceoryx_dds/include/ioxdds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp similarity index 67% rename from iceoryx_dds/include/ioxdds/gateway/dds_to_iox.hpp rename to iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index ae8a3fe70f..7f397cd3a3 100644 --- a/iceoryx_dds/include/ioxdds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -2,10 +2,9 @@ #include -#include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/dds_gateway_generic.hpp" -#include "ioxdds/gateway/channel.hpp" -#include "ioxdds/gateway/input_channel.hpp" +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_dds/gateway/channel.hpp" namespace iox { namespace dds { @@ -22,4 +21,4 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric } // namespace dds } // namespace iox -#include "ioxdds/internal/gateway/dds_to_iox.inl" +#include "iceoryx_dds/internal/gateway/dds_to_iox.inl" diff --git a/iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp similarity index 83% rename from iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp rename to iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 50848643bb..84c932eb64 100644 --- a/iceoryx_dds/include/ioxdds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -24,11 +24,11 @@ #include #include -#include "ioxdds/dds/data_writer.hpp" -#include "ioxdds/dds/dds_configs.hpp" -#include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/dds_gateway_generic.hpp" -#include "ioxdds/gateway/channel.hpp" +#include "iceoryx_dds/dds/data_writer.hpp" +#include "iceoryx_dds/dds/dds_configs.hpp" +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_dds/gateway/channel.hpp" namespace iox { @@ -51,4 +51,4 @@ class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric } // dds } // iox -#include "ioxdds/internal/gateway/iox_to_dds.inl" +#include "iceoryx_dds/internal/gateway/iox_to_dds.inl" diff --git a/iceoryx_dds/include/ioxdds/internal/dds/data_writer.inl b/iceoryx_dds/include/iceoryx_dds/internal/dds/data_writer.inl similarity index 100% rename from iceoryx_dds/include/ioxdds/internal/dds/data_writer.inl rename to iceoryx_dds/include/iceoryx_dds/internal/dds/data_writer.inl diff --git a/iceoryx_dds/include/ioxdds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl similarity index 98% rename from iceoryx_dds/include/ioxdds/internal/gateway/channel.inl rename to iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 80185de74a..070562b541 100644 --- a/iceoryx_dds/include/ioxdds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "ioxdds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/channel.hpp" namespace iox { diff --git a/iceoryx_dds/include/ioxdds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl similarity index 97% rename from iceoryx_dds/include/ioxdds/internal/gateway/dds_gateway_generic.inl rename to iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index ffea971df8..41ed737825 100644 --- a/iceoryx_dds/include/ioxdds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -1,10 +1,9 @@ #include -#include "ioxdds/internal/log/logging.hpp" - -#include "ioxdds/dds/dds_types.hpp" -#include "ioxdds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" // ================================================== Public ================================================== // diff --git a/iceoryx_dds/include/ioxdds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl similarity index 87% rename from iceoryx_dds/include/ioxdds/internal/gateway/dds_to_iox.inl rename to iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index bd88660f52..d4319be12c 100644 --- a/iceoryx_dds/include/ioxdds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -4,8 +4,8 @@ #include #include -#include "ioxdds/gateway/dds_to_iox.hpp" -#include "ioxdds/internal/log/logging.hpp" +#include "iceoryx_dds/gateway/dds_to_iox.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" namespace iox { namespace dds { diff --git a/iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl similarity index 97% rename from iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl rename to iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 3978a4340d..a96afc4721 100644 --- a/iceoryx_dds/include/ioxdds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -17,9 +17,8 @@ #include -#include "ioxdds/internal/log/logging.hpp" - -#include "ioxdds/gateway/iox_to_dds.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_dds/gateway/iox_to_dds.hpp" namespace iox { diff --git a/iceoryx_dds/include/ioxdds/internal/log/logging.hpp b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp similarity index 100% rename from iceoryx_dds/include/ioxdds/internal/log/logging.hpp rename to iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index 0a3f0ea7b8..7c5e00239c 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -3,7 +3,7 @@ #include #include -#include "ioxdds/gateway/dds_to_iox.hpp" +#include "iceoryx_dds/gateway/dds_to_iox.hpp" class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 97f896ae83..2195816fe6 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp index 3c5859f2a0..5b34fa78a2 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp @@ -1,5 +1,5 @@ -#include "ioxdds/dds/cyclone_data_reader.hpp" +#include "iceoryx_dds/dds/cyclone_data_reader.hpp" iox::dds::CycloneDataReader::CycloneDataReader(IdString serviceId, IdString instanceId, IdString eventId) noexcept { diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp index c8f8740468..270db3130b 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp @@ -17,8 +17,8 @@ #include #include "Mempool_DCPS.hpp" -#include "ioxdds/dds/cyclone_data_writer.hpp" -#include "ioxdds/internal/log/logging.hpp" +#include "iceoryx_dds/dds/cyclone_data_writer.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" iox::dds::CycloneDataWriter::CycloneDataWriter(IdString serviceId, IdString instanceId, IdString eventId) : m_serviceId(serviceId) diff --git a/iceoryx_dds/source/iceoryx_dds/log/logging.cpp b/iceoryx_dds/source/iceoryx_dds/log/logging.cpp index 51323c8fe2..ce6cb3bb6c 100644 --- a/iceoryx_dds/source/iceoryx_dds/log/logging.cpp +++ b/iceoryx_dds/source/iceoryx_dds/log/logging.cpp @@ -1,5 +1,5 @@ -#include "ioxdds/internal/log/logging.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" namespace iox { From 1a8a90629a4e1141838901096aa3c9c2042736f6 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 4 Jun 2020 09:59:34 +0200 Subject: [PATCH 23/55] iox-#65 Add factory method to allow injection of mock channels when testing. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 1 + .../internal/gateway/dds_gateway_generic.inl | 10 ++++++++++ .../iceoryx_dds/internal/gateway/iox_to_dds.inl | 8 ++++++++ iceoryx_dds/test/CMakeLists.txt | 4 ++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 4d54515452..4c33bff15a 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -38,6 +38,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric protected: DDSGatewayGeneric() noexcept; + DDSGatewayGeneric(ChannelFactory channelFactory) noexcept; // These are made available to child classes for use in discover or forward methods. ChannelFactory m_channelFactory; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 41ed737825..43ee50482d 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -1,10 +1,12 @@ #include +#include #include "iceoryx_dds/internal/log/logging.hpp" #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" + // ================================================== Public ================================================== // template @@ -54,6 +56,13 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : io m_channelFactory = channel_t::create; } +template +inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric(std::function channelFactory) noexcept + : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS), m_channelFactory(channelFactory) +{ + LogDebug() << "[DDSGatewayGeneric] Using provided channel factory."; +} + template inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept { @@ -61,6 +70,7 @@ inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept // Search for local config. + auto config = cpptoml::parse_file("config.toml"); // Search for local config. diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index a96afc4721..938c2be0de 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -24,6 +24,10 @@ namespace iox { namespace dds { + +template +using ChannelFactory = std::function; + // ======================================== Public ======================================== // template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds::DDSGatewayGeneric() @@ -42,6 +46,10 @@ inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds:: } } +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept : iox::dds::DDSGatewayGeneric(channelFactory) +{} + template inline void Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept diff --git a/iceoryx_dds/test/CMakeLists.txt b/iceoryx_dds/test/CMakeLists.txt index e7b6387cf9..757d5cb172 100644 --- a/iceoryx_dds/test/CMakeLists.txt +++ b/iceoryx_dds/test/CMakeLists.txt @@ -4,7 +4,7 @@ project(test_iox_to_dds VERSION ${test_iox_to_dds}) find_package(iceoryx_utils_testing REQUIRED) find_package(GTest CONFIG REQUIRED) -set(PROJECT_PREFIX "ioxdds") +set(PROJECT_PREFIX "iceoryx_dds") file(GLOB_RECURSE MODULETESTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/*.cpp") @@ -17,7 +17,7 @@ set(TEST_LINK_LIBS iceoryx_utils::iceoryx_utils iceoryx_utils_testing::iceoryx_utils_testing iceoryx_posh::iceoryx_posh - iceoryx_dds_gateway::ioxdds + iceoryx_dds::iceoryx_dds ) if(NOT CMAKE_SYSTEM_NAME MATCHES QNX) From 59d1cf061c40aa78fa97002882cf877614d4931f Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 4 Jun 2020 10:00:53 +0200 Subject: [PATCH 24/55] iox-#65 Fix tests. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/iox_to_dds.hpp | 54 --- .../test/moduletests/test_iox_to_dds.cpp | 321 +++++++++--------- 2 files changed, 161 insertions(+), 214 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 84c932eb64..e69de29bb2 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -1,54 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "iceoryx_dds/dds/data_writer.hpp" -#include "iceoryx_dds/dds/dds_configs.hpp" -#include "iceoryx_dds/dds/dds_types.hpp" -#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" -#include "iceoryx_dds/gateway/channel.hpp" - -namespace iox -{ -namespace dds -{ -/// -/// @brief A Gateway to support internode communication between iceoryx nodes in a DDS network. -/// -/// Forwards data published in a local posh runtime to an attached DDS network. -/// -template > -class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric -{ - public: - Iceoryx2DDSGateway() noexcept; - void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward() noexcept; -}; - -} // dds -} // iox - -#include "iceoryx_dds/internal/gateway/iox_to_dds.inl" diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index bc11509aaa..60e192cf4e 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -15,8 +15,9 @@ #include #include -#include -#include +#include +#include +#include #include "mocks/chunk_mock.hpp" #include "roudi_gtest.hpp" @@ -65,7 +66,7 @@ class MockDataWriter : public iox::dds::DataWriter // ======================================== Helpers ======================================== // -using TestGateway = iox::dds::Iceoryx2DDSGateway; +using TestGateway = iox::dds::Iceoryx2DDSGateway>; // Holds mocks created by tests to be returned by mock factories. static std::vector> stagedMockSubscribers; @@ -104,7 +105,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::dds::OutputChannel mockChannelFactory(iox::capro::ServiceDescription sd) noexcept +static iox::dds::Channel mockChannelFactory(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; @@ -130,7 +131,7 @@ static iox::dds::OutputChannel mockChannelFactor mockDataWriter = createMockDataWriter(sd); } - return iox::dds::OutputChannel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); + return iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); } // ======================================== Fixture ======================================== // @@ -169,158 +170,158 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) EXPECT_EQ(0, gw->getNumberOfChannels()); } -TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) -{ - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - gw->discover(msg); - EXPECT_EQ(1, gw->getNumberOfChannels()); -} - -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) -{ - // === Create Mocks - auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - EXPECT_CALL(*mockSubscriber, subscribe).Times(1); - stageMockSubscriber(std::move(mockSubscriber)); - - // === Test - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - gw->discover(msg); -} - -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) -{ - // === Create Mocks - auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - EXPECT_CALL(*mockWriter, connect).Times(1); - stageMockDataWriter(std::move(mockWriter)); - - // === Test - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - gw->discover(msg); -} - -TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) -{ - // === Create Mocks - ChunkMock mockChunk{42}; - - // Set up subscriber to provide this chunk when requested - auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); - EXPECT_CALL(*mockWriter, - write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) - .Times(1); - - stageMockSubscriber(std::move(mockSubscriber)); - stageMockDataWriter(std::move(mockWriter)); - - // === Test - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - gw->discover(msg); - gw->forward(); -} - -TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) -{ - // === Create Mocks - ChunkMock mockChunk{42}; - mockChunk.chunkHeader()->m_info.m_payloadSize = 0; - - auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - EXPECT_CALL(*mockWriter, write).Times(Exactly(0)); - - stageMockSubscriber(std::move(mockSubscriber)); - stageMockDataWriter(std::move(mockWriter)); - - // === Test - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - gw->discover(msg); - gw->forward(); -} - -TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) -{ - // === Create Mocks - ChunkMock mockChunk{42}; - - auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - - // Define expected sequence of calls - { - InSequence seq; - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); - EXPECT_CALL(*mockSubscriber, getChunk).Times(1); - EXPECT_CALL(*mockWriter, write).Times(1); - EXPECT_CALL(*mockSubscriber, releaseChunk).Times(1); - } - - stageMockSubscriber(std::move(mockSubscriber)); - stageMockDataWriter(std::move(mockWriter)); - - // === Test - auto gw = std::make_shared(mockChannelFactory); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - gw->discover(msg); - gw->forward(); -} - -TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) -{ - // === Create Mocks - // Subscribers - auto firstCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - auto secondCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - - ON_CALL(*firstCreatedSubscriber, getServiceDescription) - .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); - ON_CALL(*secondCreatedSubscriber, getServiceDescription) - .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); - - { - InSequence seq; - EXPECT_CALL(*firstCreatedSubscriber, subscribe).Times(1); - EXPECT_CALL(*firstCreatedSubscriber, isDestroyed).Times(1); - EXPECT_CALL(*secondCreatedSubscriber, subscribe).Times(1); - } - - // Important ! Pass ownership, do not keep the reference here. - stageMockSubscriber(std::move(firstCreatedSubscriber)); - stageMockSubscriber(std::move(secondCreatedSubscriber)); - - // Messages - auto offerMsg = - iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - offerMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; - auto stopOfferMsg = - iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, {"Radar", "Front-Right", "Reflections"}); - stopOfferMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; - - // === Test - auto gw = std::make_shared(mockChannelFactory); - - gw->discover(offerMsg); - gw->discover(stopOfferMsg); // first subscriber must be deleted here - gw->discover(offerMsg); -} +//TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) +//{ +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; +// gw->discover(msg); +// EXPECT_EQ(1, gw->getNumberOfChannels()); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) +//{ +// // === Create Mocks +// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); +// EXPECT_CALL(*mockSubscriber, subscribe).Times(1); +// stageMockSubscriber(std::move(mockSubscriber)); + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; +// gw->discover(msg); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) +//{ +// // === Create Mocks +// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); +// EXPECT_CALL(*mockWriter, connect).Times(1); +// stageMockDataWriter(std::move(mockWriter)); + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; +// gw->discover(msg); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) +//{ +// // === Create Mocks +// ChunkMock mockChunk{42}; + +// // Set up subscriber to provide this chunk when requested +// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); +// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); + +// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); +// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); +// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); +// EXPECT_CALL(*mockWriter, +// write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) +// .Times(1); + +// stageMockSubscriber(std::move(mockSubscriber)); +// stageMockDataWriter(std::move(mockWriter)); + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// gw->discover(msg); +// gw->forward(); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) +//{ +// // === Create Mocks +// ChunkMock mockChunk{42}; +// mockChunk.chunkHeader()->m_info.m_payloadSize = 0; + +// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); +// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); + +// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); +// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); +// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); +// EXPECT_CALL(*mockWriter, write).Times(Exactly(0)); + +// stageMockSubscriber(std::move(mockSubscriber)); +// stageMockDataWriter(std::move(mockWriter)); + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// gw->discover(msg); +// gw->forward(); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) +//{ +// // === Create Mocks +// ChunkMock mockChunk{42}; + +// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); +// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); + +// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); +// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); + +// // Define expected sequence of calls +// { +// InSequence seq; +// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); +// EXPECT_CALL(*mockSubscriber, getChunk).Times(1); +// EXPECT_CALL(*mockWriter, write).Times(1); +// EXPECT_CALL(*mockSubscriber, releaseChunk).Times(1); +// } + +// stageMockSubscriber(std::move(mockSubscriber)); +// stageMockDataWriter(std::move(mockWriter)); + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); +// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// gw->discover(msg); +// gw->forward(); +//} + +//TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) +//{ +// // === Create Mocks +// // Subscribers +// auto firstCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); +// auto secondCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); + +// ON_CALL(*firstCreatedSubscriber, getServiceDescription) +// .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); +// ON_CALL(*secondCreatedSubscriber, getServiceDescription) +// .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); + +// { +// InSequence seq; +// EXPECT_CALL(*firstCreatedSubscriber, subscribe).Times(1); +// EXPECT_CALL(*firstCreatedSubscriber, isDestroyed).Times(1); +// EXPECT_CALL(*secondCreatedSubscriber, subscribe).Times(1); +// } + +// // Important ! Pass ownership, do not keep the reference here. +// stageMockSubscriber(std::move(firstCreatedSubscriber)); +// stageMockSubscriber(std::move(secondCreatedSubscriber)); + +// // Messages +// auto offerMsg = +// iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); +// offerMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; +// auto stopOfferMsg = +// iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, {"Radar", "Front-Right", "Reflections"}); +// stopOfferMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; + +// // === Test +// auto gw = std::make_shared(mockChannelFactory); + +// gw->discover(offerMsg); +// gw->discover(stopOfferMsg); // first subscriber must be deleted here +// gw->discover(offerMsg); +//} From 228b7de6c5b55fe66e8eba3d61c8a719338b0855 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 4 Jun 2020 14:14:58 +0200 Subject: [PATCH 25/55] iox-#65 Move configuration logic to concrete gateway implementation. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../dds/{dds_configs.hpp => dds_config.hpp} | 0 .../include/iceoryx_dds/gateway/channel.hpp | 2 +- .../gateway/dds_gateway_generic.hpp | 11 ++++++- .../iceoryx_dds/gateway/dds_to_iox.hpp | 3 ++ .../iceoryx_dds/gateway/gateway_config.hpp | 17 +++++++++++ .../iceoryx_dds/gateway/iox_to_dds.hpp | 27 +++++++++++++++++ .../internal/gateway/dds_gateway_generic.inl | 30 ------------------- .../internal/gateway/dds_to_iox.inl | 9 ++++-- .../internal/gateway/iox_to_dds.inl | 27 +++++++++-------- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 7 ++++- 10 files changed, 85 insertions(+), 48 deletions(-) rename iceoryx_dds/include/iceoryx_dds/dds/{dds_configs.hpp => dds_config.hpp} (100%) create mode 100644 iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_configs.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp similarity index 100% rename from iceoryx_dds/include/iceoryx_dds/dds/dds_configs.hpp rename to iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index ca4639bfbe..786ead656d 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -4,7 +4,7 @@ #include #include -#include "iceoryx_dds/dds/dds_configs.hpp" +#include "iceoryx_dds/dds/dds_config.hpp" namespace iox { namespace dds{ diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 4c33bff15a..96addbb766 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -5,10 +5,14 @@ #include #include +#include +#include #include #include #include "iceoryx_dds/dds/dds_configs.hpp" +#include "iceoryx_dds/gateway/gateway_config.hpp" + namespace iox { namespace dds { @@ -28,6 +32,12 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric DDSGatewayGeneric(DDSGatewayGeneric&&) = delete; DDSGatewayGeneric& operator=(DDSGatewayGeneric&&) = delete; + /// + /// @brief loadConfiguration Load the provided configuration. + /// @note This method is virtual pure since different configuration likely to be different across implementations. + /// @param config + /// + virtual void loadConfiguration(GatewayConfig config) = 0; void runMultithreaded() noexcept; void shutdown() noexcept; @@ -44,7 +54,6 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric ChannelFactory m_channelFactory; ConcurrentChannelVector m_channels; - void loadConfiguration() noexcept; channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; void discardChannel(const iox::capro::ServiceDescription& service) noexcept; bool channelExists(const iox::capro::ServiceDescription& service) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 7f397cd3a3..7253b5e62f 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -12,8 +12,11 @@ namespace dds { template > class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric { + using ChannelFactory = std::function; public: DDS2IceoryxGateway() noexcept; + DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; + void loadConfiguration(GatewayConfig config); void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp new file mode 100644 index 0000000000..780ccbd6d6 --- /dev/null +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +namespace iox { +namespace dds { + +struct GatewayConfig +{ +public: + iox::cxx::vector m_configuredServices; +}; + +} +} diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index e69de29bb2..8157253b01 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_dds/gateway/channel.hpp" + +namespace iox { +namespace dds { + +template > +class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric +{ + using ChannelFactory = std::function; +public: + Iceoryx2DDSGateway() noexcept; + Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept; + void loadConfiguration(GatewayConfig config); + void discover(const iox::capro::CaproMessage& msg) noexcept; + void forward() noexcept; +}; + +} // namespace dds +} // namespace iox + +#include "iceoryx_dds/internal/gateway/iox_to_dds.inl" diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 43ee50482d..de2dc7530b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -63,36 +63,6 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric(std::function -inline void iox::dds::DDSGatewayGeneric::loadConfiguration() noexcept -{ - // Search for config passed as command line argument. - - - // Search for local config. - - auto config = cpptoml::parse_file("config.toml"); - - // Search for local config. - - - // Setup data readers and publishers - auto configuredTopics = config->get_table_array("services"); - LogDebug() << "[DDSGatewayGeneric] Setting up channels for pre-configured services."; - for(const auto& topic : *configuredTopics) - { - auto service = topic->get_as("service").value_or(""); - auto instance = topic->get_as("instance").value_or(""); - auto event = topic->get_as("event").value_or(""); - - this->setupChannel(iox::capro::ServiceDescription( - IdString(iox::cxx::TruncateToCapacity, service.c_str()), - IdString(iox::cxx::TruncateToCapacity, instance.c_str()), - IdString(iox::cxx::TruncateToCapacity, event.c_str()) - )); - } -} - template inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index d4319be12c..bff39b64fd 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -14,10 +14,15 @@ template inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept : iox::dds::DDSGatewayGeneric() { - // Initialize pre-configured services - this->loadConfiguration(); } +template +inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) +{ + +} + + template inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 938c2be0de..0edb0ed838 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -25,30 +25,31 @@ namespace iox namespace dds { -template -using ChannelFactory = std::function; +//template +//using ChannelFactory = std::function; // ======================================== Public ======================================== // template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds::DDSGatewayGeneric() -{ - // Create channels for all pre-configured services. - this->loadConfiguration(); +{} - // Connect the terminals of the created channels. - auto guardedVector = this->m_channels.GetScopeGuard(); - for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept : iox::dds::DDSGatewayGeneric(channelFactory) +{} + +template +inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) +{ + for(const auto& service : config.m_configuredServices) { - auto subscriber = channel->getIceoryxTerminal(); - auto dataWriter = channel->getDDSTerminal(); + auto channel = this->setupChannel(service); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); dataWriter->connect(); } } -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept : iox::dds::DDSGatewayGeneric(channelFactory) -{} template inline void diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 2195816fe6..8130f84d5b 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include class ShutdownManager { @@ -46,10 +47,14 @@ int main(int argc, char* argv[]) signal(SIGINT, ShutdownManager::scheduleShutdown); signal(SIGTERM, ShutdownManager::scheduleShutdown); + // Parse configuration + iox::dds::GatewayConfig config; + // Start application - iox::runtime::PoshRuntime::getInstance("/gateway_iox2dds"); + iox::runtime::PoshRuntime::getInstance("/gateway_iceoryx2dds"); iox::dds::Iceoryx2DDSGateway<> gateway; + gateway.loadConfiguration(config); gateway.runMultithreaded(); // Run until SIGINT or SIGTERM From 47bf2a89f1f799693507f31fadb7fcd39b2ab9f0 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Fri, 5 Jun 2020 16:15:00 +0200 Subject: [PATCH 26/55] iox-#65 Made collection of channels in GenericDDSGateway private so that it can take full responsibility of concurrent access & added required methods to allow concrete DDS gateways to access the element of the collection. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 5 + .../gateway/dds_gateway_generic.hpp | 48 ++++++++-- .../iceoryx_dds/gateway/dds_to_iox.hpp | 2 +- .../iceoryx_dds/gateway/iox_to_dds.hpp | 7 +- .../iceoryx_dds/internal/gateway/channel.inl | 38 ++++++++ .../internal/gateway/dds_gateway_generic.inl | 44 +++++---- .../internal/gateway/dds_to_iox.inl | 5 +- .../internal/gateway/iox_to_dds.inl | 42 ++++---- .../test/moduletests/test_iox_to_dds.cpp | 95 +++++++++++++------ 9 files changed, 205 insertions(+), 81 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 786ead656d..5f836ea287 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -41,6 +41,11 @@ class Channel Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; + ~Channel() noexcept; + Channel(const Channel&) noexcept; + Channel& operator=(const Channel&) noexcept; + Channel(Channel&&) noexcept; + Channel& operator=(Channel&&) noexcept; static Channel create(const iox::capro::ServiceDescription& service) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 96addbb766..d86359e26c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "iceoryx_dds/dds/dds_configs.hpp" @@ -25,6 +26,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric using ConcurrentChannelVector = iox::concurrent::smart_lock; public: + virtual ~DDSGatewayGeneric() noexcept; DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; @@ -37,7 +39,7 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric /// @note This method is virtual pure since different configuration likely to be different across implementations. /// @param config /// - virtual void loadConfiguration(GatewayConfig config) = 0; + virtual void loadConfiguration(GatewayConfig config) noexcept = 0; void runMultithreaded() noexcept; void shutdown() noexcept; @@ -47,18 +49,52 @@ class DDSGatewayGeneric : public iox::popo::GatewayGeneric uint64_t getNumberOfChannels() const noexcept; protected: + DDSGatewayGeneric() noexcept; - DDSGatewayGeneric(ChannelFactory channelFactory) noexcept; - // These are made available to child classes for use in discover or forward methods. ChannelFactory m_channelFactory; - ConcurrentChannelVector m_channels; - channel_t setupChannel(const iox::capro::ServiceDescription& service) noexcept; + /// + /// @brief addChannel Creates a channel for the given service and stores a copy of it in an internal collection for + /// later access. + /// @param service The service to create a channel for. + /// @return A copy of the created channel. + /// + /// @note Channels are supposed to be lightweight, consisting only of pointers to the terminals and a copy of the + /// service description, therefore a copy is provided to any entity that requires them. + /// When no more copies of a channel exists in the system, the terminals will automatically be cleaned up via + /// the custom deleters included in their pointers. + /// + /// The service description is perhaps too large for copying since they contain strings, however this should be + /// addressed with the service description repository feature. + /// + channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept; + + /// + /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns + /// it one exists. + /// \param service The service to find a channel for. + /// \return An optional containining the matching channel if one exists, otherwise an empty optional. + /// + iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) noexcept; + + /// + /// @brief forEachChannel Executs the given function for each channel in the internally stored collection. + /// @param f The function to execute. + /// @note This operation allows thread-safe access to the internal collection. + /// + void forEachChannel(const std::function f) noexcept; + + /// + /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. + /// @param service The service whose channels hiould be discarded. + /// void discardChannel(const iox::capro::ServiceDescription& service) noexcept; - bool channelExists(const iox::capro::ServiceDescription& service) noexcept; private: + + ConcurrentChannelVector m_channels; + std::atomic_bool m_isRunning{false}; std::atomic_bool m_runForwardingLoop{false}; std::atomic_bool m_runDiscoveryLoop{false}; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 7253b5e62f..fa2a7d3eb9 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -16,7 +16,7 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric public: DDS2IceoryxGateway() noexcept; DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; - void loadConfiguration(GatewayConfig config); + void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 8157253b01..6d4e888fd0 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -9,14 +9,15 @@ namespace iox { namespace dds { -template > -class Iceoryx2DDSGateway : public iox::dds::DDSGatewayGeneric +template , + typename gateway_t = iox::dds::DDSGatewayGeneric> +class Iceoryx2DDSGateway : public gateway_t { using ChannelFactory = std::function; public: Iceoryx2DDSGateway() noexcept; Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept; - void loadConfiguration(GatewayConfig config); + void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; }; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 070562b541..219fc9efdf 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -41,6 +41,44 @@ inline Channel::Channel(const iox::capro::ServiceD { } +template +inline Channel::~Channel() noexcept +{ + +} + +template +inline Channel::Channel(const Channel& rhs) noexcept +{ + m_service = rhs.m_service; + m_ddsTerminal = rhs.m_ddsTerminal; + m_iceoryxTerminal = rhs.m_iceoryxTerminal; +} + +template +inline Channel& Channel::operator=(const Channel& rhs) noexcept +{ + m_service = rhs.m_service; + m_ddsTerminal = rhs.m_ddsTerminal; + m_iceoryxTerminal = rhs.m_iceoryxTerminal; +} + +template +inline Channel::Channel(Channel&& rhs) noexcept +{ + m_service = std::move(rhs.m_service); + m_ddsTerminal = std::move(rhs.m_ddsTerminal); + m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); +} + +template +inline Channel& Channel::operator=(Channel&& rhs) noexcept +{ + m_service = std::move(rhs.m_service); + m_ddsTerminal = std::move(rhs.m_ddsTerminal); + m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); +} + template inline Channel Channel::create(const iox::capro::ServiceDescription& service) noexcept diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index de2dc7530b..2d5348ffdf 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -57,15 +57,7 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : io } template -inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric(std::function channelFactory) noexcept - : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS), m_channelFactory(channelFactory) -{ - LogDebug() << "[DDSGatewayGeneric] Using provided channel factory."; -} - - -template -inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox::capro::ServiceDescription& service) noexcept +inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); m_channels->push_back(channel); @@ -76,31 +68,49 @@ inline channel_t iox::dds::DDSGatewayGeneric::setupChannel(const iox: } template -inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept +inline iox::cxx::optional iox::dds::DDSGatewayGeneric::findChannel(const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); auto channel = std::find_if( guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { return channel.getService() == service; }); - if (channel != guardedVector->end()) + if(channel == guardedVector->end()) { - guardedVector->erase(channel); - iox::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); + return iox::cxx::nullopt_t(); + } + else + { + // Needs to be dereferenced since the smart lock returns pointers to elements in concurrent collections. + return iox::cxx::make_optional(*channel); + } +} + +template +inline void iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) noexcept +{ + auto guardedVector = m_channels.GetScopeGuard(); + for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) + { + f(*channel); } } template -inline bool iox::dds::DDSGatewayGeneric::channelExists(const iox::capro::ServiceDescription& service) noexcept +inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); auto channel = std::find_if( guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { return channel.getService() == service; }); - return channel != guardedVector->end(); + if (channel != guardedVector->end()) + { + guardedVector->erase(channel); + iox::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + } } // ================================================== Private ================================================== // diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index bff39b64fd..cbc0ce28ce 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -17,22 +17,19 @@ inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept } template -inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) +inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) noexcept { - } template inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessage& msg) noexcept { - } template inline void DDS2IceoryxGateway::forward() noexcept { - } } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 0edb0ed838..0379e674aa 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -29,20 +29,22 @@ namespace dds //using ChannelFactory = std::function; // ======================================== Public ======================================== // -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : iox::dds::DDSGatewayGeneric() +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : gateway_t() {} -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept : iox::dds::DDSGatewayGeneric(channelFactory) -{} +template +inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept +{ +} -template -inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) +template +inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) noexcept { + iox::LogDebug() << "[Iceoryx2DDSGateway] Configuring gateway."; for(const auto& service : config.m_configuredServices) { - auto channel = this->setupChannel(service); + auto channel = this->addChannel(service); auto subscriber = channel.getIceoryxTerminal(); auto dataWriter = channel.getDDSTerminal(); subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); @@ -51,9 +53,9 @@ inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig confi } -template +template inline void -Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept +Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] " << iox::capro::CaproMessageTypeString[static_cast(msg.m_type)] @@ -74,9 +76,9 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe { case iox::capro::CaproMessageType::OFFER: { - if(!this->channelExists(msg.m_serviceDescription)) + if(!this->findChannel(msg.m_serviceDescription).has_value()) { - auto channel = this->setupChannel(msg.m_serviceDescription); + auto channel = this->addChannel(msg.m_serviceDescription); auto subscriber = channel.getIceoryxTerminal(); auto dataWriter = channel.getDDSTerminal(); subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); @@ -86,7 +88,7 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe } case iox::capro::CaproMessageType::STOP_OFFER: { - if(this->channelExists(msg.m_serviceDescription)) + if(this->findChannel(msg.m_serviceDescription).has_value()) { this->discardChannel(msg.m_serviceDescription); } @@ -99,25 +101,23 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noe } } -template -inline void Iceoryx2DDSGateway::forward() noexcept +template +inline void Iceoryx2DDSGateway::forward() noexcept { - auto guardedVector = this->m_channels.GetScopeGuard(); - for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) - { - auto subscriber = channel->getIceoryxTerminal(); + this->forEachChannel([](channel_t channel){ + auto subscriber = channel.getIceoryxTerminal(); if (subscriber->hasNewChunks()) { const iox::mepoo::ChunkHeader* header; subscriber->getChunk(&header); if (header->m_info.m_payloadSize > 0) { - auto dataWriter = channel->getDDSTerminal(); + auto dataWriter = channel.getDDSTerminal(); dataWriter->write(static_cast(header->payload()), header->m_info.m_payloadSize); } subscriber->releaseChunk(header); } - } + }); } } // namespace dds diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 60e192cf4e..402486c4cd 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -64,9 +65,20 @@ class MockDataWriter : public iox::dds::DataWriter MOCK_CONST_METHOD0(getEventId, std::string(void)); }; +class MockGenericDDSGateway +{ +public: + MockGenericDDSGateway(){}; + MockGenericDDSGateway(const iox::capro::Interfaces i){}; + MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); + MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); +}; + // ======================================== Helpers ======================================== // -using TestGateway = iox::dds::Iceoryx2DDSGateway>; +using TestGateway = iox::dds::Iceoryx2DDSGateway, MockGenericDDSGateway>; // Holds mocks created by tests to be returned by mock factories. static std::vector> stagedMockSubscribers; @@ -151,60 +163,82 @@ class Iceoryx2DDSGatewayTest : public Test // ======================================== Tests ======================================== // TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) { - auto gw = std::make_shared(mockChannelFactory); + // === Setup + TestGateway gw{mockChannelFactory}; auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Introspection", iox::capro::AnyInstanceString, iox::capro::AnyEventString}); msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - gw->discover(msg); - EXPECT_EQ(0, gw->getNumberOfChannels()); + + EXPECT_CALL(gw, addChannel).Times(0); + + // === Test + gw.discover(msg); } TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) { - auto gw = std::make_shared(mockChannelFactory); + // === Setup + TestGateway gw{mockChannelFactory}; auto msg = iox::capro::CaproMessage( iox::capro::CaproMessageType::OFFER, {iox::capro::AnyServiceString, iox::capro::AnyInstanceString, iox::capro::AnyEventString}); msg.m_subType = iox::capro::CaproMessageSubType::SERVICE; - gw->discover(msg); - EXPECT_EQ(0, gw->getNumberOfChannels()); + + EXPECT_CALL(gw, addChannel).Times(0); + + // === Test + gw.discover(msg); } -//TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) -//{ -// auto gw = std::make_shared(mockChannelFactory); -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; -// gw->discover(msg); -// EXPECT_EQ(1, gw->getNumberOfChannels()); -//} +TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) +{ + // === Setup + TestGateway gw{mockChannelFactory}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); + msg.m_subType = iox::capro::CaproMessageSubType::EVENT; + + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); + EXPECT_CALL(gw, addChannel).Times(1); + + // === Test + gw.discover(msg); +} //TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) //{ -// // === Create Mocks +// // === Setup // auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); // EXPECT_CALL(*mockSubscriber, subscribe).Times(1); // stageMockSubscriber(std::move(mockSubscriber)); -// // === Test -// auto gw = std::make_shared(mockChannelFactory); +// TestGateway gw{mockChannelFactory}; // auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); // msg.m_subType = iox::capro::CaproMessageSubType::EVENT; -// gw->discover(msg); + +// ON_CALL(gw, channelExists).WillByDefault(Return(false)); +// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); + +// // === Test +// gw.discover(msg); //} //TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) //{ -// // === Create Mocks +// // === Setup // auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); // EXPECT_CALL(*mockWriter, connect).Times(1); // stageMockDataWriter(std::move(mockWriter)); -// // === Test -// auto gw = std::make_shared(mockChannelFactory); +// TestGateway gw{mockChannelFactory}; // auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); // msg.m_subType = iox::capro::CaproMessageSubType::EVENT; -// gw->discover(msg); + +// ON_CALL(gw, channelExists).WillByDefault(Return(false)); +// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); + +// // === Test +// gw.discover(msg); //} //TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) @@ -214,11 +248,10 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) // // Set up subscriber to provide this chunk when requested // auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - // ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); // ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); // EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); +// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); // EXPECT_CALL(*mockWriter, // write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) // .Times(1); @@ -226,11 +259,15 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) // stageMockSubscriber(std::move(mockSubscriber)); // stageMockDataWriter(std::move(mockWriter)); -// // === Test -// auto gw = std::make_shared(mockChannelFactory); +// TestGateway gw{mockChannelFactory}; // auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// gw->discover(msg); -// gw->forward(); + +// ON_CALL(gw, channelExists).WillByDefault(Return(false)); +// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); + +// // === Test +// gw.discover(msg); +// gw.forward(); //} //TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) From 64673730cd610103e448e0d0b4c356e9bf42a0cb Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Fri, 5 Jun 2020 17:48:27 +0200 Subject: [PATCH 27/55] iox-#65 Update tests to work with new dds gateway API. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/iox_to_dds.hpp | 1 - .../internal/gateway/iox_to_dds.inl | 5 - .../test/moduletests/test_iox_to_dds.cpp | 387 ++++++++++-------- 3 files changed, 224 insertions(+), 169 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 6d4e888fd0..2d63d9fc95 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -16,7 +16,6 @@ class Iceoryx2DDSGateway : public gateway_t using ChannelFactory = std::function; public: Iceoryx2DDSGateway() noexcept; - Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept; void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward() noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 0379e674aa..283a4a2a3e 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -33,11 +33,6 @@ template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : gateway_t() {} -template -inline Iceoryx2DDSGateway::Iceoryx2DDSGateway(ChannelFactory channelFactory) noexcept -{ -} - template inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) noexcept { diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 402486c4cd..d1d3c0818d 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -74,6 +74,7 @@ class MockGenericDDSGateway MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); MOCK_METHOD1(findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(forEachChannel, void(const std::function&)>)); }; // ======================================== Helpers ======================================== // @@ -117,7 +118,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::dds::Channel mockChannelFactory(iox::capro::ServiceDescription sd) noexcept +static iox::dds::Channel createTestChannel(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; @@ -164,7 +165,7 @@ class Iceoryx2DDSGatewayTest : public Test TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) { // === Setup - TestGateway gw{mockChannelFactory}; + TestGateway gw{}; auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Introspection", iox::capro::AnyInstanceString, iox::capro::AnyEventString}); msg.m_subType = iox::capro::CaproMessageSubType::EVENT; @@ -178,7 +179,7 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) { // === Setup - TestGateway gw{mockChannelFactory}; + TestGateway gw{}; auto msg = iox::capro::CaproMessage( iox::capro::CaproMessageType::OFFER, {iox::capro::AnyServiceString, iox::capro::AnyInstanceString, iox::capro::AnyEventString}); @@ -193,172 +194,232 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) { // === Setup - TestGateway gw{mockChannelFactory}; - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + TestGateway gw{}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); msg.m_subType = iox::capro::CaproMessageSubType::EVENT; ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + EXPECT_CALL(gw, addChannel).Times(1); // === Test gw.discover(msg); } -//TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) -//{ -// // === Setup -// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// EXPECT_CALL(*mockSubscriber, subscribe).Times(1); -// stageMockSubscriber(std::move(mockSubscriber)); - -// TestGateway gw{mockChannelFactory}; -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - -// ON_CALL(gw, channelExists).WillByDefault(Return(false)); -// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); - -// // === Test -// gw.discover(msg); -//} - -//TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) -//{ -// // === Setup -// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); -// EXPECT_CALL(*mockWriter, connect).Times(1); -// stageMockDataWriter(std::move(mockWriter)); - -// TestGateway gw{mockChannelFactory}; -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - -// ON_CALL(gw, channelExists).WillByDefault(Return(false)); -// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); - -// // === Test -// gw.discover(msg); -//} - -//TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) -//{ -// // === Create Mocks -// ChunkMock mockChunk{42}; - -// // Set up subscriber to provide this chunk when requested -// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); -// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); -// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); -// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); -// EXPECT_CALL(*mockWriter, -// write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) -// .Times(1); - -// stageMockSubscriber(std::move(mockSubscriber)); -// stageMockDataWriter(std::move(mockWriter)); - -// TestGateway gw{mockChannelFactory}; -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); - -// ON_CALL(gw, channelExists).WillByDefault(Return(false)); -// ON_CALL(gw, setupChannel).WillByDefault(Return(mockChannelFactory(msg.m_serviceDescription))); - -// // === Test -// gw.discover(msg); -// gw.forward(); -//} - -//TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) -//{ -// // === Create Mocks -// ChunkMock mockChunk{42}; -// mockChunk.chunkHeader()->m_info.m_payloadSize = 0; - -// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - -// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); -// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); -// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); -// EXPECT_CALL(*mockWriter, write).Times(Exactly(0)); - -// stageMockSubscriber(std::move(mockSubscriber)); -// stageMockDataWriter(std::move(mockWriter)); - -// // === Test -// auto gw = std::make_shared(mockChannelFactory); -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// gw->discover(msg); -// gw->forward(); -//} - -//TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) -//{ -// // === Create Mocks -// ChunkMock mockChunk{42}; - -// auto mockSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// auto mockWriter = createMockDataWriter({"Radar", "Front-Right", "Reflections"}); - -// ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); -// ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - -// // Define expected sequence of calls -// { -// InSequence seq; -// EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); -// EXPECT_CALL(*mockSubscriber, getChunk).Times(1); -// EXPECT_CALL(*mockWriter, write).Times(1); -// EXPECT_CALL(*mockSubscriber, releaseChunk).Times(1); -// } - -// stageMockSubscriber(std::move(mockSubscriber)); -// stageMockDataWriter(std::move(mockWriter)); - -// // === Test -// auto gw = std::make_shared(mockChannelFactory); -// auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// gw->discover(msg); -// gw->forward(); -//} - -//TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) -//{ -// // === Create Mocks -// // Subscribers -// auto firstCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); -// auto secondCreatedSubscriber = createMockSubscriber({"Radar", "Front-Right", "Reflections"}); - -// ON_CALL(*firstCreatedSubscriber, getServiceDescription) -// .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); -// ON_CALL(*secondCreatedSubscriber, getServiceDescription) -// .WillByDefault(Return(iox::capro::ServiceDescription("Radar", "Front-Right", "Reflections"))); - -// { -// InSequence seq; -// EXPECT_CALL(*firstCreatedSubscriber, subscribe).Times(1); -// EXPECT_CALL(*firstCreatedSubscriber, isDestroyed).Times(1); -// EXPECT_CALL(*secondCreatedSubscriber, subscribe).Times(1); -// } - -// // Important ! Pass ownership, do not keep the reference here. -// stageMockSubscriber(std::move(firstCreatedSubscriber)); -// stageMockSubscriber(std::move(secondCreatedSubscriber)); - -// // Messages -// auto offerMsg = -// iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Radar", "Front-Right", "Reflections"}); -// offerMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; -// auto stopOfferMsg = -// iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, {"Radar", "Front-Right", "Reflections"}); -// stopOfferMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; - -// // === Test -// auto gw = std::make_shared(mockChannelFactory); - -// gw->discover(offerMsg); -// gw->discover(stopOfferMsg); // first subscriber must be deleted here -// gw->discover(offerMsg); -//} +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + auto mockSubscriber = createMockSubscriber(testService); + EXPECT_CALL(*mockSubscriber, subscribe).Times(1); + stageMockSubscriber(std::move(mockSubscriber)); + + TestGateway gw{}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + msg.m_subType = iox::capro::CaproMessageSubType::EVENT; + + // Mock methods of the mock generic dds gateway base class + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + + // === Test + gw.discover(msg); +} + +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + auto mockWriter = createMockDataWriter(testService); + EXPECT_CALL(*mockWriter, connect).Times(1); + stageMockDataWriter(std::move(mockWriter)); + + TestGateway gw{}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + msg.m_subType = iox::capro::CaproMessageSubType::EVENT; + + // Mock methods of the mock generic dds gateway base class + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + + // === Test + gw.discover(msg); +} + +TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + + // Prepare a mock mempool chunk + ChunkMock mockChunk{42}; + + // Set up subscriber to provide this chunk when requested + auto mockSubscriber = createMockSubscriber(testService); + ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); + ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); + EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); + stageMockSubscriber(std::move(mockSubscriber)); + + // We expect one attempt to write the mock chunk to the mock writer + auto mockWriter = createMockDataWriter(testService); + EXPECT_CALL(*mockWriter, + write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) + .Times(1); + stageMockDataWriter(std::move(mockWriter)); + + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + auto testChannel = createTestChannel(testService); // Keep a copy for use in mutliple mocks + TestGateway gw{}; + + // Mock methods of the mock generic dds gateway base class + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); + + // Capture the function containing the logic the implementation wants to run and run it on the test channel + // to verify correctness. + EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ + f(testChannel); + }); + + // === Test + gw.discover(msg); // Trigger setup of channel with mock subscriber and data writer. + gw.forward(); // Trigger forwarding of mock chunk from mock subscriber to mock data writer. +} + +TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + + // Prepare a mock mempool chunk zero size + ChunkMock mockChunk{42}; + mockChunk.chunkHeader()->m_info.m_payloadSize = 0; + + // Set up subscriber to provide this chunk when requested + auto mockSubscriber = createMockSubscriber(testService); + EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); + ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); + ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); + stageMockSubscriber(std::move(mockSubscriber)); + + // We expect exactly zero attempts to write to the data writer since the mempool chunk is size zero + auto mockWriter = createMockDataWriter(testService); + EXPECT_CALL(*mockWriter, write).Times(Exactly(0)); + stageMockDataWriter(std::move(mockWriter)); + + TestGateway gw{}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + auto testChannel = createTestChannel(testService); + + // Mock methods of the mock generic dds gateway base class + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); + + // Capture the function containing the logic the implementation wants to run and run it on the test channel + // to verify correctness. + EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ + f(testChannel); + }); + + // === Test + gw.discover(msg); + gw.forward(); +} + +TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + + ChunkMock mockChunk{42}; + + auto mockSubscriber = createMockSubscriber(testService); + ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); + ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); + + auto mockWriter = createMockDataWriter(testService); + + { + InSequence seq; + EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); + EXPECT_CALL(*mockSubscriber, getChunk).Times(1); + EXPECT_CALL(*mockWriter, write).Times(1); + EXPECT_CALL(*mockSubscriber, releaseChunk).Times(1); + } + + stageMockSubscriber(std::move(mockSubscriber)); + stageMockDataWriter(std::move(mockWriter)); + + TestGateway gw{}; + auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + auto testChannel = createTestChannel(testService); + + // Mock methods of the mock generic dds gateway base class + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); + + // Capture the function containing the logic the implementation wants to run and run it on the test channel + // to verify correctness. + EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ + f(testChannel); + }); + + // === Test + gw.discover(msg); + gw.forward(); + +} + +TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) +{ + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + + // Subscribers + auto firstCreatedSubscriber = createMockSubscriber(testService); + auto secondCreatedSubscriber = createMockSubscriber(testService); + ON_CALL(*firstCreatedSubscriber, getServiceDescription) + .WillByDefault(Return(testService)); + ON_CALL(*secondCreatedSubscriber, getServiceDescription) + .WillByDefault(Return(testService)); + { + InSequence seq; + EXPECT_CALL(*firstCreatedSubscriber, subscribe).Times(1); + EXPECT_CALL(*secondCreatedSubscriber, subscribe).Times(1); + } + + stageMockSubscriber(std::move(firstCreatedSubscriber)); + stageMockSubscriber(std::move(secondCreatedSubscriber)); + + // Messages + auto offerMsg = + iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + offerMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; + auto stopOfferMsg = + iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, testService); + stopOfferMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; + + // Get the test channels here as we need to use them in expectations + auto testChannelOne = createTestChannel(testService); + auto testChannelTwo = createTestChannel(testService); + + TestGateway gw{}; + // EXPECT_CALL is used here because it allows specifying different return values for consecutive calls + EXPECT_CALL(gw, findChannel) + .WillOnce(Return(iox::cxx::nullopt_t())) + .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) + .WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel) + .WillOnce(Return(testChannelOne)) + .WillOnce(Return(testChannelTwo)); + EXPECT_CALL(gw, discardChannel) + .Times(1); + + // === Test + gw.discover(offerMsg); + gw.discover(stopOfferMsg); // first subscriber must be deleted here + gw.discover(offerMsg); +} From 0b0e11cc3d096596cc7d08d225df2c6e61cad166 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Fri, 5 Jun 2020 17:53:12 +0200 Subject: [PATCH 28/55] iox-#65 Add missing copyright notices. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/dds/cyclone_data_reader.hpp | 14 ++++++++++++++ .../include/iceoryx_dds/dds/data_reader.hpp | 14 ++++++++++++++ iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp | 14 ++++++++++++++ .../include/iceoryx_dds/gateway/channel.hpp | 14 ++++++++++++++ .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 14 ++++++++++++++ .../include/iceoryx_dds/gateway/dds_to_iox.hpp | 14 ++++++++++++++ .../include/iceoryx_dds/gateway/gateway_config.hpp | 14 ++++++++++++++ .../include/iceoryx_dds/gateway/iox_to_dds.hpp | 14 ++++++++++++++ .../internal/gateway/dds_gateway_generic.inl | 13 +++++++++++++ .../iceoryx_dds/internal/gateway/dds_to_iox.inl | 13 +++++++++++++ .../source/iceoryx_dds/dds/cyclone_data_reader.cpp | 13 +++++++++++++ 11 files changed, 151 insertions(+) diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index 309c5e6c07..f8b111afe2 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include "iceoryx_dds/dds/data_reader.hpp" diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index 432c40f6a9..dc79c5228c 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index 302f9b4c13..96954a11a9 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 5f836ea287..7c95b030d9 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index d86359e26c..b0ab948fc7 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index fa2a7d3eb9..b2c5570f8e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp index 780ccbd6d6..4c76316247 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 2d63d9fc95..4a61ebf73d 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #pragma once #include diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 2d5348ffdf..d6595b0754 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -1,3 +1,16 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. #include diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index cbc0ce28ce..e5315b1da1 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -1,3 +1,16 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. #include diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp index 5b34fa78a2..ff95956c3a 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp @@ -1,3 +1,16 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. #include "iceoryx_dds/dds/cyclone_data_reader.hpp" From ff247773a17603fde8aae3234173556f044fda4e Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Fri, 5 Jun 2020 19:41:50 +0200 Subject: [PATCH 29/55] iox-#65 Add tests for DDSGatewayGeneric Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../gateway/dds_gateway_generic.hpp | 6 +- .../internal/gateway/dds_gateway_generic.inl | 58 ++++++------ .../helpers/stubbed_dds_gateway_generic.hpp | 76 ++++++++++++++++ iceoryx_dds/test/mocks/google_mocks.hpp | 57 ++++++++++++ .../moduletests/test_generic_dds_gateway.cpp | 89 +++++++++++++++++++ .../test/moduletests/test_iox_to_dds.cpp | 49 +--------- 6 files changed, 256 insertions(+), 79 deletions(-) create mode 100644 iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp create mode 100644 iceoryx_dds/test/mocks/google_mocks.hpp create mode 100644 iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index b0ab948fc7..b2d18fe08a 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -25,14 +25,14 @@ #include #include -#include "iceoryx_dds/dds/dds_configs.hpp" +#include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_dds/gateway/gateway_config.hpp" namespace iox { namespace dds { -template -class DDSGatewayGeneric : public iox::popo::GatewayGeneric +template +class DDSGatewayGeneric : public gateway_t { using ChannelFactory = std::function; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index d6595b0754..617c955f2b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -22,26 +22,26 @@ // ================================================== Public ================================================== // -template -inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() noexcept +template +inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() noexcept { shutdown(); } -template -inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept +template +inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept { m_discoveryThread = std::thread([this] { discoveryLoop(); }); m_forwardingThread = std::thread([this] { forwardingLoop(); }); m_isRunning.store(true, std::memory_order_relaxed); } -template -inline void iox::dds::DDSGatewayGeneric::shutdown() noexcept +template +inline void iox::dds::DDSGatewayGeneric::shutdown() noexcept { if (m_isRunning.load(std::memory_order_relaxed)) { - iox::LogDebug() << "[DDSGatewayGeneric] Shutting down Posh2DDSGateway."; + iox::dds::LogDebug() << "[DDSGatewayGeneric] Shutting down Posh2DDSGateway."; m_runDiscoveryLoop.store(false, std::memory_order_relaxed); m_runForwardingLoop.store(false, std::memory_order_relaxed); @@ -53,8 +53,8 @@ inline void iox::dds::DDSGatewayGeneric::shutdown() noexcept } } -template -inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept +template +inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept { auto guardedVector = m_channels.GetScopeGuard(); return guardedVector->size(); @@ -62,26 +62,26 @@ inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() co // ================================================== Protected ================================================== // -template -inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : iox::popo::GatewayGeneric(iox::capro::Interfaces::DDS) +template +inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : gateway_t(iox::capro::Interfaces::DDS) { LogDebug() << "[DDSGatewayGeneric] Using default channel factory."; m_channelFactory = channel_t::create; } -template -inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); m_channels->push_back(channel); - iox::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); return channel; } -template -inline iox::cxx::optional iox::dds::DDSGatewayGeneric::findChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline iox::cxx::optional iox::dds::DDSGatewayGeneric::findChannel(const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); auto channel = std::find_if( @@ -99,8 +99,8 @@ inline iox::cxx::optional iox::dds::DDSGatewayGeneric::fin } } -template -inline void iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) noexcept +template +inline void iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) noexcept { auto guardedVector = m_channels.GetScopeGuard(); for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) @@ -109,8 +109,8 @@ inline void iox::dds::DDSGatewayGeneric::forEachChannel(const std::fu } } -template -inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); auto channel = std::find_if( @@ -120,7 +120,7 @@ inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::ca if (channel != guardedVector->end()) { guardedVector->erase(channel); - iox::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); } @@ -128,10 +128,10 @@ inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::ca // ================================================== Private ================================================== // -template -inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept +template +inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept { - iox::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; + iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; m_runDiscoveryLoop.store(true, std::memory_order_relaxed); while (m_runDiscoveryLoop.load(std::memory_order_relaxed)) { @@ -143,13 +143,13 @@ inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept std::this_thread::sleep_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(DISCOVERY_PERIOD.milliSeconds())); } - iox::LogDebug() << "[DDSGatewayGeneric] Stopped discovery."; + iox::dds::LogDebug() << "[DDSGatewayGeneric] Stopped discovery."; } -template -inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept +template +inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept { - iox::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; + iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; m_runForwardingLoop.store(true, std::memory_order_relaxed); while (m_runForwardingLoop.load(std::memory_order_relaxed)) { @@ -157,6 +157,6 @@ inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept std::this_thread::sleep_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(FORWARDING_PERIOD.milliSeconds())); }; - iox::LogDebug() << "[DDSGatewayGeneric] Stopped forwarding."; + iox::dds::LogDebug() << "[DDSGatewayGeneric] Stopped forwarding."; } diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp new file mode 100644 index 0000000000..ffff26f880 --- /dev/null +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -0,0 +1,76 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. +#pragma once + +#include +#include + +#include "mocks/google_mocks.hpp" + +namespace iox { +namespace dds { + +template +using TestDDSGatewayGeneric = iox::dds::DDSGatewayGeneric; + +/// +/// @brief The StubbedDDSGatewayGeneric class stubs out the pure virtual methods and exposes the protected methods +/// to allow them to be tested. +/// Only to be used in testing. +/// +template +class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric +{ + +public: + + virtual void loadConfiguration(GatewayConfig config) noexcept + { + // Stubbed. + } + + void discover(const iox::capro::CaproMessage& msg) noexcept + { + // Stubbed. + } + + void forward() noexcept + { + // Stubbed. + } + + channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept + { + TestDDSGatewayGeneric::addChannel(service); + } + + iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) noexcept + { + TestDDSGatewayGeneric::findChannel(service); + } + + void forEachChannel(const std::function f) noexcept + { + TestDDSGatewayGeneric::forEachChannel(f); + } + + void discardChannel(const iox::capro::ServiceDescription& service) noexcept + { + TestDDSGatewayGeneric::discardChannel(service); + } + +}; + +} +} diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp new file mode 100644 index 0000000000..bac08f5df1 --- /dev/null +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include "test.hpp" +#include +#include +#include +#include +#include + +using namespace ::testing; +using ::testing::_; + +class MockGenericGateway +{ + public: + MockGenericGateway(const iox::capro::Interfaces i){}; + MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); +}; + +class MockSubscriber +{ + public: + MockSubscriber(const iox::capro::ServiceDescription& sd){}; + MOCK_METHOD0(isDestroyed, void()); // Allows testing for destruction + virtual ~MockSubscriber() + { + isDestroyed(); + } + MOCK_CONST_METHOD0(hasNewChunks, bool()); + MOCK_METHOD0(getServiceDescription, iox::capro::ServiceDescription()); + MOCK_METHOD1(getChunk, bool(const iox::mepoo::ChunkHeader**)); + MOCK_METHOD1(releaseChunk, bool(const void* const payload)); + MOCK_METHOD1(subscribe, void(const uint32_t)); +}; + +class MockDataWriter : public iox::dds::DataWriter +{ + public: + MockDataWriter(const iox::capro::ServiceDescription& sd){}; + MOCK_METHOD0(connect, void(void)); + MOCK_METHOD2(write, bool(uint8_t*, uint64_t)); + MOCK_CONST_METHOD0(getServiceId, std::string(void)); + MOCK_CONST_METHOD0(getInstanceId, std::string(void)); + MOCK_CONST_METHOD0(getEventId, std::string(void)); +}; + +class MockGenericDDSGateway +{ +public: + MockGenericDDSGateway(){}; + MockGenericDDSGateway(const iox::capro::Interfaces i){}; + MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); + MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(forEachChannel, void(const std::function&)>)); +}; diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp new file mode 100644 index 0000000000..eaec017b72 --- /dev/null +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -0,0 +1,89 @@ +#include +#include + +#include "test.hpp" + +#include "helpers/stubbed_dds_gateway_generic.hpp" + +using namespace ::testing; +using ::testing::_; + +// ======================================== Helpers ======================================== // +// We do not need real channel terminals to test the base class. +struct StubbedIceoryxTerminal{ + StubbedIceoryxTerminal(iox::capro::ServiceDescription sd){}; +}; + +struct StubbedDDSTerminal{ + StubbedDDSTerminal(iox::dds::IdString sid, iox::dds::IdString iid, iox::dds::IdString eid){}; +}; + +// ======================================== Fixture ======================================== // +class DDSGatewayGenericTest : public Test +{ + public: + void SetUp(){}; + void TearDown(){}; +}; + +// ======================================== Tests ======================================== // +TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("", "", ""); + + iox::dds::StubbedDDSGatewayGeneric> gw{}; + + // ===== Test + gw.addChannel(testService); + + EXPECT_EQ(1, gw.getNumberOfChannels()); + +} + +TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("", "", ""); + + iox::dds::StubbedDDSGatewayGeneric> gw{}; + + // ===== Test + gw.addChannel(testService); + gw.discardChannel(testService); + + EXPECT_EQ(0, gw.getNumberOfChannels()); + +} + +TEST_F(DDSGatewayGenericTest, FindChannelReturnsCopyOfFoundChannel) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("service", "instance", "event"); + + iox::dds::StubbedDDSGatewayGeneric> gw{}; + + // ===== Test + gw.addChannel(testService); + auto foundChannel = gw.findChannel(testService); + EXPECT_EQ(1, gw.getNumberOfChannels()); + EXPECT_EQ(true, foundChannel.has_value()); + if(foundChannel.has_value()) + { + EXPECT_EQ(testService, foundChannel.value().getService()); + } + +} + +TEST_F(DDSGatewayGenericTest, FindChannelGivesEmptyOptionalIfNoneFound) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("", "", ""); + + iox::dds::StubbedDDSGatewayGeneric> gw{}; + + // ===== Test + auto foundChannel = gw.findChannel(testService); + EXPECT_EQ(false, foundChannel.has_value()); +} + diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index d1d3c0818d..44ab9e32f1 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -15,12 +15,14 @@ #include #include +#include #include #include #include #include #include "mocks/chunk_mock.hpp" +#include "mocks/google_mocks.hpp" #include "roudi_gtest.hpp" #include "test.hpp" @@ -30,53 +32,6 @@ using ::testing::Return; using ::testing::SetArgPointee; using ::testing::InSequence; -// ======================================== Mocks ======================================== // -class MockGenericGateway -{ - public: - MockGenericGateway(const iox::capro::Interfaces i){}; - MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); -}; - -class MockSubscriber -{ - public: - MockSubscriber(const iox::capro::ServiceDescription& sd){}; - MOCK_METHOD0(isDestroyed, void()); // Allows testing for destruction - virtual ~MockSubscriber() - { - isDestroyed(); - } - MOCK_CONST_METHOD0(hasNewChunks, bool()); - MOCK_METHOD0(getServiceDescription, iox::capro::ServiceDescription()); - MOCK_METHOD1(getChunk, bool(const iox::mepoo::ChunkHeader**)); - MOCK_METHOD1(releaseChunk, bool(const void* const payload)); - MOCK_METHOD1(subscribe, void(const uint32_t)); -}; - -class MockDataWriter : public iox::dds::DataWriter -{ - public: - MockDataWriter(const iox::capro::ServiceDescription& sd){}; - MOCK_METHOD0(connect, void(void)); - MOCK_METHOD2(write, bool(uint8_t*, uint64_t)); - MOCK_CONST_METHOD0(getServiceId, std::string(void)); - MOCK_CONST_METHOD0(getInstanceId, std::string(void)); - MOCK_CONST_METHOD0(getEventId, std::string(void)); -}; - -class MockGenericDDSGateway -{ -public: - MockGenericDDSGateway(){}; - MockGenericDDSGateway(const iox::capro::Interfaces i){}; - MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(forEachChannel, void(const std::function&)>)); -}; - // ======================================== Helpers ======================================== // using TestGateway = iox::dds::Iceoryx2DDSGateway, MockGenericDDSGateway>; From 58333c7b6f438b857d50a4c8c248c2621539d045 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 14:07:25 +0200 Subject: [PATCH 30/55] iox-#65 Added more tests for dds gateway generic. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../helpers/stubbed_dds_gateway_generic.hpp | 4 +- .../moduletests/test_generic_dds_gateway.cpp | 47 +++++++++++++++---- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index ffff26f880..2c25861ce5 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -52,12 +52,12 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept { - TestDDSGatewayGeneric::addChannel(service); + return TestDDSGatewayGeneric::addChannel(service); } iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) noexcept { - TestDDSGatewayGeneric::findChannel(service); + return TestDDSGatewayGeneric::findChannel(service); } void forEachChannel(const std::function f) noexcept diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index eaec017b72..ffc2658e12 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -18,6 +18,9 @@ struct StubbedDDSTerminal{ StubbedDDSTerminal(iox::dds::IdString sid, iox::dds::IdString iid, iox::dds::IdString eid){}; }; +using TestChannel = iox::dds::Channel; +using TestDDSGatewayGeneric = iox::dds::StubbedDDSGatewayGeneric; + // ======================================== Fixture ======================================== // class DDSGatewayGenericTest : public Test { @@ -30,9 +33,9 @@ class DDSGatewayGenericTest : public Test TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) { // ===== Setup - auto testService = iox::capro::ServiceDescription("", "", ""); + auto testService = iox::capro::ServiceDescription("service", "instance", "event"); - iox::dds::StubbedDDSGatewayGeneric> gw{}; + TestDDSGatewayGeneric gw{}; // ===== Test gw.addChannel(testService); @@ -44,14 +47,14 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup - auto testService = iox::capro::ServiceDescription("", "", ""); + auto testService = iox::capro::ServiceDescription("service", "instance", "event"); - iox::dds::StubbedDDSGatewayGeneric> gw{}; + TestDDSGatewayGeneric gw{}; // ===== Test gw.addChannel(testService); + EXPECT_EQ(1, gw.getNumberOfChannels()); gw.discardChannel(testService); - EXPECT_EQ(0, gw.getNumberOfChannels()); } @@ -61,12 +64,11 @@ TEST_F(DDSGatewayGenericTest, FindChannelReturnsCopyOfFoundChannel) // ===== Setup auto testService = iox::capro::ServiceDescription("service", "instance", "event"); - iox::dds::StubbedDDSGatewayGeneric> gw{}; + TestDDSGatewayGeneric gw{}; // ===== Test gw.addChannel(testService); auto foundChannel = gw.findChannel(testService); - EXPECT_EQ(1, gw.getNumberOfChannels()); EXPECT_EQ(true, foundChannel.has_value()); if(foundChannel.has_value()) { @@ -78,12 +80,37 @@ TEST_F(DDSGatewayGenericTest, FindChannelReturnsCopyOfFoundChannel) TEST_F(DDSGatewayGenericTest, FindChannelGivesEmptyOptionalIfNoneFound) { // ===== Setup - auto testService = iox::capro::ServiceDescription("", "", ""); + auto storedChannelService = iox::capro::ServiceDescription("service", "instance", "event"); + auto notStoredChannelService = iox::capro::ServiceDescription("otherService", "otherInstance", "otherEvent"); - iox::dds::StubbedDDSGatewayGeneric> gw{}; + TestDDSGatewayGeneric gw{}; // ===== Test - auto foundChannel = gw.findChannel(testService); + gw.addChannel(storedChannelService); + auto foundChannel = gw.findChannel(notStoredChannelService); EXPECT_EQ(false, foundChannel.has_value()); } +TEST_F(DDSGatewayGenericTest, ForEachChannelExecutesGivenFunctionForAllStoredChannels) +{ + // ===== Setup + auto testServiceA = iox::capro::ServiceDescription("serviceA", "instanceA", "eventA"); + auto testServiceB = iox::capro::ServiceDescription("serviceB", "instanceB", "eventB"); + auto testServiceC = iox::capro::ServiceDescription("serviceC", "instanceC", "eventC"); + + auto count = 0u; + auto f = [&count](TestChannel& channel){ + count++; + }; + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(testServiceA); + gw.addChannel(testServiceB); + gw.addChannel(testServiceC); + gw.forEachChannel(f); + + EXPECT_EQ(3, count); + +} From 62a0c87d8303c05d2e49ea39a05322ccfa8eb119 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 14:50:43 +0200 Subject: [PATCH 31/55] iox-#65 Updated unit tests for iceoryx2dds gateway to properly test forwarding logic. Previously tests were only testing the attempt to forward rather than what was actually being done in the forwarding. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../gateway/dds_gateway_generic.hpp | 2 +- .../iceoryx_dds/gateway/dds_to_iox.hpp | 2 +- .../iceoryx_dds/gateway/iox_to_dds.hpp | 2 +- .../internal/gateway/dds_gateway_generic.inl | 4 +- .../internal/gateway/dds_to_iox.inl | 2 +- .../internal/gateway/iox_to_dds.inl | 24 ++-- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 9 +- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 8 +- .../helpers/stubbed_dds_gateway_generic.hpp | 2 +- .../test/moduletests/test_iox_to_dds.cpp | 106 +++++++----------- 10 files changed, 69 insertions(+), 92 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index b2d18fe08a..6096784b8e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -58,7 +58,7 @@ class DDSGatewayGeneric : public gateway_t void shutdown() noexcept; virtual void discover(const iox::capro::CaproMessage& msg) noexcept = 0; - virtual void forward() noexcept = 0; + virtual void forward(channel_t channel) noexcept = 0; uint64_t getNumberOfChannels() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index b2c5570f8e..e9292435f7 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -32,7 +32,7 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward() noexcept; + void forward(channel_t channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 4a61ebf73d..260e4a1aee 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -32,7 +32,7 @@ class Iceoryx2DDSGateway : public gateway_t Iceoryx2DDSGateway() noexcept; void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward() noexcept; + void forward(channel_t channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 617c955f2b..10bedd68a9 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -153,7 +153,9 @@ inline void iox::dds::DDSGatewayGeneric::forwardingLoop() m_runForwardingLoop.store(true, std::memory_order_relaxed); while (m_runForwardingLoop.load(std::memory_order_relaxed)) { - forward(); + forEachChannel([this](channel_t channel){ + this->forward(channel); + }); std::this_thread::sleep_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(FORWARDING_PERIOD.milliSeconds())); }; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index e5315b1da1..b577643230 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -41,7 +41,7 @@ inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessa } template -inline void DDS2IceoryxGateway::forward() noexcept +inline void DDS2IceoryxGateway::forward(channel_t channel) noexcept { } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 283a4a2a3e..71c47d8509 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -97,22 +97,20 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessag } template -inline void Iceoryx2DDSGateway::forward() noexcept +inline void Iceoryx2DDSGateway::forward(channel_t channel) noexcept { - this->forEachChannel([](channel_t channel){ - auto subscriber = channel.getIceoryxTerminal(); - if (subscriber->hasNewChunks()) + auto subscriber = channel.getIceoryxTerminal(); + if (subscriber->hasNewChunks()) + { + const iox::mepoo::ChunkHeader* header; + subscriber->getChunk(&header); + if (header->m_info.m_payloadSize > 0) { - const iox::mepoo::ChunkHeader* header; - subscriber->getChunk(&header); - if (header->m_info.m_payloadSize > 0) - { - auto dataWriter = channel.getDDSTerminal(); - dataWriter->write(static_cast(header->payload()), header->m_info.m_payloadSize); - } - subscriber->releaseChunk(header); + auto dataWriter = channel.getDDSTerminal(); + dataWriter->write(static_cast(header->payload()), header->m_info.m_payloadSize); } - }); + subscriber->releaseChunk(header); + } } } // namespace dds diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index 7c5e00239c..cedfa474f0 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -27,14 +27,17 @@ iox::posix::Semaphore ShutdownManager::s_semaphore = iox::posix::Semaphore::crea int main(int argc, char *argv[]) { + // Set OS signal handlers + signal(SIGINT, ShutdownManager::scheduleShutdown); + signal(SIGTERM, ShutdownManager::scheduleShutdown); - iox::runtime::PoshRuntime::getInstance("/gateway_dds2iox"); + // Start application + iox::runtime::PoshRuntime::getInstance("/gateway_dds2iceoryx"); iox::dds::DDS2IceoryxGateway<> gw; gw.runMultithreaded(); - std::cout << "Hello." << std::endl; - + // Run until SIGINT or SIGTERM ShutdownManager::waitUntilShutdown(); return 0; diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 8130f84d5b..846c85e5a6 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -47,15 +47,11 @@ int main(int argc, char* argv[]) signal(SIGINT, ShutdownManager::scheduleShutdown); signal(SIGTERM, ShutdownManager::scheduleShutdown); - // Parse configuration - iox::dds::GatewayConfig config; - // Start application iox::runtime::PoshRuntime::getInstance("/gateway_iceoryx2dds"); - iox::dds::Iceoryx2DDSGateway<> gateway; - gateway.loadConfiguration(config); - gateway.runMultithreaded(); + iox::dds::Iceoryx2DDSGateway<> gw; + gw.runMultithreaded(); // Run until SIGINT or SIGTERM ShutdownManager::waitUntilShutdown(); diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 2c25861ce5..8f01eb921a 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -45,7 +45,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - void forward() noexcept + void forward(channel_t channel) noexcept { // Stubbed. } diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 44ab9e32f1..46a96c1204 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -146,7 +146,22 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) gw.discover(msg); } -TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) +TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForConfiguredServices) +{ + +} + +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromConfiguredServices) +{ + +} + +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForConfiguredServices) +{ + +} + +TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForDiscoveredServices) { // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -163,7 +178,7 @@ TEST_F(Iceoryx2DDSGatewayTest, CreatesSubscriberAndDataWriterForOfferedServices) gw.discover(msg); } -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers) +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDiscoveredServices) { // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -183,7 +198,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDetectedPublishers gw.discover(msg); } -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork) +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForDiscoveredServices) { // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -203,7 +218,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersToDDSNetwork gw.discover(msg); } -TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) +TEST_F(Iceoryx2DDSGatewayTest, ForwardsChunkFromSubscriberToDataWriter) { // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -211,96 +226,71 @@ TEST_F(Iceoryx2DDSGatewayTest, ForwardsFromPoshSubscriberToDDSDataWriter) // Prepare a mock mempool chunk ChunkMock mockChunk{42}; - // Set up subscriber to provide this chunk when requested + // Set up subscriber to provide the chunk auto mockSubscriber = createMockSubscriber(testService); - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); + EXPECT_CALL(*mockSubscriber, hasNewChunks).WillOnce(Return(true)); + EXPECT_CALL(*mockSubscriber, getChunk).WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); stageMockSubscriber(std::move(mockSubscriber)); - // We expect one attempt to write the mock chunk to the mock writer + // Verify expected write to the data writer auto mockWriter = createMockDataWriter(testService); EXPECT_CALL(*mockWriter, write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_info.m_payloadSize)) .Times(1); stageMockDataWriter(std::move(mockWriter)); - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); - auto testChannel = createTestChannel(testService); // Keep a copy for use in mutliple mocks + auto testChannel = createTestChannel(testService); TestGateway gw{}; - // Mock methods of the mock generic dds gateway base class - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); - - // Capture the function containing the logic the implementation wants to run and run it on the test channel - // to verify correctness. - EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ - f(testChannel); - }); - // === Test - gw.discover(msg); // Trigger setup of channel with mock subscriber and data writer. - gw.forward(); // Trigger forwarding of mock chunk from mock subscriber to mock data writer. + gw.forward(testChannel); } TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) { + // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); - // Prepare a mock mempool chunk zero size - ChunkMock mockChunk{42}; + // Prepare a mock mempool chunk + ChunkMock mockChunk{0}; mockChunk.chunkHeader()->m_info.m_payloadSize = 0; - // Set up subscriber to provide this chunk when requested + // Set up subscriber to provide the chunk auto mockSubscriber = createMockSubscriber(testService); - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); + EXPECT_CALL(*mockSubscriber, hasNewChunks).WillOnce(Return(true)); + EXPECT_CALL(*mockSubscriber, getChunk).WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); stageMockSubscriber(std::move(mockSubscriber)); - // We expect exactly zero attempts to write to the data writer since the mempool chunk is size zero + // Verify expected write to the data writer auto mockWriter = createMockDataWriter(testService); EXPECT_CALL(*mockWriter, write).Times(Exactly(0)); stageMockDataWriter(std::move(mockWriter)); - TestGateway gw{}; - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); auto testChannel = createTestChannel(testService); - - // Mock methods of the mock generic dds gateway base class - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); - - // Capture the function containing the logic the implementation wants to run and run it on the test channel - // to verify correctness. - EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ - f(testChannel); - }); + TestGateway gw{}; // === Test - gw.discover(msg); - gw.forward(); + gw.forward(testChannel); + } TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) { + // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + // Prepare a mock mempool chunk ChunkMock mockChunk{42}; + // Set up expect sequence of interactions with subscriber and data writer auto mockSubscriber = createMockSubscriber(testService); - ON_CALL(*mockSubscriber, hasNewChunks).WillByDefault(Return(true)); - ON_CALL(*mockSubscriber, getChunk).WillByDefault(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); - auto mockWriter = createMockDataWriter(testService); - { InSequence seq; - EXPECT_CALL(*mockSubscriber, hasNewChunks).Times(1); - EXPECT_CALL(*mockSubscriber, getChunk).Times(1); + EXPECT_CALL(*mockSubscriber, hasNewChunks).WillOnce(Return(true)); + EXPECT_CALL(*mockSubscriber, getChunk).WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); EXPECT_CALL(*mockWriter, write).Times(1); EXPECT_CALL(*mockSubscriber, releaseChunk).Times(1); } @@ -308,23 +298,11 @@ TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) stageMockSubscriber(std::move(mockSubscriber)); stageMockDataWriter(std::move(mockWriter)); - TestGateway gw{}; - auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); auto testChannel = createTestChannel(testService); - - // Mock methods of the mock generic dds gateway base class - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(testChannel)); - - // Capture the function containing the logic the implementation wants to run and run it on the test channel - // to verify correctness. - EXPECT_CALL(gw, forEachChannel).WillOnce([&testChannel](const std::function&)> f){ - f(testChannel); - }); + TestGateway gw{}; // === Test - gw.discover(msg); - gw.forward(); + gw.forward(testChannel); } From 5958deed3fdd8359dbfa8ef1de11d399a0d859ca Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 14:55:39 +0200 Subject: [PATCH 32/55] iox-#65 Fixed expectations in tests. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../test/moduletests/test_iox_to_dds.cpp | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 46a96c1204..346687a381 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -117,6 +117,21 @@ class Iceoryx2DDSGatewayTest : public Test }; // ======================================== Tests ======================================== // +TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForConfiguredServices) +{ + +} + +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromConfiguredServices) +{ + +} + +TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForConfiguredServices) +{ + +} + TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) { // === Setup @@ -146,21 +161,6 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresServiceMessages) gw.discover(msg); } -TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForConfiguredServices) -{ - -} - -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromConfiguredServices) -{ - -} - -TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForConfiguredServices) -{ - -} - TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForDiscoveredServices) { // === Setup @@ -169,10 +169,8 @@ TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForDiscoveredServices) auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); msg.m_subType = iox::capro::CaproMessageSubType::EVENT; - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); - - EXPECT_CALL(gw, addChannel).Times(1); + EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); // === Test gw.discover(msg); @@ -191,8 +189,8 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDiscoveredServices msg.m_subType = iox::capro::CaproMessageSubType::EVENT; // Mock methods of the mock generic dds gateway base class - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); // === Test gw.discover(msg); @@ -211,8 +209,8 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForDiscovere msg.m_subType = iox::capro::CaproMessageSubType::EVENT; // Mock methods of the mock generic dds gateway base class - ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); - ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); // === Test gw.discover(msg); @@ -314,10 +312,6 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop // Subscribers auto firstCreatedSubscriber = createMockSubscriber(testService); auto secondCreatedSubscriber = createMockSubscriber(testService); - ON_CALL(*firstCreatedSubscriber, getServiceDescription) - .WillByDefault(Return(testService)); - ON_CALL(*secondCreatedSubscriber, getServiceDescription) - .WillByDefault(Return(testService)); { InSequence seq; EXPECT_CALL(*firstCreatedSubscriber, subscribe).Times(1); @@ -340,7 +334,6 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop auto testChannelTwo = createTestChannel(testService); TestGateway gw{}; - // EXPECT_CALL is used here because it allows specifying different return values for consecutive calls EXPECT_CALL(gw, findChannel) .WillOnce(Return(iox::cxx::nullopt_t())) .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) From cbd8b4e05da4dfc53eaea8e616e7cc03c1586048 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 14:58:52 +0200 Subject: [PATCH 33/55] iox-#65 Remove redundant run-check flags. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 2 -- .../internal/gateway/dds_gateway_generic.inl | 10 +++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 6096784b8e..9d9bced208 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -110,8 +110,6 @@ class DDSGatewayGeneric : public gateway_t ConcurrentChannelVector m_channels; std::atomic_bool m_isRunning{false}; - std::atomic_bool m_runForwardingLoop{false}; - std::atomic_bool m_runDiscoveryLoop{false}; std::thread m_discoveryThread; std::thread m_forwardingThread; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 10bedd68a9..299f47a8d8 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -43,13 +43,11 @@ inline void iox::dds::DDSGatewayGeneric::shutdown() noexce { iox::dds::LogDebug() << "[DDSGatewayGeneric] Shutting down Posh2DDSGateway."; - m_runDiscoveryLoop.store(false, std::memory_order_relaxed); - m_runForwardingLoop.store(false, std::memory_order_relaxed); + m_isRunning.store(false, std::memory_order_relaxed); m_discoveryThread.join(); m_forwardingThread.join(); - m_isRunning.store(false, std::memory_order_relaxed); } } @@ -132,8 +130,7 @@ template inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept { iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; - m_runDiscoveryLoop.store(true, std::memory_order_relaxed); - while (m_runDiscoveryLoop.load(std::memory_order_relaxed)) + while (m_isRunning.load(std::memory_order_relaxed)) { iox::capro::CaproMessage msg; while (this->getCaProMessage(msg)) @@ -150,8 +147,7 @@ template inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept { iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; - m_runForwardingLoop.store(true, std::memory_order_relaxed); - while (m_runForwardingLoop.load(std::memory_order_relaxed)) + while (m_isRunning.load(std::memory_order_relaxed)) { forEachChannel([this](channel_t channel){ this->forward(channel); From d614f0898f890ef0a00d5d59fc7032358ee13ac8 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 15:12:38 +0200 Subject: [PATCH 34/55] iox-#65 Added test for loading configuration in iceoryx2dds gateway. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../internal/gateway/iox_to_dds.inl | 13 +++-- .../test/moduletests/test_iox_to_dds.cpp | 47 +++++++++++++++++-- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 71c47d8509..5c8c419830 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -39,11 +39,14 @@ inline void Iceoryx2DDSGateway::loadConfiguration(GatewayC iox::LogDebug() << "[Iceoryx2DDSGateway] Configuring gateway."; for(const auto& service : config.m_configuredServices) { - auto channel = this->addChannel(service); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); + if(!this->findChannel(service).has_value()) + { + auto channel = this->addChannel(service); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); + } } } diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 346687a381..aa455fc602 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "mocks/chunk_mock.hpp" @@ -119,17 +120,55 @@ class Iceoryx2DDSGatewayTest : public Test // ======================================== Tests ======================================== // TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForConfiguredServices) { + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + iox::dds::GatewayConfig config{}; + config.m_configuredServices.push_back(testService); + + TestGateway gw{}; + EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); + // === Test + gw.loadConfiguration(config); } TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromConfiguredServices) { + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + iox::dds::GatewayConfig config{}; + config.m_configuredServices.push_back(testService); + + auto mockSubscriber = createMockSubscriber(testService); + EXPECT_CALL(*mockSubscriber, subscribe).Times(1); + stageMockSubscriber(std::move(mockSubscriber)); + + TestGateway gw{}; + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + // === Test + gw.loadConfiguration(config); } TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForConfiguredServices) { + // === Setup + auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); + iox::dds::GatewayConfig config{}; + config.m_configuredServices.push_back(testService); + + auto mockWriter = createMockDataWriter(testService); + EXPECT_CALL(*mockWriter, connect).Times(1); + stageMockDataWriter(std::move(mockWriter)); + TestGateway gw{}; + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); + + // === Test + gw.loadConfiguration(config); } TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) @@ -189,8 +228,8 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelySubscribesToDataFromDiscoveredServices msg.m_subType = iox::capro::CaproMessageSubType::EVENT; // Mock methods of the mock generic dds gateway base class - EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); - EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); // === Test gw.discover(msg); @@ -209,8 +248,8 @@ TEST_F(Iceoryx2DDSGatewayTest, ImmediatelyConnectsCreatedDataWritersForDiscovere msg.m_subType = iox::capro::CaproMessageSubType::EVENT; // Mock methods of the mock generic dds gateway base class - EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::cxx::nullopt_t())); - EXPECT_CALL(gw, addChannel).WillOnce(Return(createTestChannel(testService))); + ON_CALL(gw, findChannel).WillByDefault(Return(iox::cxx::nullopt_t())); + ON_CALL(gw, addChannel).WillByDefault(Return(createTestChannel(testService))); // === Test gw.discover(msg); From e5cc9a84e0bbe812b596d418705486a5431dbb2f Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 15:35:42 +0200 Subject: [PATCH 35/55] iox-#65 Clean up code for PR & run clang format. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/dds/cyclone_data_reader.hpp | 9 ++- .../include/iceoryx_dds/dds/data_reader.hpp | 11 +-- .../include/iceoryx_dds/dds/dds_types.hpp | 1 - .../include/iceoryx_dds/gateway/channel.hpp | 14 ++-- .../gateway/dds_gateway_generic.hpp | 49 ++++++------ .../iceoryx_dds/gateway/dds_to_iox.hpp | 15 ++-- .../iceoryx_dds/gateway/gateway_config.hpp | 13 ++-- .../iceoryx_dds/gateway/iox_to_dds.hpp | 15 ++-- .../iceoryx_dds/internal/gateway/channel.inl | 19 ++--- .../internal/gateway/dds_gateway_generic.inl | 75 ++++++++++--------- .../internal/gateway/dds_to_iox.inl | 12 +-- .../internal/gateway/iox_to_dds.inl | 21 +++--- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 2 +- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 4 +- .../iceoryx_dds/dds/cyclone_data_reader.cpp | 1 - .../helpers/stubbed_dds_gateway_generic.hpp | 13 ++-- iceoryx_dds/test/mocks/google_mocks.hpp | 22 +++--- .../moduletests/test_generic_dds_gateway.cpp | 16 ++-- .../test/moduletests/test_iox_to_dds.cpp | 32 +++----- 19 files changed, 176 insertions(+), 168 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index f8b111afe2..0569c33e52 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -16,12 +16,13 @@ #include "iceoryx_dds/dds/data_reader.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ class CycloneDataReader : DataReader { -public: + public: CycloneDataReader(IdString serviceId, IdString instanceId, IdString eventId) noexcept; }; diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index dc79c5228c..9d47bd2bac 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -16,14 +16,15 @@ #include -namespace iox { -namespace dds { +namespace iox +{ +namespace dds +{ using IdString = iox::cxx::string<100>; template -class DataReader{ - +class DataReader +{ }; - } } diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp index 5a1d21923b..e1e3800f8b 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp @@ -25,7 +25,6 @@ namespace iox { namespace dds { - // Fixed strings using IdString = iox::cxx::string<100>; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 7c95b030d9..184a359d59 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -16,13 +16,14 @@ #include +#include "iceoryx_dds/dds/dds_config.hpp" #include #include -#include "iceoryx_dds/dds/dds_config.hpp" - -namespace iox { -namespace dds{ +namespace iox +{ +namespace dds +{ /// /// @class Channel /// @brief A data structure representing a channel between Iceoryx and DDS. @@ -50,8 +51,7 @@ class Channel using DDSTerminalPtr = std::shared_ptr; using DDSTerminalPool = iox::cxx::ObjectPool; -public: - + public: Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; @@ -67,7 +67,7 @@ class Channel IceoryxTerminalPtr getIceoryxTerminal() const noexcept; DDSTerminalPtr getDDSTerminal() const noexcept; -private: + private: static IceoryxTerminalPool s_iceoryxTerminals; static DDSTerminalPool s_ddsTerminals; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 9d9bced208..5f376c357b 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -14,33 +14,36 @@ #pragma once -#include #include +#include -#include #include #include +#include +#include #include #include -#include #include #include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_dds/gateway/gateway_config.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ +/// +/// @brief Base class for DDS gateways containing common logic used by all implementations. Methods that are expected +/// to differ across implementations are left as pure virtual. +/// template class DDSGatewayGeneric : public gateway_t { - using ChannelFactory = std::function; using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; -public: - + public: virtual ~DDSGatewayGeneric() noexcept; DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; @@ -48,22 +51,28 @@ class DDSGatewayGeneric : public gateway_t DDSGatewayGeneric(DDSGatewayGeneric&&) = delete; DDSGatewayGeneric& operator=(DDSGatewayGeneric&&) = delete; + void runMultithreaded() noexcept; + void shutdown() noexcept; + /// /// @brief loadConfiguration Load the provided configuration. - /// @note This method is virtual pure since different configuration likely to be different across implementations. - /// @param config + /// @param config Generic dds gateway configuration which is applicable to all implementations. /// virtual void loadConfiguration(GatewayConfig config) noexcept = 0; - void runMultithreaded() noexcept; - void shutdown() noexcept; - + /// + /// @brief discover Process discovery messages coming from iceoryx. + /// @param msg The discovery message. + /// virtual void discover(const iox::capro::CaproMessage& msg) noexcept = 0; + /// + /// @brief forward Forward data between the two terminals of the channel used by the implementation. + /// @param channel The channel to propogate data across. + /// virtual void forward(channel_t channel) noexcept = 0; uint64_t getNumberOfChannels() const noexcept; -protected: - + protected: DDSGatewayGeneric() noexcept; ChannelFactory m_channelFactory; @@ -90,14 +99,14 @@ class DDSGatewayGeneric : public gateway_t /// \param service The service to find a channel for. /// \return An optional containining the matching channel if one exists, otherwise an empty optional. /// - iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) const noexcept; /// /// @brief forEachChannel Executs the given function for each channel in the internally stored collection. /// @param f The function to execute. /// @note This operation allows thread-safe access to the internal collection. /// - void forEachChannel(const std::function f) noexcept; + void forEachChannel(const std::function f) const noexcept; /// /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. @@ -105,8 +114,7 @@ class DDSGatewayGeneric : public gateway_t /// void discardChannel(const iox::capro::ServiceDescription& service) noexcept; -private: - + private: ConcurrentChannelVector m_channels; std::atomic_bool m_isRunning{false}; @@ -116,7 +124,6 @@ class DDSGatewayGeneric : public gateway_t void forwardingLoop() noexcept; void discoveryLoop() noexcept; - }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index e9292435f7..8c698fa0cc 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -17,17 +17,22 @@ #include #include "iceoryx_dds/dds/dds_types.hpp" -#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ +/// +/// @brief DDS Gateway implementation for the DDS to iceoryx direction. +/// template > class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric { using ChannelFactory = std::function; -public: + + public: DDS2IceoryxGateway() noexcept; DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; void loadConfiguration(GatewayConfig config) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp index 4c76316247..28692c1be2 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -18,14 +18,17 @@ #include #include -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ +/// +/// @brief Generic configuration for DDS gateways. +/// struct GatewayConfig { -public: + public: iox::cxx::vector m_configuredServices; }; - } } diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 260e4a1aee..52bfd89e29 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -17,18 +17,23 @@ #include #include "iceoryx_dds/dds/dds_types.hpp" -#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ +/// +/// @brief DDS Gateway implementation for the iceoryx to DDS direction. +/// template , typename gateway_t = iox::dds::DDSGatewayGeneric> class Iceoryx2DDSGateway : public gateway_t { using ChannelFactory = std::function; -public: + + public: Iceoryx2DDSGateway() noexcept; void loadConfiguration(GatewayConfig config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 219fc9efdf..991236ca46 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -18,7 +18,6 @@ namespace iox { namespace dds { - // Typedefs template using IceoryxTerminalPool = iox::cxx::ObjectPool; @@ -33,8 +32,8 @@ DDSTerminalPool Channel::s_ddsTermina template inline Channel::Channel(const iox::capro::ServiceDescription& service, - const IceoryxTerminalPtr iceoryxTerminal, - const DDSTerminalPtr ddsTerminal) noexcept + const IceoryxTerminalPtr iceoryxTerminal, + const DDSTerminalPtr ddsTerminal) noexcept : m_service(service), m_iceoryxTerminal(iceoryxTerminal), m_ddsTerminal(ddsTerminal) @@ -44,7 +43,6 @@ inline Channel::Channel(const iox::capro::ServiceD template inline Channel::~Channel() noexcept { - } template @@ -56,7 +54,8 @@ inline Channel::Channel(const Channel -inline Channel& Channel::operator=(const Channel& rhs) noexcept +inline Channel& Channel:: +operator=(const Channel& rhs) noexcept { m_service = rhs.m_service; m_ddsTerminal = rhs.m_ddsTerminal; @@ -72,7 +71,8 @@ inline Channel::Channel(Channel -inline Channel& Channel::operator=(Channel&& rhs) noexcept +inline Channel& Channel:: +operator=(Channel&& rhs) noexcept { m_service = std::move(rhs.m_service); m_ddsTerminal = std::move(rhs.m_ddsTerminal); @@ -85,11 +85,12 @@ Channel::create(const iox::capro::ServiceDescripti { // Create objects in the pool. auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); - auto rawDDSTerminalPtr = s_ddsTerminals.create( - service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); + auto rawDDSTerminalPtr = + s_ddsTerminals.create(service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); // Wrap in smart pointer with custom deleter to ensure automatic cleanup. - auto iceoryxTerminalPtr = IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* p) { s_iceoryxTerminals.free(p); }); + auto iceoryxTerminalPtr = + IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* p) { s_iceoryxTerminals.free(p); }); auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* p) { s_ddsTerminals.free(p); }); return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 299f47a8d8..fe304492c3 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -14,21 +14,21 @@ #include -#include -#include "iceoryx_dds/internal/log/logging.hpp" #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" +#include // ================================================== Public ================================================== // -template +template inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() noexcept { shutdown(); } -template +template inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept { m_discoveryThread = std::thread([this] { discoveryLoop(); }); @@ -36,7 +36,7 @@ inline void iox::dds::DDSGatewayGeneric::runMultithreaded( m_isRunning.store(true, std::memory_order_relaxed); } -template +template inline void iox::dds::DDSGatewayGeneric::shutdown() noexcept { if (m_isRunning.load(std::memory_order_relaxed)) @@ -47,11 +47,10 @@ inline void iox::dds::DDSGatewayGeneric::shutdown() noexce m_discoveryThread.join(); m_forwardingThread.join(); - } } -template +template inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept { auto guardedVector = m_channels.GetScopeGuard(); @@ -60,33 +59,36 @@ inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfCh // ================================================== Protected ================================================== // -template -inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept : gateway_t(iox::capro::Interfaces::DDS) +template +inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() noexcept + : gateway_t(iox::capro::Interfaces::DDS) { - LogDebug() << "[DDSGatewayGeneric] Using default channel factory."; + LogDebug() << "[DDSGatewayGeneric] Using default channel factory."; m_channelFactory = channel_t::create; } -template -inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline channel_t +iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { auto channel = m_channelFactory(service); m_channels->push_back(channel); iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); return channel; } -template -inline iox::cxx::optional iox::dds::DDSGatewayGeneric::findChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline iox::cxx::optional +iox::dds::DDSGatewayGeneric::findChannel(const iox::capro::ServiceDescription& service) const + noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); - auto channel = std::find_if( - guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { - return channel.getService() == service; - }); - if(channel == guardedVector->end()) + auto channel = std::find_if(guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { + return channel.getService() == service; + }); + if (channel == guardedVector->end()) { return iox::cxx::nullopt_t(); } @@ -97,8 +99,10 @@ inline iox::cxx::optional iox::dds::DDSGatewayGeneric -inline void iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) noexcept +template +inline void +iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) const + noexcept { auto guardedVector = m_channels.GetScopeGuard(); for (auto channel = guardedVector->begin(); channel != guardedVector->end(); ++channel) @@ -107,26 +111,26 @@ inline void iox::dds::DDSGatewayGeneric::forEachChannel(co } } -template -inline void iox::dds::DDSGatewayGeneric::discardChannel(const iox::capro::ServiceDescription& service) noexcept +template +inline void iox::dds::DDSGatewayGeneric::discardChannel( + const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); - auto channel = std::find_if( - guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { - return channel.getService() == service; - }); + auto channel = std::find_if(guardedVector->begin(), guardedVector->end(), [&service](const channel_t& channel) { + return channel.getService() == service; + }); if (channel != guardedVector->end()) { guardedVector->erase(channel); iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); } } // ================================================== Private ================================================== // -template +template inline void iox::dds::DDSGatewayGeneric::discoveryLoop() noexcept { iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting discovery."; @@ -143,18 +147,15 @@ inline void iox::dds::DDSGatewayGeneric::discoveryLoop() n iox::dds::LogDebug() << "[DDSGatewayGeneric] Stopped discovery."; } -template +template inline void iox::dds::DDSGatewayGeneric::forwardingLoop() noexcept { iox::dds::LogDebug() << "[DDSGatewayGeneric] Starting forwarding."; while (m_isRunning.load(std::memory_order_relaxed)) { - forEachChannel([this](channel_t channel){ - this->forward(channel); - }); + forEachChannel([this](channel_t channel) { this->forward(channel); }); std::this_thread::sleep_until(std::chrono::steady_clock::now() + std::chrono::milliseconds(FORWARDING_PERIOD.milliSeconds())); }; iox::dds::LogDebug() << "[DDSGatewayGeneric] Stopped forwarding."; } - diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index b577643230..337ff8a5ca 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -20,16 +20,16 @@ #include "iceoryx_dds/gateway/dds_to_iox.hpp" #include "iceoryx_dds/internal/log/logging.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ template -inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept - : iox::dds::DDSGatewayGeneric() +inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept : iox::dds::DDSGatewayGeneric() { } -template +template inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) noexcept { } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 5c8c419830..7ce255362d 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -17,29 +17,29 @@ #include -#include "iceoryx_dds/internal/log/logging.hpp" #include "iceoryx_dds/gateway/iox_to_dds.hpp" +#include "iceoryx_dds/internal/log/logging.hpp" namespace iox { namespace dds { - -//template -//using ChannelFactory = std::function; +// template +// using ChannelFactory = std::function; // ======================================== Public ======================================== // template inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : gateway_t() -{} +{ +} template inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] Configuring gateway."; - for(const auto& service : config.m_configuredServices) + for (const auto& service : config.m_configuredServices) { - if(!this->findChannel(service).has_value()) + if (!this->findChannel(service).has_value()) { auto channel = this->addChannel(service); auto subscriber = channel.getIceoryxTerminal(); @@ -52,8 +52,7 @@ inline void Iceoryx2DDSGateway::loadConfiguration(GatewayC template -inline void -Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept +inline void Iceoryx2DDSGateway::discover(const iox::capro::CaproMessage& msg) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] " << iox::capro::CaproMessageTypeString[static_cast(msg.m_type)] @@ -74,7 +73,7 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessag { case iox::capro::CaproMessageType::OFFER: { - if(!this->findChannel(msg.m_serviceDescription).has_value()) + if (!this->findChannel(msg.m_serviceDescription).has_value()) { auto channel = this->addChannel(msg.m_serviceDescription); auto subscriber = channel.getIceoryxTerminal(); @@ -86,7 +85,7 @@ Iceoryx2DDSGateway::discover(const iox::capro::CaproMessag } case iox::capro::CaproMessageType::STOP_OFFER: { - if(this->findChannel(msg.m_serviceDescription).has_value()) + if (this->findChannel(msg.m_serviceDescription).has_value()) { this->discardChannel(msg.m_serviceDescription); } diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index cedfa474f0..ac9d14d063 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -25,7 +25,7 @@ class ShutdownManager }; iox::posix::Semaphore ShutdownManager::s_semaphore = iox::posix::Semaphore::create(0u).get_value(); -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { // Set OS signal handlers signal(SIGINT, ShutdownManager::scheduleShutdown); diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 846c85e5a6..8c96d6c32f 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -14,12 +14,12 @@ #include +#include +#include #include #include #include #include -#include -#include class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp index ff95956c3a..f402658e8b 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_reader.cpp @@ -16,5 +16,4 @@ iox::dds::CycloneDataReader::CycloneDataReader(IdString serviceId, IdString instanceId, IdString eventId) noexcept { - } diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 8f01eb921a..700717314c 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -18,9 +18,10 @@ #include "mocks/google_mocks.hpp" -namespace iox { -namespace dds { - +namespace iox +{ +namespace dds +{ template using TestDDSGatewayGeneric = iox::dds::DDSGatewayGeneric; @@ -32,9 +33,7 @@ using TestDDSGatewayGeneric = iox::dds::DDSGatewayGeneric class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric { - -public: - + public: virtual void loadConfiguration(GatewayConfig config) noexcept { // Stubbed. @@ -69,8 +68,6 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric { TestDDSGatewayGeneric::discardChannel(service); } - }; - } } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index bac08f5df1..391c8f1fdc 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -1,11 +1,11 @@ #pragma once #include "test.hpp" +#include +#include #include #include #include -#include -#include using namespace ::testing; using ::testing::_; @@ -46,12 +46,14 @@ class MockDataWriter : public iox::dds::DataWriter class MockGenericDDSGateway { -public: - MockGenericDDSGateway(){}; - MockGenericDDSGateway(const iox::capro::Interfaces i){}; - MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(forEachChannel, void(const std::function&)>)); + public: + MockGenericDDSGateway(){}; + MockGenericDDSGateway(const iox::capro::Interfaces i){}; + MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); + MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); + MOCK_METHOD1( + findChannel, + iox::cxx::optional>(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(forEachChannel, void(const std::function&)>)); }; diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index ffc2658e12..5f5406a537 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -10,11 +10,13 @@ using ::testing::_; // ======================================== Helpers ======================================== // // We do not need real channel terminals to test the base class. -struct StubbedIceoryxTerminal{ +struct StubbedIceoryxTerminal +{ StubbedIceoryxTerminal(iox::capro::ServiceDescription sd){}; }; -struct StubbedDDSTerminal{ +struct StubbedDDSTerminal +{ StubbedDDSTerminal(iox::dds::IdString sid, iox::dds::IdString iid, iox::dds::IdString eid){}; }; @@ -41,7 +43,6 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) gw.addChannel(testService); EXPECT_EQ(1, gw.getNumberOfChannels()); - } TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) @@ -56,7 +57,6 @@ TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) EXPECT_EQ(1, gw.getNumberOfChannels()); gw.discardChannel(testService); EXPECT_EQ(0, gw.getNumberOfChannels()); - } TEST_F(DDSGatewayGenericTest, FindChannelReturnsCopyOfFoundChannel) @@ -70,11 +70,10 @@ TEST_F(DDSGatewayGenericTest, FindChannelReturnsCopyOfFoundChannel) gw.addChannel(testService); auto foundChannel = gw.findChannel(testService); EXPECT_EQ(true, foundChannel.has_value()); - if(foundChannel.has_value()) + if (foundChannel.has_value()) { EXPECT_EQ(testService, foundChannel.value().getService()); } - } TEST_F(DDSGatewayGenericTest, FindChannelGivesEmptyOptionalIfNoneFound) @@ -99,9 +98,7 @@ TEST_F(DDSGatewayGenericTest, ForEachChannelExecutesGivenFunctionForAllStoredCha auto testServiceC = iox::capro::ServiceDescription("serviceC", "instanceC", "eventC"); auto count = 0u; - auto f = [&count](TestChannel& channel){ - count++; - }; + auto f = [&count](TestChannel& channel) { count++; }; TestDDSGatewayGeneric gw{}; @@ -112,5 +109,4 @@ TEST_F(DDSGatewayGenericTest, ForEachChannelExecutesGivenFunctionForAllStoredCha gw.forEachChannel(f); EXPECT_EQ(3, count); - } diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index aa455fc602..8c1721aead 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -14,13 +14,13 @@ #include -#include -#include -#include #include #include #include #include +#include +#include +#include #include "mocks/chunk_mock.hpp" #include "mocks/google_mocks.hpp" @@ -35,7 +35,8 @@ using ::testing::InSequence; // ======================================== Helpers ======================================== // -using TestGateway = iox::dds::Iceoryx2DDSGateway, MockGenericDDSGateway>; +using TestGateway = + iox::dds::Iceoryx2DDSGateway, MockGenericDDSGateway>; // Holds mocks created by tests to be returned by mock factories. static std::vector> stagedMockSubscribers; @@ -285,7 +286,6 @@ TEST_F(Iceoryx2DDSGatewayTest, ForwardsChunkFromSubscriberToDataWriter) TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) { - // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -309,12 +309,10 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) // === Test gw.forward(testChannel); - } TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) { - // === Setup auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); @@ -340,7 +338,6 @@ TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) // === Test gw.forward(testChannel); - } TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) @@ -361,11 +358,9 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop stageMockSubscriber(std::move(secondCreatedSubscriber)); // Messages - auto offerMsg = - iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); + auto offerMsg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); offerMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; - auto stopOfferMsg = - iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, testService); + auto stopOfferMsg = iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, testService); stopOfferMsg.m_subType = iox::capro::CaproMessageSubType::EVENT; // Get the test channels here as we need to use them in expectations @@ -374,14 +369,11 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop TestGateway gw{}; EXPECT_CALL(gw, findChannel) - .WillOnce(Return(iox::cxx::nullopt_t())) - .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) - .WillOnce(Return(iox::cxx::nullopt_t())); - EXPECT_CALL(gw, addChannel) - .WillOnce(Return(testChannelOne)) - .WillOnce(Return(testChannelTwo)); - EXPECT_CALL(gw, discardChannel) - .Times(1); + .WillOnce(Return(iox::cxx::nullopt_t())) + .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) + .WillOnce(Return(iox::cxx::nullopt_t())); + EXPECT_CALL(gw, addChannel).WillOnce(Return(testChannelOne)).WillOnce(Return(testChannelTwo)); + EXPECT_CALL(gw, discardChannel).Times(1); // === Test gw.discover(offerMsg); From a93d7e519a6382561168588b6ba765b8e79e8135 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Sun, 7 Jun 2020 15:40:13 +0200 Subject: [PATCH 36/55] iox-#65 Clean up code for PR & run clang format. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/dds_gateway_generic.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 5f376c357b..1f448cf931 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -89,15 +89,15 @@ class DDSGatewayGeneric : public gateway_t /// the custom deleters included in their pointers. /// /// The service description is perhaps too large for copying since they contain strings, however this should be - /// addressed with the service description repository feature. + /// addressed with a service description repository feature. /// channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns /// it one exists. - /// \param service The service to find a channel for. - /// \return An optional containining the matching channel if one exists, otherwise an empty optional. + /// @param service The service to find a channel for. + /// @return An optional containining the matching channel if one exists, otherwise an empty optional. /// iox::cxx::optional findChannel(const iox::capro::ServiceDescription& service) const noexcept; From 3ef39c84936bb720781a215487b115b640f4fbfe Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 10 Jun 2020 12:30:37 +0200 Subject: [PATCH 37/55] iox-#65 Change to include guards. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/dds/cyclone_data_reader.hpp | 5 ++++- .../include/iceoryx_dds/dds/cyclone_data_writer.hpp | 7 ++++--- iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp | 5 ++++- iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp | 9 +++++---- iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp | 5 ++++- iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp | 7 ++++--- iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp | 5 ++++- .../include/iceoryx_dds/gateway/dds_gateway_generic.hpp | 5 ++++- iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp | 5 ++++- .../include/iceoryx_dds/gateway/gateway_config.hpp | 5 ++++- iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp | 5 ++++- .../include/iceoryx_dds/internal/gateway/channel.inl | 2 -- .../iceoryx_dds/internal/gateway/dds_gateway_generic.inl | 1 - .../include/iceoryx_dds/internal/gateway/dds_to_iox.inl | 1 - .../include/iceoryx_dds/internal/gateway/iox_to_dds.inl | 1 - iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp | 7 ++++--- 16 files changed, 49 insertions(+), 26 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index 0569c33e52..24471dd06b 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_DDS_CYCLONE_DATA_READER_HPP +#define IOX_DDS_DDS_CYCLONE_DATA_READER_HPP #include "iceoryx_dds/dds/data_reader.hpp" @@ -28,3 +29,5 @@ class CycloneDataReader : DataReader } // namespace dds } // namespace iox + +#endif // IOX_DDS_DDS_CYCLONE_DATA_READER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index f00430c3bc..8545b74907 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -11,8 +11,9 @@ // 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. -#ifndef IOX_DDS_GATEWAY_DDS_CYCLONE_DATA_WRITER_HPP -#define IOX_DDS_GATEWAY_DDS_CYCLONE_DATA_WRITER_HPP + +#ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP +#define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP #include #include @@ -61,4 +62,4 @@ class CycloneDataWriter : public iox::dds::DataWriter } // namespace dds } // namespace iox -#endif // IOX_DDS_GATEWAY_DDS_CYCLONE_DATA_WRITER_HPP +#endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index 9d47bd2bac..d20c7ff22b 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_DDS_DATA_READER_HPP +#define IOX_DDS_DDS_DATA_READER_HPP #include @@ -28,3 +29,5 @@ class DataReader }; } } + +#endif // IOX_DDS_DDS_DATA_READER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp index 942b969ac0..cdeb142e19 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp @@ -11,8 +11,9 @@ // 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. -#ifndef IOX_DDS_GATEWAY_DDS_DATA_WRITER_HPP -#define IOX_DDS_GATEWAY_DDS_DATA_WRITER_HPP + +#ifndef IOX_DDS_DDS_DATA_WRITER_HPP +#define IOX_DDS_DDS_DATA_WRITER_HPP #include @@ -72,6 +73,6 @@ class DataWriter } // namespace dds } // namespace iox -#include "ioxdds/internal/dds/data_writer.inl" +#include "iceoryx_dds/internal/dds/data_writer.inl" -#endif // IOX_DDS_GATEWAY_DDS_DATA_WRITER_HPP +#endif // IOX_DDS_DDS_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index 96954a11a9..7f8e34d7ae 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_DDS_CONFIG_HPP +#define IOX_DDS_DDS_CONFIG_HPP #include @@ -27,3 +28,5 @@ static constexpr uint32_t MAX_CHANNEL_NUMBER = iox::MAX_PORT_NUMBER; } // namespace dds } // namespace iox + +#endif // IOX_DDS_DDS_CONFIG_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp index 004e5e3025..86ada6df10 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp @@ -11,8 +11,9 @@ // 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. -#ifndef IOX_DDS_GATEWAY_DDS_DDS_TYPES_HPP -#define IOX_DDS_GATEWAY_DDS_DDS_TYPES_HPP + +#ifndef IOX_DDS_DDS_DDS_TYPES_HPP +#define IOX_DDS_DDS_DDS_TYPES_HPP #ifdef USE_CYCLONE_DDS #include "iceoryx_dds/dds/cyclone_data_reader.hpp" @@ -38,4 +39,4 @@ using data_writer_t = iox::dds::CycloneDataWriter; } } -#endif // IOX_DDS_GATEWAY_DDS_DDS_TYPES_HPP +#endif // IOX_DDS_DDS_DDS_TYPES_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 184a359d59..e073b25fbc 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_GATEWAY_CHANNEL_HPP +#define IOX_DDS_GATEWAY_CHANNEL_HPP #include @@ -80,3 +81,5 @@ class Channel } // namespace iox #include "iceoryx_dds/internal/gateway/channel.inl" + +#endif // IOX_DDS_DDS_DDS_TYPES_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 1f448cf931..951f0ef57c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP +#define IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP #include #include @@ -130,3 +131,5 @@ class DDSGatewayGeneric : public gateway_t } // namespace iox #include "iceoryx_dds/internal/gateway/dds_gateway_generic.inl" + +#endif // IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 8c698fa0cc..0b02c59735 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_GATEWAY_DDS_TO_IOX_HPP +#define IOX_DDS_GATEWAY_DDS_TO_IOX_HPP #include @@ -44,3 +45,5 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric } // namespace iox #include "iceoryx_dds/internal/gateway/dds_to_iox.inl" + +#endif // IOX_DDS_GATEWAY_DDS_TO_IOX_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp index 28692c1be2..11b40be5e1 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP +#define IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP #include #include @@ -32,3 +33,5 @@ struct GatewayConfig }; } } + +#endif // IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 52bfd89e29..7d45a84cc4 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#pragma once +#ifndef IOX_DDS_GATEWAY_IOX_TO_DDS_HPP +#define IOX_DDS_GATEWAY_IOX_TO_DDS_HPP #include @@ -44,3 +45,5 @@ class Iceoryx2DDSGateway : public gateway_t } // namespace iox #include "iceoryx_dds/internal/gateway/iox_to_dds.inl" + +#endif // IOX_DDS_GATEWAY_IOX_TO_DDS_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 991236ca46..f497513637 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "iceoryx_dds/gateway/channel.hpp" - namespace iox { namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index fe304492c3..956060cd40 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -15,7 +15,6 @@ #include #include "iceoryx_dds/dds/dds_types.hpp" -#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "iceoryx_dds/internal/log/logging.hpp" #include diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index 337ff8a5ca..4327809a0c 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -17,7 +17,6 @@ #include #include -#include "iceoryx_dds/gateway/dds_to_iox.hpp" #include "iceoryx_dds/internal/log/logging.hpp" namespace iox diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 7ce255362d..c8dc428d5e 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -17,7 +17,6 @@ #include -#include "iceoryx_dds/gateway/iox_to_dds.hpp" #include "iceoryx_dds/internal/log/logging.hpp" namespace iox diff --git a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp index fadd241e71..188edea6e7 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp +++ b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp @@ -11,8 +11,9 @@ // 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. -#ifndef IOX_DDS_GATEWAY_LOG_LOGGING_HPP -#define IOX_DDS_GATEWAY_LOG_LOGGING_HPP + +#ifndef IOX_DDS_LOG_LOGGING_HPP +#define IOX_DDS_LOG_LOGGING_HPP #include @@ -36,4 +37,4 @@ static constexpr auto LogVerbose = iox::log::ffbb::LogVerbose Date: Tue, 16 Jun 2020 15:00:38 +0200 Subject: [PATCH 38/55] iox-#65 Code cleanliness fixes. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds/CMakeLists.txt | 4 ++-- .../include/iceoryx_dds/dds/data_reader.hpp | 2 +- iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp | 2 +- iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp | 2 +- .../include/iceoryx_dds/gateway/channel.hpp | 2 +- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 4 ++-- .../include/iceoryx_dds/gateway/dds_to_iox.hpp | 4 ++-- .../include/iceoryx_dds/gateway/iox_to_dds.hpp | 4 ++-- .../iceoryx_dds/internal/gateway/channel.inl | 9 ++------- .../internal/gateway/dds_gateway_generic.inl | 8 +++----- .../iceoryx_dds/internal/gateway/dds_to_iox.inl | 4 ++-- .../iceoryx_dds/internal/gateway/iox_to_dds.inl | 6 ++---- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 14 ++++++++++++++ iceoryx_dds/test/mocks/google_mocks.hpp | 5 ++++- 14 files changed, 39 insertions(+), 31 deletions(-) diff --git a/iceoryx_dds/CMakeLists.txt b/iceoryx_dds/CMakeLists.txt index 792de7ec42..0c3adc7608 100644 --- a/iceoryx_dds/CMakeLists.txt +++ b/iceoryx_dds/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) -set(iceoryx_dds_VERSION 0.1.0) -project(iceoryx_dds VERSION ${iceoryx_dds_VERSION}) +file (STRINGS "../VERSION" iceoryx_dds_VERSION) +project(iceoryx_posh VERSION ${iceoryx_dds_VERSION}) option(BUILD_TESTS "build test binaries") diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index d20c7ff22b..f7ad1df217 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -21,7 +21,7 @@ namespace iox { namespace dds { -using IdString = iox::cxx::string<100>; +using IdString = iox::cxx::string<100u>; template class DataReader diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index 7f8e34d7ae..f52f5040de 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -23,7 +23,7 @@ namespace dds { static constexpr units::Duration DISCOVERY_PERIOD = 1000_ms; static constexpr units::Duration FORWARDING_PERIOD = 50_ms; -static constexpr uint32_t SUBSCRIBER_CACHE_SIZE = 128; +static constexpr uint32_t SUBSCRIBER_CACHE_SIZE = 128u; static constexpr uint32_t MAX_CHANNEL_NUMBER = iox::MAX_PORT_NUMBER; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp index 86ada6df10..d50132d9b0 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp @@ -27,7 +27,7 @@ namespace iox namespace dds { // Fixed strings -using IdString = iox::cxx::string<100>; +using IdString = iox::cxx::string<100u>; // DDS implementation defined with compiler flags #ifdef USE_CYCLONE_DDS diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index e073b25fbc..dab24db462 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -56,7 +56,7 @@ class Channel Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; - ~Channel() noexcept; + ~Channel() noexcept = default; Channel(const Channel&) noexcept; Channel& operator=(const Channel&) noexcept; Channel(Channel&&) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 951f0ef57c..333eeacdd2 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -59,7 +59,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief loadConfiguration Load the provided configuration. /// @param config Generic dds gateway configuration which is applicable to all implementations. /// - virtual void loadConfiguration(GatewayConfig config) noexcept = 0; + virtual void loadConfiguration(const GatewayConfig& config) noexcept = 0; /// /// @brief discover Process discovery messages coming from iceoryx. /// @param msg The discovery message. @@ -69,7 +69,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief forward Forward data between the two terminals of the channel used by the implementation. /// @param channel The channel to propogate data across. /// - virtual void forward(channel_t channel) noexcept = 0; + virtual void forward(const channel_t& channel) noexcept = 0; uint64_t getNumberOfChannels() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 0b02c59735..8e5ddbce84 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -36,9 +36,9 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric public: DDS2IceoryxGateway() noexcept; DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; - void loadConfiguration(GatewayConfig config) noexcept; + void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward(channel_t channel) noexcept; + void forward(const channel_t& channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 7d45a84cc4..6b262de3a8 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -36,9 +36,9 @@ class Iceoryx2DDSGateway : public gateway_t public: Iceoryx2DDSGateway() noexcept; - void loadConfiguration(GatewayConfig config) noexcept; + void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward(channel_t channel) noexcept; + void forward(const channel_t& channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index f497513637..ad6c000421 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -38,11 +38,6 @@ inline Channel::Channel(const iox::capro::ServiceD { } -template -inline Channel::~Channel() noexcept -{ -} - template inline Channel::Channel(const Channel& rhs) noexcept { @@ -88,8 +83,8 @@ Channel::create(const iox::capro::ServiceDescripti // Wrap in smart pointer with custom deleter to ensure automatic cleanup. auto iceoryxTerminalPtr = - IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* p) { s_iceoryxTerminals.free(p); }); - auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* p) { s_ddsTerminals.free(p); }); + IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* const p) { s_iceoryxTerminals.free(p); }); + auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* const p) { s_ddsTerminals.free(p); }); return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 956060cd40..6f4db9257a 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -30,8 +30,8 @@ inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() n template inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept { - m_discoveryThread = std::thread([this] { discoveryLoop(); }); - m_forwardingThread = std::thread([this] { forwardingLoop(); }); + m_discoveryThread = std::thread([this] { this->discoveryLoop(); }); + m_forwardingThread = std::thread([this] { this->forwardingLoop(); }); m_isRunning.store(true, std::memory_order_relaxed); } @@ -52,8 +52,7 @@ inline void iox::dds::DDSGatewayGeneric::shutdown() noexce template inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept { - auto guardedVector = m_channels.GetScopeGuard(); - return guardedVector->size(); + return m_channels->size(); } // ================================================== Protected ================================================== // @@ -93,7 +92,6 @@ iox::dds::DDSGatewayGeneric::findChannel(const iox::capro: } else { - // Needs to be dereferenced since the smart lock returns pointers to elements in concurrent collections. return iox::cxx::make_optional(*channel); } } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index 4327809a0c..2c04e276c8 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -29,7 +29,7 @@ inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept : iox::dds:: } template -inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) noexcept +inline void DDS2IceoryxGateway::loadConfiguration(const GatewayConfig& config) noexcept { } @@ -40,7 +40,7 @@ inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessa } template -inline void DDS2IceoryxGateway::forward(channel_t channel) noexcept +inline void DDS2IceoryxGateway::forward(const channel_t& channel) noexcept { } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index c8dc428d5e..6990b2498f 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -23,8 +23,6 @@ namespace iox { namespace dds { -// template -// using ChannelFactory = std::function; // ======================================== Public ======================================== // template @@ -33,7 +31,7 @@ inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : } template -inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) noexcept +inline void Iceoryx2DDSGateway::loadConfiguration(const GatewayConfig& config) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] Configuring gateway."; for (const auto& service : config.m_configuredServices) @@ -98,7 +96,7 @@ inline void Iceoryx2DDSGateway::discover(const iox::capro: } template -inline void Iceoryx2DDSGateway::forward(channel_t channel) noexcept +inline void Iceoryx2DDSGateway::forward(const channel_t& channel) noexcept { auto subscriber = channel.getIceoryxTerminal(); if (subscriber->hasNewChunks()) diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index ac9d14d063..e5c7e8256a 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #include #include diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 391c8f1fdc..1d30c7288f 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP +#define IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP #include "test.hpp" #include @@ -57,3 +58,5 @@ class MockGenericDDSGateway iox::cxx::optional>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(forEachChannel, void(const std::function&)>)); }; + +#endif // IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP From 9a7b977d58907cbdc3cf3fa74402a5159c97910b Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 09:17:43 +0200 Subject: [PATCH 39/55] iox-#65 Fixed header organization. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/dds/cyclone_data_writer.hpp | 3 +- .../dds/cyclone_data_writer.hpp.autosave | 66 +++++++++++++++++++ .../include/iceoryx_dds/dds/data_reader.hpp | 2 +- .../include/iceoryx_dds/dds/data_writer.hpp | 4 +- .../include/iceoryx_dds/dds/dds_config.hpp | 2 +- .../include/iceoryx_dds/gateway/channel.hpp | 8 +-- .../gateway/dds_gateway_generic.hpp | 21 +++--- .../iceoryx_dds/gateway/dds_to_iox.hpp | 3 +- .../iceoryx_dds/gateway/gateway_config.hpp | 6 +- .../iceoryx_dds/gateway/iox_to_dds.hpp | 3 +- .../internal/gateway/dds_gateway_generic.inl | 4 +- .../internal/gateway/dds_to_iox.inl | 7 +- .../internal/gateway/iox_to_dds.inl | 7 +- .../iceoryx_dds/internal/log/logging.hpp | 2 +- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 8 +-- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 12 ++-- .../iceoryx_dds/dds/cyclone_data_writer.cpp | 8 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 10 +-- 18 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index 8545b74907..6c70dc0c4d 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -15,10 +15,11 @@ #ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP #define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP +#include "iceoryx_dds/dds/data_writer.hpp" + #include #include -#include "iceoryx_dds/dds/data_writer.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave new file mode 100644 index 0000000000..16838a6da7 --- /dev/null +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave @@ -0,0 +1,66 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + +#ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP +#define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP + +#include "iceoryx_dds/dds/data_writer.hpp" + +#include +#include + + +namespace iox +{ +namespace dds +{ +/// +/// @brief Implementation of the DataWriter interface using the cyclonedds implementation. +/// +class CycloneDataWriter : public iox::dds::DataWriter +{ + public: + CycloneDataWriter() = delete; + CycloneDataWriter(const IdString serviceId, const IdString instanceId, const IdString eventId); + virtual ~CycloneDataWriter(); + + CycloneDataWriter(const CycloneDataWriter&) = delete; + CycloneDataWriter& operator=(const CycloneDataWriter&) = delete; + + // Required for vector + CycloneDataWriter(CycloneDataWriter&&) = default; + CycloneDataWriter& operator=(CycloneDataWriter&&) = default; + + void connect() noexcept; + void write(const uint8_t* const bytes, const uint64_t size) noexcept; + std::string getServiceId() const noexcept; + std::string getInstanceId() const noexcept; + std::string getEventId() const noexcept; + + private: + IdString m_serviceId{""}; + IdString m_instanceId{""}; + IdString m_eventId{""}; + + ::dds::pub::Publisher m_publisher = ::dds::core::null; + ::dds::topic::Topic m_topic = ::dds::core::null; + ::dds::pub::DataWriter m_writer = ::dds::core::null; + + static ::dds::domain::DomainParticipant& getParticipant() noexcept; +}; + +} // namespace dds +} // namespace iox + +#endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index f7ad1df217..2acca09135 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_DDS_DATA_READER_HPP #define IOX_DDS_DDS_DATA_READER_HPP -#include +#include "iceoryx_utils/cxx/string.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp index cdeb142e19..165f1e4e8a 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp @@ -15,9 +15,9 @@ #ifndef IOX_DDS_DDS_DATA_WRITER_HPP #define IOX_DDS_DDS_DATA_WRITER_HPP -#include +#include "iceoryx_utils/cxx/string.hpp" -#include +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index f52f5040de..a543261221 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_DDS_CONFIG_HPP #define IOX_DDS_DDS_CONFIG_HPP -#include +#include "iceoryx_posh/iceoryx_posh_types.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index dab24db462..2e3957ea46 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -15,11 +15,11 @@ #ifndef IOX_DDS_GATEWAY_CHANNEL_HPP #define IOX_DDS_GATEWAY_CHANNEL_HPP -#include - #include "iceoryx_dds/dds/dds_config.hpp" -#include -#include +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/internal/objectpool/objectpool.hpp" + +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 333eeacdd2..fda2b17a27 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -15,19 +15,18 @@ #ifndef IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP #define IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/popo/gateway_generic.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/string.hpp" +#include "iceoryx_utils/cxx/vector.hpp" +#include "iceoryx_utils/internal/concurrent/smart_lock.hpp" + +#include +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 8e5ddbce84..149730dec1 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -15,11 +15,10 @@ #ifndef IOX_DDS_GATEWAY_DDS_TO_IOX_HPP #define IOX_DDS_GATEWAY_DDS_TO_IOX_HPP -#include - #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/channel.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_posh/popo/publisher.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp index 11b40be5e1..182845823c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -15,9 +15,9 @@ #ifndef IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP #define IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP -#include -#include -#include +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_utils/cxx/vector.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 6b262de3a8..0152f47634 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -15,11 +15,10 @@ #ifndef IOX_DDS_GATEWAY_IOX_TO_DDS_HPP #define IOX_DDS_GATEWAY_IOX_TO_DDS_HPP -#include - #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/channel.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_posh/popo/subscriber.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 6f4db9257a..a945ac306d 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -12,12 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/internal/log/logging.hpp" -#include - +#include "iceoryx_utils/internal/file_reader/file_reader.hpp" // ================================================== Public ================================================== // diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index 2c04e276c8..7aedc41ad3 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -12,12 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - -#include -#include - #include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/cxx/string.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 6990b2498f..14f0db89c4 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" + #include #include -#include - -#include "iceoryx_dds/internal/log/logging.hpp" - namespace iox { namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp index 188edea6e7..8a059d7815 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp +++ b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_LOG_LOGGING_HPP #define IOX_DDS_LOG_LOGGING_HPP -#include +#include "iceoryx_utils/log/logging_free_function_building_block.hpp" namespace iox { diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index e5c7e8256a..018b3b2d09 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - -#include -#include #include "iceoryx_dds/gateway/dds_to_iox.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_utils/posix_wrapper/semaphore.hpp" + +#include class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 8c96d6c32f..f74bf5c15f 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -14,12 +14,12 @@ #include -#include -#include -#include -#include -#include -#include +#include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_dds/gateway/iox_to_dds.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_utils/cxx/helplets.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/posix_wrapper/semaphore.hpp" class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp index 270db3130b..b561ae2a22 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include - #include "Mempool_DCPS.hpp" #include "iceoryx_dds/dds/cyclone_data_writer.hpp" #include "iceoryx_dds/internal/log/logging.hpp" +#include +#include +#include + iox::dds::CycloneDataWriter::CycloneDataWriter(IdString serviceId, IdString instanceId, IdString eventId) : m_serviceId(serviceId) , m_instanceId(instanceId) diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 1d30c7288f..4b36a6d1b6 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -2,11 +2,11 @@ #define IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP #include "test.hpp" -#include -#include -#include -#include -#include +#include "iceoryx_dds/dds/data_writer.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_posh/internal/capro/capro_message.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iceoryx_utils/cxx/optional.hpp" using namespace ::testing; using ::testing::_; From e7ee7c647b520949021a89d857fb52391ccdea39 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 11:28:55 +0200 Subject: [PATCH 40/55] iox-#65 Change std::function to cxx::function_ref where possible Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds/CMakeLists.txt | 2 +- .../iceoryx_dds/dds/cyclone_data_reader.hpp | 2 + .../iceoryx_dds/dds/cyclone_data_writer.hpp | 2 +- .../dds/cyclone_data_writer.hpp.autosave | 66 ------------------- .../include/iceoryx_dds/dds/data_reader.hpp | 1 + .../gateway/dds_gateway_generic.hpp | 3 +- .../internal/gateway/dds_gateway_generic.inl | 2 +- .../helpers/stubbed_dds_gateway_generic.hpp | 10 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 3 +- 9 files changed, 15 insertions(+), 76 deletions(-) delete mode 100644 iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave diff --git a/iceoryx_dds/CMakeLists.txt b/iceoryx_dds/CMakeLists.txt index 0c3adc7608..74a37b7dd9 100644 --- a/iceoryx_dds/CMakeLists.txt +++ b/iceoryx_dds/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) file (STRINGS "../VERSION" iceoryx_dds_VERSION) -project(iceoryx_posh VERSION ${iceoryx_dds_VERSION}) +project(iceoryx_dds VERSION ${iceoryx_dds_VERSION}) option(BUILD_TESTS "build test binaries") diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index 24471dd06b..7d8cee5d38 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -21,6 +21,8 @@ namespace iox { namespace dds { + +/// @note Implementation coming soon. class CycloneDataReader : DataReader { public: diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index 6c70dc0c4d..16838a6da7 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -17,8 +17,8 @@ #include "iceoryx_dds/dds/data_writer.hpp" -#include #include +#include namespace iox diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave deleted file mode 100644 index 16838a6da7..0000000000 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -#ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP -#define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP - -#include "iceoryx_dds/dds/data_writer.hpp" - -#include -#include - - -namespace iox -{ -namespace dds -{ -/// -/// @brief Implementation of the DataWriter interface using the cyclonedds implementation. -/// -class CycloneDataWriter : public iox::dds::DataWriter -{ - public: - CycloneDataWriter() = delete; - CycloneDataWriter(const IdString serviceId, const IdString instanceId, const IdString eventId); - virtual ~CycloneDataWriter(); - - CycloneDataWriter(const CycloneDataWriter&) = delete; - CycloneDataWriter& operator=(const CycloneDataWriter&) = delete; - - // Required for vector - CycloneDataWriter(CycloneDataWriter&&) = default; - CycloneDataWriter& operator=(CycloneDataWriter&&) = default; - - void connect() noexcept; - void write(const uint8_t* const bytes, const uint64_t size) noexcept; - std::string getServiceId() const noexcept; - std::string getInstanceId() const noexcept; - std::string getEventId() const noexcept; - - private: - IdString m_serviceId{""}; - IdString m_instanceId{""}; - IdString m_eventId{""}; - - ::dds::pub::Publisher m_publisher = ::dds::core::null; - ::dds::topic::Topic m_topic = ::dds::core::null; - ::dds::pub::DataWriter m_writer = ::dds::core::null; - - static ::dds::domain::DomainParticipant& getParticipant() noexcept; -}; - -} // namespace dds -} // namespace iox - -#endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index 2acca09135..b41dbd3c3d 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -23,6 +23,7 @@ namespace dds { using IdString = iox::cxx::string<100u>; +/// @note Implementation coming soon. template class DataReader { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index fda2b17a27..d20936dca7 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -23,6 +23,7 @@ #include "iceoryx_utils/cxx/optional.hpp" #include "iceoryx_utils/cxx/string.hpp" #include "iceoryx_utils/cxx/vector.hpp" +#include "iceoryx_utils/cxx/function_ref.hpp" #include "iceoryx_utils/internal/concurrent/smart_lock.hpp" #include @@ -106,7 +107,7 @@ class DDSGatewayGeneric : public gateway_t /// @param f The function to execute. /// @note This operation allows thread-safe access to the internal collection. /// - void forEachChannel(const std::function f) const noexcept; + void forEachChannel(const iox::cxx::function_ref f) const noexcept; /// /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index a945ac306d..572566f908 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -96,7 +96,7 @@ iox::dds::DDSGatewayGeneric::findChannel(const iox::capro: template inline void -iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) const +iox::dds::DDSGatewayGeneric::forEachChannel(const iox::cxx::function_ref f) const noexcept { auto guardedVector = m_channels.GetScopeGuard(); diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 700717314c..865eabdb87 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -13,8 +13,8 @@ // limitations under the License. #pragma once -#include -#include +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "mocks/google_mocks.hpp" @@ -34,7 +34,7 @@ template class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric { public: - virtual void loadConfiguration(GatewayConfig config) noexcept + void loadConfiguration(const GatewayConfig& config) noexcept { // Stubbed. } @@ -44,7 +44,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - void forward(channel_t channel) noexcept + void forward(const channel_t& channel) noexcept { // Stubbed. } @@ -59,7 +59,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric return TestDDSGatewayGeneric::findChannel(service); } - void forEachChannel(const std::function f) noexcept + void forEachChannel(const iox::cxx::function_ref f) noexcept { TestDDSGatewayGeneric::forEachChannel(f); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 4b36a6d1b6..26dbbd02ad 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -7,6 +7,7 @@ #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/function_ref.hpp" using namespace ::testing; using ::testing::_; @@ -56,7 +57,7 @@ class MockGenericDDSGateway MOCK_METHOD1( findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(forEachChannel, void(const std::function&)>)); + MOCK_METHOD1(forEachChannel, void(const iox::cxx::function_ref&)>)); }; #endif // IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP From 5a2423aec9ebfc9d7601d39c9b958929b714f97b Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 12:11:46 +0200 Subject: [PATCH 41/55] iox-#65 Remove unneeded move/copy constructors. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 6 +--- .../iceoryx_dds/internal/gateway/channel.inl | 32 ++----------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 2e3957ea46..c804ed19dc 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -56,11 +56,7 @@ class Channel Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; - ~Channel() noexcept = default; - Channel(const Channel&) noexcept; - Channel& operator=(const Channel&) noexcept; - Channel(Channel&&) noexcept; - Channel& operator=(Channel&&) noexcept; + constexpr bool operator==(const Channel& rhs) const noexcept; static Channel create(const iox::capro::ServiceDescription& service) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index ad6c000421..f9540cfee7 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -39,37 +39,9 @@ inline Channel::Channel(const iox::capro::ServiceD } template -inline Channel::Channel(const Channel& rhs) noexcept +constexpr inline bool Channel::operator==(const Channel& rhs) const noexcept { - m_service = rhs.m_service; - m_ddsTerminal = rhs.m_ddsTerminal; - m_iceoryxTerminal = rhs.m_iceoryxTerminal; -} - -template -inline Channel& Channel:: -operator=(const Channel& rhs) noexcept -{ - m_service = rhs.m_service; - m_ddsTerminal = rhs.m_ddsTerminal; - m_iceoryxTerminal = rhs.m_iceoryxTerminal; -} - -template -inline Channel::Channel(Channel&& rhs) noexcept -{ - m_service = std::move(rhs.m_service); - m_ddsTerminal = std::move(rhs.m_ddsTerminal); - m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); -} - -template -inline Channel& Channel:: -operator=(Channel&& rhs) noexcept -{ - m_service = std::move(rhs.m_service); - m_ddsTerminal = std::move(rhs.m_ddsTerminal); - m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); + return m_service == rhs.getService(); } template From cee04ae6c1fea5710658ef90ad629ee1e2b4a014 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 18:02:31 +0200 Subject: [PATCH 42/55] iox-#65 Avoid adding duplicate channels. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../internal/gateway/dds_gateway_generic.inl | 20 +++++++++++++------ .../moduletests/test_generic_dds_gateway.cpp | 14 +++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 572566f908..c896f48932 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -67,12 +67,20 @@ template inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { - auto channel = m_channelFactory(service); - m_channels->push_back(channel); - iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - return channel; + auto existingChannel = findChannel(service); + if(existingChannel.has_value()) + { + return existingChannel.value(); + } + else + { + auto channel = m_channelFactory(service); + m_channels->push_back(channel); + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return channel; + } } template diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 5f5406a537..383274c5f1 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -45,6 +45,20 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) EXPECT_EQ(1, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("service", "instance", "event"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(testService); + gw.addChannel(testService); + + EXPECT_EQ(1, gw.getNumberOfChannels()); +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup From f6cd43a53be60b0005c160d2e364907bb3e69420 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 11:57:05 +0200 Subject: [PATCH 43/55] iox-#65 Ignore wildcard services. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../gateway/dds_gateway_generic.hpp | 7 ++-- .../iceoryx_dds/gateway/iox_to_dds.hpp | 5 +++ .../internal/gateway/dds_gateway_generic.inl | 14 ++++++-- .../internal/gateway/iox_to_dds.inl | 28 +++++++++------ .../helpers/stubbed_dds_gateway_generic.hpp | 2 +- iceoryx_dds/test/mocks/google_mocks.hpp | 2 +- iceoryx_dds/test/moduletests/test_channel.cpp | 36 +++++++++++++++++++ .../moduletests/test_generic_dds_gateway.cpp | 20 +++++++++++ .../test/moduletests/test_iox_to_dds.cpp | 28 ++++++++------- 9 files changed, 112 insertions(+), 30 deletions(-) create mode 100644 iceoryx_dds/test/moduletests/test_channel.cpp diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index d20936dca7..320e23a3db 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -21,6 +21,7 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/popo/gateway_generic.hpp" #include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "iceoryx_utils/cxx/string.hpp" #include "iceoryx_utils/cxx/vector.hpp" #include "iceoryx_utils/cxx/function_ref.hpp" @@ -82,7 +83,9 @@ class DDSGatewayGeneric : public gateway_t /// @brief addChannel Creates a channel for the given service and stores a copy of it in an internal collection for /// later access. /// @param service The service to create a channel for. - /// @return A copy of the created channel. + /// @return An optional containing a copy of the created channel if successful, otherwise an empty optional. + /// + /// @note Wildcard services are not allowed and will be ignored. /// /// @note Channels are supposed to be lightweight, consisting only of pointers to the terminals and a copy of the /// service description, therefore a copy is provided to any entity that requires them. @@ -92,7 +95,7 @@ class DDSGatewayGeneric : public gateway_t /// The service description is perhaps too large for copying since they contain strings, however this should be /// addressed with a service description repository feature. /// - channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 0152f47634..feee4588b0 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -38,6 +38,11 @@ class Iceoryx2DDSGateway : public gateway_t void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward(const channel_t& channel) noexcept; + + private: + + void setupChannel(const iox::capro::ServiceDescription& service) noexcept; + }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index c896f48932..4aa7eb480a 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -64,13 +64,21 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() no } template -inline channel_t +inline iox::cxx::expected iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { + + // Filter out wildcard services + if(service.getServiceID() == iox::capro::AnyService || service.getInstanceID() == iox::capro::AnyInstance || service.getEventID() == iox::capro::AnyEvent) + { + return iox::cxx::error(1); + } + + // Add channel if it doesn't already exist auto existingChannel = findChannel(service); if(existingChannel.has_value()) { - return existingChannel.value(); + return iox::cxx::success(existingChannel.value()); } else { @@ -79,7 +87,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - return channel; + return iox::cxx::success(channel); } } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 14f0db89c4..d42b7e2b52 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -18,6 +18,8 @@ #include #include +#include "iceoryx_dds/gateway/iox_to_dds.hpp" + namespace iox { namespace dds @@ -37,11 +39,7 @@ inline void Iceoryx2DDSGateway::loadConfiguration(const Ga { if (!this->findChannel(service).has_value()) { - auto channel = this->addChannel(service); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); + setupChannel(service); } } } @@ -71,11 +69,7 @@ inline void Iceoryx2DDSGateway::discover(const iox::capro: { if (!this->findChannel(msg.m_serviceDescription).has_value()) { - auto channel = this->addChannel(msg.m_serviceDescription); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); + setupChannel(msg.m_serviceDescription); } break; } @@ -111,5 +105,19 @@ inline void Iceoryx2DDSGateway::forward(const channel_t& c } } +// ======================================== Private ======================================== // + +template +void Iceoryx2DDSGateway::setupChannel(const iox::capro::ServiceDescription& service) noexcept +{ + this->addChannel(service).on_success([](iox::cxx::expected result){ + auto channel = result.get_value(); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); + }); +} + } // namespace dds } // namespace iox diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 865eabdb87..e7fa72c86d 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -49,7 +49,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept { return TestDDSGatewayGeneric::addChannel(service); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 26dbbd02ad..aa39a7fb5e 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -52,7 +52,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(){}; MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(addChannel, iox::cxx::expected, uint8_t>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, diff --git a/iceoryx_dds/test/moduletests/test_channel.cpp b/iceoryx_dds/test/moduletests/test_channel.cpp new file mode 100644 index 0000000000..273ce49328 --- /dev/null +++ b/iceoryx_dds/test/moduletests/test_channel.cpp @@ -0,0 +1,36 @@ +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_posh/capro/service_description.hpp" + +#include "test.hpp" + +using namespace ::testing; +using ::testing::_; + +// ======================================== Helpers ======================================== // +// We do not need real channel terminals to test the base class. +struct StubbedIceoryxTerminal +{ + StubbedIceoryxTerminal(iox::capro::ServiceDescription sd){}; +}; + +struct StubbedDDSTerminal +{ + StubbedDDSTerminal(iox::dds::IdString sid, iox::dds::IdString iid, iox::dds::IdString eid){}; +}; + +using TestChannel = iox::dds::Channel; + +// ======================================== Fixture ======================================== // +class ChannelTest : public Test +{ + public: + void SetUp(){}; + void TearDown(){}; +}; + +// ======================================== Tests ======================================== // +TEST_F(ChannelTest, ReturnsEmptyOptionalIfObjectPoolExhausted) +{ + auto channel = iox::dds::Channel::create({"", "", ""}); +} diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 383274c5f1..59dba1b342 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -59,6 +59,26 @@ TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) EXPECT_EQ(1, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) +{ + // ===== Setup + auto completeWildcardService = iox::capro::ServiceDescription(iox::capro::AnyServiceString, iox::capro::AnyInstanceString, iox::capro::AnyEventString); + auto wildcardServiceService = iox::capro::ServiceDescription(iox::capro::AnyServiceString, "instance", "event"); + auto wildcardInstanceService = iox::capro::ServiceDescription("service", iox::capro::AnyInstanceString, "event"); + auto wildcardEventService = iox::capro::ServiceDescription("service", "instance", iox::capro::AnyEventString); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(completeWildcardService); + gw.addChannel(wildcardServiceService); + gw.addChannel(wildcardInstanceService); + gw.addChannel(wildcardEventService); + + + EXPECT_EQ(0, gw.getNumberOfChannels()); +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 8c1721aead..15af5fea50 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -14,13 +14,14 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "iceoryx_dds/dds/data_writer.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_dds/gateway/iox_to_dds.hpp" +#include "iceoryx_posh/internal/capro/capro_message.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "mocks/chunk_mock.hpp" #include "mocks/google_mocks.hpp" @@ -75,7 +76,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::dds::Channel createTestChannel(iox::capro::ServiceDescription sd) noexcept +static iox::cxx::expected, uint8_t> createTestChannel(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; @@ -101,7 +102,8 @@ static iox::dds::Channel createTestChannel(iox:: mockDataWriter = createMockDataWriter(sd); } - return iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); + return iox::cxx::success>(iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter))); + } // ======================================== Fixture ======================================== // @@ -281,7 +283,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ForwardsChunkFromSubscriberToDataWriter) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) @@ -308,7 +310,7 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) @@ -337,7 +339,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) @@ -370,7 +372,7 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop TestGateway gw{}; EXPECT_CALL(gw, findChannel) .WillOnce(Return(iox::cxx::nullopt_t())) - .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) + .WillOnce(Return(iox::cxx::make_optional>(testChannelOne.get_value()))) .WillOnce(Return(iox::cxx::nullopt_t())); EXPECT_CALL(gw, addChannel).WillOnce(Return(testChannelOne)).WillOnce(Return(testChannelTwo)); EXPECT_CALL(gw, discardChannel).Times(1); From d74b0a2631322df2a621cdb1c2862ab9f631117a Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 14:16:55 +0200 Subject: [PATCH 44/55] iox-#65 Test boundary conditions of generic dds gateway. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 3 +- .../gateway/dds_gateway_generic.hpp | 2 +- .../iceoryx_dds/internal/gateway/channel.inl | 14 +++- .../internal/gateway/dds_gateway_generic.inl | 26 +++++-- .../moduletests/test_generic_dds_gateway.cpp | 70 ++++++++++++++++++- 5 files changed, 102 insertions(+), 13 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index c804ed19dc..358b29e35c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -17,6 +17,7 @@ #include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "iceoryx_utils/internal/objectpool/objectpool.hpp" #include @@ -58,7 +59,7 @@ class Channel const DDSTerminalPtr ddsTerminal) noexcept; constexpr bool operator==(const Channel& rhs) const noexcept; - static Channel create(const iox::capro::ServiceDescription& service) noexcept; + static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; IceoryxTerminalPtr getIceoryxTerminal() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 320e23a3db..5408fcff3e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -41,7 +41,7 @@ namespace dds template class DDSGatewayGeneric : public gateway_t { - using ChannelFactory = std::function; + using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index f9540cfee7..9902b56f3b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_dds/gateway/channel.hpp" + namespace iox { namespace dds @@ -45,20 +47,28 @@ constexpr inline bool Channel::operator==(const Ch } template -inline Channel +inline iox::cxx::expected, uint8_t> Channel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); + if(rawIceoryxTerminalPtr == nullptr) + { + return iox::cxx::error(1); + } auto rawDDSTerminalPtr = s_ddsTerminals.create(service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); + if(rawDDSTerminalPtr == nullptr) + { + return iox::cxx::error(2); + } // Wrap in smart pointer with custom deleter to ensure automatic cleanup. auto iceoryxTerminalPtr = IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* const p) { s_iceoryxTerminals.free(p); }); auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* const p) { s_ddsTerminals.free(p); }); - return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); + return iox::cxx::success(Channel(service, iceoryxTerminalPtr, ddsTerminalPtr)); } template diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 4aa7eb480a..c9043b79ed 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -74,7 +74,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: return iox::cxx::error(1); } - // Add channel if it doesn't already exist + // Return existing channel if one for the service already exists, otherwise create a new one auto existingChannel = findChannel(service); if(existingChannel.has_value()) { @@ -82,12 +82,24 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: } else { - auto channel = m_channelFactory(service); - m_channels->push_back(channel); - iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - return iox::cxx::success(channel); + auto result = m_channelFactory(service); + if(result.has_error()) + { + iox::dds::LogError() << "[DDSGatewayGeneric] Unable to set up channel for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return iox::cxx::error(2); + } + else + { + auto channel = result.get_value(); + m_channels->push_back(channel); + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return iox::cxx::success(channel); + } + } } diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 59dba1b342..975812eec0 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/gateway_config.hpp" #include "test.hpp" @@ -79,6 +80,71 @@ TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) EXPECT_EQ(0, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, ProperlyManagesMultipleChannels) +{ + // ===== Setup + auto serviceOne = iox::capro::ServiceDescription("serviceOne", "instanceOne", "eventOne"); + auto serviceTwo = iox::capro::ServiceDescription("serviceTwo", "instanceTwo", "eventTwo"); + auto serviceThree = iox::capro::ServiceDescription("serviceThree", "instanceThree", "eventThree"); + auto serviceFour = iox::capro::ServiceDescription("serviceFour", "instanceFour", "eventFour"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(serviceOne); + gw.addChannel(serviceTwo); + gw.addChannel(serviceThree); + gw.addChannel(serviceFour); + + + EXPECT_EQ(4, gw.getNumberOfChannels()); + EXPECT_EQ(true, gw.findChannel(serviceOne).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceTwo).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceThree).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceFour).has_value()); + +} + +TEST_F(DDSGatewayGenericTest, HandlesMaxmimumChannelCapacity) +{ + // ===== Setup + TestDDSGatewayGeneric gw{}; + + // ===== Test + for(auto i=0u; i Date: Thu, 18 Jun 2020 14:49:28 +0200 Subject: [PATCH 45/55] iox-#65 Add errors for gateway to enum. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 10 +++++++++- .../internal/gateway/dds_gateway_generic.inl | 6 +++--- .../iceoryx_dds/internal/gateway/iox_to_dds.inl | 2 +- .../test/helpers/stubbed_dds_gateway_generic.hpp | 2 +- iceoryx_dds/test/mocks/google_mocks.hpp | 3 ++- .../test/moduletests/test_generic_dds_gateway.cpp | 13 +++++++++---- iceoryx_dds/test/moduletests/test_iox_to_dds.cpp | 2 +- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 5408fcff3e..0bb240484e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -34,6 +34,13 @@ namespace iox { namespace dds { + +enum class GatewayError : uint8_t +{ + UNSUPPORTED_SERVICE_TYPE, + UNSUCCESSFUL_CHANNEL_CREATION +}; + /// /// @brief Base class for DDS gateways containing common logic used by all implementations. Methods that are expected /// to differ across implementations are left as pure virtual. @@ -46,6 +53,7 @@ class DDSGatewayGeneric : public gateway_t using ConcurrentChannelVector = iox::concurrent::smart_lock; public: + virtual ~DDSGatewayGeneric() noexcept; DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; @@ -95,7 +103,7 @@ class DDSGatewayGeneric : public gateway_t /// The service description is perhaps too large for copying since they contain strings, however this should be /// addressed with a service description repository feature. /// - iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index c9043b79ed..b038701739 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -64,14 +64,14 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() no } template -inline iox::cxx::expected +inline iox::cxx::expected iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { // Filter out wildcard services if(service.getServiceID() == iox::capro::AnyService || service.getInstanceID() == iox::capro::AnyInstance || service.getEventID() == iox::capro::AnyEvent) { - return iox::cxx::error(1); + return iox::cxx::error(GatewayError::UNSUPPORTED_SERVICE_TYPE); } // Return existing channel if one for the service already exists, otherwise create a new one @@ -88,7 +88,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: iox::dds::LogError() << "[DDSGatewayGeneric] Unable to set up channel for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - return iox::cxx::error(2); + return iox::cxx::error(GatewayError::UNSUCCESSFUL_CHANNEL_CREATION); } else { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index d42b7e2b52..d2c585ef33 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -110,7 +110,7 @@ inline void Iceoryx2DDSGateway::forward(const channel_t& c template void Iceoryx2DDSGateway::setupChannel(const iox::capro::ServiceDescription& service) noexcept { - this->addChannel(service).on_success([](iox::cxx::expected result){ + this->addChannel(service).on_success([](iox::cxx::expected result){ auto channel = result.get_value(); auto subscriber = channel.getIceoryxTerminal(); auto dataWriter = channel.getDDSTerminal(); diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index e7fa72c86d..20107f63e8 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -49,7 +49,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept { return TestDDSGatewayGeneric::addChannel(service); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index aa39a7fb5e..ff5de26f82 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -4,6 +4,7 @@ #include "test.hpp" #include "iceoryx_dds/dds/data_writer.hpp" #include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_utils/cxx/optional.hpp" @@ -52,7 +53,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(){}; MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::cxx::expected, uint8_t>(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(addChannel, iox::cxx::expected, iox::dds::GatewayError>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 975812eec0..b03dd64539 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -71,11 +71,15 @@ TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) TestDDSGatewayGeneric gw{}; // ===== Test - gw.addChannel(completeWildcardService); - gw.addChannel(wildcardServiceService); - gw.addChannel(wildcardInstanceService); - gw.addChannel(wildcardEventService); + auto resultOne = gw.addChannel(completeWildcardService); + auto resultTwo = gw.addChannel(wildcardServiceService); + auto resultThree = gw.addChannel(wildcardInstanceService); + auto resultFour = gw.addChannel(wildcardEventService); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultOne.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultTwo.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultThree.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultFour.get_error()); EXPECT_EQ(0, gw.getNumberOfChannels()); } @@ -142,6 +146,7 @@ TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenExceedingMaximumChannelCapaicity) auto result = gw.addChannel({"oneTooMany", "oneTooMany", "oneTooMany"}); EXPECT_EQ(true, result.has_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUCCESSFUL_CHANNEL_CREATION, result.get_error()); } diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 15af5fea50..de4cd75c82 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -76,7 +76,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::cxx::expected, uint8_t> createTestChannel(iox::capro::ServiceDescription sd) noexcept +static iox::cxx::expected, iox::dds::GatewayError> createTestChannel(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; From 01116fda0fbf2be9531afb6c63e8f8b128435472 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 16:16:06 +0200 Subject: [PATCH 46/55] iox-#65 Add more error handling. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 8 +++++- .../gateway/dds_gateway_generic.hpp | 10 +++++--- .../iceoryx_dds/internal/gateway/channel.inl | 6 ++--- .../internal/gateway/dds_gateway_generic.inl | 8 +++++- .../helpers/stubbed_dds_gateway_generic.hpp | 4 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 2 +- .../moduletests/test_generic_dds_gateway.cpp | 25 +++++++++++++++++-- 7 files changed, 49 insertions(+), 14 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 358b29e35c..98ea849478 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -26,6 +26,12 @@ namespace iox { namespace dds { + +enum class ChannelError : uint8_t +{ + OBJECT_POOL_FULL +}; + /// /// @class Channel /// @brief A data structure representing a channel between Iceoryx and DDS. @@ -59,7 +65,7 @@ class Channel const DDSTerminalPtr ddsTerminal) noexcept; constexpr bool operator==(const Channel& rhs) const noexcept; - static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; + static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; IceoryxTerminalPtr getIceoryxTerminal() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 0bb240484e..a5a5582785 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -38,7 +38,8 @@ namespace dds enum class GatewayError : uint8_t { UNSUPPORTED_SERVICE_TYPE, - UNSUCCESSFUL_CHANNEL_CREATION + UNSUCCESSFUL_CHANNEL_CREATION, + NONEXISTANT_CHANNEL }; /// @@ -48,7 +49,7 @@ enum class GatewayError : uint8_t template class DDSGatewayGeneric : public gateway_t { - using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; + using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; @@ -91,7 +92,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief addChannel Creates a channel for the given service and stores a copy of it in an internal collection for /// later access. /// @param service The service to create a channel for. - /// @return An optional containing a copy of the created channel if successful, otherwise an empty optional. + /// @return an expected containing a copy of the added channel, otherwise an error /// /// @note Wildcard services are not allowed and will be ignored. /// @@ -123,8 +124,9 @@ class DDSGatewayGeneric : public gateway_t /// /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. /// @param service The service whose channels hiould be discarded. + /// @return an empty expected on success, otherwise an error /// - void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected discardChannel(const iox::capro::ServiceDescription& service) noexcept; private: ConcurrentChannelVector m_channels; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 9902b56f3b..6f0f8d25d1 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -47,20 +47,20 @@ constexpr inline bool Channel::operator==(const Ch } template -inline iox::cxx::expected, uint8_t> +inline iox::cxx::expected, ChannelError> Channel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); if(rawIceoryxTerminalPtr == nullptr) { - return iox::cxx::error(1); + return iox::cxx::error(ChannelError::OBJECT_POOL_FULL); } auto rawDDSTerminalPtr = s_ddsTerminals.create(service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); if(rawDDSTerminalPtr == nullptr) { - return iox::cxx::error(2); + return iox::cxx::error(ChannelError::OBJECT_POOL_FULL); } // Wrap in smart pointer with custom deleter to ensure automatic cleanup. diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index b038701739..c6082b352b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -135,7 +135,8 @@ iox::dds::DDSGatewayGeneric::forEachChannel(const iox::cxx } template -inline void iox::dds::DDSGatewayGeneric::discardChannel( +inline iox::cxx::expected +iox::dds::DDSGatewayGeneric::discardChannel( const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); @@ -148,6 +149,11 @@ inline void iox::dds::DDSGatewayGeneric::discardChannel( iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); + return iox::cxx::success(); + } + else + { + return iox::cxx::error(GatewayError::NONEXISTANT_CHANNEL); } } diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 20107f63e8..08d057edd8 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -64,9 +64,9 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric TestDDSGatewayGeneric::forEachChannel(f); } - void discardChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected discardChannel(const iox::capro::ServiceDescription& service) noexcept { - TestDDSGatewayGeneric::discardChannel(service); + return TestDDSGatewayGeneric::discardChannel(service); } }; } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index ff5de26f82..d73400cbe1 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -54,7 +54,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); MOCK_METHOD1(addChannel, iox::cxx::expected, iox::dds::GatewayError>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(discardChannel, iox::cxx::expected(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index b03dd64539..6f6715e2b3 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -46,7 +46,7 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) EXPECT_EQ(1, gw.getNumberOfChannels()); } -TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) +TEST_F(DDSGatewayGenericTest, DoesNotAddDuplicateChannels) { // ===== Setup auto testService = iox::capro::ServiceDescription("service", "instance", "event"); @@ -150,6 +150,26 @@ TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenExceedingMaximumChannelCapaicity) } +TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenAttemptingToRemoveNonexistantChannel) +{ + // ===== Setup + auto testServiceA = iox::capro::ServiceDescription("serviceA", "instanceA", "eventA"); + auto testServiceB = iox::capro::ServiceDescription("serviceB", "instanceB", "eventB"); + auto testServiceC = iox::capro::ServiceDescription("serviceC", "instanceC", "eventC"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(testServiceA); + gw.addChannel(testServiceB); + EXPECT_EQ(2, gw.getNumberOfChannels()); + + auto result = gw.discardChannel(testServiceC); + EXPECT_EQ(true, result.has_error()); + EXPECT_EQ(2, gw.getNumberOfChannels()); + +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup @@ -160,7 +180,8 @@ TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) // ===== Test gw.addChannel(testService); EXPECT_EQ(1, gw.getNumberOfChannels()); - gw.discardChannel(testService); + auto result = gw.discardChannel(testService); + EXPECT_EQ(false, result.has_error()); EXPECT_EQ(0, gw.getNumberOfChannels()); } From 7f0c3ff2ce556c5e9d3a375725df61e1b4fdef17 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Tue, 16 Jun 2020 15:00:38 +0200 Subject: [PATCH 47/55] iox-#65 Code cleanliness fixes. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds/CMakeLists.txt | 4 ++-- .../include/iceoryx_dds/dds/data_reader.hpp | 2 +- iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp | 2 +- iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp | 2 +- .../include/iceoryx_dds/gateway/channel.hpp | 2 +- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 4 ++-- .../include/iceoryx_dds/gateway/dds_to_iox.hpp | 4 ++-- .../include/iceoryx_dds/gateway/iox_to_dds.hpp | 4 ++-- .../iceoryx_dds/internal/gateway/channel.inl | 9 ++------- .../internal/gateway/dds_gateway_generic.inl | 8 +++----- .../iceoryx_dds/internal/gateway/dds_to_iox.inl | 4 ++-- .../iceoryx_dds/internal/gateway/iox_to_dds.inl | 6 ++---- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 14 ++++++++++++++ iceoryx_dds/test/mocks/google_mocks.hpp | 5 ++++- 14 files changed, 39 insertions(+), 31 deletions(-) diff --git a/iceoryx_dds/CMakeLists.txt b/iceoryx_dds/CMakeLists.txt index 792de7ec42..0c3adc7608 100644 --- a/iceoryx_dds/CMakeLists.txt +++ b/iceoryx_dds/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) -set(iceoryx_dds_VERSION 0.1.0) -project(iceoryx_dds VERSION ${iceoryx_dds_VERSION}) +file (STRINGS "../VERSION" iceoryx_dds_VERSION) +project(iceoryx_posh VERSION ${iceoryx_dds_VERSION}) option(BUILD_TESTS "build test binaries") diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index d20c7ff22b..f7ad1df217 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -21,7 +21,7 @@ namespace iox { namespace dds { -using IdString = iox::cxx::string<100>; +using IdString = iox::cxx::string<100u>; template class DataReader diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index 7f8e34d7ae..f52f5040de 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -23,7 +23,7 @@ namespace dds { static constexpr units::Duration DISCOVERY_PERIOD = 1000_ms; static constexpr units::Duration FORWARDING_PERIOD = 50_ms; -static constexpr uint32_t SUBSCRIBER_CACHE_SIZE = 128; +static constexpr uint32_t SUBSCRIBER_CACHE_SIZE = 128u; static constexpr uint32_t MAX_CHANNEL_NUMBER = iox::MAX_PORT_NUMBER; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp index 86ada6df10..d50132d9b0 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_types.hpp @@ -27,7 +27,7 @@ namespace iox namespace dds { // Fixed strings -using IdString = iox::cxx::string<100>; +using IdString = iox::cxx::string<100u>; // DDS implementation defined with compiler flags #ifdef USE_CYCLONE_DDS diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index e073b25fbc..dab24db462 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -56,7 +56,7 @@ class Channel Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; - ~Channel() noexcept; + ~Channel() noexcept = default; Channel(const Channel&) noexcept; Channel& operator=(const Channel&) noexcept; Channel(Channel&&) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 951f0ef57c..333eeacdd2 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -59,7 +59,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief loadConfiguration Load the provided configuration. /// @param config Generic dds gateway configuration which is applicable to all implementations. /// - virtual void loadConfiguration(GatewayConfig config) noexcept = 0; + virtual void loadConfiguration(const GatewayConfig& config) noexcept = 0; /// /// @brief discover Process discovery messages coming from iceoryx. /// @param msg The discovery message. @@ -69,7 +69,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief forward Forward data between the two terminals of the channel used by the implementation. /// @param channel The channel to propogate data across. /// - virtual void forward(channel_t channel) noexcept = 0; + virtual void forward(const channel_t& channel) noexcept = 0; uint64_t getNumberOfChannels() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 0b02c59735..8e5ddbce84 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -36,9 +36,9 @@ class DDS2IceoryxGateway : public iox::dds::DDSGatewayGeneric public: DDS2IceoryxGateway() noexcept; DDS2IceoryxGateway(ChannelFactory channelFactory) noexcept; - void loadConfiguration(GatewayConfig config) noexcept; + void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward(channel_t channel) noexcept; + void forward(const channel_t& channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 7d45a84cc4..6b262de3a8 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -36,9 +36,9 @@ class Iceoryx2DDSGateway : public gateway_t public: Iceoryx2DDSGateway() noexcept; - void loadConfiguration(GatewayConfig config) noexcept; + void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; - void forward(channel_t channel) noexcept; + void forward(const channel_t& channel) noexcept; }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index f497513637..ad6c000421 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -38,11 +38,6 @@ inline Channel::Channel(const iox::capro::ServiceD { } -template -inline Channel::~Channel() noexcept -{ -} - template inline Channel::Channel(const Channel& rhs) noexcept { @@ -88,8 +83,8 @@ Channel::create(const iox::capro::ServiceDescripti // Wrap in smart pointer with custom deleter to ensure automatic cleanup. auto iceoryxTerminalPtr = - IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* p) { s_iceoryxTerminals.free(p); }); - auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* p) { s_ddsTerminals.free(p); }); + IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* const p) { s_iceoryxTerminals.free(p); }); + auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* const p) { s_ddsTerminals.free(p); }); return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 956060cd40..6f4db9257a 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -30,8 +30,8 @@ inline iox::dds::DDSGatewayGeneric::~DDSGatewayGeneric() n template inline void iox::dds::DDSGatewayGeneric::runMultithreaded() noexcept { - m_discoveryThread = std::thread([this] { discoveryLoop(); }); - m_forwardingThread = std::thread([this] { forwardingLoop(); }); + m_discoveryThread = std::thread([this] { this->discoveryLoop(); }); + m_forwardingThread = std::thread([this] { this->forwardingLoop(); }); m_isRunning.store(true, std::memory_order_relaxed); } @@ -52,8 +52,7 @@ inline void iox::dds::DDSGatewayGeneric::shutdown() noexce template inline uint64_t iox::dds::DDSGatewayGeneric::getNumberOfChannels() const noexcept { - auto guardedVector = m_channels.GetScopeGuard(); - return guardedVector->size(); + return m_channels->size(); } // ================================================== Protected ================================================== // @@ -93,7 +92,6 @@ iox::dds::DDSGatewayGeneric::findChannel(const iox::capro: } else { - // Needs to be dereferenced since the smart lock returns pointers to elements in concurrent collections. return iox::cxx::make_optional(*channel); } } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index 4327809a0c..2c04e276c8 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -29,7 +29,7 @@ inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept : iox::dds:: } template -inline void DDS2IceoryxGateway::loadConfiguration(GatewayConfig config) noexcept +inline void DDS2IceoryxGateway::loadConfiguration(const GatewayConfig& config) noexcept { } @@ -40,7 +40,7 @@ inline void DDS2IceoryxGateway::discover(const iox::capro::CaproMessa } template -inline void DDS2IceoryxGateway::forward(channel_t channel) noexcept +inline void DDS2IceoryxGateway::forward(const channel_t& channel) noexcept { } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index c8dc428d5e..6990b2498f 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -23,8 +23,6 @@ namespace iox { namespace dds { -// template -// using ChannelFactory = std::function; // ======================================== Public ======================================== // template @@ -33,7 +31,7 @@ inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept : } template -inline void Iceoryx2DDSGateway::loadConfiguration(GatewayConfig config) noexcept +inline void Iceoryx2DDSGateway::loadConfiguration(const GatewayConfig& config) noexcept { iox::LogDebug() << "[Iceoryx2DDSGateway] Configuring gateway."; for (const auto& service : config.m_configuredServices) @@ -98,7 +96,7 @@ inline void Iceoryx2DDSGateway::discover(const iox::capro: } template -inline void Iceoryx2DDSGateway::forward(channel_t channel) noexcept +inline void Iceoryx2DDSGateway::forward(const channel_t& channel) noexcept { auto subscriber = channel.getIceoryxTerminal(); if (subscriber->hasNewChunks()) diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index ac9d14d063..e5c7e8256a 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -1,3 +1,17 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + #include #include diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 391c8f1fdc..1d30c7288f 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP +#define IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP #include "test.hpp" #include @@ -57,3 +58,5 @@ class MockGenericDDSGateway iox::cxx::optional>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(forEachChannel, void(const std::function&)>)); }; + +#endif // IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP From 9b8a20fba639c28d0e949f5b9a202874a1f449f0 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 09:17:43 +0200 Subject: [PATCH 48/55] iox-#65 Fixed header organization. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/dds/cyclone_data_writer.hpp | 3 +- .../dds/cyclone_data_writer.hpp.autosave | 66 +++++++++++++++++++ .../include/iceoryx_dds/dds/data_reader.hpp | 2 +- .../include/iceoryx_dds/dds/data_writer.hpp | 4 +- .../include/iceoryx_dds/dds/dds_config.hpp | 2 +- .../include/iceoryx_dds/gateway/channel.hpp | 8 +-- .../gateway/dds_gateway_generic.hpp | 21 +++--- .../iceoryx_dds/gateway/dds_to_iox.hpp | 3 +- .../iceoryx_dds/gateway/gateway_config.hpp | 6 +- .../iceoryx_dds/gateway/iox_to_dds.hpp | 3 +- .../internal/gateway/dds_gateway_generic.inl | 4 +- .../internal/gateway/dds_to_iox.inl | 7 +- .../internal/gateway/iox_to_dds.inl | 7 +- .../iceoryx_dds/internal/log/logging.hpp | 2 +- iceoryx_dds/source/dds2iceoryx_app/main.cpp | 8 +-- iceoryx_dds/source/iceoryx2dds_app/main.cpp | 12 ++-- .../iceoryx_dds/dds/cyclone_data_writer.cpp | 8 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 10 +-- 18 files changed, 117 insertions(+), 59 deletions(-) create mode 100644 iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index 8545b74907..6c70dc0c4d 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -15,10 +15,11 @@ #ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP #define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP +#include "iceoryx_dds/dds/data_writer.hpp" + #include #include -#include "iceoryx_dds/dds/data_writer.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave new file mode 100644 index 0000000000..16838a6da7 --- /dev/null +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave @@ -0,0 +1,66 @@ +// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// +// 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. + +#ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP +#define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP + +#include "iceoryx_dds/dds/data_writer.hpp" + +#include +#include + + +namespace iox +{ +namespace dds +{ +/// +/// @brief Implementation of the DataWriter interface using the cyclonedds implementation. +/// +class CycloneDataWriter : public iox::dds::DataWriter +{ + public: + CycloneDataWriter() = delete; + CycloneDataWriter(const IdString serviceId, const IdString instanceId, const IdString eventId); + virtual ~CycloneDataWriter(); + + CycloneDataWriter(const CycloneDataWriter&) = delete; + CycloneDataWriter& operator=(const CycloneDataWriter&) = delete; + + // Required for vector + CycloneDataWriter(CycloneDataWriter&&) = default; + CycloneDataWriter& operator=(CycloneDataWriter&&) = default; + + void connect() noexcept; + void write(const uint8_t* const bytes, const uint64_t size) noexcept; + std::string getServiceId() const noexcept; + std::string getInstanceId() const noexcept; + std::string getEventId() const noexcept; + + private: + IdString m_serviceId{""}; + IdString m_instanceId{""}; + IdString m_eventId{""}; + + ::dds::pub::Publisher m_publisher = ::dds::core::null; + ::dds::topic::Topic m_topic = ::dds::core::null; + ::dds::pub::DataWriter m_writer = ::dds::core::null; + + static ::dds::domain::DomainParticipant& getParticipant() noexcept; +}; + +} // namespace dds +} // namespace iox + +#endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index f7ad1df217..2acca09135 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_DDS_DATA_READER_HPP #define IOX_DDS_DDS_DATA_READER_HPP -#include +#include "iceoryx_utils/cxx/string.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp index cdeb142e19..165f1e4e8a 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_writer.hpp @@ -15,9 +15,9 @@ #ifndef IOX_DDS_DDS_DATA_WRITER_HPP #define IOX_DDS_DDS_DATA_WRITER_HPP -#include +#include "iceoryx_utils/cxx/string.hpp" -#include +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp index f52f5040de..a543261221 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/dds_config.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_DDS_CONFIG_HPP #define IOX_DDS_DDS_CONFIG_HPP -#include +#include "iceoryx_posh/iceoryx_posh_types.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index dab24db462..2e3957ea46 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -15,11 +15,11 @@ #ifndef IOX_DDS_GATEWAY_CHANNEL_HPP #define IOX_DDS_GATEWAY_CHANNEL_HPP -#include - #include "iceoryx_dds/dds/dds_config.hpp" -#include -#include +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/internal/objectpool/objectpool.hpp" + +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 333eeacdd2..fda2b17a27 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -15,19 +15,18 @@ #ifndef IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP #define IOX_DDS_GATEWAY_DDS_GATEWAY_GENERIC_HPP -#include -#include - -#include -#include -#include -#include -#include -#include -#include - #include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_posh/popo/gateway_generic.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/string.hpp" +#include "iceoryx_utils/cxx/vector.hpp" +#include "iceoryx_utils/internal/concurrent/smart_lock.hpp" + +#include +#include namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp index 8e5ddbce84..149730dec1 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_to_iox.hpp @@ -15,11 +15,10 @@ #ifndef IOX_DDS_GATEWAY_DDS_TO_IOX_HPP #define IOX_DDS_GATEWAY_DDS_TO_IOX_HPP -#include - #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/channel.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_posh/popo/publisher.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp index 11b40be5e1..182845823c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/gateway_config.hpp @@ -15,9 +15,9 @@ #ifndef IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP #define IOX_DDS_GATEWAY_GATEWAY_CONFIG_HPP -#include -#include -#include +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iceoryx_utils/cxx/vector.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 6b262de3a8..0152f47634 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -15,11 +15,10 @@ #ifndef IOX_DDS_GATEWAY_IOX_TO_DDS_HPP #define IOX_DDS_GATEWAY_IOX_TO_DDS_HPP -#include - #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/gateway/channel.hpp" #include "iceoryx_dds/gateway/dds_gateway_generic.hpp" +#include "iceoryx_posh/popo/subscriber.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 6f4db9257a..a945ac306d 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -12,12 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include "iceoryx_dds/dds/dds_types.hpp" #include "iceoryx_dds/internal/log/logging.hpp" -#include - +#include "iceoryx_utils/internal/file_reader/file_reader.hpp" // ================================================== Public ================================================== // diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl index 2c04e276c8..7aedc41ad3 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_to_iox.inl @@ -12,12 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - -#include -#include - #include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/cxx/string.hpp" namespace iox { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 6990b2498f..14f0db89c4 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_dds/internal/log/logging.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" + #include #include -#include - -#include "iceoryx_dds/internal/log/logging.hpp" - namespace iox { namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp index 188edea6e7..8a059d7815 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp +++ b/iceoryx_dds/include/iceoryx_dds/internal/log/logging.hpp @@ -15,7 +15,7 @@ #ifndef IOX_DDS_LOG_LOGGING_HPP #define IOX_DDS_LOG_LOGGING_HPP -#include +#include "iceoryx_utils/log/logging_free_function_building_block.hpp" namespace iox { diff --git a/iceoryx_dds/source/dds2iceoryx_app/main.cpp b/iceoryx_dds/source/dds2iceoryx_app/main.cpp index e5c7e8256a..018b3b2d09 100644 --- a/iceoryx_dds/source/dds2iceoryx_app/main.cpp +++ b/iceoryx_dds/source/dds2iceoryx_app/main.cpp @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - -#include -#include #include "iceoryx_dds/gateway/dds_to_iox.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_utils/posix_wrapper/semaphore.hpp" + +#include class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx2dds_app/main.cpp b/iceoryx_dds/source/iceoryx2dds_app/main.cpp index 8c96d6c32f..f74bf5c15f 100644 --- a/iceoryx_dds/source/iceoryx2dds_app/main.cpp +++ b/iceoryx_dds/source/iceoryx2dds_app/main.cpp @@ -14,12 +14,12 @@ #include -#include -#include -#include -#include -#include -#include +#include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_dds/gateway/iox_to_dds.hpp" +#include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iceoryx_utils/cxx/helplets.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/posix_wrapper/semaphore.hpp" class ShutdownManager { diff --git a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp index 270db3130b..b561ae2a22 100644 --- a/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp +++ b/iceoryx_dds/source/iceoryx_dds/dds/cyclone_data_writer.cpp @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include - #include "Mempool_DCPS.hpp" #include "iceoryx_dds/dds/cyclone_data_writer.hpp" #include "iceoryx_dds/internal/log/logging.hpp" +#include +#include +#include + iox::dds::CycloneDataWriter::CycloneDataWriter(IdString serviceId, IdString instanceId, IdString eventId) : m_serviceId(serviceId) , m_instanceId(instanceId) diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 1d30c7288f..4b36a6d1b6 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -2,11 +2,11 @@ #define IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP #include "test.hpp" -#include -#include -#include -#include -#include +#include "iceoryx_dds/dds/data_writer.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_posh/internal/capro/capro_message.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iceoryx_utils/cxx/optional.hpp" using namespace ::testing; using ::testing::_; From 6eee4e3abf4e5ca645ba185a78b3c0f3317de60d Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 11:28:55 +0200 Subject: [PATCH 49/55] iox-#65 Change std::function to cxx::function_ref where possible Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- iceoryx_dds/CMakeLists.txt | 2 +- .../iceoryx_dds/dds/cyclone_data_reader.hpp | 2 + .../iceoryx_dds/dds/cyclone_data_writer.hpp | 2 +- .../dds/cyclone_data_writer.hpp.autosave | 66 ------------------- .../include/iceoryx_dds/dds/data_reader.hpp | 1 + .../gateway/dds_gateway_generic.hpp | 3 +- .../internal/gateway/dds_gateway_generic.inl | 2 +- .../helpers/stubbed_dds_gateway_generic.hpp | 10 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 3 +- 9 files changed, 15 insertions(+), 76 deletions(-) delete mode 100644 iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave diff --git a/iceoryx_dds/CMakeLists.txt b/iceoryx_dds/CMakeLists.txt index 0c3adc7608..74a37b7dd9 100644 --- a/iceoryx_dds/CMakeLists.txt +++ b/iceoryx_dds/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) file (STRINGS "../VERSION" iceoryx_dds_VERSION) -project(iceoryx_posh VERSION ${iceoryx_dds_VERSION}) +project(iceoryx_dds VERSION ${iceoryx_dds_VERSION}) option(BUILD_TESTS "build test binaries") diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp index 24471dd06b..7d8cee5d38 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_reader.hpp @@ -21,6 +21,8 @@ namespace iox { namespace dds { + +/// @note Implementation coming soon. class CycloneDataReader : DataReader { public: diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp index 6c70dc0c4d..16838a6da7 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp @@ -17,8 +17,8 @@ #include "iceoryx_dds/dds/data_writer.hpp" -#include #include +#include namespace iox diff --git a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave b/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave deleted file mode 100644 index 16838a6da7..0000000000 --- a/iceoryx_dds/include/iceoryx_dds/dds/cyclone_data_writer.hpp.autosave +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. -// -// 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. - -#ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP -#define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP - -#include "iceoryx_dds/dds/data_writer.hpp" - -#include -#include - - -namespace iox -{ -namespace dds -{ -/// -/// @brief Implementation of the DataWriter interface using the cyclonedds implementation. -/// -class CycloneDataWriter : public iox::dds::DataWriter -{ - public: - CycloneDataWriter() = delete; - CycloneDataWriter(const IdString serviceId, const IdString instanceId, const IdString eventId); - virtual ~CycloneDataWriter(); - - CycloneDataWriter(const CycloneDataWriter&) = delete; - CycloneDataWriter& operator=(const CycloneDataWriter&) = delete; - - // Required for vector - CycloneDataWriter(CycloneDataWriter&&) = default; - CycloneDataWriter& operator=(CycloneDataWriter&&) = default; - - void connect() noexcept; - void write(const uint8_t* const bytes, const uint64_t size) noexcept; - std::string getServiceId() const noexcept; - std::string getInstanceId() const noexcept; - std::string getEventId() const noexcept; - - private: - IdString m_serviceId{""}; - IdString m_instanceId{""}; - IdString m_eventId{""}; - - ::dds::pub::Publisher m_publisher = ::dds::core::null; - ::dds::topic::Topic m_topic = ::dds::core::null; - ::dds::pub::DataWriter m_writer = ::dds::core::null; - - static ::dds::domain::DomainParticipant& getParticipant() noexcept; -}; - -} // namespace dds -} // namespace iox - -#endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP diff --git a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp index 2acca09135..b41dbd3c3d 100644 --- a/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp +++ b/iceoryx_dds/include/iceoryx_dds/dds/data_reader.hpp @@ -23,6 +23,7 @@ namespace dds { using IdString = iox::cxx::string<100u>; +/// @note Implementation coming soon. template class DataReader { diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index fda2b17a27..d20936dca7 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -23,6 +23,7 @@ #include "iceoryx_utils/cxx/optional.hpp" #include "iceoryx_utils/cxx/string.hpp" #include "iceoryx_utils/cxx/vector.hpp" +#include "iceoryx_utils/cxx/function_ref.hpp" #include "iceoryx_utils/internal/concurrent/smart_lock.hpp" #include @@ -106,7 +107,7 @@ class DDSGatewayGeneric : public gateway_t /// @param f The function to execute. /// @note This operation allows thread-safe access to the internal collection. /// - void forEachChannel(const std::function f) const noexcept; + void forEachChannel(const iox::cxx::function_ref f) const noexcept; /// /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index a945ac306d..572566f908 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -96,7 +96,7 @@ iox::dds::DDSGatewayGeneric::findChannel(const iox::capro: template inline void -iox::dds::DDSGatewayGeneric::forEachChannel(const std::function f) const +iox::dds::DDSGatewayGeneric::forEachChannel(const iox::cxx::function_ref f) const noexcept { auto guardedVector = m_channels.GetScopeGuard(); diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 700717314c..865eabdb87 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -13,8 +13,8 @@ // limitations under the License. #pragma once -#include -#include +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "mocks/google_mocks.hpp" @@ -34,7 +34,7 @@ template class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric { public: - virtual void loadConfiguration(GatewayConfig config) noexcept + void loadConfiguration(const GatewayConfig& config) noexcept { // Stubbed. } @@ -44,7 +44,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - void forward(channel_t channel) noexcept + void forward(const channel_t& channel) noexcept { // Stubbed. } @@ -59,7 +59,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric return TestDDSGatewayGeneric::findChannel(service); } - void forEachChannel(const std::function f) noexcept + void forEachChannel(const iox::cxx::function_ref f) noexcept { TestDDSGatewayGeneric::forEachChannel(f); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 4b36a6d1b6..26dbbd02ad 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -7,6 +7,7 @@ #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/function_ref.hpp" using namespace ::testing; using ::testing::_; @@ -56,7 +57,7 @@ class MockGenericDDSGateway MOCK_METHOD1( findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(forEachChannel, void(const std::function&)>)); + MOCK_METHOD1(forEachChannel, void(const iox::cxx::function_ref&)>)); }; #endif // IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP From 688b773548e18b55abdd3448d0ea3b64aef689b7 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 12:11:46 +0200 Subject: [PATCH 50/55] iox-#65 Remove unneeded move/copy constructors. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 6 +--- .../iceoryx_dds/internal/gateway/channel.inl | 32 ++----------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 2e3957ea46..c804ed19dc 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -56,11 +56,7 @@ class Channel Channel(const iox::capro::ServiceDescription& service, const IceoryxTerminalPtr iceoryxTerminal, const DDSTerminalPtr ddsTerminal) noexcept; - ~Channel() noexcept = default; - Channel(const Channel&) noexcept; - Channel& operator=(const Channel&) noexcept; - Channel(Channel&&) noexcept; - Channel& operator=(Channel&&) noexcept; + constexpr bool operator==(const Channel& rhs) const noexcept; static Channel create(const iox::capro::ServiceDescription& service) noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index ad6c000421..f9540cfee7 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -39,37 +39,9 @@ inline Channel::Channel(const iox::capro::ServiceD } template -inline Channel::Channel(const Channel& rhs) noexcept +constexpr inline bool Channel::operator==(const Channel& rhs) const noexcept { - m_service = rhs.m_service; - m_ddsTerminal = rhs.m_ddsTerminal; - m_iceoryxTerminal = rhs.m_iceoryxTerminal; -} - -template -inline Channel& Channel:: -operator=(const Channel& rhs) noexcept -{ - m_service = rhs.m_service; - m_ddsTerminal = rhs.m_ddsTerminal; - m_iceoryxTerminal = rhs.m_iceoryxTerminal; -} - -template -inline Channel::Channel(Channel&& rhs) noexcept -{ - m_service = std::move(rhs.m_service); - m_ddsTerminal = std::move(rhs.m_ddsTerminal); - m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); -} - -template -inline Channel& Channel:: -operator=(Channel&& rhs) noexcept -{ - m_service = std::move(rhs.m_service); - m_ddsTerminal = std::move(rhs.m_ddsTerminal); - m_iceoryxTerminal = std::move(rhs.m_iceoryxTerminal); + return m_service == rhs.getService(); } template From 64fd03aafa81ecc47d186ee079c17d08a05c832c Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Wed, 17 Jun 2020 18:02:31 +0200 Subject: [PATCH 51/55] iox-#65 Avoid adding duplicate channels. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../internal/gateway/dds_gateway_generic.inl | 20 +++++++++++++------ .../moduletests/test_generic_dds_gateway.cpp | 14 +++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 572566f908..c896f48932 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -67,12 +67,20 @@ template inline channel_t iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { - auto channel = m_channelFactory(service); - m_channels->push_back(channel); - iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - return channel; + auto existingChannel = findChannel(service); + if(existingChannel.has_value()) + { + return existingChannel.value(); + } + else + { + auto channel = m_channelFactory(service); + m_channels->push_back(channel); + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return channel; + } } template diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 5f5406a537..383274c5f1 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -45,6 +45,20 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) EXPECT_EQ(1, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) +{ + // ===== Setup + auto testService = iox::capro::ServiceDescription("service", "instance", "event"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(testService); + gw.addChannel(testService); + + EXPECT_EQ(1, gw.getNumberOfChannels()); +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup From 4b3e7d008acd77b157e7f0c72d526f0bda5da84d Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 11:57:05 +0200 Subject: [PATCH 52/55] iox-#65 Ignore wildcard services. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../gateway/dds_gateway_generic.hpp | 7 ++-- .../iceoryx_dds/gateway/iox_to_dds.hpp | 5 +++ .../internal/gateway/dds_gateway_generic.inl | 14 ++++++-- .../internal/gateway/iox_to_dds.inl | 28 +++++++++------ .../helpers/stubbed_dds_gateway_generic.hpp | 2 +- iceoryx_dds/test/mocks/google_mocks.hpp | 2 +- iceoryx_dds/test/moduletests/test_channel.cpp | 36 +++++++++++++++++++ .../moduletests/test_generic_dds_gateway.cpp | 20 +++++++++++ .../test/moduletests/test_iox_to_dds.cpp | 28 ++++++++------- 9 files changed, 112 insertions(+), 30 deletions(-) create mode 100644 iceoryx_dds/test/moduletests/test_channel.cpp diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index d20936dca7..320e23a3db 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -21,6 +21,7 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/popo/gateway_generic.hpp" #include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "iceoryx_utils/cxx/string.hpp" #include "iceoryx_utils/cxx/vector.hpp" #include "iceoryx_utils/cxx/function_ref.hpp" @@ -82,7 +83,9 @@ class DDSGatewayGeneric : public gateway_t /// @brief addChannel Creates a channel for the given service and stores a copy of it in an internal collection for /// later access. /// @param service The service to create a channel for. - /// @return A copy of the created channel. + /// @return An optional containing a copy of the created channel if successful, otherwise an empty optional. + /// + /// @note Wildcard services are not allowed and will be ignored. /// /// @note Channels are supposed to be lightweight, consisting only of pointers to the terminals and a copy of the /// service description, therefore a copy is provided to any entity that requires them. @@ -92,7 +95,7 @@ class DDSGatewayGeneric : public gateway_t /// The service description is perhaps too large for copying since they contain strings, however this should be /// addressed with a service description repository feature. /// - channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp index 0152f47634..feee4588b0 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/iox_to_dds.hpp @@ -38,6 +38,11 @@ class Iceoryx2DDSGateway : public gateway_t void loadConfiguration(const GatewayConfig& config) noexcept; void discover(const iox::capro::CaproMessage& msg) noexcept; void forward(const channel_t& channel) noexcept; + + private: + + void setupChannel(const iox::capro::ServiceDescription& service) noexcept; + }; } // namespace dds diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index c896f48932..4aa7eb480a 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -64,13 +64,21 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() no } template -inline channel_t +inline iox::cxx::expected iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { + + // Filter out wildcard services + if(service.getServiceID() == iox::capro::AnyService || service.getInstanceID() == iox::capro::AnyInstance || service.getEventID() == iox::capro::AnyEvent) + { + return iox::cxx::error(1); + } + + // Add channel if it doesn't already exist auto existingChannel = findChannel(service); if(existingChannel.has_value()) { - return existingChannel.value(); + return iox::cxx::success(existingChannel.value()); } else { @@ -79,7 +87,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - return channel; + return iox::cxx::success(channel); } } diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index 14f0db89c4..d42b7e2b52 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -18,6 +18,8 @@ #include #include +#include "iceoryx_dds/gateway/iox_to_dds.hpp" + namespace iox { namespace dds @@ -37,11 +39,7 @@ inline void Iceoryx2DDSGateway::loadConfiguration(const Ga { if (!this->findChannel(service).has_value()) { - auto channel = this->addChannel(service); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); + setupChannel(service); } } } @@ -71,11 +69,7 @@ inline void Iceoryx2DDSGateway::discover(const iox::capro: { if (!this->findChannel(msg.m_serviceDescription).has_value()) { - auto channel = this->addChannel(msg.m_serviceDescription); - auto subscriber = channel.getIceoryxTerminal(); - auto dataWriter = channel.getDDSTerminal(); - subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); - dataWriter->connect(); + setupChannel(msg.m_serviceDescription); } break; } @@ -111,5 +105,19 @@ inline void Iceoryx2DDSGateway::forward(const channel_t& c } } +// ======================================== Private ======================================== // + +template +void Iceoryx2DDSGateway::setupChannel(const iox::capro::ServiceDescription& service) noexcept +{ + this->addChannel(service).on_success([](iox::cxx::expected result){ + auto channel = result.get_value(); + auto subscriber = channel.getIceoryxTerminal(); + auto dataWriter = channel.getDDSTerminal(); + subscriber->subscribe(SUBSCRIBER_CACHE_SIZE); + dataWriter->connect(); + }); +} + } // namespace dds } // namespace iox diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 865eabdb87..e7fa72c86d 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -49,7 +49,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - channel_t addChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept { return TestDDSGatewayGeneric::addChannel(service); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index 26dbbd02ad..aa39a7fb5e 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -52,7 +52,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(){}; MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::dds::Channel(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(addChannel, iox::cxx::expected, uint8_t>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, diff --git a/iceoryx_dds/test/moduletests/test_channel.cpp b/iceoryx_dds/test/moduletests/test_channel.cpp new file mode 100644 index 0000000000..273ce49328 --- /dev/null +++ b/iceoryx_dds/test/moduletests/test_channel.cpp @@ -0,0 +1,36 @@ +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_posh/capro/service_description.hpp" + +#include "test.hpp" + +using namespace ::testing; +using ::testing::_; + +// ======================================== Helpers ======================================== // +// We do not need real channel terminals to test the base class. +struct StubbedIceoryxTerminal +{ + StubbedIceoryxTerminal(iox::capro::ServiceDescription sd){}; +}; + +struct StubbedDDSTerminal +{ + StubbedDDSTerminal(iox::dds::IdString sid, iox::dds::IdString iid, iox::dds::IdString eid){}; +}; + +using TestChannel = iox::dds::Channel; + +// ======================================== Fixture ======================================== // +class ChannelTest : public Test +{ + public: + void SetUp(){}; + void TearDown(){}; +}; + +// ======================================== Tests ======================================== // +TEST_F(ChannelTest, ReturnsEmptyOptionalIfObjectPoolExhausted) +{ + auto channel = iox::dds::Channel::create({"", "", ""}); +} diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 383274c5f1..59dba1b342 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -59,6 +59,26 @@ TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) EXPECT_EQ(1, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) +{ + // ===== Setup + auto completeWildcardService = iox::capro::ServiceDescription(iox::capro::AnyServiceString, iox::capro::AnyInstanceString, iox::capro::AnyEventString); + auto wildcardServiceService = iox::capro::ServiceDescription(iox::capro::AnyServiceString, "instance", "event"); + auto wildcardInstanceService = iox::capro::ServiceDescription("service", iox::capro::AnyInstanceString, "event"); + auto wildcardEventService = iox::capro::ServiceDescription("service", "instance", iox::capro::AnyEventString); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(completeWildcardService); + gw.addChannel(wildcardServiceService); + gw.addChannel(wildcardInstanceService); + gw.addChannel(wildcardEventService); + + + EXPECT_EQ(0, gw.getNumberOfChannels()); +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 8c1721aead..15af5fea50 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -14,13 +14,14 @@ #include -#include -#include -#include -#include -#include -#include -#include +#include "iceoryx_dds/dds/data_writer.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/gateway_config.hpp" +#include "iceoryx_dds/gateway/iox_to_dds.hpp" +#include "iceoryx_posh/internal/capro/capro_message.hpp" +#include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iceoryx_utils/cxx/optional.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "mocks/chunk_mock.hpp" #include "mocks/google_mocks.hpp" @@ -75,7 +76,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::dds::Channel createTestChannel(iox::capro::ServiceDescription sd) noexcept +static iox::cxx::expected, uint8_t> createTestChannel(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; @@ -101,7 +102,8 @@ static iox::dds::Channel createTestChannel(iox:: mockDataWriter = createMockDataWriter(sd); } - return iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter)); + return iox::cxx::success>(iox::dds::Channel(sd, std::move(mockSubscriber), std::move(mockDataWriter))); + } // ======================================== Fixture ======================================== // @@ -281,7 +283,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ForwardsChunkFromSubscriberToDataWriter) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) @@ -308,7 +310,7 @@ TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) @@ -337,7 +339,7 @@ TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) TestGateway gw{}; // === Test - gw.forward(testChannel); + gw.forward(testChannel.get_value()); } TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) @@ -370,7 +372,7 @@ TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStop TestGateway gw{}; EXPECT_CALL(gw, findChannel) .WillOnce(Return(iox::cxx::nullopt_t())) - .WillOnce(Return(iox::cxx::make_optional>(testChannelOne))) + .WillOnce(Return(iox::cxx::make_optional>(testChannelOne.get_value()))) .WillOnce(Return(iox::cxx::nullopt_t())); EXPECT_CALL(gw, addChannel).WillOnce(Return(testChannelOne)).WillOnce(Return(testChannelTwo)); EXPECT_CALL(gw, discardChannel).Times(1); From cc34dcd1ce843bcb8022cf160f203bf0ecb09e14 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 14:16:55 +0200 Subject: [PATCH 53/55] iox-#65 Test boundary conditions of generic dds gateway. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 3 +- .../gateway/dds_gateway_generic.hpp | 2 +- .../iceoryx_dds/internal/gateway/channel.inl | 14 +++- .../internal/gateway/dds_gateway_generic.inl | 26 +++++-- .../moduletests/test_generic_dds_gateway.cpp | 70 ++++++++++++++++++- 5 files changed, 102 insertions(+), 13 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index c804ed19dc..358b29e35c 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -17,6 +17,7 @@ #include "iceoryx_dds/dds/dds_config.hpp" #include "iceoryx_posh/capro/service_description.hpp" +#include "iceoryx_utils/cxx/expected.hpp" #include "iceoryx_utils/internal/objectpool/objectpool.hpp" #include @@ -58,7 +59,7 @@ class Channel const DDSTerminalPtr ddsTerminal) noexcept; constexpr bool operator==(const Channel& rhs) const noexcept; - static Channel create(const iox::capro::ServiceDescription& service) noexcept; + static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; IceoryxTerminalPtr getIceoryxTerminal() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 320e23a3db..5408fcff3e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -41,7 +41,7 @@ namespace dds template class DDSGatewayGeneric : public gateway_t { - using ChannelFactory = std::function; + using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index f9540cfee7..9902b56f3b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "iceoryx_dds/gateway/channel.hpp" + namespace iox { namespace dds @@ -45,20 +47,28 @@ constexpr inline bool Channel::operator==(const Ch } template -inline Channel +inline iox::cxx::expected, uint8_t> Channel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); + if(rawIceoryxTerminalPtr == nullptr) + { + return iox::cxx::error(1); + } auto rawDDSTerminalPtr = s_ddsTerminals.create(service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); + if(rawDDSTerminalPtr == nullptr) + { + return iox::cxx::error(2); + } // Wrap in smart pointer with custom deleter to ensure automatic cleanup. auto iceoryxTerminalPtr = IceoryxTerminalPtr(rawIceoryxTerminalPtr, [](IceoryxTerminal* const p) { s_iceoryxTerminals.free(p); }); auto ddsTerminalPtr = DDSTerminalPtr(rawDDSTerminalPtr, [](DDSTerminal* const p) { s_ddsTerminals.free(p); }); - return Channel(service, iceoryxTerminalPtr, ddsTerminalPtr); + return iox::cxx::success(Channel(service, iceoryxTerminalPtr, ddsTerminalPtr)); } template diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index 4aa7eb480a..c9043b79ed 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -74,7 +74,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: return iox::cxx::error(1); } - // Add channel if it doesn't already exist + // Return existing channel if one for the service already exists, otherwise create a new one auto existingChannel = findChannel(service); if(existingChannel.has_value()) { @@ -82,12 +82,24 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: } else { - auto channel = m_channelFactory(service); - m_channels->push_back(channel); - iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " - << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" - << service.getEventIDString(); - return iox::cxx::success(channel); + auto result = m_channelFactory(service); + if(result.has_error()) + { + iox::dds::LogError() << "[DDSGatewayGeneric] Unable to set up channel for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return iox::cxx::error(2); + } + else + { + auto channel = result.get_value(); + m_channels->push_back(channel); + iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel set up for service: " + << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" + << service.getEventIDString(); + return iox::cxx::success(channel); + } + } } diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 59dba1b342..975812eec0 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -1,5 +1,6 @@ -#include -#include +#include "iceoryx_dds/dds/dds_types.hpp" +#include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/gateway_config.hpp" #include "test.hpp" @@ -79,6 +80,71 @@ TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) EXPECT_EQ(0, gw.getNumberOfChannels()); } +TEST_F(DDSGatewayGenericTest, ProperlyManagesMultipleChannels) +{ + // ===== Setup + auto serviceOne = iox::capro::ServiceDescription("serviceOne", "instanceOne", "eventOne"); + auto serviceTwo = iox::capro::ServiceDescription("serviceTwo", "instanceTwo", "eventTwo"); + auto serviceThree = iox::capro::ServiceDescription("serviceThree", "instanceThree", "eventThree"); + auto serviceFour = iox::capro::ServiceDescription("serviceFour", "instanceFour", "eventFour"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(serviceOne); + gw.addChannel(serviceTwo); + gw.addChannel(serviceThree); + gw.addChannel(serviceFour); + + + EXPECT_EQ(4, gw.getNumberOfChannels()); + EXPECT_EQ(true, gw.findChannel(serviceOne).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceTwo).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceThree).has_value()); + EXPECT_EQ(true, gw.findChannel(serviceFour).has_value()); + +} + +TEST_F(DDSGatewayGenericTest, HandlesMaxmimumChannelCapacity) +{ + // ===== Setup + TestDDSGatewayGeneric gw{}; + + // ===== Test + for(auto i=0u; i Date: Thu, 18 Jun 2020 14:49:28 +0200 Subject: [PATCH 54/55] iox-#65 Add errors for gateway to enum. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../iceoryx_dds/gateway/dds_gateway_generic.hpp | 10 +++++++++- .../internal/gateway/dds_gateway_generic.inl | 6 +++--- .../iceoryx_dds/internal/gateway/iox_to_dds.inl | 2 +- .../test/helpers/stubbed_dds_gateway_generic.hpp | 2 +- iceoryx_dds/test/mocks/google_mocks.hpp | 3 ++- .../test/moduletests/test_generic_dds_gateway.cpp | 13 +++++++++---- iceoryx_dds/test/moduletests/test_iox_to_dds.cpp | 2 +- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 5408fcff3e..0bb240484e 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -34,6 +34,13 @@ namespace iox { namespace dds { + +enum class GatewayError : uint8_t +{ + UNSUPPORTED_SERVICE_TYPE, + UNSUCCESSFUL_CHANNEL_CREATION +}; + /// /// @brief Base class for DDS gateways containing common logic used by all implementations. Methods that are expected /// to differ across implementations are left as pure virtual. @@ -46,6 +53,7 @@ class DDSGatewayGeneric : public gateway_t using ConcurrentChannelVector = iox::concurrent::smart_lock; public: + virtual ~DDSGatewayGeneric() noexcept; DDSGatewayGeneric(const DDSGatewayGeneric&) = delete; @@ -95,7 +103,7 @@ class DDSGatewayGeneric : public gateway_t /// The service description is perhaps too large for copying since they contain strings, however this should be /// addressed with a service description repository feature. /// - iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept; /// /// @brief findChannel Searches for a channel for the given service in the internally stored collection and returns diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index c9043b79ed..b038701739 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -64,14 +64,14 @@ inline iox::dds::DDSGatewayGeneric::DDSGatewayGeneric() no } template -inline iox::cxx::expected +inline iox::cxx::expected iox::dds::DDSGatewayGeneric::addChannel(const iox::capro::ServiceDescription& service) noexcept { // Filter out wildcard services if(service.getServiceID() == iox::capro::AnyService || service.getInstanceID() == iox::capro::AnyInstance || service.getEventID() == iox::capro::AnyEvent) { - return iox::cxx::error(1); + return iox::cxx::error(GatewayError::UNSUPPORTED_SERVICE_TYPE); } // Return existing channel if one for the service already exists, otherwise create a new one @@ -88,7 +88,7 @@ iox::dds::DDSGatewayGeneric::addChannel(const iox::capro:: iox::dds::LogError() << "[DDSGatewayGeneric] Unable to set up channel for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); - return iox::cxx::error(2); + return iox::cxx::error(GatewayError::UNSUCCESSFUL_CHANNEL_CREATION); } else { diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl index d42b7e2b52..d2c585ef33 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/iox_to_dds.inl @@ -110,7 +110,7 @@ inline void Iceoryx2DDSGateway::forward(const channel_t& c template void Iceoryx2DDSGateway::setupChannel(const iox::capro::ServiceDescription& service) noexcept { - this->addChannel(service).on_success([](iox::cxx::expected result){ + this->addChannel(service).on_success([](iox::cxx::expected result){ auto channel = result.get_value(); auto subscriber = channel.getIceoryxTerminal(); auto dataWriter = channel.getDDSTerminal(); diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index e7fa72c86d..20107f63e8 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -49,7 +49,7 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric // Stubbed. } - iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected addChannel(const iox::capro::ServiceDescription& service) noexcept { return TestDDSGatewayGeneric::addChannel(service); } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index aa39a7fb5e..ff5de26f82 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -4,6 +4,7 @@ #include "test.hpp" #include "iceoryx_dds/dds/data_writer.hpp" #include "iceoryx_dds/gateway/channel.hpp" +#include "iceoryx_dds/gateway/dds_gateway_generic.hpp" #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_utils/cxx/optional.hpp" @@ -52,7 +53,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(){}; MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); - MOCK_METHOD1(addChannel, iox::cxx::expected, uint8_t>(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(addChannel, iox::cxx::expected, iox::dds::GatewayError>(const iox::capro::ServiceDescription&)); MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index 975812eec0..b03dd64539 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -71,11 +71,15 @@ TEST_F(DDSGatewayGenericTest, IgnoresWildcardServices) TestDDSGatewayGeneric gw{}; // ===== Test - gw.addChannel(completeWildcardService); - gw.addChannel(wildcardServiceService); - gw.addChannel(wildcardInstanceService); - gw.addChannel(wildcardEventService); + auto resultOne = gw.addChannel(completeWildcardService); + auto resultTwo = gw.addChannel(wildcardServiceService); + auto resultThree = gw.addChannel(wildcardInstanceService); + auto resultFour = gw.addChannel(wildcardEventService); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultOne.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultTwo.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultThree.get_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUPPORTED_SERVICE_TYPE, resultFour.get_error()); EXPECT_EQ(0, gw.getNumberOfChannels()); } @@ -142,6 +146,7 @@ TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenExceedingMaximumChannelCapaicity) auto result = gw.addChannel({"oneTooMany", "oneTooMany", "oneTooMany"}); EXPECT_EQ(true, result.has_error()); + EXPECT_EQ(iox::dds::GatewayError::UNSUCCESSFUL_CHANNEL_CREATION, result.get_error()); } diff --git a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp index 15af5fea50..de4cd75c82 100644 --- a/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp +++ b/iceoryx_dds/test/moduletests/test_iox_to_dds.cpp @@ -76,7 +76,7 @@ void stageMockSubscriber(std::shared_ptr&& mock) // ======================================== Mock Factories ======================================== // -static iox::cxx::expected, uint8_t> createTestChannel(iox::capro::ServiceDescription sd) noexcept +static iox::cxx::expected, iox::dds::GatewayError> createTestChannel(iox::capro::ServiceDescription sd) noexcept { // Get or create a mock subscriber std::shared_ptr mockSubscriber; From 3a7474ddd156e7c593c68f0183524363845c3f97 Mon Sep 17 00:00:00 2001 From: "Ithier Jeff (CC-AD/EYF1)" Date: Thu, 18 Jun 2020 16:16:06 +0200 Subject: [PATCH 55/55] iox-#65 Add more error handling. Signed-off-by: Ithier Jeff (CC-AD/EYF1) --- .../include/iceoryx_dds/gateway/channel.hpp | 8 +++++- .../gateway/dds_gateway_generic.hpp | 10 +++++--- .../iceoryx_dds/internal/gateway/channel.inl | 6 ++--- .../internal/gateway/dds_gateway_generic.inl | 8 +++++- .../helpers/stubbed_dds_gateway_generic.hpp | 4 +-- iceoryx_dds/test/mocks/google_mocks.hpp | 2 +- .../moduletests/test_generic_dds_gateway.cpp | 25 +++++++++++++++++-- 7 files changed, 49 insertions(+), 14 deletions(-) diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp index 358b29e35c..98ea849478 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/channel.hpp @@ -26,6 +26,12 @@ namespace iox { namespace dds { + +enum class ChannelError : uint8_t +{ + OBJECT_POOL_FULL +}; + /// /// @class Channel /// @brief A data structure representing a channel between Iceoryx and DDS. @@ -59,7 +65,7 @@ class Channel const DDSTerminalPtr ddsTerminal) noexcept; constexpr bool operator==(const Channel& rhs) const noexcept; - static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; + static iox::cxx::expected create(const iox::capro::ServiceDescription& service) noexcept; iox::capro::ServiceDescription getService() const noexcept; IceoryxTerminalPtr getIceoryxTerminal() const noexcept; diff --git a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp index 0bb240484e..a5a5582785 100644 --- a/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp +++ b/iceoryx_dds/include/iceoryx_dds/gateway/dds_gateway_generic.hpp @@ -38,7 +38,8 @@ namespace dds enum class GatewayError : uint8_t { UNSUPPORTED_SERVICE_TYPE, - UNSUCCESSFUL_CHANNEL_CREATION + UNSUCCESSFUL_CHANNEL_CREATION, + NONEXISTANT_CHANNEL }; /// @@ -48,7 +49,7 @@ enum class GatewayError : uint8_t template class DDSGatewayGeneric : public gateway_t { - using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; + using ChannelFactory = std::function(const iox::capro::ServiceDescription)>; using ChannelVector = iox::cxx::vector; using ConcurrentChannelVector = iox::concurrent::smart_lock; @@ -91,7 +92,7 @@ class DDSGatewayGeneric : public gateway_t /// @brief addChannel Creates a channel for the given service and stores a copy of it in an internal collection for /// later access. /// @param service The service to create a channel for. - /// @return An optional containing a copy of the created channel if successful, otherwise an empty optional. + /// @return an expected containing a copy of the added channel, otherwise an error /// /// @note Wildcard services are not allowed and will be ignored. /// @@ -123,8 +124,9 @@ class DDSGatewayGeneric : public gateway_t /// /// @brief discardChannel Discard the channel for the given service in the internal collection if one exists. /// @param service The service whose channels hiould be discarded. + /// @return an empty expected on success, otherwise an error /// - void discardChannel(const iox::capro::ServiceDescription& service) noexcept; + iox::cxx::expected discardChannel(const iox::capro::ServiceDescription& service) noexcept; private: ConcurrentChannelVector m_channels; diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl index 9902b56f3b..6f0f8d25d1 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/channel.inl @@ -47,20 +47,20 @@ constexpr inline bool Channel::operator==(const Ch } template -inline iox::cxx::expected, uint8_t> +inline iox::cxx::expected, ChannelError> Channel::create(const iox::capro::ServiceDescription& service) noexcept { // Create objects in the pool. auto rawIceoryxTerminalPtr = s_iceoryxTerminals.create(std::forward(service)); if(rawIceoryxTerminalPtr == nullptr) { - return iox::cxx::error(1); + return iox::cxx::error(ChannelError::OBJECT_POOL_FULL); } auto rawDDSTerminalPtr = s_ddsTerminals.create(service.getServiceIDString(), service.getInstanceIDString(), service.getEventIDString()); if(rawDDSTerminalPtr == nullptr) { - return iox::cxx::error(2); + return iox::cxx::error(ChannelError::OBJECT_POOL_FULL); } // Wrap in smart pointer with custom deleter to ensure automatic cleanup. diff --git a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl index b038701739..c6082b352b 100644 --- a/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl +++ b/iceoryx_dds/include/iceoryx_dds/internal/gateway/dds_gateway_generic.inl @@ -135,7 +135,8 @@ iox::dds::DDSGatewayGeneric::forEachChannel(const iox::cxx } template -inline void iox::dds::DDSGatewayGeneric::discardChannel( +inline iox::cxx::expected +iox::dds::DDSGatewayGeneric::discardChannel( const iox::capro::ServiceDescription& service) noexcept { auto guardedVector = this->m_channels.GetScopeGuard(); @@ -148,6 +149,11 @@ inline void iox::dds::DDSGatewayGeneric::discardChannel( iox::dds::LogDebug() << "[DDSGatewayGeneric] Channel taken down for service: " << "/" << service.getInstanceIDString() << "/" << service.getServiceIDString() << "/" << service.getEventIDString(); + return iox::cxx::success(); + } + else + { + return iox::cxx::error(GatewayError::NONEXISTANT_CHANNEL); } } diff --git a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp index 20107f63e8..08d057edd8 100644 --- a/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp +++ b/iceoryx_dds/test/helpers/stubbed_dds_gateway_generic.hpp @@ -64,9 +64,9 @@ class StubbedDDSGatewayGeneric : public TestDDSGatewayGeneric TestDDSGatewayGeneric::forEachChannel(f); } - void discardChannel(const iox::capro::ServiceDescription& service) noexcept + iox::cxx::expected discardChannel(const iox::capro::ServiceDescription& service) noexcept { - TestDDSGatewayGeneric::discardChannel(service); + return TestDDSGatewayGeneric::discardChannel(service); } }; } diff --git a/iceoryx_dds/test/mocks/google_mocks.hpp b/iceoryx_dds/test/mocks/google_mocks.hpp index ff5de26f82..d73400cbe1 100644 --- a/iceoryx_dds/test/mocks/google_mocks.hpp +++ b/iceoryx_dds/test/mocks/google_mocks.hpp @@ -54,7 +54,7 @@ class MockGenericDDSGateway MockGenericDDSGateway(const iox::capro::Interfaces i){}; MOCK_METHOD1(getCaProMessage, bool(iox::capro::CaproMessage&)); MOCK_METHOD1(addChannel, iox::cxx::expected, iox::dds::GatewayError>(const iox::capro::ServiceDescription&)); - MOCK_METHOD1(discardChannel, void(const iox::capro::ServiceDescription&)); + MOCK_METHOD1(discardChannel, iox::cxx::expected(const iox::capro::ServiceDescription&)); MOCK_METHOD1( findChannel, iox::cxx::optional>(const iox::capro::ServiceDescription&)); diff --git a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp index b03dd64539..6f6715e2b3 100644 --- a/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp +++ b/iceoryx_dds/test/moduletests/test_generic_dds_gateway.cpp @@ -46,7 +46,7 @@ TEST_F(DDSGatewayGenericTest, AddedChannelsAreStored) EXPECT_EQ(1, gw.getNumberOfChannels()); } -TEST_F(DDSGatewayGenericTest, DoesNotAddWhenChannelAlreadyExists) +TEST_F(DDSGatewayGenericTest, DoesNotAddDuplicateChannels) { // ===== Setup auto testService = iox::capro::ServiceDescription("service", "instance", "event"); @@ -150,6 +150,26 @@ TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenExceedingMaximumChannelCapaicity) } +TEST_F(DDSGatewayGenericTest, ThrowsErrorWhenAttemptingToRemoveNonexistantChannel) +{ + // ===== Setup + auto testServiceA = iox::capro::ServiceDescription("serviceA", "instanceA", "eventA"); + auto testServiceB = iox::capro::ServiceDescription("serviceB", "instanceB", "eventB"); + auto testServiceC = iox::capro::ServiceDescription("serviceC", "instanceC", "eventC"); + + TestDDSGatewayGeneric gw{}; + + // ===== Test + gw.addChannel(testServiceA); + gw.addChannel(testServiceB); + EXPECT_EQ(2, gw.getNumberOfChannels()); + + auto result = gw.discardChannel(testServiceC); + EXPECT_EQ(true, result.has_error()); + EXPECT_EQ(2, gw.getNumberOfChannels()); + +} + TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) { // ===== Setup @@ -160,7 +180,8 @@ TEST_F(DDSGatewayGenericTest, DiscardedChannelsAreNotStored) // ===== Test gw.addChannel(testService); EXPECT_EQ(1, gw.getNumberOfChannels()); - gw.discardChannel(testService); + auto result = gw.discardChannel(testService); + EXPECT_EQ(false, result.has_error()); EXPECT_EQ(0, gw.getNumberOfChannels()); }