From 90707525a3066176f98fc35f60d65c6c24243040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Fri, 30 Jul 2021 09:16:14 +0200 Subject: [PATCH] Moved example to other repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- .../RTPSTest_custom_transport/CMakeLists.txt | 55 ------ .../TestReaderSocket.cpp | 157 ------------------ .../TestReaderSocket.h | 62 ------- .../TestWriterSocket.cpp | 157 ------------------ .../TestWriterSocket.h | 47 ------ .../main_RTPSTest.cpp | 97 ----------- examples/CMakeLists.txt | 1 - 7 files changed, 576 deletions(-) delete mode 100644 examples/C++/RTPSTest_custom_transport/CMakeLists.txt delete mode 100644 examples/C++/RTPSTest_custom_transport/TestReaderSocket.cpp delete mode 100644 examples/C++/RTPSTest_custom_transport/TestReaderSocket.h delete mode 100644 examples/C++/RTPSTest_custom_transport/TestWriterSocket.cpp delete mode 100644 examples/C++/RTPSTest_custom_transport/TestWriterSocket.h delete mode 100644 examples/C++/RTPSTest_custom_transport/main_RTPSTest.cpp diff --git a/examples/C++/RTPSTest_custom_transport/CMakeLists.txt b/examples/C++/RTPSTest_custom_transport/CMakeLists.txt deleted file mode 100644 index 58e6debf896..00000000000 --- a/examples/C++/RTPSTest_custom_transport/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cmake_minimum_required(VERSION 2.8.12) - -if(NOT CMAKE_VERSION VERSION_LESS 3.0) - cmake_policy(SET CMP0048 NEW) -endif() - -project("RTPSTest_custom_transport") - -# Find requirements -if(NOT fastcdr_FOUND) - find_package(fastcdr REQUIRED) -endif() - -if(NOT foonathan_memory_FOUND) - find_package(foonathan_memory REQUIRED) -endif() - -if(NOT fastrtps_FOUND) - find_package(fastrtps REQUIRED) -endif() - -# Set C++11 -include(CheckCXXCompilerFlag) -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR - CMAKE_CXX_COMPILER_ID MATCHES "Clang") - check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) - if(SUPPORTS_CXX11) - add_compile_options(-std=c++11) - else() - message(FATAL_ERROR "Compiler doesn't support C++11") - endif() -endif() - -message(STATUS "Configuring RTPSTest_custom_transport...") -file(GLOB RTPSTESTASSOCKET_SOURCES "*.cpp") - -add_executable(RTPSTest_custom_transport ${RTPSTESTASSOCKET_SOURCES}) -target_link_libraries(RTPSTest_custom_transport fastrtps fastcdr foonathan_memory) -install(TARGETS RTPSTest_custom_transport - RUNTIME DESTINATION examples/C++/RTPSTest_custom_transport/${BIN_INSTALL_DIR} - ) diff --git a/examples/C++/RTPSTest_custom_transport/TestReaderSocket.cpp b/examples/C++/RTPSTest_custom_transport/TestReaderSocket.cpp deleted file mode 100644 index 52ef9d0c480..00000000000 --- a/examples/C++/RTPSTest_custom_transport/TestReaderSocket.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file TestReaderSocket.cpp - * - */ - -#include "TestReaderSocket.h" - -#include - -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -using namespace eprosima; -using namespace eprosima::fastdds; -using namespace eprosima::fastdds::rtps; - -TestReaderSocket::TestReaderSocket() - : mp_participant(nullptr) - , mp_reader(nullptr) - , mp_history(nullptr) -{ -} - -TestReaderSocket::~TestReaderSocket() -{ - fastrtps::rtps::RTPSDomain::removeRTPSParticipant(mp_participant); - delete(mp_history); -} - -static int callback_num = 0; - -bool TestReaderSocket::init( - std::string ip, - uint32_t port) -{ - fastrtps::rtps::RTPSParticipantAttributes PParam; - - //PREPARE TRANSPORTS - - // Lowest level is UDPv4 - auto udpTr = std::make_shared(); - - // Timestamp on top of UDPv4 - auto tsDesc = std::make_shared(udpTr); - tsDesc->callback_parameter = &callback_num; - tsDesc->callback = [](void* p, int32_t sender_time, int32_t my_time, uint32_t packet_len) - { - int* pNum = (int*)p; - *pNum = *pNum + 1; - - std::cout << "Packet no " << *pNum << " of " << packet_len << " bytes sent at " << sender_time << - " and received at " << my_time << std::endl; - }; - -#if HAVE_ZLIB || HAVE_BZIP2 - // Compression on top of timestamp - auto zDesc = std::make_shared(tsDesc); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.payload_compression.compression_library", - "AUTOMATIC")); - - // Header reduction on top of compression - auto hrDesc = std::make_shared(zDesc); -#else - // Header reduction on top of timestamp - auto hrDesc = std::make_shared(tsDesc); -#endif // if HAVE_ZLIB || HAVE_BZIP2 - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.header_reduction.remove_version", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.header_reduction.remove_vendor_id", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property( - "rtps.header_reduction.submessage.combine_id_and_flags", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property( - "rtps.header_reduction.submessage.compress_entitiy_ids", - "16,16")); - - // Activate custom transport chain - PParam.useBuiltinTransports = false; - PParam.userTransports.push_back(hrDesc); - - //CREATE PARTICIPANT - mp_participant = fastrtps::rtps::RTPSDomain::createParticipant(0, PParam); - if (mp_participant == nullptr) - { - return false; - } - //CREATE READERHISTORY - fastrtps::rtps::HistoryAttributes hatt; - hatt.payloadMaxSize = 1024; - mp_history = new fastrtps::rtps::ReaderHistory(hatt); - - //CREATE READER - fastrtps::rtps::ReaderAttributes ratt; - fastrtps::rtps::Locator_t loc; - fastrtps::rtps::IPLocator::setIPv4(loc, ip); - loc.port = static_cast(port); - ratt.endpoint.multicastLocatorList.push_back(loc); - mp_reader = fastrtps::rtps::RTPSDomain::createRTPSReader(mp_participant, ratt, mp_history, &m_listener); - if (mp_reader == nullptr) - { - return false; - } - - return true; -} - -void TestReaderSocket::run() -{ - printf("Enter number to stop reader.\n"); - int aux; - std::cin >> aux; -} - -void TestReaderSocket::MyListener::onNewCacheChangeAdded( - fastrtps::rtps::RTPSReader* reader, - const fastrtps::rtps::CacheChange_t* const change) -{ - printf("Received %u bytes:", change->serializedPayload.length); - for (uint32_t i = 0; i < change->serializedPayload.length; i++) - { - if ((i & 15) == 0) - { - printf("\n%06x ", i); - } - printf(" %02x", change->serializedPayload.data[i]); - } - printf("\n"); - reader->getHistory()->remove_change((fastrtps::rtps::CacheChange_t*)change); - m_received++; -} diff --git a/examples/C++/RTPSTest_custom_transport/TestReaderSocket.h b/examples/C++/RTPSTest_custom_transport/TestReaderSocket.h deleted file mode 100644 index c6183868031..00000000000 --- a/examples/C++/RTPSTest_custom_transport/TestReaderSocket.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file TestReaderSocket.h - * - */ - -#ifndef TESTREADERSOCKET_H_ -#define TESTREADERSOCKET_H_ - -#include -#include -#include - -class TestReaderSocket -{ -public: - - TestReaderSocket(); - virtual ~TestReaderSocket(); - eprosima::fastrtps::rtps::RTPSParticipant* mp_participant; - eprosima::fastrtps::rtps::RTPSReader* mp_reader; - eprosima::fastrtps::rtps::ReaderHistory* mp_history; - bool init( - std::string ip, - uint32_t port); - void run(); - class MyListener : public eprosima::fastrtps::rtps::ReaderListener - { - public: - - MyListener() - : m_received(0) - { - } - - ~MyListener() - { - } - - void onNewCacheChangeAdded( - eprosima::fastrtps::rtps::RTPSReader* reader, - const eprosima::fastrtps::rtps::CacheChange_t* const change); - uint32_t m_received; - } - m_listener; - -}; - -#endif // ifndef TESTREADERSOCKET_H_ diff --git a/examples/C++/RTPSTest_custom_transport/TestWriterSocket.cpp b/examples/C++/RTPSTest_custom_transport/TestWriterSocket.cpp deleted file mode 100644 index c722f5787f8..00000000000 --- a/examples/C++/RTPSTest_custom_transport/TestWriterSocket.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file TestWriterSocket.cpp - * - */ - -#include "TestWriterSocket.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace eprosima; -using namespace eprosima::fastdds; -using namespace eprosima::fastdds::rtps; - -TestWriterSocket::TestWriterSocket() - : mp_participant(nullptr) - , mp_writer(nullptr) - , mp_history(nullptr) -{ -} - -TestWriterSocket::~TestWriterSocket() -{ - fastrtps::rtps::RTPSDomain::removeRTPSParticipant(mp_participant); - delete(mp_history); -} - -static int callback_num = 0; - -bool TestWriterSocket::init( - std::string ip, - uint32_t port) -{ - fastrtps::rtps::RTPSParticipantAttributes PParam; - - //PREPARE TRANSPORTS - - // Lowest level is UDPv4 - auto udpTr = std::make_shared(); - - // Timestamp on top of UDPv4 - auto tsDesc = std::make_shared(udpTr); - tsDesc->callback_parameter = &callback_num; - tsDesc->callback = [](void* p, int32_t sender_time, int32_t my_time, uint32_t packet_len) - { - int* pNum = (int*)p; - *pNum = *pNum + 1; - - std::cout << "Packet no " << *pNum << " of " << packet_len << " bytes sent at " << sender_time << - " and received at " << my_time << std::endl; - }; - -#if HAVE_ZLIB || HAVE_BZIP2 - // Compression on top of timestamp - auto zDesc = std::make_shared(tsDesc); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.payload_compression.compression_library", - "AUTOMATIC")); - - // Header reduction on top of compression - auto hrDesc = std::make_shared(zDesc); -#else - // Header reduction on top of timestamp - auto hrDesc = std::make_shared(tsDesc); -#endif // if HAVE_ZLIB || HAVE_BZIP2 - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.header_reduction.remove_version", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property("rtps.header_reduction.remove_vendor_id", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property( - "rtps.header_reduction.submessage.combine_id_and_flags", - "true")); - PParam.properties.properties().emplace_back(fastrtps::rtps::Property( - "rtps.header_reduction.submessage.compress_entitiy_ids", - "16,16")); - - // Activate custom transport chain - PParam.useBuiltinTransports = false; - PParam.userTransports.push_back(hrDesc); - - //CREATE PARTICIPANT - mp_participant = fastrtps::rtps::RTPSDomain::createParticipant(0, PParam); - if (mp_participant == nullptr) - { - return false; - } - - //CREATE WRITERHISTORY - fastrtps::rtps::HistoryAttributes hatt; - hatt.payloadMaxSize = 255; - mp_history = new fastrtps::rtps::WriterHistory(hatt); - - //CREATE WRITER - fastrtps::rtps::WriterAttributes watt; - watt.endpoint.reliabilityKind = fastrtps::rtps::BEST_EFFORT; - mp_writer = fastrtps::rtps::RTPSDomain::createRTPSWriter(mp_participant, watt, mp_history); - if (mp_writer == nullptr) - { - return false; - } - - //ADD REMOTE READER (IN THIS CASE A READER IN THE SAME MACHINE) - fastrtps::rtps::ReaderProxyData ratt(4u, 1u); - ratt.guid({fastrtps::rtps::c_GuidPrefix_Unknown, 0x304}); - fastrtps::rtps::Locator_t loc; - fastrtps::rtps::IPLocator::setIPv4(loc, ip); - loc.port = static_cast(port); - ratt.add_multicast_locator(loc); - mp_writer->matched_reader_add(ratt); - return true; -} - -void TestWriterSocket::run( - uint16_t nmsgs) -{ - for (int i = 0; i < nmsgs; ++i ) - { - fastrtps::rtps::CacheChange_t* ch = mp_writer->new_change([]() -> uint32_t - { - return 255; - }, fastrtps::rtps::ALIVE); -#if defined(_WIN32) - ch->serializedPayload.length = - sprintf_s((char*)ch->serializedPayload.data, 255, "My example string %d", i) + 1; -#else - ch->serializedPayload.length = - sprintf((char*)ch->serializedPayload.data, "My example string %d", i) + 1; -#endif // if defined(_WIN32) - printf("Sending: %s\n", (char*)ch->serializedPayload.data); - mp_history->add_change(ch); - } -} diff --git a/examples/C++/RTPSTest_custom_transport/TestWriterSocket.h b/examples/C++/RTPSTest_custom_transport/TestWriterSocket.h deleted file mode 100644 index 7c2f9af06b3..00000000000 --- a/examples/C++/RTPSTest_custom_transport/TestWriterSocket.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @file TestWriterSocket.h - * - */ - -#ifndef TESTWRITERSOCKET_H_ -#define TESTWRITERSOCKET_H_ - -#include -#include - - -#include -#include -#include - -class TestWriterSocket -{ -public: - - TestWriterSocket(); - virtual ~TestWriterSocket(); - eprosima::fastrtps::rtps::RTPSParticipant* mp_participant; - eprosima::fastrtps::rtps::RTPSWriter* mp_writer; - eprosima::fastrtps::rtps::WriterHistory* mp_history; - bool init( - std::string ip, - uint32_t port); - void run( - uint16_t nmsgs); -}; - -#endif /* TESTWRITER_H_ */ diff --git a/examples/C++/RTPSTest_custom_transport/main_RTPSTest.cpp b/examples/C++/RTPSTest_custom_transport/main_RTPSTest.cpp deleted file mode 100644 index 2b3c1bea316..00000000000 --- a/examples/C++/RTPSTest_custom_transport/main_RTPSTest.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include -#include -#include - -#include "fastrtps/log/Log.h" -#include "fastrtps/rtps/RTPSDomain.h" - -#include "TestWriterSocket.h" -#include "TestReaderSocket.h" - -using namespace eprosima; -using namespace fastrtps; -using namespace rtps; -using namespace std; - - -int main( - int argc, - char** argv) -{ - - std::cout << "Starting" << std::endl; - int type; - uint32_t port = 7000; - if (argc > 1) - { - if (strcmp(argv[1], "writer") == 0) - { - type = 1; - } - else if (strcmp(argv[1], "reader") == 0) - { - type = 2; - } - else - { - std::cout << "NEEDS writer OR reader as first argument" << std::endl; - return 0; - } - - if (argc > 2) - { - port = atol(argv[2]); - } - } - else - { - std::cout << "NEEDS writer OR reader ARGUMENT" << std::endl; - std::cout << "RTPSTest writer" << std::endl; - std::cout << "RTPSTest reader" << std::endl; - return 0; - } - switch (type) - { - case 1: - { - TestWriterSocket TW; - if (TW.init("239.255.1.5", port)) - { - TW.run(10); - } - break; - } - case 2: - { - TestReaderSocket TR; - if (TR.init("239.255.1.5", port)) - { - TR.run(); - } - break; - } - } - - RTPSDomain::stopAll(); - std::cout << "EVERYTHING STOPPED FINE" << std::endl; - - return 0; -} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b0936edda87..23bf59ae8a7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -39,7 +39,6 @@ add_subdirectory(C++/StaticHelloWorldExample) add_subdirectory(C++/XMLProfiles) add_subdirectory(C++/Benchmark) add_subdirectory(C++/DDS) -add_subdirectory(C++/RTPSTest_custom_transport) if(SECURITY) add_subdirectory(C++/SecureHelloWorldExample)