├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── build.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── NOTICE.md ├── README.md ├── cmake ├── Config.cmake.in ├── cyclonedds │ ├── CMakeLists.txt │ ├── COLCON_IGNORE │ ├── cyclonedds-cxx.cmake.in │ └── cyclonedds.cmake.in └── fastdds │ ├── CMakeLists.txt │ ├── COLCON_IGNORE │ ├── fastcdr.cmake.in │ ├── fastdds.cmake.in │ ├── fastddsgen.cmake.in │ └── foonathan_memory_vendor.cmake.in ├── doc └── 3rd_party_licenses │ ├── cyclonedds-cxx │ └── LICENSE │ ├── cyclonedds │ ├── LICENSE │ └── NOTICE.md │ └── fastdds │ └── LICENSE ├── examples ├── README.md ├── docker │ ├── publisher_node.dockerfile │ ├── publisher_node.entrypoint │ ├── simple_internode_communication.yml │ ├── subscriber_node.dockerfile │ └── subscriber_node.entrypoint └── run_example.sh ├── include └── iceoryx_dds │ ├── dds │ ├── cyclone_context.hpp │ ├── cyclone_data_reader.hpp │ ├── cyclone_data_writer.hpp │ ├── data_reader.hpp │ ├── data_writer.hpp │ ├── dds_config.hpp │ ├── dds_types.hpp │ ├── fast_context.hpp │ ├── fast_data_reader.hpp │ ├── fast_data_writer.hpp │ └── iox_chunk_datagram_header.hpp │ ├── gateway │ ├── dds_to_iox.hpp │ └── iox_to_dds.hpp │ └── internal │ └── gateway │ ├── dds_to_iox.inl │ └── iox_to_dds.inl ├── msg └── Mempool.idl ├── source ├── gateway │ └── main.cpp └── iceoryx_dds │ └── dds │ ├── cyclone_context.cpp │ ├── cyclone_data_reader.cpp │ ├── cyclone_data_writer.cpp │ ├── fast_context.cpp │ ├── fast_data_reader.cpp │ ├── fast_data_writer.cpp │ └── iox_chunk_datagram_header.cpp └── test ├── .clang-tidy ├── CMakeLists.txt ├── helpers └── fixture_dds_gateway.hpp ├── mocks └── google_mocks.hpp ├── moduletests ├── main.cpp ├── test_cyclone_data_reader.cpp ├── test_dds_to_iox.cpp ├── test_fast_data_reader.cpp └── test_iox_to_dds.cpp └── test.hpp /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # for complete code formatting of codebase please type: 3 | # "find . -type f -regex '.*\.\(inl\|cpp\|h\|hpp\|cc\|c\|cxx\)' -exec clang-format -style=file -i {} \;" 4 | Language: Cpp 5 | # BasedOnStyle: LLVM 6 | AccessModifierOffset: -2 7 | AlignAfterOpenBracket: Align 8 | AlignConsecutiveAssignments: false 9 | AlignConsecutiveDeclarations: false 10 | AlignEscapedNewlinesLeft: false 11 | AlignOperands: true 12 | AlignTrailingComments: true 13 | AllowAllParametersOfDeclarationOnNextLine: true 14 | AllowShortBlocksOnASingleLine: false 15 | AllowShortCaseLabelsOnASingleLine: false 16 | AllowShortFunctionsOnASingleLine: None 17 | AllowShortIfStatementsOnASingleLine: false 18 | AllowShortLoopsOnASingleLine: false 19 | AlwaysBreakAfterDefinitionReturnType: None 20 | AlwaysBreakAfterReturnType: None 21 | AlwaysBreakBeforeMultilineStrings: false 22 | AlwaysBreakTemplateDeclarations: true 23 | BinPackArguments: false 24 | BinPackParameters: false # If false, a function declaration's or function definition's parameters will either all be on the same line or will have one line each. 25 | BreakBeforeBraces: Custom 26 | BraceWrapping: 27 | AfterCaseLabel: true 28 | AfterClass: true 29 | AfterControlStatement: true 30 | AfterEnum: true 31 | AfterFunction: true 32 | AfterNamespace: true 33 | AfterObjCDeclaration: true 34 | AfterStruct: true 35 | AfterUnion: true 36 | BeforeCatch: true 37 | BeforeElse: true 38 | IndentBraces: false 39 | BreakBeforeBinaryOperators: NonAssignment 40 | BreakBeforeTernaryOperators: true 41 | BreakConstructorInitializersBeforeComma: true 42 | ColumnLimit: 120 43 | CompactNamespaces: true 44 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 45 | ConstructorInitializerIndentWidth: 4 46 | ContinuationIndentWidth: 4 47 | Cpp11BracedListStyle: true 48 | DerivePointerAlignment: false 49 | DisableFormat: false 50 | ExperimentalAutoDetectBinPacking: false 51 | FixNamespaceComments: true 52 | IndentCaseLabels: false 53 | IndentWidth: 4 54 | IndentWrappedFunctionNames: false 55 | KeepEmptyLinesAtTheStartOfBlocks: false 56 | MacroBlockBegin: '' 57 | MacroBlockEnd: '' 58 | MaxEmptyLinesToKeep: 2 59 | NamespaceIndentation: None 60 | PenaltyBreakBeforeFirstCallParameter: 19 61 | PenaltyBreakComment: 300 62 | PenaltyBreakFirstLessLess: 120 63 | PenaltyBreakString: 1000 64 | PenaltyExcessCharacter: 1000000 65 | PenaltyReturnTypeOnItsOwnLine: 60 66 | PointerAlignment: Left 67 | ReflowComments: true 68 | SortIncludes: true 69 | SpaceAfterCStyleCast: false 70 | SpaceBeforeAssignmentOperators: true 71 | SpaceBeforeParens: ControlStatements 72 | SpaceInEmptyParentheses: false 73 | SpacesBeforeTrailingComments: 1 74 | SpacesInAngles: false 75 | SpacesInContainerLiterals: false 76 | SpacesInCStyleCastParentheses: false 77 | SpacesInParentheses: false 78 | SpacesInSquareBrackets: false 79 | Standard: c++14 80 | TabWidth: 4 81 | UseTab: Never 82 | ... 83 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Required information 11 | 12 | **Operating system:** 13 | E.g. Ubuntu 18.04 LTS 14 | 15 | **Compiler version:** 16 | E.g. GCC 7.4.0 17 | 18 | **Observed result or behaviour:** 19 | A clear and precise description of the observed result. 20 | 21 | **Expected result or behaviour:** 22 | What do you expect to happen? 23 | 24 | **Conditions where it occurred / Performed steps:** 25 | Describe how one can reproduce the bug. 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Brief feature description 11 | 12 | Please describe in a few sentences what should be implemented 13 | 14 | ## Detailed information 15 | 16 | E.g. a list of pros and cons of different considerations and how iceoryx and its user could benefit from it 17 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Pre-Review Checklist for the PR Author 2 | 3 | 1. [ ] Code is formatted with clang-format 4 | 1. [ ] Update the PR title 5 | - Follow the same conventions as for commit messages 6 | - Link to the relevant issue 7 | 1. [ ] Relevant issues are linked 8 | 1. [ ] Add sensible notes for the reviewer 9 | 1. [ ] All checks have passed 10 | 1. [ ] Assign PR to reviewer 11 | 12 | ## Notes for Reviewer 13 | 14 | 15 | ## Checklist for the PR Reviewer 16 | 17 | - [ ] Commits are properly organized and messages are according to the guideline 18 | - [ ] Code according to our coding style and naming conventions 19 | - [ ] Unit tests have been written for new behavior 20 | - [ ] Copyright owner are updated in the changed files 21 | - [ ] PR title describes the changes 22 | 23 | ## Post-review Checklist for the PR Author 24 | 25 | 1. [ ] All open points are addressed and tracked via issues 26 | 27 | ## References 28 | 29 | - Closes **TBD** 30 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # This workflow builds the repo 2 | 3 | name: Build 4 | 5 | # Triggers the workflow on push or pull request events but only for the main branch 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main, release* ] 11 | workflow_dispatch: 12 | 13 | jobs: 14 | build-ubuntu-cyclone-dds: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Install dependencies 19 | run: sudo apt update && sudo apt install -y libacl1-dev libncurses5-dev 20 | - name: Build 21 | run: cmake -Bbuild -DBUILD_TEST=ON -DDDS_STACK=CYCLONE_DDS && cmake --build build -- -j$(nproc) 22 | - name: Module tests 23 | run: ./build/dds_gateway/test/dds_gateway_moduletests 24 | build-ubuntu-fast-dds: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@v3 28 | - name: Install dependencies 29 | run: sudo apt update && sudo apt install -y libacl1-dev libncurses5-dev 30 | - name: Build 31 | run: cmake -Bbuild -DBUILD_TEST=ON -DDDS_STACK=FAST_DDS && cmake --build build -- -j$(nproc) 32 | - name: Module tests 33 | run: LD_LIBRARY_PATH=./build/dependencies/install/lib ./build/dds_gateway/test/dds_gateway_moduletests 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | install 3 | clangd 4 | .vscode 5 | *.project 6 | __pycache__ 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. 3 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | 19 | cmake_minimum_required(VERSION 3.16) 20 | 21 | # check if iceoryx is in CMAKE_PREFIX_PATH 22 | find_package(iceoryx_platform QUIET) 23 | find_package(iceoryx_hoofs QUIET) 24 | find_package(iceoryx_posh QUIET) 25 | 26 | # Link iceoryx_hoofs and iceoryx_posh libraries statically 27 | option(BUILD_SHARED_LIBS "Link libraries dynamically" OFF) 28 | 29 | # Create compile_commands.json file 30 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 31 | 32 | # fetch iceoryx if not found 33 | if(NOT iceoryx_platform_FOUND OR NOT iceoryx_hoofs_FOUND OR NOT iceoryx_posh_FOUND) 34 | if(iceoryx_platform_FOUND) 35 | message(FATAL_ERROR "iceoryx_platform was not found with 'find_package' but other parts were found!") 36 | endif() 37 | if(iceoryx_hoofs_FOUND) 38 | message(FATAL_ERROR "iceoryx_hoofs was not found with 'find_package' but other parts were found!") 39 | endif() 40 | if(iceoryx_posh_FOUND) 41 | message(FATAL_ERROR "iceoryx_posh was not found with 'find_package' but other parts were found!") 42 | endif() 43 | 44 | include(FetchContent) 45 | FetchContent_Declare( 46 | iceoryx 47 | GIT_REPOSITORY https://github.com/eclipse-iceoryx/iceoryx.git 48 | GIT_TAG v2.95.3 49 | ) 50 | FetchContent_GetProperties(iceoryx) 51 | if (NOT iceoryx_POPULATED) 52 | message(STATUS "updating: iceoryx" ) 53 | FetchContent_Populate(iceoryx) 54 | endif() 55 | 56 | set(ICEORYX_WITH_FETCH_CONTENT true CACHE INTERNAL "") 57 | set(iceoryx_SOURCE_DIR ${iceoryx_SOURCE_DIR} CACHE INTERNAL "") 58 | set(iceoryx_BINARY_DIR ${iceoryx_BINARY_DIR} CACHE INTERNAL "") 59 | set(TEMP_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 60 | set(CMAKE_CURRENT_SOURCE_DIR ${iceoryx_SOURCE_DIR}/iceoryx_meta/ CACHE INTERNAL "") 61 | include(${iceoryx_SOURCE_DIR}/iceoryx_meta/tests.cmake) 62 | set(CMAKE_CURRENT_SOURCE_DIR ${TEMP_DIR} CACHE INTERNAL "") 63 | endif() 64 | 65 | if(ICEORYX_WITH_FETCH_CONTENT) 66 | # we do not need to build the examples 67 | set(EXAMPLES OFF) 68 | 69 | add_subdirectory(${iceoryx_SOURCE_DIR}/iceoryx_platform ${iceoryx_BINARY_DIR}/iceoryx_platform) 70 | add_subdirectory(${iceoryx_SOURCE_DIR}/iceoryx_hoofs ${iceoryx_BINARY_DIR}/iceoryx_hoofs) 71 | add_subdirectory(${iceoryx_SOURCE_DIR}/iceoryx_posh ${iceoryx_BINARY_DIR}/iceoryx_posh) 72 | 73 | find_package(iceoryx_platform REQUIRED) 74 | find_package(iceoryx_hoofs REQUIRED) 75 | find_package(iceoryx_posh REQUIRED) 76 | endif() 77 | 78 | include(IceoryxPackageHelper) 79 | include(IceoryxPlatform) 80 | 81 | project(iceoryx_dds VERSION 0.1) 82 | 83 | set(PREFIX iceoryx/v${CMAKE_PROJECT_VERSION}) 84 | 85 | if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin) 86 | option(BUILD_SHARED_LIBS "Create shared libraries by default" ON) 87 | endif() 88 | 89 | # 90 | ########## feature flags ########## 91 | # 92 | set(ALLOWED_VALUES CYCLONE_DDS FAST_DDS) 93 | set(DDS_STACK CYCLONE_DDS CACHE STRING "Activate use of DDS stack") 94 | set_property(CACHE DDS_STACK PROPERTY STRINGS CYCLONE_DDS FAST_DDS) 95 | # Check that specified value is allowed 96 | if(NOT DDS_STACK IN_LIST ALLOWED_VALUES) 97 | message(FATAL_ERROR, "Wrong configuration of DDS_STACK. Allowed values: ${ALLOWED_VALUES}") 98 | endif() 99 | 100 | if(${DDS_STACK} STREQUAL "CYCLONE_DDS") 101 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cyclonedds ${CMAKE_BINARY_DIR}/dependencies/cyclonedds/prebuild) 102 | message(INFO " Using CycloneDDS stack") 103 | find_package(CycloneDDS CONFIG REQUIRED) 104 | find_package(CycloneDDS-CXX CONFIG REQUIRED) 105 | elseif(${DDS_STACK} STREQUAL "FAST_DDS") 106 | add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fastdds ${CMAKE_BINARY_DIR}/dependencies/fastdds/prebuild) 107 | message(INFO " Using FastDDS stack") 108 | find_package(fastcdr CONFIG REQUIRED) 109 | find_package(foonathan_memory CONFIG REQUIRED) 110 | find_package(fastrtps CONFIG REQUIRED) 111 | endif() 112 | 113 | # 114 | ########## build building-block library ########## 115 | # 116 | iox_add_library( 117 | NO_FIND_PACKAGE_SUPPORT 118 | TARGET iceoryx_dds 119 | NAMESPACE iceoryx_dds 120 | PROJECT_PREFIX ${PREFIX} 121 | BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include 122 | ${CMAKE_BINARY_DIR}/dependencies/install/include 123 | INSTALL_INTERFACE include/${PREFIX} 124 | PRIVATE_LIBS iceoryx_posh::iceoryx_posh 125 | iceoryx_posh::iceoryx_posh_config 126 | iceoryx_posh::iceoryx_posh_gateway 127 | iceoryx_hoofs::iceoryx_hoofs 128 | ) 129 | 130 | if(${DDS_STACK} STREQUAL "CYCLONE_DDS") 131 | target_sources(iceoryx_dds 132 | PRIVATE 133 | source/iceoryx_dds/dds/cyclone_context.cpp 134 | source/iceoryx_dds/dds/cyclone_data_reader.cpp 135 | source/iceoryx_dds/dds/cyclone_data_writer.cpp 136 | source/iceoryx_dds/dds/iox_chunk_datagram_header.cpp 137 | ) 138 | 139 | # Generate IDL at configure time 140 | set(MESSAGE_DEFINITION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/msg") 141 | get_filename_component(MEMPOOL_IDL "${MESSAGE_DEFINITION_DIR}/Mempool.idl" ABSOLUTE) 142 | 143 | add_custom_command( 144 | OUTPUT "Mempool.hpp" 145 | COMMAND CycloneDDS::idlc 146 | ARGS -l $ ${MEMPOOL_IDL} 147 | DEPENDS CycloneDDS::idlc CycloneDDS-CXX::idlcxx 148 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 149 | COMMENT "Generating serialization for Mempool bytestream" 150 | VERBATIM 151 | ) 152 | 153 | add_custom_target(mempool_header ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/Mempool.hpp) 154 | 155 | add_dependencies(iceoryx_dds mempool_header) 156 | 157 | target_include_directories(iceoryx_dds PUBLIC 158 | $ 159 | $ 160 | ) 161 | 162 | target_compile_definitions(iceoryx_dds PUBLIC -DUSE_CYCLONE_DDS) 163 | target_link_libraries(iceoryx_dds 164 | PUBLIC 165 | CycloneDDS-CXX::ddscxx 166 | iceoryx_hoofs::iceoryx_hoofs 167 | ) 168 | elseif(${DDS_STACK} STREQUAL "FAST_DDS") 169 | # Generate IDL at configure time 170 | set(MESSAGE_DEFINITION_DIR "${CMAKE_CURRENT_SOURCE_DIR}/msg") 171 | get_filename_component(MEMPOOL_IDL "${MESSAGE_DEFINITION_DIR}/Mempool.idl" ABSOLUTE) 172 | 173 | find_program(FASTDDS_GEN "fastddsgen") 174 | if(NOT FASTDDS_GEN) 175 | message(FATAL_ERROR "Could not find program fastddsgen in path") 176 | endif() 177 | 178 | add_custom_command( 179 | OUTPUT "Mempool.h" "Mempool.cxx" "MempoolPubSubTypes.h" "MempoolPubSubTypes.cxx" 180 | COMMAND ${FASTDDS_GEN} 181 | ARGS -replace ${MEMPOOL_IDL} 182 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 183 | COMMENT "Generating serialization for Mempool bytestream" 184 | VERBATIM 185 | ) 186 | 187 | add_custom_target(mempool_files ALL DEPENDS 188 | ${CMAKE_CURRENT_BINARY_DIR}/Mempool.h 189 | ${CMAKE_CURRENT_BINARY_DIR}/Mempool.cxx 190 | ${CMAKE_CURRENT_BINARY_DIR}/MempoolPubSubTypes.h 191 | ${CMAKE_CURRENT_BINARY_DIR}/MempoolPubSubTypes.cxx 192 | ) 193 | 194 | add_dependencies(iceoryx_dds mempool_files) 195 | 196 | target_sources(iceoryx_dds 197 | PRIVATE 198 | ${CMAKE_CURRENT_BINARY_DIR}/Mempool.cxx 199 | ${CMAKE_CURRENT_BINARY_DIR}/MempoolPubSubTypes.cxx 200 | source/iceoryx_dds/dds/fast_context.cpp 201 | source/iceoryx_dds/dds/fast_data_reader.cpp 202 | source/iceoryx_dds/dds/fast_data_writer.cpp 203 | source/iceoryx_dds/dds/iox_chunk_datagram_header.cpp 204 | ) 205 | 206 | target_include_directories(iceoryx_dds PUBLIC 207 | $ 208 | $ 209 | ) 210 | 211 | target_compile_definitions(iceoryx_dds PUBLIC -DUSE_FAST_DDS) 212 | target_link_libraries(iceoryx_dds 213 | PUBLIC 214 | fastrtps 215 | fastcdr 216 | foonathan_memory 217 | iceoryx_hoofs::iceoryx_hoofs 218 | ) 219 | endif() 220 | 221 | # 222 | ########## build gateway app ########## 223 | # 224 | iox_add_executable( 225 | NO_PACKAGE_SETUP 226 | NO_FIND_PACKAGE_SUPPORT 227 | TARGET iox-dds-gateway 228 | LIBS iceoryx_posh::iceoryx_posh 229 | iceoryx_posh::iceoryx_posh_gateway 230 | iceoryx_posh::iceoryx_posh_config 231 | iceoryx_dds::iceoryx_dds 232 | FILES 233 | source/gateway/main.cpp 234 | ) 235 | 236 | # 237 | ########## build test executables ########## 238 | # 239 | if(BUILD_TEST) 240 | add_subdirectory(test) 241 | endif() 242 | 243 | if(ICEORYX_WITH_FETCH_CONTENT) 244 | message(" 245 | ############################################################# 246 | The project was build by obtaining iceoryx with FetchContent. 247 | If you want to use an existing installation use 248 | '-DCMAKE_PREFIX_PATH=/path/to/installed/iceoryx'! 249 | ############################################################# 250 | ") 251 | endif() 252 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE.md: -------------------------------------------------------------------------------- 1 | # Notices for Eclipse iceoryx 2 | 3 | This content is produced and maintained by the Eclipse iceoryx project. 4 | 5 | * Project home: 6 | 7 | ## Trademarks 8 | 9 | Eclipse iceoryx is a trademark of the Eclipse Foundation. 10 | 11 | ## Copyright 12 | 13 | All content is the property of the respective authors or their employers. For 14 | more information regarding authorship of content, please consult the listed 15 | source code repository logs. 16 | 17 | ## Declared Project Licenses 18 | 19 | This program and the accompanying materials are made available under the terms 20 | of the Apache License, Version 2.0 which is available at 21 | . 22 | 23 | SPDX-License-Identifier: Apache-2.0 24 | 25 | ## Source Code 26 | 27 | The project maintains the following source code repositories: 28 | 29 | * 30 | 31 | ## Third-party Dependencies 32 | 33 | This project leverages the following third party content. 34 | The corresponding license files can be found at or in the folder `share/doc/iceoryx/3rd_party_licenses` of your local iceoryx installation. 35 | 36 | ### System Libraries 37 | 38 | libacl library 39 | 40 | * Usage: as-is, dynamic-linking 41 | * Notes: system-header `` is used. 42 | 43 | libncurses library 44 | 45 | * Usage: as-is, dynamic-linking 46 | * Notes: system-header `` is used. 47 | 48 | ### Build Dependencies 49 | 50 | Eclipse Cyclone DDS (Branch master) 51 | 52 | * License: Eclipse Public License v. 2.0 or the Eclipse Distribution License v. 1.0 53 | * Project: 54 | * Source: 55 | * Usage: as-is, static-linking 56 | 57 | C++ binding for Eclipse Cyclone DDS (Branch master) 58 | 59 | * License: Eclipse Public License v. 2.0 or the Eclipse Distribution License v. 1.0 60 | * Project: 61 | * Source: 62 | * Usage: as-is, static-linking 63 | 64 | ## Cryptography 65 | 66 | Content may contain encryption software. The country in which you are currently 67 | may have restrictions on the import, possession, and use, and/or re-export to 68 | another country, of encryption software. BEFORE using any encryption software, 69 | please check the country's laws, regulations and policies concerning the import, 70 | possession, or use, and re-export of encryption software, to see if this is 71 | permitted. 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gateway to DDS Networks 2 | 3 | A gateway for bridging between iceoryx systems and DDS networks. 4 | The gateway enables iceoryx systems running on separate hosts to communicate with each other. 5 | 6 | i.e. Data published by a publisher on `Host A` can be received by a matching subscriber on `Host B`. 7 | 8 | # Organization 9 | 10 | This module exports the `iox-dds-gateway` executable which manages a POSH runtime 11 | and handles the gateway logic of communication. 12 | 13 | The common building blocks logic for this binary are consolidated in the exported 14 | library, `libiceoryx_dds`. 15 | 16 | Applications may instead directly embed the gateway by using the exported lib. 17 | 18 | # Building 19 | 20 | The DDS stack used by the gateway is abstracted and needs to made explicit at compile time. 21 | 22 | ## Pre-requisites 23 | 24 | - Bison is installed 25 | - CMake is installed 26 | 27 | ```bash 28 | sudo apt install cmake bison 29 | ``` 30 | 31 | ## CMake Build 32 | 33 | You can use the standard iceoryx cmake build approach with an activated `-DDDS_STACK=CYCLONE_DDS` 34 | or `-DDDS_STACK=FAST_DDS` switch. 35 | 36 | By default, the value of DDS_STACK is CYCLONE_DDS. 37 | 38 | 1. Generate the necessary build files 39 | 40 | CycloneDDS: 41 | 42 | ```sh 43 | cmake -Bbuild -DBUILD_TEST=ON -DDDS_STACK=CYCLONE_DDS 44 | ``` 45 | 46 | FastDDS: 47 | 48 | ```sh 49 | cmake -Bbuild -DBUILD_TEST=ON -DDDS_STACK=CYCLONE_DDS 50 | ``` 51 | 52 | 2. Compile the source code 53 | 54 | ```sh 55 | cmake --build build -- -j$(nproc) 56 | ``` 57 | 58 | # Usage 59 | 60 | ## Configuration 61 | 62 | In `/etc/iceoryx/gateway_config.toml` you find the dds gateway configuration. 63 | Every service which should be offered or to which you would like to 64 | subscribe has to be listed in here. 65 | 66 | ```toml 67 | [[services]] 68 | service = "Radar" 69 | instance = "FrontLeft" 70 | event = "Object" 71 | 72 | [[services]] 73 | service = "larry_robotics" 74 | instance = "SystemMonitor" 75 | event = "larry_info" 76 | ``` 77 | 78 | In this example we would like to offer or subscribe to the two services 79 | `Radar.FrontLeft.Object` from our [icedelivery example](../iceoryx_examples/icedelivery) 80 | and to one service `larry_robotics.SystemMonitor.larry_info` from our 81 | [larry demonstrator](https://gitlab.com/larry.robotics/larry.robotics). 82 | 83 | ## Running icedelivery via CycloneDDS or FastDDS 84 | 85 | We can use CycloneDDS or FastDDS to run our [icedelivery example](../iceoryx_examples/icedelivery) 86 | via a local area network. First we have to adjust the gateway configuration file 87 | in `/etc/iceoryx/gateway_config.toml` and have to add the publisher service description 88 | from our example. 89 | 90 | ```toml 91 | [[services]] 92 | service = "Radar" 93 | instance = "FrontLeft" 94 | event = "Object" 95 | ``` 96 | 97 | Now two connected machines `A` and `B` can communicate over a local area network 98 | via iceoryx. 99 | 100 | Open three terminals on machine `A` and execute the following commands: 101 | 102 | - Terminal 1: `./build/iox-roudi` 103 | - Terminal 2: `./build/iceoryx_dds/iox-dds-gateway` to send all samples from the publisher to DDS 104 | - Terminal 3: `./build/iceoryx_examples/icedelivery/iox-cpp-publisher` 105 | 106 | Open another three terminals on machine `B` and execute the commands: 107 | 108 | - Terminal 1: `./build/iox-roudi` 109 | - Terminal 2: `./build/iceoryx_dds/iox-dds-gateway` to receive all samples from the publisher via DDS 110 | - Terminal 3: `./build/iceoryx_examples/icedelivery/iox-cpp-subscriber` 111 | 112 | ## Running with shared libraries 113 | 114 | Before running, you may need to add the install directory to the library load 115 | path if it is not standard (so that the runtime dependencies can be found). 116 | i.e. 117 | 118 | ``` 119 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$INSTALL_DIR/lib 120 | ``` 121 | 122 | Then, simply run the gateway executables as desired. 123 | 124 | e.g. 125 | 126 | ```bash 127 | $INSTALL_DIR/bin/iox-dds-gateway 128 | ``` 129 | -------------------------------------------------------------------------------- /cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | 18 | @PACKAGE_INIT@ 19 | 20 | include(CMakeFindDependencyMacro) 21 | 22 | find_dependency(iceoryx_platform) 23 | find_dependency(iceoryx_hoofs) 24 | find_dependency(iceoryx_posh) 25 | 26 | include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") 27 | check_required_components("@PROJECT_NAME@") 28 | -------------------------------------------------------------------------------- /cmake/cyclonedds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | cmake_minimum_required(VERSION 3.16) 18 | project(cyclonedds-build CXX) 19 | 20 | include(ProcessorCount) 21 | ProcessorCount(N) 22 | 23 | if(NOT N EQUAL 0) 24 | if(((${CMAKE_VERSION} VERSION_GREATER "3.12.0") OR ${CMAKE_VERSION} VERSION_EQUAL "3.12.0")) 25 | set(CMAKE_BUILD_FLAGS -j ${N}) 26 | elseif(LINUX OR QNX) 27 | set(CMAKE_BUILD_FLAGS -- -j ${N}) 28 | endif() 29 | endif() 30 | 31 | set(EXTRA_CMAKE_ARGS) 32 | if(DEFINED CMAKE_CXX_FLAGS) 33 | list(APPEND EXTRA_CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}) 34 | endif() 35 | 36 | if(DEFINED CMAKE_TOOLCHAIN_FILE) 37 | list(APPEND EXTRA_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") 38 | endif() 39 | 40 | # ===== Helpers 41 | function(fetch_and_install name) 42 | set(DOWNLOAD_CONFIG_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/download) 43 | set(SOURCE_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/src) 44 | set(BUILD_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/build) 45 | set(INSTALL_DIR ${CMAKE_BINARY_DIR}/dependencies/install) 46 | 47 | # Fetch source 48 | configure_file(${name}.cmake.in ${DOWNLOAD_CONFIG_DIR}/CMakeLists.txt) 49 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${DOWNLOAD_CONFIG_DIR}" "${EXTRA_CMAKE_ARGS}" 50 | RESULT_VARIABLE result 51 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 52 | if(result) 53 | message(FATAL_ERROR "CMake step [configure download] for ${name} failed: ${result}") 54 | endif() 55 | 56 | execute_process(COMMAND ${CMAKE_COMMAND} --build . ${CMAKE_BUILD_FLAGS} 57 | RESULT_VARIABLE result 58 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 59 | if(result) 60 | message(FATAL_ERROR "Build step [download] for ${name} failed: ${result}") 61 | endif() 62 | 63 | # Build 64 | file(MAKE_DIRECTORY "${BUILD_DIR}") 65 | 66 | # Parse additional CMake flags 67 | set(ADDITIONAL_CMAKE_FLAGS "") 68 | foreach(flag IN LISTS ARGN) 69 | list(APPEND ADDITIONAL_CMAKE_FLAGS ${flag}) 70 | endforeach() 71 | string( REPLACE ";" " " ADDITIONAL_CMAKE_FLAGS "${ADDITIONAL_CMAKE_FLAGS}") 72 | 73 | set(CYCLONE_BUILD_ARGS "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" "${EXTRA_CMAKE_ARGS}" "${SOURCE_DIR}") 74 | 75 | if(NOT ADDITIONAL_CMAKE_FLAGS STREQUAL "") 76 | list(APPEND CYCLONE_BUILD_ARGS ${ADDITIONAL_CMAKE_FLAGS}) 77 | endif() 78 | 79 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${CYCLONE_BUILD_ARGS} 80 | RESULT_VARIABLE result 81 | WORKING_DIRECTORY ${BUILD_DIR} ) 82 | if(result) 83 | message(FATAL_ERROR "CMake step [configure] for ${name} failed: ${result}") 84 | endif() 85 | 86 | execute_process(COMMAND ${CMAKE_COMMAND} --build . --target install ${CMAKE_BUILD_FLAGS} 87 | RESULT_VARIABLE result 88 | WORKING_DIRECTORY ${BUILD_DIR} ) 89 | if(result) 90 | message(FATAL_ERROR "Build step [build and install] for ${name} failed: ${result}") 91 | endif() 92 | endfunction() 93 | 94 | # ===== Install 95 | 96 | fetch_and_install(cyclonedds -DBUILD_IDLC=ON) 97 | fetch_and_install(cyclonedds-cxx) 98 | -------------------------------------------------------------------------------- /cmake/cyclonedds/COLCON_IGNORE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eclipse-iceoryx/iceoryx-gateway-dds/fead82bd1fb4f55de3fee4682553430598004b4d/cmake/cyclonedds/COLCON_IGNORE -------------------------------------------------------------------------------- /cmake/cyclonedds/cyclonedds-cxx.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | cmake_minimum_required(VERSION 3.16) 18 | 19 | project(cyclonedds-cxx-download NONE) 20 | 21 | include(ExternalProject) 22 | ExternalProject_Add(ext_cyclonedds_cxx 23 | GIT_REPOSITORY https://github.com/eclipse-cyclonedds/cyclonedds-cxx.git 24 | GIT_TAG e466345f44f9f0062bceb6928931a2177c616bef # Tag 0.8.2 25 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/cyclonedds-cxx/src" 26 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/cyclonedds-cxx/build" 27 | CONFIGURE_COMMAND "" 28 | BUILD_COMMAND "" 29 | INSTALL_COMMAND "" 30 | TEST_COMMAND "" 31 | ) 32 | -------------------------------------------------------------------------------- /cmake/cyclonedds/cyclonedds.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | # SPDX-License-Identifier: Apache-2.0 17 | cmake_minimum_required(VERSION 3.16) 18 | 19 | project(cyclonedds-download NONE) 20 | 21 | include(ExternalProject) 22 | ExternalProject_Add(ext_cyclonedds 23 | GIT_REPOSITORY https://github.com/eclipse-cyclonedds/cyclonedds.git 24 | GIT_TAG d63de72fab679b028725bbe1c314767e689723a0 # Tag 0.8.2 25 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/cyclonedds/src" 26 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/cyclonedds/build" 27 | CONFIGURE_COMMAND "" 28 | BUILD_COMMAND "" 29 | INSTALL_COMMAND "" 30 | TEST_COMMAND "" 31 | ) 32 | -------------------------------------------------------------------------------- /cmake/fastdds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | cmake_minimum_required(VERSION 3.16) 17 | project(fastdds-build CXX) 18 | 19 | include(ProcessorCount) 20 | ProcessorCount(N) 21 | 22 | if(NOT N EQUAL 0) 23 | if(((${CMAKE_VERSION} VERSION_GREATER "3.12.0") OR ${CMAKE_VERSION} VERSION_EQUAL "3.12.0")) 24 | set(CMAKE_BUILD_FLAGS -j ${N}) 25 | elseif(LINUX OR QNX) 26 | set(CMAKE_BUILD_FLAGS -- -j ${N}) 27 | endif() 28 | endif() 29 | 30 | set(EXTRA_CMAKE_ARGS) 31 | if(DEFINED CMAKE_CXX_FLAGS) 32 | list(APPEND EXTRA_CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}) 33 | endif() 34 | 35 | if(DEFINED CMAKE_TOOLCHAIN_FILE) 36 | list(APPEND EXTRA_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") 37 | endif() 38 | 39 | # ===== Helpers 40 | function(cmake_fetch_and_install name) 41 | set(DOWNLOAD_CONFIG_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/download) 42 | set(SOURCE_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/src) 43 | set(BUILD_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/build) 44 | set(INSTALL_DIR ${CMAKE_BINARY_DIR}/dependencies/install) 45 | 46 | # Fetch source 47 | configure_file(${name}.cmake.in ${DOWNLOAD_CONFIG_DIR}/CMakeLists.txt) 48 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${DOWNLOAD_CONFIG_DIR}" "${EXTRA_CMAKE_ARGS}" 49 | RESULT_VARIABLE result 50 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 51 | if(result) 52 | message(FATAL_ERROR "CMake step [configure download] for ${name} failed: ${result}") 53 | endif() 54 | 55 | execute_process(COMMAND ${CMAKE_COMMAND} --build . ${CMAKE_BUILD_FLAGS} 56 | RESULT_VARIABLE result 57 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 58 | if(result) 59 | message(FATAL_ERROR "Build step [download] for ${name} failed: ${result}") 60 | endif() 61 | 62 | # Build 63 | file(MAKE_DIRECTORY "${BUILD_DIR}") 64 | 65 | # Parse additional CMake flags 66 | set(ADDITIONAL_CMAKE_FLAGS "") 67 | foreach(flag IN LISTS ARGN) 68 | list(APPEND ADDITIONAL_CMAKE_FLAGS ${flag}) 69 | endforeach() 70 | string( REPLACE ";" " " ADDITIONAL_CMAKE_FLAGS "${ADDITIONAL_CMAKE_FLAGS}") 71 | 72 | set(FAST_BUILD_ARGS "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" "${EXTRA_CMAKE_ARGS}" "${SOURCE_DIR}") 73 | 74 | if(NOT ADDITIONAL_CMAKE_FLAGS STREQUAL "") 75 | list(APPEND FAST_BUILD_ARGS ${ADDITIONAL_CMAKE_FLAGS}) 76 | endif() 77 | 78 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${FAST_BUILD_ARGS} 79 | RESULT_VARIABLE result 80 | WORKING_DIRECTORY ${BUILD_DIR} ) 81 | if(result) 82 | message(FATAL_ERROR "CMake step [configure] for ${name} failed: ${result}") 83 | endif() 84 | 85 | execute_process(COMMAND ${CMAKE_COMMAND} --build . --target install ${CMAKE_BUILD_FLAGS} 86 | RESULT_VARIABLE result 87 | WORKING_DIRECTORY ${BUILD_DIR} ) 88 | if(result) 89 | message(FATAL_ERROR "Build step [build and install] for ${name} failed: ${result}") 90 | endif() 91 | endfunction() 92 | 93 | function(gradlew_fetch_and_install name) 94 | set(DOWNLOAD_CONFIG_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/download) 95 | set(SOURCE_DIR ${CMAKE_BINARY_DIR}/dependencies/${name}/src) 96 | set(INSTALL_DIR ${CMAKE_BINARY_DIR}/dependencies/install) 97 | 98 | # Fetch source 99 | configure_file(${name}.cmake.in ${DOWNLOAD_CONFIG_DIR}/CMakeLists.txt) 100 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${DOWNLOAD_CONFIG_DIR}" "${EXTRA_CMAKE_ARGS}" 101 | RESULT_VARIABLE result 102 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 103 | if(result) 104 | message(FATAL_ERROR "CMake step [configure download] for ${name} failed: ${result}") 105 | endif() 106 | 107 | execute_process(COMMAND ${CMAKE_COMMAND} --build . ${CMAKE_BUILD_FLAGS} 108 | RESULT_VARIABLE result 109 | WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} ) 110 | if(result) 111 | message(FATAL_ERROR "Build step [download] for ${name} failed: ${result}") 112 | endif() 113 | 114 | # Build 115 | set(GRADLEW_COMMAND ${SOURCE_DIR}/gradlew) 116 | 117 | execute_process(COMMAND ${GRADLEW_COMMAND} assemble 118 | RESULT_VARIABLE result 119 | WORKING_DIRECTORY ${SOURCE_DIR} ) 120 | if(result) 121 | message(FATAL_ERROR "CMake step [build] for ${name} failed: ${result}") 122 | endif() 123 | 124 | execute_process(COMMAND ${GRADLEW_COMMAND} install --install_path=${INSTALL_DIR} 125 | RESULT_VARIABLE result 126 | WORKING_DIRECTORY ${SOURCE_DIR} ) 127 | if(result) 128 | message(FATAL_ERROR "Build step [install] for ${name} failed: ${result}") 129 | endif() 130 | endfunction() 131 | 132 | # ===== Install 133 | 134 | cmake_fetch_and_install(foonathan_memory_vendor -DBUILD_SHARED_LIBS=ON) 135 | cmake_fetch_and_install(fastcdr) 136 | cmake_fetch_and_install(fastdds -DTHIRDPARTY=ON) 137 | 138 | gradlew_fetch_and_install(fastddsgen) 139 | -------------------------------------------------------------------------------- /cmake/fastdds/COLCON_IGNORE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eclipse-iceoryx/iceoryx-gateway-dds/fead82bd1fb4f55de3fee4682553430598004b4d/cmake/fastdds/COLCON_IGNORE -------------------------------------------------------------------------------- /cmake/fastdds/fastcdr.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | cmake_minimum_required(VERSION 3.16) 17 | 18 | project(fastcdr-download NONE) 19 | 20 | include(ExternalProject) 21 | ExternalProject_Add(ext_fastcdr 22 | GIT_REPOSITORY https://github.com/eProsima/Fast-CDR.git 23 | GIT_TAG v1.0.28 24 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/fastcdr/src" 25 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/fastcdr/build" 26 | CONFIGURE_COMMAND "" 27 | BUILD_COMMAND "" 28 | INSTALL_COMMAND "" 29 | TEST_COMMAND "" 30 | ) 31 | -------------------------------------------------------------------------------- /cmake/fastdds/fastdds.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | cmake_minimum_required(VERSION 3.16) 17 | 18 | project(fastdds-download NONE) 19 | 20 | include(ExternalProject) 21 | ExternalProject_Add(ext_fastdds 22 | GIT_REPOSITORY https://github.com/eProsima/Fast-DDS.git 23 | GIT_TAG v2.10.6 24 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/fastdds/src" 25 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/fastdds/build" 26 | CONFIGURE_COMMAND "" 27 | BUILD_COMMAND "" 28 | INSTALL_COMMAND "" 29 | TEST_COMMAND "" 30 | ) 31 | -------------------------------------------------------------------------------- /cmake/fastdds/fastddsgen.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | cmake_minimum_required(VERSION 3.16) 17 | 18 | project(fastddsgen-download NONE) 19 | 20 | include(ExternalProject) 21 | ExternalProject_Add(ext_fastddsgen 22 | GIT_REPOSITORY https://github.com/eProsima/Fast-DDS-Gen.git 23 | GIT_TAG v2.5.2 24 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/fastddsgen/src" 25 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/fastddsgen/build" 26 | CONFIGURE_COMMAND "" 27 | BUILD_COMMAND "" 28 | INSTALL_COMMAND "" 29 | TEST_COMMAND "" 30 | ) 31 | -------------------------------------------------------------------------------- /cmake/fastdds/foonathan_memory_vendor.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | cmake_minimum_required(VERSION 3.16) 17 | 18 | project(foonathan_memory_vendor-download NONE) 19 | 20 | include(ExternalProject) 21 | ExternalProject_Add(ext_foonathan_memory_vendor 22 | GIT_REPOSITORY https://github.com/eProsima/foonathan_memory_vendor.git 23 | GIT_TAG v1.3.0 24 | SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/foonathan_memory_vendor/src" 25 | BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/foonathan_memory_vendor/build" 26 | CONFIGURE_COMMAND "" 27 | BUILD_COMMAND "" 28 | INSTALL_COMMAND "" 29 | TEST_COMMAND "" 30 | ) 31 | -------------------------------------------------------------------------------- /doc/3rd_party_licenses/cyclonedds/LICENSE: -------------------------------------------------------------------------------- 1 | This program and the accompanying materials are made available under the 2 | terms of the Eclipse Public License v. 2.0 which is available at 3 | http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License 4 | v. 1.0 which is available at 5 | http://www.eclipse.org/org/documents/edl-v10.php. 6 | 7 | 8 | 9 | Eclipse Public License - v 2.0 10 | 11 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 12 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION 13 | OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 14 | 15 | 1. DEFINITIONS 16 | 17 | "Contribution" means: 18 | 19 | a) in the case of the initial Contributor, the initial content 20 | Distributed under this Agreement, and 21 | 22 | b) in the case of each subsequent Contributor: 23 | i) changes to the Program, and 24 | ii) additions to the Program; 25 | where such changes and/or additions to the Program originate from 26 | and are Distributed by that particular Contributor. A Contribution 27 | "originates" from a Contributor if it was added to the Program by 28 | such Contributor itself or anyone acting on such Contributor's behalf. 29 | Contributions do not include changes or additions to the Program that 30 | are not Modified Works. 31 | 32 | "Contributor" means any person or entity that Distributes the Program. 33 | 34 | "Licensed Patents" mean patent claims licensable by a Contributor which 35 | are necessarily infringed by the use or sale of its Contribution alone 36 | or when combined with the Program. 37 | 38 | "Program" means the Contributions Distributed in accordance with this 39 | Agreement. 40 | 41 | "Recipient" means anyone who receives the Program under this Agreement 42 | or any Secondary License (as applicable), including Contributors. 43 | 44 | "Derivative Works" shall mean any work, whether in Source Code or other 45 | form, that is based on (or derived from) the Program and for which the 46 | editorial revisions, annotations, elaborations, or other modifications 47 | represent, as a whole, an original work of authorship. 48 | 49 | "Modified Works" shall mean any work in Source Code or other form that 50 | results from an addition to, deletion from, or modification of the 51 | contents of the Program, including, for purposes of clarity any new file 52 | in Source Code form that contains any contents of the Program. Modified 53 | Works shall not include works that contain only declarations, 54 | interfaces, types, classes, structures, or files of the Program solely 55 | in each case in order to link to, bind by name, or subclass the Program 56 | or Modified Works thereof. 57 | 58 | "Distribute" means the acts of a) distributing or b) making available 59 | in any manner that enables the transfer of a copy. 60 | 61 | "Source Code" means the form of a Program preferred for making 62 | modifications, including but not limited to software source code, 63 | documentation source, and configuration files. 64 | 65 | "Secondary License" means either the GNU General Public License, 66 | Version 2.0, or any later versions of that license, including any 67 | exceptions or additional permissions as identified by the initial 68 | Contributor. 69 | 70 | 2. GRANT OF RIGHTS 71 | 72 | a) Subject to the terms of this Agreement, each Contributor hereby 73 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 74 | license to reproduce, prepare Derivative Works of, publicly display, 75 | publicly perform, Distribute and sublicense the Contribution of such 76 | Contributor, if any, and such Derivative Works. 77 | 78 | b) Subject to the terms of this Agreement, each Contributor hereby 79 | grants Recipient a non-exclusive, worldwide, royalty-free patent 80 | license under Licensed Patents to make, use, sell, offer to sell, 81 | import and otherwise transfer the Contribution of such Contributor, 82 | if any, in Source Code or other form. This patent license shall 83 | apply to the combination of the Contribution and the Program if, at 84 | the time the Contribution is added by the Contributor, such addition 85 | of the Contribution causes such combination to be covered by the 86 | Licensed Patents. The patent license shall not apply to any other 87 | combinations which include the Contribution. No hardware per se is 88 | licensed hereunder. 89 | 90 | c) Recipient understands that although each Contributor grants the 91 | licenses to its Contributions set forth herein, no assurances are 92 | provided by any Contributor that the Program does not infringe the 93 | patent or other intellectual property rights of any other entity. 94 | Each Contributor disclaims any liability to Recipient for claims 95 | brought by any other entity based on infringement of intellectual 96 | property rights or otherwise. As a condition to exercising the 97 | rights and licenses granted hereunder, each Recipient hereby 98 | assumes sole responsibility to secure any other intellectual 99 | property rights needed, if any. For example, if a third party 100 | patent license is required to allow Recipient to Distribute the 101 | Program, it is Recipient's responsibility to acquire that license 102 | before distributing the Program. 103 | 104 | d) Each Contributor represents that to its knowledge it has 105 | sufficient copyright rights in its Contribution, if any, to grant 106 | the copyright license set forth in this Agreement. 107 | 108 | e) Notwithstanding the terms of any Secondary License, no 109 | Contributor makes additional grants to any Recipient (other than 110 | those set forth in this Agreement) as a result of such Recipient's 111 | receipt of the Program under the terms of a Secondary License 112 | (if permitted under the terms of Section 3). 113 | 114 | 3. REQUIREMENTS 115 | 116 | 3.1 If a Contributor Distributes the Program in any form, then: 117 | 118 | a) the Program must also be made available as Source Code, in 119 | accordance with section 3.2, and the Contributor must accompany 120 | the Program with a statement that the Source Code for the Program 121 | is available under this Agreement, and informs Recipients how to 122 | obtain it in a reasonable manner on or through a medium customarily 123 | used for software exchange; and 124 | 125 | b) the Contributor may Distribute the Program under a license 126 | different than this Agreement, provided that such license: 127 | i) effectively disclaims on behalf of all other Contributors all 128 | warranties and conditions, express and implied, including 129 | warranties or conditions of title and non-infringement, and 130 | implied warranties or conditions of merchantability and fitness 131 | for a particular purpose; 132 | 133 | ii) effectively excludes on behalf of all other Contributors all 134 | liability for damages, including direct, indirect, special, 135 | incidental and consequential damages, such as lost profits; 136 | 137 | iii) does not attempt to limit or alter the recipients' rights 138 | in the Source Code under section 3.2; and 139 | 140 | iv) requires any subsequent distribution of the Program by any 141 | party to be under a license that satisfies the requirements 142 | of this section 3. 143 | 144 | 3.2 When the Program is Distributed as Source Code: 145 | 146 | a) it must be made available under this Agreement, or if the 147 | Program (i) is combined with other material in a separate file or 148 | files made available under a Secondary License, and (ii) the initial 149 | Contributor attached to the Source Code the notice described in 150 | Exhibit A of this Agreement, then the Program may be made available 151 | under the terms of such Secondary Licenses, and 152 | 153 | b) a copy of this Agreement must be included with each copy of 154 | the Program. 155 | 156 | 3.3 Contributors may not remove or alter any copyright, patent, 157 | trademark, attribution notices, disclaimers of warranty, or limitations 158 | of liability ("notices") contained within the Program from any copy of 159 | the Program which they Distribute, provided that Contributors may add 160 | their own appropriate notices. 161 | 162 | 4. COMMERCIAL DISTRIBUTION 163 | 164 | Commercial distributors of software may accept certain responsibilities 165 | with respect to end users, business partners and the like. While this 166 | license is intended to facilitate the commercial use of the Program, 167 | the Contributor who includes the Program in a commercial product 168 | offering should do so in a manner which does not create potential 169 | liability for other Contributors. Therefore, if a Contributor includes 170 | the Program in a commercial product offering, such Contributor 171 | ("Commercial Contributor") hereby agrees to defend and indemnify every 172 | other Contributor ("Indemnified Contributor") against any losses, 173 | damages and costs (collectively "Losses") arising from claims, lawsuits 174 | and other legal actions brought by a third party against the Indemnified 175 | Contributor to the extent caused by the acts or omissions of such 176 | Commercial Contributor in connection with its distribution of the Program 177 | in a commercial product offering. The obligations in this section do not 178 | apply to any claims or Losses relating to any actual or alleged 179 | intellectual property infringement. In order to qualify, an Indemnified 180 | Contributor must: a) promptly notify the Commercial Contributor in 181 | writing of such claim, and b) allow the Commercial Contributor to control, 182 | and cooperate with the Commercial Contributor in, the defense and any 183 | related settlement negotiations. The Indemnified Contributor may 184 | participate in any such claim at its own expense. 185 | 186 | For example, a Contributor might include the Program in a commercial 187 | product offering, Product X. That Contributor is then a Commercial 188 | Contributor. If that Commercial Contributor then makes performance 189 | claims, or offers warranties related to Product X, those performance 190 | claims and warranties are such Commercial Contributor's responsibility 191 | alone. Under this section, the Commercial Contributor would have to 192 | defend claims against the other Contributors related to those performance 193 | claims and warranties, and if a court requires any other Contributor to 194 | pay any damages as a result, the Commercial Contributor must pay 195 | those damages. 196 | 197 | 5. NO WARRANTY 198 | 199 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 200 | PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" 201 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 202 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF 203 | TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 204 | PURPOSE. Each Recipient is solely responsible for determining the 205 | appropriateness of using and distributing the Program and assumes all 206 | risks associated with its exercise of rights under this Agreement, 207 | including but not limited to the risks and costs of program errors, 208 | compliance with applicable laws, damage to or loss of data, programs 209 | or equipment, and unavailability or interruption of operations. 210 | 211 | 6. DISCLAIMER OF LIABILITY 212 | 213 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 214 | PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS 215 | SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 216 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 217 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 218 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 219 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 220 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE 221 | POSSIBILITY OF SUCH DAMAGES. 222 | 223 | 7. GENERAL 224 | 225 | If any provision of this Agreement is invalid or unenforceable under 226 | applicable law, it shall not affect the validity or enforceability of 227 | the remainder of the terms of this Agreement, and without further 228 | action by the parties hereto, such provision shall be reformed to the 229 | minimum extent necessary to make such provision valid and enforceable. 230 | 231 | If Recipient institutes patent litigation against any entity 232 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 233 | Program itself (excluding combinations of the Program with other software 234 | or hardware) infringes such Recipient's patent(s), then such Recipient's 235 | rights granted under Section 2(b) shall terminate as of the date such 236 | litigation is filed. 237 | 238 | All Recipient's rights under this Agreement shall terminate if it 239 | fails to comply with any of the material terms or conditions of this 240 | Agreement and does not cure such failure in a reasonable period of 241 | time after becoming aware of such noncompliance. If all Recipient's 242 | rights under this Agreement terminate, Recipient agrees to cease use 243 | and distribution of the Program as soon as reasonably practicable. 244 | However, Recipient's obligations under this Agreement and any licenses 245 | granted by Recipient relating to the Program shall continue and survive. 246 | 247 | Everyone is permitted to copy and distribute copies of this Agreement, 248 | but in order to avoid inconsistency the Agreement is copyrighted and 249 | may only be modified in the following manner. The Agreement Steward 250 | reserves the right to publish new versions (including revisions) of 251 | this Agreement from time to time. No one other than the Agreement 252 | Steward has the right to modify this Agreement. The Eclipse Foundation 253 | is the initial Agreement Steward. The Eclipse Foundation may assign the 254 | responsibility to serve as the Agreement Steward to a suitable separate 255 | entity. Each new version of the Agreement will be given a distinguishing 256 | version number. The Program (including Contributions) may always be 257 | Distributed subject to the version of the Agreement under which it was 258 | received. In addition, after a new version of the Agreement is published, 259 | Contributor may elect to Distribute the Program (including its 260 | Contributions) under the new version. 261 | 262 | Except as expressly stated in Sections 2(a) and 2(b) above, Recipient 263 | receives no rights or licenses to the intellectual property of any 264 | Contributor under this Agreement, whether expressly, by implication, 265 | estoppel or otherwise. All rights in the Program not expressly granted 266 | under this Agreement are reserved. Nothing in this Agreement is intended 267 | to be enforceable by any entity that is not a Contributor or Recipient. 268 | No third-party beneficiary rights are created under this Agreement. 269 | 270 | Exhibit A - Form of Secondary Licenses Notice 271 | 272 | "This Source Code may also be made available under the following 273 | Secondary Licenses when the conditions for such availability set forth 274 | in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), 275 | version(s), and exceptions or additional permissions here}." 276 | 277 | Simply including a copy of this Agreement, including this Exhibit A 278 | is not sufficient to license the Source Code under Secondary Licenses. 279 | 280 | If it is not possible or desirable to put the notice in a particular 281 | file, then You may include the notice in a location (such as a LICENSE 282 | file in a relevant directory) where a recipient would be likely to 283 | look for such a notice. 284 | 285 | You may add additional accurate notices of copyright ownership. 286 | 287 | 288 | 289 | Eclipse Distribution License - v 1.0 290 | 291 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. 292 | 293 | All rights reserved. 294 | 295 | Redistribution and use in source and binary forms, with or without 296 | modification, are permitted provided that the following conditions are 297 | met: 298 | 299 | Redistributions of source code must retain the above copyright notice, 300 | this list of conditions and the following disclaimer. 301 | Redistributions in binary form must reproduce the above copyright 302 | notice, this list of conditions and the following disclaimer in the 303 | documentation and/or other materials provided with the distribution. 304 | Neither the name of the Eclipse Foundation, Inc. nor the names of its 305 | contributors may be used to endorse or promote products derived from 306 | this software without specific prior written permission. 307 | 308 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 309 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 310 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 311 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 312 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 313 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 314 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 315 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 316 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 317 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 318 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 319 | -------------------------------------------------------------------------------- /doc/3rd_party_licenses/cyclonedds/NOTICE.md: -------------------------------------------------------------------------------- 1 | # Notices for Eclipse Cyclone DDS 2 | 3 | This content is produced and maintained by the Eclipse Cyclone DDS project. 4 | 5 | * Project home: https://projects.eclipse.org/projects/iot.cyclonedds 6 | 7 | ## Trademarks 8 | 9 | Eclipse Cyclone DDS is a trademark of the Eclipse Foundation. 10 | 11 | ## Copyright 12 | 13 | All content is the property of the respective authors or their employers. For 14 | more information regarding authorship of content, please consult the listed 15 | source code repository logs. 16 | 17 | ## Declared Project Licenses 18 | 19 | This program and the accompanying materials are made available under the terms 20 | of the Eclipse Public License v. 2.0 which is available at 21 | http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License v. 1.0 22 | which is available at http://www.eclipse.org/org/documents/edl-v10.php. 23 | 24 | SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause 25 | 26 | ## Source Code 27 | 28 | The project maintains the following source code repositories: 29 | 30 | * https://github.com/eclipse/cyclonedds 31 | 32 | ## Third-party Content 33 | 34 | libmd5-rfc (2002-04-13) 35 | 36 | * License: Zlib 37 | 38 | grammers-v4 (git SHA 6610e82ee235992f50e108cd59204f3bcd7128c1) 39 | 40 | * License: New BSD License 41 | 42 | getopt 1.5 (1998-03-11) 43 | 44 | * License: Public domain 45 | 46 | ## Cryptography 47 | 48 | Content may contain encryption software. The country in which you are currently 49 | may have restrictions on the import, possession, and use, and/or re-export to 50 | another country, of encryption software. BEFORE using any encryption software, 51 | please check the country's laws, regulations and policies concerning the import, 52 | possession, or use, and re-export of encryption software, to see if this is 53 | permitted. 54 | 55 | -------------------------------------------------------------------------------- /doc/3rd_party_licenses/fastdds/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | 2 | # DDS Gateway Examples 3 | 4 | Here you can find examples how to use the dds gateway in a real system. 5 | The examples use docker to simulate separated hosts running iceoryx. 6 | 7 | ## Running the Examples 8 | 9 | Simply run the script: `run_example.sh` 10 | 11 | You will be given an option to choose an example to run, after which the 12 | necessary Docker containers will be built and run automatically. 13 | 14 | ## Setting up your own system 15 | 16 | For help setting up your own iceoryx systems to use the DDS gateway, 17 | refer to the entrypoint scripts used by the example docker containers. 18 | -------------------------------------------------------------------------------- /examples/docker/publisher_node.dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM iceoryx:latest 17 | 18 | COPY publisher_node.entrypoint /root/ 19 | ENTRYPOINT ["/root/publisher_node.entrypoint"] 20 | -------------------------------------------------------------------------------- /examples/docker/publisher_node.entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | GATEWAY_CONF_PATH=/etc/iceoryx/gateway_config.toml 19 | 20 | mkdir -p /etc/iceoryx 21 | 22 | if [[ ! -f "$GATEWAY_CONF_PATH" ]]; then 23 | cat <> /etc/iceoryx/gateway_config.toml 24 | [[services]] 25 | service = "Radar" 26 | instance = "FrontLeft" 27 | event = "Object" 28 | EOF 29 | fi 30 | 31 | /usr/bin/iox-roudi & 32 | /usr/bin/iox-dds-gateway & 33 | /usr/bin/iox-cpp-publisher-untyped 34 | -------------------------------------------------------------------------------- /examples/docker/simple_internode_communication.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | version: '3.7' 17 | services: 18 | publisher-node: 19 | build: 20 | context: . 21 | dockerfile: publisher_node.dockerfile 22 | shm_size: '300M' 23 | image: iceoryx-publisher-node:latest 24 | networks: 25 | - iceoryx-dds 26 | subscriber-node: 27 | build: 28 | context: . 29 | dockerfile: subscriber_node.dockerfile 30 | shm_size: '300M' 31 | image: iceoryx-subscriber-node:latest 32 | networks: 33 | - iceoryx-dds 34 | networks: 35 | iceoryx-dds: 36 | driver: bridge 37 | name: iceoryx-dds 38 | -------------------------------------------------------------------------------- /examples/docker/subscriber_node.dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | FROM iceoryx:latest 17 | 18 | COPY subscriber_node.entrypoint /root/ 19 | ENTRYPOINT ["/root/subscriber_node.entrypoint"] 20 | -------------------------------------------------------------------------------- /examples/docker/subscriber_node.entrypoint: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | GATEWAY_CONF_PATH=/etc/iceoryx/gateway_config.toml 19 | 20 | mkdir -p /etc/iceoryx 21 | 22 | if [[ ! -f "$GATEWAY_CONF_PATH" ]]; then 23 | cat <> /etc/iceoryx/gateway_config.toml 24 | [[services]] 25 | service = "Radar" 26 | instance = "FrontLeft" 27 | event = "Object" 28 | EOF 29 | fi 30 | 31 | /usr/bin/iox-roudi & 32 | /usr/bin/iox-dds-gateway & 33 | /usr/bin/iox-cpp-subscriber-untyped 34 | -------------------------------------------------------------------------------- /examples/run_example.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | SCRIPT_DIR=`dirname $(realpath -s $0)` 19 | 20 | echo $SCRIPT_DIR 21 | 22 | build_iceoryx_docker() { 23 | if [[ "$(docker images -q iceoryx:latest 2> /dev/null)" == "" ]]; then 24 | echo "Building base iceoryx docker image." 25 | $SCRIPT_DIR/../../tools/docker/build_iceoryx_docker.sh 26 | fi 27 | } 28 | 29 | echo "Select an example:" 30 | echo "" 31 | options=("Simple Internode-Communcation" "Quit") 32 | select opt in "${options[@]}" 33 | do 34 | case $opt in 35 | "Simple Internode-Communcation") 36 | build_iceoryx_docker 37 | cd $SCRIPT_DIR/docker 38 | docker-compose -f simple_internode_communication.yml up 39 | break 40 | ;; 41 | "Quit") 42 | break 43 | ;; 44 | *) echo invalid option;; 45 | 46 | esac 47 | done 48 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/cyclone_context.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef CYCLONE_CONTEXT_HPP 18 | #define CYCLONE_CONTEXT_HPP 19 | 20 | #include 21 | 22 | namespace iox 23 | { 24 | namespace dds 25 | { 26 | /// 27 | /// @brief The CycloneContext manages cyclone configurations and singleton artifacts shared throughout an application. 28 | /// 29 | class CycloneContext 30 | { 31 | public: 32 | /// 33 | /// @brief getParticipant Get the DDS Domain Participant for the current runtime. 34 | /// @return The DDS Domain Participant. 35 | /// 36 | static ::dds::domain::DomainParticipant& getParticipant() noexcept; 37 | }; 38 | 39 | } // namespace dds 40 | } // namespace iox 41 | 42 | #endif // CYCLONE_CONTEXT_HPP 43 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/cyclone_data_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_CYCLONE_DATA_READER_HPP 19 | #define IOX_DDS_DDS_CYCLONE_DATA_READER_HPP 20 | 21 | #include "Mempool.hpp" 22 | #include "iceoryx_dds/dds/data_reader.hpp" 23 | 24 | #include 25 | #include 26 | 27 | namespace iox 28 | { 29 | namespace dds 30 | { 31 | /// @brief Implementation of the DataReader abstraction using the cyclonedds implementation. 32 | class CycloneDataReader : public DataReader 33 | { 34 | public: 35 | CycloneDataReader() = delete; 36 | 37 | /// @brief Constructor to set cyclone data reader object from given IDs 38 | /// @param[in] serviceId ID of the service 39 | /// @param[in] instanceId ID of the instance of the service 40 | /// @param[in] eventId ID of the event 41 | CycloneDataReader(const capro::IdString_t serviceId, 42 | const capro::IdString_t instanceId, 43 | const capro::IdString_t eventId) noexcept; 44 | 45 | virtual ~CycloneDataReader(); 46 | 47 | CycloneDataReader(const CycloneDataReader&) = delete; 48 | CycloneDataReader& operator=(const CycloneDataReader&) = delete; 49 | CycloneDataReader(CycloneDataReader&&) = delete; 50 | CycloneDataReader& operator=(CycloneDataReader&&) = delete; 51 | 52 | /// @brief Connect cylcone data reader to the underlying DDS network 53 | void connect() noexcept override; 54 | 55 | iox::optional peekNextIoxChunkDatagramHeader() noexcept override; 56 | bool hasSamples() noexcept override; 57 | iox::expected takeNext(const IoxChunkDatagramHeader datagramHeader, 58 | uint8_t* const userHeaderBuffer, 59 | uint8_t* const userPayloadBuffer) noexcept override; 60 | 61 | capro::IdString_t getServiceId() const noexcept override; 62 | capro::IdString_t getInstanceId() const noexcept override; 63 | capro::IdString_t getEventId() const noexcept override; 64 | 65 | private: 66 | capro::IdString_t m_serviceId{""}; 67 | capro::IdString_t m_instanceId{""}; 68 | capro::IdString_t m_eventId{""}; 69 | 70 | ::dds::sub::DataReader m_impl = ::dds::core::null; 71 | 72 | std::atomic_bool m_isConnected{false}; 73 | }; 74 | 75 | } // namespace dds 76 | } // namespace iox 77 | 78 | #endif // IOX_DDS_DDS_CYCLONE_DATA_READER_HPP 79 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/cyclone_data_writer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 19 | #define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 20 | 21 | #include "Mempool.hpp" 22 | #include "iceoryx_dds/dds/data_writer.hpp" 23 | 24 | #include 25 | 26 | namespace iox 27 | { 28 | namespace dds 29 | { 30 | /// @brief Implementation of the DataWriter abstraction using the cyclonedds implementation. 31 | class CycloneDataWriter : public iox::dds::DataWriter 32 | { 33 | public: 34 | CycloneDataWriter() = delete; 35 | 36 | /// @brief Constructor to set cyclone data writer object from given IDs 37 | /// @param[in] serviceId ID of the service 38 | /// @param[in] instanceId ID of the instance of the service 39 | /// @param[in] eventId ID of the event 40 | CycloneDataWriter(const capro::IdString_t serviceId, 41 | const capro::IdString_t instanceId, 42 | const capro::IdString_t eventId) noexcept; 43 | 44 | virtual ~CycloneDataWriter(); 45 | 46 | CycloneDataWriter(const CycloneDataWriter&) = delete; 47 | CycloneDataWriter& operator=(const CycloneDataWriter&) = delete; 48 | CycloneDataWriter(CycloneDataWriter&& rhs) = default; 49 | CycloneDataWriter& operator=(CycloneDataWriter&& rhs) = default; 50 | 51 | /// @brief connect cyclone data writer to the underlying DDS network 52 | void connect() noexcept override; 53 | void write(iox::dds::IoxChunkDatagramHeader datagramHeader, 54 | const uint8_t* const userHeaderBytes, 55 | const uint8_t* const userPayloadBytes) noexcept override; 56 | 57 | capro::IdString_t getServiceId() const noexcept override; 58 | capro::IdString_t getInstanceId() const noexcept override; 59 | capro::IdString_t getEventId() const noexcept override; 60 | 61 | private: 62 | capro::IdString_t m_serviceId{""}; 63 | capro::IdString_t m_instanceId{""}; 64 | capro::IdString_t m_eventId{""}; 65 | 66 | ::dds::pub::Publisher m_publisher = ::dds::core::null; 67 | ::dds::topic::Topic m_topic = ::dds::core::null; 68 | ::dds::pub::DataWriter m_writer = ::dds::core::null; 69 | }; 70 | 71 | } // namespace dds 72 | } // namespace iox 73 | 74 | #endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 75 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/data_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_DATA_READER_HPP 19 | #define IOX_DDS_DDS_DATA_READER_HPP 20 | 21 | #include "iceoryx_dds/dds/iox_chunk_datagram_header.hpp" 22 | #include "iceoryx_posh/iceoryx_posh_types.hpp" 23 | #include "iox/expected.hpp" 24 | #include "iox/optional.hpp" 25 | 26 | namespace iox 27 | { 28 | namespace dds 29 | { 30 | enum class DataReaderError : uint8_t 31 | { 32 | NOT_CONNECTED, 33 | INVALID_DATAGRAM_HEADER_SIZE, 34 | INVALID_BUFFER_PARAMETER_FOR_USER_HEADER, 35 | INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD, 36 | INVALID_DATA, 37 | BUFFER_SIZE_MISMATCH 38 | }; 39 | 40 | constexpr const char* DataReaderErrorString[] = {"NOT_CONNECTED", 41 | "INVALID_DATAGRAM_HEADER_SIZE", 42 | "INVALID_BUFFER_PARAMETER_FOR_USER_HEADER", 43 | "INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD", 44 | "INVALID_DATA", 45 | "BUFFER_SIZE_MISMATCH"}; 46 | 47 | /// @brief Abstraction for DDS Data Readers. 48 | class DataReader 49 | { 50 | public: 51 | /// @brief Connect the DataReader to the underlying DDS network. 52 | virtual void connect() noexcept = 0; 53 | 54 | /// @brief peekNextIoxChunkDatagramHeader Get the IoxChunkDatagramHeader of the next sample if one is available. 55 | /// @return The IoxChunkDatagramHeader of the next sample if one is available. 56 | virtual iox::optional peekNextIoxChunkDatagramHeader() noexcept = 0; 57 | 58 | /// @brief Checks if new samples are ready to take. 59 | /// @return True if new samples are available. 60 | virtual bool hasSamples() noexcept = 0; 61 | 62 | /// @brief take Take the next available sample from the DDS data space. 63 | /// @param datagramHeader with size information 64 | /// @param userHeaderBuffer buffer for the user-header 65 | /// @param userPayloadBuffer buffer for the user-payload 66 | /// @return Error if unsuccessful. 67 | virtual iox::expected takeNext(const IoxChunkDatagramHeader datagramHeader, 68 | uint8_t* const userHeaderBuffer, 69 | uint8_t* const userPayloadBuffer) noexcept = 0; 70 | 71 | /// @brief get ID of the service 72 | virtual capro::IdString_t getServiceId() const noexcept = 0; 73 | 74 | /// @brief get ID of the instance 75 | virtual capro::IdString_t getInstanceId() const noexcept = 0; 76 | 77 | /// @brief get ID of the event 78 | virtual capro::IdString_t getEventId() const noexcept = 0; 79 | 80 | protected: 81 | DataReader() noexcept = default; 82 | }; 83 | } // namespace dds 84 | } // namespace iox 85 | 86 | #endif // IOX_DDS_DDS_DATA_READER_HPP 87 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/data_writer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_DATA_WRITER_HPP 19 | #define IOX_DDS_DDS_DATA_WRITER_HPP 20 | 21 | #include "iceoryx_dds/dds/iox_chunk_datagram_header.hpp" 22 | 23 | #include "iceoryx_posh/iceoryx_posh_types.hpp" 24 | 25 | #include 26 | 27 | namespace iox 28 | { 29 | namespace dds 30 | { 31 | /// @brief Abstraction for DDS Data Writers. 32 | /// @note Provides the minimum functionality required for posh-dds gateway implementations. 33 | class DataWriter 34 | { 35 | public: 36 | virtual ~DataWriter() = default; 37 | 38 | /// @brief Connect the DataWriter to the underlying DDS network. 39 | virtual void connect() noexcept = 0; 40 | 41 | /// @brief write Write the provided header and bytes on the DDS network on the topic: serviceId/instanceId/eventId 42 | /// @param datagramHeader with size information 43 | /// @param userHeaderBytes buffer with the user-header 44 | /// @param userPayloadBytes buffer with the user-payload 45 | virtual void write(iox::dds::IoxChunkDatagramHeader datagramHeader, 46 | const uint8_t* const userHeaderBytes, 47 | const uint8_t* const userPayloadBytes) noexcept = 0; 48 | 49 | /// @brief Get ID of the service 50 | virtual capro::IdString_t getServiceId() const noexcept = 0; 51 | 52 | /// @brief Get ID of the instance 53 | virtual capro::IdString_t getInstanceId() const noexcept = 0; 54 | 55 | /// @brief Get ID of the event 56 | virtual capro::IdString_t getEventId() const noexcept = 0; 57 | 58 | protected: 59 | DataWriter() = default; 60 | }; 61 | 62 | } // namespace dds 63 | } // namespace iox 64 | 65 | #endif // IOX_DDS_DDS_DATA_WRITER_HPP 66 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/dds_config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef IOX_DDS_DDS_CONFIG_HPP 18 | #define IOX_DDS_DDS_CONFIG_HPP 19 | 20 | #include "iceoryx_posh/iceoryx_posh_types.hpp" 21 | 22 | namespace iox 23 | { 24 | namespace dds 25 | { 26 | using namespace units::duration_literals; 27 | static constexpr units::Duration DISCOVERY_PERIOD = 1000_ms; 28 | static constexpr units::Duration FORWARDING_PERIOD = 50_ms; 29 | static constexpr uint32_t SUBSCRIBER_CACHE_SIZE = 128u; 30 | 31 | } // namespace dds 32 | } // namespace iox 33 | 34 | #endif // IOX_DDS_DDS_CONFIG_HPP 35 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/dds_types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_DDS_TYPES_HPP 19 | #define IOX_DDS_DDS_DDS_TYPES_HPP 20 | 21 | #ifdef USE_CYCLONE_DDS 22 | #include "iceoryx_dds/dds/cyclone_data_reader.hpp" 23 | #include "iceoryx_dds/dds/cyclone_data_writer.hpp" 24 | #elif defined USE_FAST_DDS 25 | #include "iceoryx_dds/dds/fast_data_reader.hpp" 26 | #include "iceoryx_dds/dds/fast_data_writer.hpp" 27 | #else 28 | #error "A DDS implementation must be provided." 29 | #endif 30 | 31 | namespace iox 32 | { 33 | namespace dds 34 | { 35 | // DDS implementation defined with compiler flags 36 | #ifdef USE_CYCLONE_DDS 37 | using data_reader_t = iox::dds::CycloneDataReader; 38 | using data_writer_t = iox::dds::CycloneDataWriter; 39 | #elif defined USE_FAST_DDS 40 | using data_reader_t = iox::dds::FastDataReader; 41 | using data_writer_t = iox::dds::FastDataWriter; 42 | #else 43 | #error "A DDS implementation must be set." 44 | #endif 45 | } // namespace dds 46 | } // namespace iox 47 | 48 | #endif // IOX_DDS_DDS_DDS_TYPES_HPP 49 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/fast_context.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef FAST_CONTEXT_HPP 18 | #define FAST_CONTEXT_HPP 19 | 20 | #include 21 | 22 | namespace iox 23 | { 24 | namespace dds 25 | { 26 | /// 27 | /// @brief The FastContext manages fast configurations and singleton artifacts shared throughout an application. 28 | /// 29 | class FastContext 30 | { 31 | public: 32 | /// 33 | /// @brief getInstance Get the DDS Context Instance for the current runtime. 34 | /// @return The DDS Context Instance. 35 | /// 36 | static FastContext& getInstance(); 37 | 38 | /// 39 | /// @brief getParticipant Get the DDS Domain Participant for the current runtime. 40 | /// @return The DDS Domain Participant. 41 | /// 42 | eprosima::fastdds::dds::DomainParticipant* getParticipant(); 43 | 44 | /// 45 | /// @brief getTopic Get the DDS Topic for the current runtime. 46 | /// @param[in] serviceId ID of the service 47 | /// @return The DDS Topic . 48 | /// 49 | eprosima::fastdds::dds::Topic* getTopic(const std::string& topicName); 50 | 51 | private: 52 | FastContext(); 53 | 54 | eprosima::fastdds::dds::DomainParticipant* m_participant = nullptr; 55 | eprosima::fastdds::dds::TypeSupport m_type; 56 | }; 57 | 58 | } // namespace dds 59 | } // namespace iox 60 | 61 | #endif // CYCLONE_CONTEXT_HPP 62 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/fast_data_reader.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef IOX_DDS_DDS_FAST_DATA_READER_HPP 18 | #define IOX_DDS_DDS_FAST_DATA_READER_HPP 19 | 20 | #include "iceoryx_dds/dds/data_reader.hpp" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace iox 27 | { 28 | namespace dds 29 | { 30 | /// @brief Implementation of the DataReader abstraction using the fastdds implementation. 31 | class FastDataReader : public DataReader 32 | { 33 | public: 34 | FastDataReader() = delete; 35 | 36 | /// @brief Constructor to set fast data reader object from given IDs 37 | /// @param[in] serviceId ID of the service 38 | /// @param[in] instanceId ID of the instance of the service 39 | /// @param[in] eventId ID of the event 40 | FastDataReader(const capro::IdString_t& serviceId, 41 | const capro::IdString_t& instanceId, 42 | const capro::IdString_t& eventId) noexcept; 43 | 44 | virtual ~FastDataReader(); 45 | 46 | FastDataReader(const FastDataReader&) = delete; 47 | FastDataReader& operator=(const FastDataReader&) = delete; 48 | FastDataReader(FastDataReader&&) = delete; 49 | FastDataReader& operator=(FastDataReader&&) = delete; 50 | 51 | /// @brief Connect fast data reader to the underlying DDS network 52 | void connect() noexcept override; 53 | 54 | iox::optional peekNextIoxChunkDatagramHeader() noexcept override; 55 | bool hasSamples() noexcept override; 56 | iox::expected takeNext(const IoxChunkDatagramHeader datagramHeader, 57 | uint8_t* const userHeaderBuffer, 58 | uint8_t* const userPayloadBuffer) noexcept override; 59 | 60 | capro::IdString_t getServiceId() const noexcept override; 61 | capro::IdString_t getInstanceId() const noexcept override; 62 | capro::IdString_t getEventId() const noexcept override; 63 | 64 | private: 65 | capro::IdString_t m_serviceId{""}; 66 | capro::IdString_t m_instanceId{""}; 67 | capro::IdString_t m_eventId{""}; 68 | 69 | eprosima::fastdds::dds::Subscriber* m_subscriber = nullptr; 70 | eprosima::fastdds::dds::Topic* m_topic = nullptr; 71 | eprosima::fastdds::dds::DataReader* m_reader = nullptr; 72 | 73 | std::atomic_bool m_isConnected{false}; 74 | }; 75 | 76 | } // namespace dds 77 | } // namespace iox 78 | 79 | #endif // IOX_DDS_DDS_CYCLONE_DATA_READER_HPP 80 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/fast_data_writer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 18 | #define IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 19 | 20 | #include "iceoryx_dds/dds/data_writer.hpp" 21 | 22 | #include 23 | 24 | namespace iox 25 | { 26 | namespace dds 27 | { 28 | /// @brief Implementation of the DataWriter abstraction using the fastdds implementation. 29 | class FastDataWriter : public iox::dds::DataWriter 30 | { 31 | public: 32 | FastDataWriter() = delete; 33 | 34 | /// @brief Constructor to set fast data writer object from given IDs 35 | /// @param[in] serviceId ID of the service 36 | /// @param[in] instanceId ID of the instance of the service 37 | /// @param[in] eventId ID of the event 38 | FastDataWriter(const capro::IdString_t& serviceId, 39 | const capro::IdString_t& instanceId, 40 | const capro::IdString_t& eventId) noexcept; 41 | 42 | virtual ~FastDataWriter(); 43 | 44 | FastDataWriter(const FastDataWriter&) = delete; 45 | FastDataWriter& operator=(const FastDataWriter&) = delete; 46 | FastDataWriter(FastDataWriter&& rhs) = default; 47 | FastDataWriter& operator=(FastDataWriter&& rhs) = default; 48 | 49 | /// @brief connect fast data writer to the underlying DDS network 50 | void connect() noexcept override; 51 | void write(iox::dds::IoxChunkDatagramHeader datagramHeader, 52 | const uint8_t* const userHeaderBytes, 53 | const uint8_t* const userPayloadBytes) noexcept override; 54 | 55 | capro::IdString_t getServiceId() const noexcept override; 56 | capro::IdString_t getInstanceId() const noexcept override; 57 | capro::IdString_t getEventId() const noexcept override; 58 | 59 | private: 60 | capro::IdString_t m_serviceId{""}; 61 | capro::IdString_t m_instanceId{""}; 62 | capro::IdString_t m_eventId{""}; 63 | 64 | eprosima::fastdds::dds::Publisher* m_publisher = nullptr; 65 | eprosima::fastdds::dds::Topic* m_topic = nullptr; 66 | eprosima::fastdds::dds::DataWriter* m_writer = nullptr; 67 | }; 68 | 69 | } // namespace dds 70 | } // namespace iox 71 | 72 | #endif // IOX_DDS_DDS_CYCLONE_DATA_WRITER_HPP 73 | -------------------------------------------------------------------------------- /include/iceoryx_dds/dds/iox_chunk_datagram_header.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef IOX_DDS_DDS_IOX_CHUNK_DATAGRAM_HEADER_HPP 18 | #define IOX_DDS_DDS_IOX_CHUNK_DATAGRAM_HEADER_HPP 19 | 20 | #include "iox/vector.hpp" 21 | 22 | #include 23 | 24 | namespace iox 25 | { 26 | namespace dds 27 | { 28 | /// @brief the endianess of the serialized data 29 | enum class Endianess : uint8_t 30 | { 31 | UNDEFINED, 32 | LITTLE, 33 | BIG, 34 | MIXED, 35 | }; 36 | 37 | constexpr const char* EndianessString[] = {"UNDEFINED", "LITTLE", "BIG", "MIXED"}; 38 | 39 | /// @brief Detects the endianness of the system 40 | Endianess getEndianess(); 41 | 42 | /// @brief The datagram header with chunk metadata for user-header and user-payload 43 | struct IoxChunkDatagramHeader 44 | { 45 | using Serialized_t = iox::vector; 46 | 47 | /// @brief Serializes a IoxChunkDatagramHeader into a vector of uint8_t 48 | /// @param[in] datagramHeader to serialize 49 | /// @return the serialized IoxChunkDatagramHeader 50 | static Serialized_t serialize(const IoxChunkDatagramHeader& datagramHeader); 51 | 52 | /// @brief Deserializes a vector of uint8_t into a IoxChunkDatagramHeader 53 | /// @param[in] serializedDatagram is the serialized IoxChunkDatagramHeader 54 | /// @return the deserialized IoxChunkDatagramHeader 55 | static IoxChunkDatagramHeader deserialize(const Serialized_t& serializedDatagramHeader); 56 | 57 | /// @brief From the 1.0 release onward, this must be incremented for each incompatible change, e.g. 58 | /// - data width of members changes 59 | /// - members are rearranged 60 | /// - semantic meaning of a member changes 61 | static constexpr uint8_t DATAGRAM_VERSION{1U}; 62 | 63 | /// @note This must always be the first member and always 1 bytes in order to prevent issues with endianess when 64 | /// deserialized or incorrectly detected versions due to different size 65 | uint8_t datagramVersion{DATAGRAM_VERSION}; 66 | /// @note This must always be 1 byte in order to prevent issues with endianess when deserialized 67 | Endianess endianness{Endianess::UNDEFINED}; 68 | uint16_t userHeaderId{0xFFFF}; 69 | uint32_t userHeaderSize{0U}; 70 | uint64_t userPayloadSize{0U}; 71 | uint32_t userPayloadAlignment{0U}; 72 | }; 73 | 74 | } // namespace dds 75 | } // namespace iox 76 | 77 | #endif // IOX_DDS_DDS_IOX_CHUNK_DATAGRAM_HEADER_HPP 78 | -------------------------------------------------------------------------------- /include/iceoryx_dds/gateway/dds_to_iox.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_TO_IOX_HPP 19 | #define IOX_DDS_DDS_TO_IOX_HPP 20 | 21 | #include "iceoryx_dds/dds/dds_types.hpp" 22 | #include "iceoryx_posh/gateway/channel.hpp" 23 | #include "iceoryx_posh/gateway/gateway_config.hpp" 24 | #include "iceoryx_posh/gateway/gateway_generic.hpp" 25 | #include "iceoryx_posh/popo/untyped_publisher.hpp" 26 | 27 | namespace iox 28 | { 29 | namespace dds 30 | { 31 | /// @brief DDS Gateway implementation for the DDS to iceoryx direction. 32 | template , 33 | typename gateway_t = gw::GatewayGeneric> 34 | class DDS2IceoryxGateway : public gateway_t 35 | { 36 | public: 37 | /// @brief Creates a gateway with DDS set as interface 38 | DDS2IceoryxGateway() noexcept; 39 | 40 | void loadConfiguration(const config::GatewayConfig& config) noexcept; 41 | void discover(const capro::CaproMessage& msg) noexcept; 42 | void forward(const channel_t& channel) noexcept; 43 | 44 | private: 45 | void* m_reservedChunk = nullptr; 46 | 47 | expected setupChannel(const capro::ServiceDescription& service, 48 | const popo::PublisherOptions& publisherOptions) noexcept; 49 | }; 50 | 51 | } // namespace dds 52 | } // namespace iox 53 | 54 | #include "iceoryx_dds/internal/gateway/dds_to_iox.inl" 55 | 56 | #endif // IOX_DDS_DDS_TO_IOX_HPP 57 | -------------------------------------------------------------------------------- /include/iceoryx_dds/gateway/iox_to_dds.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 - 2021 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_IOX_TO_DDS_HPP 19 | #define IOX_DDS_IOX_TO_DDS_HPP 20 | 21 | #include "iceoryx_dds/dds/dds_types.hpp" 22 | #include "iceoryx_posh/gateway/channel.hpp" 23 | #include "iceoryx_posh/gateway/gateway_generic.hpp" 24 | #include "iceoryx_posh/popo/untyped_subscriber.hpp" 25 | 26 | namespace iox 27 | { 28 | namespace dds 29 | { 30 | /// @brief DDS Gateway implementation for the iceoryx to DDS direction. 31 | template , 32 | typename gateway_t = gw::GatewayGeneric> 33 | class Iceoryx2DDSGateway : public gateway_t 34 | { 35 | public: 36 | /// @brief Creates a gateway with DDS set as interface 37 | Iceoryx2DDSGateway() noexcept; 38 | 39 | void loadConfiguration(const config::GatewayConfig& config) noexcept; 40 | void discover(const capro::CaproMessage& msg) noexcept; 41 | void forward(const channel_t& channel) noexcept; 42 | 43 | private: 44 | expected setupChannel(const capro::ServiceDescription& service, 45 | const popo::SubscriberOptions& subscriberOptions) noexcept; 46 | }; 47 | 48 | } // namespace dds 49 | } // namespace iox 50 | 51 | #include "iceoryx_dds/internal/gateway/iox_to_dds.inl" 52 | 53 | #endif // IOX_DDS_IOX_TO_DDS_HPP 54 | -------------------------------------------------------------------------------- /include/iceoryx_dds/internal/gateway/dds_to_iox.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_DDS_TO_IOX_INL 19 | #define IOX_DDS_DDS_TO_IOX_INL 20 | 21 | #include "iceoryx_dds/dds/dds_config.hpp" 22 | #include "iceoryx_posh/capro/service_description.hpp" 23 | #include "iox/logging.hpp" 24 | #include "iox/string.hpp" 25 | 26 | namespace iox 27 | { 28 | namespace dds 29 | { 30 | template 31 | inline DDS2IceoryxGateway::DDS2IceoryxGateway() noexcept 32 | : gateway_t(capro::Interfaces::DDS, DISCOVERY_PERIOD, FORWARDING_PERIOD) 33 | { 34 | } 35 | 36 | template 37 | inline void DDS2IceoryxGateway::loadConfiguration(const config::GatewayConfig& config) noexcept 38 | { 39 | IOX_LOG(DEBUG, "[DDS2IceoryxGateway] Configuring gateway..."); 40 | for (const auto& service : config.m_configuredServices) 41 | { 42 | if (!this->findChannel(service.m_serviceDescription).has_value()) 43 | { 44 | auto serviceDescription = service.m_serviceDescription; 45 | IOX_LOG(DEBUG, 46 | "[DDS2IceoryxGateway] Setting up channel for service: {" 47 | << serviceDescription.getServiceIDString() << ", " << serviceDescription.getInstanceIDString() 48 | << ", " << serviceDescription.getEventIDString() << "}"); 49 | IOX_DISCARD_RESULT(setupChannel(serviceDescription, popo::PublisherOptions())); 50 | } 51 | } 52 | } 53 | 54 | template 55 | inline void DDS2IceoryxGateway::discover([[maybe_unused]] const capro::CaproMessage& msg) noexcept 56 | { 57 | /// @note not implemented - requires dds discovery which is currently not implemented in the used dds stack. 58 | } 59 | 60 | template 61 | inline void DDS2IceoryxGateway::forward(const channel_t& channel) noexcept 62 | { 63 | auto publisher = channel.getIceoryxTerminal(); 64 | auto reader = channel.getExternalTerminal(); 65 | 66 | while (reader->hasSamples()) 67 | { 68 | reader->peekNextIoxChunkDatagramHeader().and_then([&](auto datagramHeader) { 69 | // this is safe, it is just used to check if the alignment doesn't exceed the 70 | // alignment of the ChunkHeader but since this is data from a previously valid 71 | // chunk, we can assume that the alignment was correct and use this value 72 | constexpr uint32_t USER_HEADER_ALIGNMENT{1U}; 73 | publisher 74 | ->loan(datagramHeader.userPayloadSize, 75 | datagramHeader.userPayloadAlignment, 76 | datagramHeader.userHeaderSize, 77 | USER_HEADER_ALIGNMENT) 78 | .and_then([&](auto userPayload) { 79 | auto chunkHeader = iox::mepoo::ChunkHeader::fromUserPayload(userPayload); 80 | reader 81 | ->takeNext(datagramHeader, 82 | static_cast(chunkHeader->userHeader()), 83 | static_cast(chunkHeader->userPayload())) 84 | .and_then([&]() { publisher->publish(userPayload); }) 85 | .or_else([&](DataReaderError err) { 86 | publisher->release(userPayload); 87 | IOX_LOG(WARN, 88 | "[DDS2IceoryxGateway] Encountered error reading from DDS network: " 89 | << dds::DataReaderErrorString[static_cast(err)]); 90 | }); 91 | }) 92 | .or_else([](auto& error) { 93 | IOX_LOG(ERROR, 94 | "[DDS2IceoryxGateway] Could not loan chunk! Error code: " << static_cast(error)); 95 | }); 96 | ; 97 | }); 98 | } 99 | } 100 | 101 | // ======================================== Private ======================================== // 102 | template 103 | expected 104 | DDS2IceoryxGateway::setupChannel(const capro::ServiceDescription& service, 105 | const popo::PublisherOptions& publisherOptions) noexcept 106 | { 107 | return this->addChannel(service, publisherOptions).and_then([&service](auto channel) { 108 | auto publisher = channel.getIceoryxTerminal(); 109 | auto reader = channel.getExternalTerminal(); 110 | publisher->offer(); 111 | reader->connect(); 112 | IOX_LOG(DEBUG, 113 | "[DDS2IceoryxGateway] Setup channel for service: {" << service.getServiceIDString() << ", " 114 | << service.getInstanceIDString() << ", " 115 | << service.getEventIDString() << "}"); 116 | }); 117 | } 118 | 119 | } // namespace dds 120 | } // namespace iox 121 | 122 | #endif // IOX_DDS_DDS_TO_IOX_INL 123 | -------------------------------------------------------------------------------- /include/iceoryx_dds/internal/gateway/iox_to_dds.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_IOX_TO_DDS_INL 19 | #define IOX_DDS_IOX_TO_DDS_INL 20 | 21 | #include "iceoryx_dds/dds/dds_config.hpp" 22 | #include "iceoryx_dds/dds/iox_chunk_datagram_header.hpp" 23 | #include "iceoryx_posh/capro/service_description.hpp" 24 | #include "iceoryx_posh/gateway/gateway_config.hpp" 25 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 26 | #include "iceoryx_posh/roudi/introspection_types.hpp" 27 | #include "iox/logging.hpp" 28 | 29 | #include "iceoryx_dds/gateway/iox_to_dds.hpp" 30 | 31 | namespace iox 32 | { 33 | namespace dds 34 | { 35 | // ======================================== Public ======================================== // 36 | template 37 | inline Iceoryx2DDSGateway::Iceoryx2DDSGateway() noexcept 38 | : gateway_t(capro::Interfaces::DDS, DISCOVERY_PERIOD, FORWARDING_PERIOD) 39 | { 40 | } 41 | 42 | template 43 | inline void Iceoryx2DDSGateway::loadConfiguration(const config::GatewayConfig& config) noexcept 44 | { 45 | IOX_LOG(DEBUG, "[Iceoryx2DDSGateway] Configuring gateway..."); 46 | for (const auto& service : config.m_configuredServices) 47 | { 48 | if (!this->findChannel(service.m_serviceDescription).has_value()) 49 | { 50 | auto serviceDescription = service.m_serviceDescription; 51 | IOX_LOG(DEBUG, 52 | "[DDS2IceoryxGateway] Setting up channel for service: {" 53 | << serviceDescription.getServiceIDString() << ", " << serviceDescription.getInstanceIDString() 54 | << ", " << serviceDescription.getEventIDString() << "}"); 55 | popo::SubscriberOptions options; 56 | options.queueCapacity = SUBSCRIBER_CACHE_SIZE; 57 | IOX_DISCARD_RESULT(setupChannel(serviceDescription, options)); 58 | } 59 | } 60 | } 61 | 62 | template 63 | inline void Iceoryx2DDSGateway::discover(const capro::CaproMessage& msg) noexcept 64 | { 65 | IOX_LOG(DEBUG, 66 | "[Iceoryx2DDSGateway] " 67 | << msg.m_type << " { Service: " << msg.m_serviceDescription.getServiceIDString() 68 | << ", Instance: " << msg.m_serviceDescription.getInstanceIDString() 69 | << ", Event: " << msg.m_serviceDescription.getEventIDString() << " }"); 70 | 71 | if (msg.m_serviceDescription.getServiceIDString() == capro::IdString_t(roudi::INTROSPECTION_SERVICE_ID)) 72 | { 73 | return; 74 | } 75 | if (msg.m_serviceType != capro::CaproServiceType::PUBLISHER) 76 | { 77 | return; 78 | } 79 | 80 | switch (msg.m_type) 81 | { 82 | case capro::CaproMessageType::OFFER: 83 | { 84 | if (!this->findChannel(msg.m_serviceDescription).has_value()) 85 | { 86 | popo::SubscriberOptions options; 87 | options.queueCapacity = SUBSCRIBER_CACHE_SIZE; 88 | IOX_DISCARD_RESULT(setupChannel(msg.m_serviceDescription, options)); 89 | } 90 | break; 91 | } 92 | case capro::CaproMessageType::STOP_OFFER: 93 | { 94 | if (this->findChannel(msg.m_serviceDescription).has_value()) 95 | { 96 | IOX_DISCARD_RESULT(this->discardChannel(msg.m_serviceDescription)); 97 | } 98 | break; 99 | } 100 | default: 101 | { 102 | break; 103 | } 104 | } 105 | } 106 | 107 | template 108 | inline void Iceoryx2DDSGateway::forward(const channel_t& channel) noexcept 109 | { 110 | auto subscriber = channel.getIceoryxTerminal(); 111 | while (subscriber->hasData()) 112 | { 113 | subscriber->take().and_then([&](const void* userPayload) { 114 | auto dataWriter = channel.getExternalTerminal(); 115 | auto chunkHeader = iox::mepoo::ChunkHeader::fromUserPayload(userPayload); 116 | iox::dds::IoxChunkDatagramHeader datagramHeader; 117 | datagramHeader.userHeaderId = chunkHeader->userHeaderId(); 118 | datagramHeader.userHeaderSize = chunkHeader->userHeaderSize(); 119 | datagramHeader.userPayloadSize = chunkHeader->userPayloadSize(); 120 | datagramHeader.userPayloadAlignment = chunkHeader->userPayloadAlignment(); 121 | dataWriter->write(datagramHeader, 122 | static_cast(chunkHeader->userHeader()), 123 | static_cast(chunkHeader->userPayload())); 124 | subscriber->release(userPayload); 125 | }); 126 | } 127 | } 128 | 129 | // ======================================== Private ======================================== // 130 | 131 | template 132 | expected 133 | Iceoryx2DDSGateway::setupChannel(const capro::ServiceDescription& service, 134 | const popo::SubscriberOptions& subscriberOptions) noexcept 135 | { 136 | return this->addChannel(service, subscriberOptions).and_then([](auto channel) { 137 | auto subscriber = channel.getIceoryxTerminal(); 138 | auto dataWriter = channel.getExternalTerminal(); 139 | subscriber->subscribe(); 140 | dataWriter->connect(); 141 | }); 142 | } 143 | 144 | } // namespace dds 145 | } // namespace iox 146 | 147 | #endif // IOX_DDS_IOX_TO_DDS_INL 148 | -------------------------------------------------------------------------------- /msg/Mempool.idl: -------------------------------------------------------------------------------- 1 | module Mempool 2 | { 3 | struct Chunk 4 | { 5 | sequence payload; 6 | }; 7 | #pragma keylist Chunk 8 | }; 9 | -------------------------------------------------------------------------------- /source/gateway/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "iceoryx_dds/gateway/dds_to_iox.hpp" 19 | #include "iceoryx_dds/gateway/iox_to_dds.hpp" 20 | #include "iceoryx_platform/signal.hpp" 21 | #include "iceoryx_posh/gateway/gateway_config.hpp" 22 | #include "iceoryx_posh/gateway/toml_gateway_config_parser.hpp" 23 | #include "iceoryx_posh/runtime/posh_runtime.hpp" 24 | #include "iox/logging.hpp" 25 | #include "iox/optional.hpp" 26 | #include "iox/signal_watcher.hpp" 27 | 28 | int main() 29 | { 30 | // Start application 31 | iox::runtime::PoshRuntime::initRuntime("iox-dds-gateway"); 32 | 33 | iox::config::GatewayConfig gatewayConfig; 34 | iox::dds::Iceoryx2DDSGateway<> iox2ddsGateway; 35 | iox::dds::DDS2IceoryxGateway<> dds2ioxGateway; 36 | 37 | iox::config::TomlGatewayConfigParser::parse() 38 | .and_then([&](auto config) { gatewayConfig = config; }) 39 | .or_else([&](auto err) { 40 | IOX_LOG(WARN, 41 | "[Main] Failed to parse gateway config with error: " 42 | << iox::config::TOML_GATEWAY_CONFIG_FILE_PARSE_ERROR_STRINGS[err]); 43 | IOX_LOG(WARN, "[Main] Using default configuration."); 44 | gatewayConfig.setDefaults(); 45 | }); 46 | 47 | iox2ddsGateway.loadConfiguration(gatewayConfig); 48 | dds2ioxGateway.loadConfiguration(gatewayConfig); 49 | 50 | iox2ddsGateway.runMultithreaded(); 51 | dds2ioxGateway.runMultithreaded(); 52 | 53 | // Run until SIGINT or SIGTERM 54 | iox::waitForTerminationRequest(); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/cyclone_context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "iceoryx_dds/dds/cyclone_context.hpp" 18 | 19 | ::dds::domain::DomainParticipant& iox::dds::CycloneContext::getParticipant() noexcept 20 | { 21 | static auto participant = ::dds::domain::DomainParticipant(org::eclipse::cyclonedds::domain::default_id()); 22 | return participant; 23 | } 24 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/cyclone_data_reader.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "iceoryx_dds/dds/cyclone_data_reader.hpp" 19 | #include "iceoryx_dds/dds/cyclone_context.hpp" 20 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 21 | #include "iox/assertions.hpp" 22 | #include "iox/logging.hpp" 23 | #include "iox/std_string_support.hpp" 24 | 25 | iox::dds::CycloneDataReader::CycloneDataReader(const capro::IdString_t serviceId, 26 | const capro::IdString_t instanceId, 27 | const capro::IdString_t eventId) noexcept 28 | : m_serviceId(serviceId) 29 | , m_instanceId(instanceId) 30 | , m_eventId(eventId) 31 | { 32 | IOX_LOG(DEBUG, "[CycloneDataReader] Created CycloneDataReader."); 33 | } 34 | 35 | iox::dds::CycloneDataReader::~CycloneDataReader() 36 | { 37 | IOX_LOG(DEBUG, "[CycloneDataReader] Destroyed CycloneDataReader."); 38 | } 39 | 40 | void iox::dds::CycloneDataReader::connect() noexcept 41 | { 42 | if (!m_isConnected.load(std::memory_order_relaxed)) 43 | { 44 | auto topicString = "/" + into(m_serviceId) + "/" + into(m_instanceId) + "/" 45 | + into(m_eventId); 46 | auto topic = ::dds::topic::Topic(CycloneContext::getParticipant(), topicString); 47 | auto subscriber = ::dds::sub::Subscriber(CycloneContext::getParticipant()); 48 | 49 | auto qos = ::dds::sub::qos::DataReaderQos(); 50 | 51 | /// Is required for the Gateway. When two iceoryx publisher are publishing on the same 52 | /// topic and one publisher is located on a remote iceoryx instance connected via a 53 | /// bidirectional dds gateway (iceoryx2dds & dds2iceoryx) then every sample is delivered 54 | /// twice to the local subscriber. 55 | /// Once via the local iceoryx publisher and once via dds2iceoryx which received the 56 | /// sample from the iceoryx2dds gateway. But when we ignore the local dds writer the 57 | /// sample is not forwarded to the local dds gateway and delivered a second time. 58 | auto* cqos = qos.delegate().ddsc_qos(); 59 | dds_qset_ignorelocal(cqos, DDS_IGNORELOCAL_PROCESS); 60 | qos.delegate().ddsc_qos(cqos); 61 | qos << ::dds::core::policy::History::KeepAll(); 62 | 63 | m_impl = ::dds::sub::DataReader(subscriber, topic, qos); 64 | 65 | IOX_LOG(DEBUG, "[CycloneDataReader] Connected to topic: " << topicString); 66 | 67 | m_isConnected.store(true, std::memory_order_relaxed); 68 | free(cqos); 69 | } 70 | } 71 | 72 | iox::optional iox::dds::CycloneDataReader::peekNextIoxChunkDatagramHeader() noexcept 73 | { 74 | // ensure to only read sample - do not take 75 | auto readSamples = m_impl.select().max_samples(1U).state(::dds::sub::status::SampleState::any()).read(); 76 | 77 | constexpr iox::nullopt_t NO_VALID_SAMPLE_AVAILABLE; 78 | 79 | if (readSamples.length() == 0) 80 | { 81 | return NO_VALID_SAMPLE_AVAILABLE; 82 | } 83 | 84 | auto nextSample = readSamples.begin(); 85 | auto& nextSamplePayload = nextSample->data().payload(); 86 | auto nextSampleSize = nextSamplePayload.size(); 87 | 88 | auto dropSample = [&] { 89 | m_impl.select().max_samples(1U).state(::dds::sub::status::SampleState::any()).take(); 90 | return NO_VALID_SAMPLE_AVAILABLE; 91 | }; 92 | 93 | // Ignore samples with no payload 94 | if (nextSampleSize == 0) 95 | { 96 | IOX_LOG(ERROR, "[CycloneDataReader] received sample with size zero! Dropped sample!"); 97 | return dropSample(); 98 | } 99 | 100 | // Ignore Invalid IoxChunkDatagramHeader 101 | if (nextSampleSize < sizeof(iox::dds::IoxChunkDatagramHeader)) 102 | { 103 | IOX_LOG(ERROR, [&](auto& log) -> auto& { 104 | log << "[CycloneDataReader] invalid sample size! Must be at least sizeof(IoxChunkDatagramHeader) = " 105 | << sizeof(iox::dds::IoxChunkDatagramHeader) << " but got " << nextSampleSize; 106 | if (nextSampleSize >= 1) 107 | { 108 | log << "! Potential datagram version is " << static_cast(nextSamplePayload[0]) 109 | << "! Dropped sample!"; 110 | } 111 | 112 | return log; 113 | }); 114 | return dropSample(); 115 | } 116 | 117 | iox::dds::IoxChunkDatagramHeader::Serialized_t serializedDatagramHeader; 118 | for (uint64_t i = 0U; i < serializedDatagramHeader.capacity(); ++i) 119 | { 120 | serializedDatagramHeader.emplace_back(nextSamplePayload[i]); 121 | } 122 | 123 | auto datagramHeader = iox::dds::IoxChunkDatagramHeader::deserialize(serializedDatagramHeader); 124 | 125 | if (datagramHeader.datagramVersion != iox::dds::IoxChunkDatagramHeader::DATAGRAM_VERSION) 126 | { 127 | IOX_LOG(ERROR, 128 | "[CycloneDataReader] received sample with incompatible IoxChunkDatagramHeader version! Received '" 129 | << static_cast(datagramHeader.datagramVersion) << "', expected '" 130 | << static_cast(iox::dds::IoxChunkDatagramHeader::DATAGRAM_VERSION) 131 | << "'! Dropped sample!"); 132 | return dropSample(); 133 | } 134 | 135 | if (datagramHeader.endianness != getEndianess()) 136 | { 137 | IOX_LOG(ERROR, 138 | "[CycloneDataReader] received sample with incompatible endianess! Received '" 139 | << EndianessString[static_cast(datagramHeader.endianness)] << "', expected '" 140 | << EndianessString[static_cast(getEndianess())] << "'! Dropped sample!"); 141 | return dropSample(); 142 | } 143 | 144 | return datagramHeader; 145 | } 146 | 147 | bool iox::dds::CycloneDataReader::hasSamples() noexcept 148 | { 149 | auto samples = m_impl.select().max_samples(1u).state(::dds::sub::status::SampleState::any()).read(); 150 | return samples.length() > 0; 151 | } 152 | 153 | iox::expected 154 | iox::dds::CycloneDataReader::takeNext(const iox::dds::IoxChunkDatagramHeader datagramHeader, 155 | uint8_t* const userHeaderBuffer, 156 | uint8_t* const userPayloadBuffer) noexcept 157 | { 158 | // validation checks 159 | if (!m_isConnected.load()) 160 | { 161 | return err(iox::dds::DataReaderError::NOT_CONNECTED); 162 | } 163 | // it is assume that peekNextIoxChunkDatagramHeader was called beforehand and that the provided datagramHeader 164 | // belongs to this sample 165 | if (datagramHeader.userHeaderSize > 0 166 | && (datagramHeader.userHeaderId == iox::mepoo::ChunkHeader::NO_USER_HEADER || userHeaderBuffer == nullptr)) 167 | { 168 | return err(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_HEADER); 169 | } 170 | if (datagramHeader.userPayloadSize > 0 && userPayloadBuffer == nullptr) 171 | { 172 | return err(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD); 173 | } 174 | 175 | // take next sample and copy into buffer 176 | auto takenSamples = m_impl.select().max_samples(1U).state(::dds::sub::status::SampleState::any()).take(); 177 | if (takenSamples.length() == 0) 178 | { 179 | // no samples available 180 | return ok(); 181 | } 182 | 183 | // valid size 184 | auto nextSample = takenSamples.begin(); 185 | auto samplePayload = nextSample->data().payload(); 186 | auto sampleSize = samplePayload.size(); 187 | if (sampleSize == 0) 188 | { 189 | return err(iox::dds::DataReaderError::INVALID_DATA); 190 | } 191 | if (sampleSize < sizeof(iox::dds::IoxChunkDatagramHeader)) 192 | { 193 | return err(iox::dds::DataReaderError::INVALID_DATAGRAM_HEADER_SIZE); 194 | } 195 | 196 | iox::dds::IoxChunkDatagramHeader::Serialized_t serializedDatagramHeader; 197 | for (uint64_t i = 0U; i < serializedDatagramHeader.capacity(); ++i) 198 | { 199 | serializedDatagramHeader.emplace_back(samplePayload[i]); 200 | } 201 | 202 | auto actualDatagramHeader = iox::dds::IoxChunkDatagramHeader::deserialize(serializedDatagramHeader); 203 | 204 | IOX_ENFORCE(datagramHeader.userHeaderId == actualDatagramHeader.userHeaderId, "Invalid user header ID"); 205 | IOX_ENFORCE(datagramHeader.userHeaderSize == actualDatagramHeader.userHeaderSize, "Invalid user header size"); 206 | IOX_ENFORCE(datagramHeader.userPayloadSize == actualDatagramHeader.userPayloadSize, "Invalid payload"); 207 | IOX_ENFORCE(datagramHeader.userPayloadAlignment == actualDatagramHeader.userPayloadAlignment, 208 | "Invalid payload alignment"); 209 | 210 | auto dataSize = sampleSize - sizeof(iox::dds::IoxChunkDatagramHeader); 211 | auto bufferSize = datagramHeader.userHeaderSize + datagramHeader.userPayloadSize; 212 | 213 | if (bufferSize != dataSize) 214 | { 215 | // provided buffer don't match 216 | return err(iox::dds::DataReaderError::BUFFER_SIZE_MISMATCH); 217 | } 218 | 219 | // copy data into the provided buffer 220 | if (userHeaderBuffer) 221 | { 222 | auto userHeaderBytes = &samplePayload.data()[sizeof(iox::dds::IoxChunkDatagramHeader)]; 223 | std::memcpy(userHeaderBuffer, userHeaderBytes, datagramHeader.userHeaderSize); 224 | } 225 | 226 | if (userPayloadBuffer) 227 | { 228 | auto userPayloadBytes = 229 | &samplePayload.data()[sizeof(iox::dds::IoxChunkDatagramHeader) + datagramHeader.userHeaderSize]; 230 | std::memcpy(userPayloadBuffer, userPayloadBytes, datagramHeader.userPayloadSize); 231 | } 232 | 233 | return ok(); 234 | } 235 | 236 | iox::capro::IdString_t iox::dds::CycloneDataReader::getServiceId() const noexcept 237 | { 238 | return m_serviceId; 239 | } 240 | 241 | iox::capro::IdString_t iox::dds::CycloneDataReader::getInstanceId() const noexcept 242 | { 243 | return m_instanceId; 244 | } 245 | 246 | iox::capro::IdString_t iox::dds::CycloneDataReader::getEventId() const noexcept 247 | { 248 | return m_eventId; 249 | } 250 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/cyclone_data_writer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "iceoryx_dds/dds/cyclone_data_writer.hpp" 19 | #include "Mempool.hpp" 20 | #include "iceoryx_dds/dds/cyclone_context.hpp" 21 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 22 | #include "iox/logging.hpp" 23 | #include "iox/std_string_support.hpp" 24 | 25 | #include 26 | 27 | iox::dds::CycloneDataWriter::CycloneDataWriter(const capro::IdString_t serviceId, 28 | const capro::IdString_t instanceId, 29 | const capro::IdString_t eventId) noexcept 30 | : m_serviceId(serviceId) 31 | , m_instanceId(instanceId) 32 | , m_eventId(eventId) 33 | { 34 | IOX_LOG(DEBUG, "[CycloneDataWriter] Created CycloneDataWriter."); 35 | } 36 | 37 | iox::dds::CycloneDataWriter::~CycloneDataWriter() 38 | { 39 | m_writer.close(); 40 | m_topic.close(); 41 | m_publisher.close(); 42 | IOX_LOG(DEBUG, "[CycloneDataWriter] Destroyed CycloneDataWriter."); 43 | } 44 | 45 | void iox::dds::CycloneDataWriter::connect() noexcept 46 | { 47 | m_publisher = ::dds::pub::Publisher(CycloneContext::getParticipant()); 48 | auto topic = "/" + into(m_serviceId) + "/" + into(m_instanceId) + "/" 49 | + into(m_eventId); 50 | m_topic = ::dds::topic::Topic(CycloneContext::getParticipant(), topic); 51 | m_writer = ::dds::pub::DataWriter(m_publisher, m_topic); 52 | IOX_LOG(DEBUG, "[CycloneDataWriter] Connected to topic: " << topic); 53 | } 54 | 55 | void iox::dds::CycloneDataWriter::write(iox::dds::IoxChunkDatagramHeader datagramHeader, 56 | const uint8_t* const userHeaderBytes, 57 | const uint8_t* const userPayloadBytes) noexcept 58 | { 59 | if (datagramHeader.userHeaderSize > 0 60 | && (datagramHeader.userHeaderId == iox::mepoo::ChunkHeader::NO_USER_HEADER || userHeaderBytes == nullptr)) 61 | { 62 | IOX_LOG(ERROR, "[CycloneDataWriter] invalid user-header parameter! Dropping chunk!"); 63 | return; 64 | } 65 | if (datagramHeader.userPayloadSize > 0 && userPayloadBytes == nullptr) 66 | { 67 | IOX_LOG(ERROR, "[CycloneDataWriter] invalid user-payload parameter! Dropping chunk!"); 68 | return; 69 | } 70 | 71 | datagramHeader.endianness = getEndianess(); 72 | 73 | auto serializedDatagramHeader = iox::dds::IoxChunkDatagramHeader::serialize(datagramHeader); 74 | auto datagramSize = 75 | serializedDatagramHeader.size() + datagramHeader.userHeaderSize + datagramHeader.userPayloadSize; 76 | 77 | auto chunk = Mempool::Chunk(); 78 | chunk.payload().reserve(datagramSize); 79 | 80 | std::copy(serializedDatagramHeader.data(), 81 | serializedDatagramHeader.data() + serializedDatagramHeader.size(), 82 | std::back_inserter(chunk.payload())); 83 | if (datagramHeader.userHeaderSize > 0 && userHeaderBytes != nullptr) 84 | { 85 | std::copy( 86 | userHeaderBytes, userHeaderBytes + datagramHeader.userHeaderSize, std::back_inserter(chunk.payload())); 87 | } 88 | if (datagramHeader.userPayloadSize > 0 && userPayloadBytes != nullptr) 89 | { 90 | std::copy( 91 | userPayloadBytes, userPayloadBytes + datagramHeader.userPayloadSize, std::back_inserter(chunk.payload())); 92 | } 93 | 94 | m_writer.write(chunk); 95 | } 96 | 97 | iox::capro::IdString_t iox::dds::CycloneDataWriter::getServiceId() const noexcept 98 | { 99 | return m_serviceId; 100 | } 101 | 102 | iox::capro::IdString_t iox::dds::CycloneDataWriter::getInstanceId() const noexcept 103 | { 104 | return m_instanceId; 105 | } 106 | 107 | iox::capro::IdString_t iox::dds::CycloneDataWriter::getEventId() const noexcept 108 | { 109 | return m_eventId; 110 | } 111 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/fast_context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "iceoryx_dds/dds/fast_context.hpp" 18 | #include "MempoolPubSubTypes.h" 19 | #include "iox/logging.hpp" 20 | 21 | #include 22 | 23 | iox::dds::FastContext& iox::dds::FastContext::getInstance() 24 | { 25 | static iox::dds::FastContext context; 26 | return context; 27 | } 28 | 29 | eprosima::fastdds::dds::DomainParticipant* iox::dds::FastContext::getParticipant() 30 | { 31 | return m_participant; 32 | } 33 | 34 | eprosima::fastdds::dds::Topic* iox::dds::FastContext::getTopic(const std::string& topicName) 35 | { 36 | auto topic = m_participant->find_topic(topicName, {0, 0}); 37 | if (topic != nullptr) 38 | { 39 | return topic; 40 | } 41 | else 42 | { 43 | IOX_LOG(WARN, "[FastDataReader] Failed to find topic: " << topicName); 44 | } 45 | 46 | topic = m_participant->create_topic(topicName, "Mempool::Chunk", eprosima::fastdds::dds::TOPIC_QOS_DEFAULT); 47 | if (topic == nullptr) 48 | { 49 | IOX_LOG(ERROR, "[FastDataReader] Failed to create topic: " << topicName); 50 | } 51 | 52 | return topic; 53 | } 54 | 55 | iox::dds::FastContext::FastContext() 56 | { 57 | auto factory = eprosima::fastdds::dds::DomainParticipantFactory::get_instance(); 58 | m_participant = factory->create_participant(0, eprosima::fastdds::dds::PARTICIPANT_QOS_DEFAULT); 59 | if (m_participant == nullptr) 60 | { 61 | IOX_LOG(ERROR, "[FastContext] Failed to create participant"); 62 | return; 63 | } 64 | 65 | m_type = eprosima::fastdds::dds::TypeSupport(new Mempool::ChunkPubSubType()); 66 | m_type.register_type(m_participant); 67 | } 68 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/fast_data_reader.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "iceoryx_dds/dds/fast_data_reader.hpp" 18 | #include "Mempool.h" 19 | #include "iceoryx_dds/dds/fast_context.hpp" 20 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 21 | #include "iox/assertions.hpp" 22 | #include "iox/logging.hpp" 23 | #include "iox/std_string_support.hpp" 24 | 25 | #include 26 | 27 | iox::dds::FastDataReader::FastDataReader(const capro::IdString_t& serviceId, 28 | const capro::IdString_t& instanceId, 29 | const capro::IdString_t& eventId) noexcept 30 | : m_serviceId(serviceId) 31 | , m_instanceId(instanceId) 32 | , m_eventId(eventId) 33 | { 34 | IOX_LOG(DEBUG, "[FastDataReader] Created FastDataReader."); 35 | } 36 | 37 | iox::dds::FastDataReader::~FastDataReader() 38 | { 39 | if (m_reader != nullptr) 40 | { 41 | m_subscriber->delete_datareader(m_reader); 42 | } 43 | if (m_subscriber != nullptr) 44 | { 45 | FastContext::getInstance().getParticipant()->delete_subscriber(m_subscriber); 46 | } 47 | IOX_LOG(DEBUG, "[FastDataReader] Destroyed FastDataReader."); 48 | } 49 | 50 | void iox::dds::FastDataReader::connect() noexcept 51 | { 52 | if (!m_isConnected.load(std::memory_order_relaxed)) 53 | { 54 | auto participant = FastContext::getInstance().getParticipant(); 55 | if (participant == nullptr) 56 | { 57 | IOX_LOG(ERROR, "[FastDataReader] Failed to get participant"); 58 | return; 59 | } 60 | 61 | auto topicString = "/" + into(m_serviceId) + "/" + into(m_instanceId) + "/" 62 | + into(m_eventId); 63 | m_topic = FastContext::getInstance().getTopic(topicString); 64 | if (m_topic == nullptr) 65 | { 66 | IOX_LOG(ERROR, "[FastDataReader] Failed to get topic: " << topicString); 67 | return; 68 | } 69 | 70 | m_subscriber = participant->create_subscriber(eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT); 71 | if (m_subscriber == nullptr) 72 | { 73 | IOX_LOG(ERROR, "[FastDataReader] Failed to create subscriber"); 74 | return; 75 | } 76 | 77 | /// Is required for the Gateway. When two iceoryx publisher are publishing on the same 78 | /// topic and one publisher is located on a remote iceoryx instance connected via a 79 | /// bidirectional dds gateway (iceoryx2dds & dds2iceoryx) then every sample is delivered 80 | /// twice to the local subscriber. 81 | /// Once via the local iceoryx publisher and once via dds2iceoryx which received the 82 | /// sample from the iceoryx2dds gateway. But when we ignore the local dds writer the 83 | /// sample is not forwarded to the local dds gateway and delivered a second time. 84 | auto pqos = participant->get_qos(); 85 | pqos.properties().properties().emplace_back("fastdds.ignore_local_endpoints", "true"); 86 | participant->set_qos(pqos); 87 | 88 | auto qos = eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT; 89 | qos.history().kind = eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS; 90 | m_reader = m_subscriber->create_datareader(m_topic, qos); 91 | if (m_reader == nullptr) 92 | { 93 | IOX_LOG(ERROR, "[FastDataReader] Failed to create datareader"); 94 | return; 95 | } 96 | 97 | IOX_LOG(DEBUG, "[FastDataReader] Connected to topic: " << topicString); 98 | 99 | m_isConnected.store(true, std::memory_order_relaxed); 100 | } 101 | } 102 | 103 | iox::optional iox::dds::FastDataReader::peekNextIoxChunkDatagramHeader() noexcept 104 | { 105 | constexpr iox::nullopt_t NO_VALID_SAMPLE_AVAILABLE; 106 | 107 | FASTDDS_CONST_SEQUENCE(DataSeq, Mempool::Chunk); 108 | 109 | DataSeq dataSeq; 110 | eprosima::fastdds::dds::SampleInfoSeq infoSeq; 111 | 112 | // ensure to only read sample - do not take 113 | auto ret = m_reader->read(dataSeq, infoSeq, 1); 114 | if (ret != eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) 115 | { 116 | IOX_LOG(ERROR, "[FastDataReader] Failed to read sample, return code: " << ret()); 117 | return NO_VALID_SAMPLE_AVAILABLE; 118 | } 119 | 120 | auto dropSample = [&] { 121 | // Return the sample back 122 | auto ret = m_reader->return_loan(dataSeq, infoSeq); 123 | if (ret != eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) 124 | { 125 | IOX_LOG(ERROR, "[FastDataReader] Failed to return loan, return code: " << ret()); 126 | return NO_VALID_SAMPLE_AVAILABLE; 127 | } 128 | 129 | ret = m_reader->take(dataSeq, infoSeq, 1); 130 | if (ret != eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) 131 | { 132 | IOX_LOG(ERROR, "[FastDataReader] Failed to take sample, return code: " << ret()); 133 | return NO_VALID_SAMPLE_AVAILABLE; 134 | } 135 | 136 | ret = m_reader->return_loan(dataSeq, infoSeq); 137 | if (ret != eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) 138 | { 139 | IOX_LOG(ERROR, "[FastDataReader] Failed to return loan, return code: " << ret()); 140 | return NO_VALID_SAMPLE_AVAILABLE; 141 | } 142 | 143 | return NO_VALID_SAMPLE_AVAILABLE; 144 | }; 145 | 146 | if (infoSeq.length() == 0) 147 | { 148 | IOX_LOG(ERROR, "[FastDataReader] received no sample! Dropped sample!"); 149 | return dropSample(); 150 | } 151 | 152 | if (!infoSeq[0].valid_data) 153 | { 154 | IOX_LOG(ERROR, "[FastDataReader] received invalid sample! Dropped sample!"); 155 | return dropSample(); 156 | } 157 | 158 | const auto& nextSample = dataSeq[0]; 159 | auto& nextSamplePayload = nextSample.payload(); 160 | auto nextSampleSize = nextSamplePayload.size(); 161 | 162 | // Ignore samples with no payload 163 | if (nextSampleSize == 0) 164 | { 165 | IOX_LOG(ERROR, "[FastDataReader] received sample with size zero! Dropped sample!"); 166 | return dropSample(); 167 | } 168 | 169 | // Ignore Invalid IoxChunkDatagramHeader 170 | if (nextSampleSize < sizeof(iox::dds::IoxChunkDatagramHeader)) 171 | { 172 | IOX_LOG(ERROR, [&](auto& log) -> auto& { 173 | log << "[FastDataReader] invalid sample size! Must be at least sizeof(IoxChunkDatagramHeader) = " 174 | << sizeof(iox::dds::IoxChunkDatagramHeader) << " but got " << nextSampleSize; 175 | if (nextSampleSize >= 1) 176 | { 177 | log << "! Potential datagram version is " << static_cast(nextSamplePayload[0]) 178 | << "! Dropped sample!"; 179 | } 180 | 181 | return log; 182 | }); 183 | return dropSample(); 184 | } 185 | 186 | iox::dds::IoxChunkDatagramHeader::Serialized_t serializedDatagramHeader; 187 | for (uint64_t i = 0U; i < serializedDatagramHeader.capacity(); ++i) 188 | { 189 | serializedDatagramHeader.emplace_back(nextSamplePayload[i]); 190 | } 191 | 192 | auto datagramHeader = iox::dds::IoxChunkDatagramHeader::deserialize(serializedDatagramHeader); 193 | 194 | if (datagramHeader.datagramVersion != iox::dds::IoxChunkDatagramHeader::DATAGRAM_VERSION) 195 | { 196 | IOX_LOG(ERROR, 197 | "[FastDataReader] received sample with incompatible IoxChunkDatagramHeader version! Received '" 198 | << static_cast(datagramHeader.datagramVersion) << "', expected '" 199 | << static_cast(iox::dds::IoxChunkDatagramHeader::DATAGRAM_VERSION) 200 | << "'! Dropped sample!"); 201 | return dropSample(); 202 | } 203 | 204 | if (datagramHeader.endianness != getEndianess()) 205 | { 206 | IOX_LOG(ERROR, 207 | "[FastDataReader] received sample with incompatible endianess! Received '" 208 | << EndianessString[static_cast(datagramHeader.endianness)] << "', expected '" 209 | << EndianessString[static_cast(getEndianess())] << "'! Dropped sample!"); 210 | return dropSample(); 211 | } 212 | 213 | return datagramHeader; 214 | } 215 | 216 | bool iox::dds::FastDataReader::hasSamples() noexcept 217 | { 218 | eprosima::fastdds::dds::SampleInfo info; 219 | return m_reader->get_first_untaken_info(&info) == eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK; 220 | } 221 | 222 | iox::expected 223 | iox::dds::FastDataReader::takeNext(const iox::dds::IoxChunkDatagramHeader datagramHeader, 224 | uint8_t* const userHeaderBuffer, 225 | uint8_t* const userPayloadBuffer) noexcept 226 | { 227 | // validation checks 228 | if (!m_isConnected.load()) 229 | { 230 | return err(iox::dds::DataReaderError::NOT_CONNECTED); 231 | } 232 | // it is assume that peekNextIoxChunkDatagramHeader was called beforehand and that the provided datagramHeader 233 | // belongs to this sample 234 | if (datagramHeader.userHeaderSize > 0 235 | && (datagramHeader.userHeaderId == iox::mepoo::ChunkHeader::NO_USER_HEADER || userHeaderBuffer == nullptr)) 236 | { 237 | return err(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_HEADER); 238 | } 239 | if (datagramHeader.userPayloadSize > 0 && userPayloadBuffer == nullptr) 240 | { 241 | return err(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD); 242 | } 243 | 244 | // take next sample and copy into buffer 245 | FASTDDS_CONST_SEQUENCE(DataSeq, Mempool::Chunk); 246 | 247 | DataSeq dataSeq; 248 | eprosima::fastdds::dds::SampleInfoSeq infoSeq; 249 | auto ret = m_reader->take(dataSeq, infoSeq, 1); 250 | if (ret != eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) 251 | { 252 | // no samples available 253 | return ok(); 254 | } 255 | 256 | auto returnSample = [&] { m_reader->return_loan(dataSeq, infoSeq); }; 257 | 258 | if (infoSeq.length() == 0) 259 | { 260 | returnSample(); 261 | // no samples available 262 | return ok(); 263 | } 264 | 265 | if (!infoSeq[0].valid_data) 266 | { 267 | returnSample(); 268 | return err(iox::dds::DataReaderError::INVALID_DATA); 269 | } 270 | 271 | // valid size 272 | auto nextSample = dataSeq[0]; 273 | auto samplePayload = nextSample.payload(); 274 | auto sampleSize = samplePayload.size(); 275 | if (sampleSize == 0) 276 | { 277 | returnSample(); 278 | return err(iox::dds::DataReaderError::INVALID_DATA); 279 | } 280 | if (sampleSize < sizeof(iox::dds::IoxChunkDatagramHeader)) 281 | { 282 | returnSample(); 283 | return err(iox::dds::DataReaderError::INVALID_DATAGRAM_HEADER_SIZE); 284 | } 285 | 286 | iox::dds::IoxChunkDatagramHeader::Serialized_t serializedDatagramHeader; 287 | for (uint64_t i = 0U; i < serializedDatagramHeader.capacity(); ++i) 288 | { 289 | serializedDatagramHeader.emplace_back(samplePayload[i]); 290 | } 291 | 292 | auto actualDatagramHeader = iox::dds::IoxChunkDatagramHeader::deserialize(serializedDatagramHeader); 293 | 294 | IOX_ENFORCE(datagramHeader.userHeaderId == actualDatagramHeader.userHeaderId, "Invalid user header ID"); 295 | IOX_ENFORCE(datagramHeader.userHeaderSize == actualDatagramHeader.userHeaderSize, "Invalid user header size"); 296 | IOX_ENFORCE(datagramHeader.userPayloadSize == actualDatagramHeader.userPayloadSize, "Invalid payload size"); 297 | IOX_ENFORCE(datagramHeader.userPayloadAlignment == actualDatagramHeader.userPayloadAlignment, 298 | "Invalid payload alignment"); 299 | 300 | auto dataSize = sampleSize - sizeof(iox::dds::IoxChunkDatagramHeader); 301 | auto bufferSize = datagramHeader.userHeaderSize + datagramHeader.userPayloadSize; 302 | 303 | if (bufferSize != dataSize) 304 | { 305 | returnSample(); 306 | // provided buffer don't match 307 | return err(iox::dds::DataReaderError::BUFFER_SIZE_MISMATCH); 308 | } 309 | 310 | // copy data into the provided buffer 311 | if (userHeaderBuffer) 312 | { 313 | auto userHeaderBytes = &samplePayload.data()[sizeof(iox::dds::IoxChunkDatagramHeader)]; 314 | std::memcpy(userHeaderBuffer, userHeaderBytes, datagramHeader.userHeaderSize); 315 | } 316 | 317 | if (userPayloadBuffer) 318 | { 319 | auto userPayloadBytes = 320 | &samplePayload.data()[sizeof(iox::dds::IoxChunkDatagramHeader) + datagramHeader.userHeaderSize]; 321 | std::memcpy(userPayloadBuffer, userPayloadBytes, datagramHeader.userPayloadSize); 322 | } 323 | 324 | returnSample(); 325 | return ok(); 326 | } 327 | 328 | iox::capro::IdString_t iox::dds::FastDataReader::getServiceId() const noexcept 329 | { 330 | return m_serviceId; 331 | } 332 | 333 | iox::capro::IdString_t iox::dds::FastDataReader::getInstanceId() const noexcept 334 | { 335 | return m_instanceId; 336 | } 337 | 338 | iox::capro::IdString_t iox::dds::FastDataReader::getEventId() const noexcept 339 | { 340 | return m_eventId; 341 | } 342 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/fast_data_writer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "iceoryx_dds/dds/fast_data_writer.hpp" 18 | #include "Mempool.h" 19 | #include "iceoryx_dds/dds/fast_context.hpp" 20 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 21 | #include "iox/logging.hpp" 22 | #include "iox/std_string_support.hpp" 23 | 24 | #include 25 | #include 26 | 27 | iox::dds::FastDataWriter::FastDataWriter(const capro::IdString_t& serviceId, 28 | const capro::IdString_t& instanceId, 29 | const capro::IdString_t& eventId) noexcept 30 | : m_serviceId(serviceId) 31 | , m_instanceId(instanceId) 32 | , m_eventId(eventId) 33 | { 34 | IOX_LOG(DEBUG, "[FastDataWriter] Created FastDataWriter."); 35 | } 36 | 37 | iox::dds::FastDataWriter::~FastDataWriter() 38 | { 39 | if (m_writer != nullptr) 40 | { 41 | m_publisher->delete_datawriter(m_writer); 42 | } 43 | if (m_topic != nullptr) 44 | { 45 | FastContext::getInstance().getParticipant()->delete_topic(m_topic); 46 | } 47 | if (m_publisher != nullptr) 48 | { 49 | FastContext::getInstance().getParticipant()->delete_publisher(m_publisher); 50 | } 51 | IOX_LOG(DEBUG, "[FastDataWriter] Destroyed FastDataWriter."); 52 | } 53 | 54 | void iox::dds::FastDataWriter::connect() noexcept 55 | { 56 | auto participant = FastContext::getInstance().getParticipant(); 57 | if (participant == nullptr) 58 | { 59 | IOX_LOG(ERROR, "[FastDataWriter] Failed to get participant"); 60 | return; 61 | } 62 | 63 | m_publisher = participant->create_publisher(eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT); 64 | if (m_publisher == nullptr) 65 | { 66 | IOX_LOG(ERROR, "[FastDataWriter] Failed to create publisher"); 67 | return; 68 | } 69 | 70 | auto topic = "/" + into(m_serviceId) + "/" + into(m_instanceId) + "/" 71 | + into(m_eventId); 72 | m_topic = FastContext::getInstance().getTopic(topic); 73 | if (m_topic == nullptr) 74 | { 75 | IOX_LOG(ERROR, "[FastDataReader] Failed to get topic: " << topic); 76 | return; 77 | } 78 | 79 | m_writer = m_publisher->create_datawriter(m_topic, eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT); 80 | if (m_writer == nullptr) 81 | { 82 | IOX_LOG(ERROR, "[FastDataWriter] Failed to create datawriter"); 83 | return; 84 | } 85 | 86 | IOX_LOG(DEBUG, "[FastDataWriter] Connected to topic: " << topic); 87 | } 88 | 89 | void iox::dds::FastDataWriter::write(iox::dds::IoxChunkDatagramHeader datagramHeader, 90 | const uint8_t* const userHeaderBytes, 91 | const uint8_t* const userPayloadBytes) noexcept 92 | { 93 | if (datagramHeader.userHeaderSize > 0 94 | && (datagramHeader.userHeaderId == iox::mepoo::ChunkHeader::NO_USER_HEADER || userHeaderBytes == nullptr)) 95 | { 96 | IOX_LOG(ERROR, "[FastDataWriter] invalid user-header parameter! Dropping chunk!"); 97 | return; 98 | } 99 | if (datagramHeader.userPayloadSize > 0 && userPayloadBytes == nullptr) 100 | { 101 | IOX_LOG(ERROR, "[FastDataWriter] invalid user-payload parameter! Dropping chunk!"); 102 | return; 103 | } 104 | 105 | datagramHeader.endianness = getEndianess(); 106 | 107 | auto serializedDatagramHeader = iox::dds::IoxChunkDatagramHeader::serialize(datagramHeader); 108 | auto datagramSize = 109 | serializedDatagramHeader.size() + datagramHeader.userHeaderSize + datagramHeader.userPayloadSize; 110 | 111 | auto chunk = Mempool::Chunk(); 112 | chunk.payload().reserve(datagramSize); 113 | 114 | std::copy(serializedDatagramHeader.data(), 115 | serializedDatagramHeader.data() + serializedDatagramHeader.size(), 116 | std::back_inserter(chunk.payload())); 117 | if (datagramHeader.userHeaderSize > 0 && userHeaderBytes != nullptr) 118 | { 119 | std::copy( 120 | userHeaderBytes, userHeaderBytes + datagramHeader.userHeaderSize, std::back_inserter(chunk.payload())); 121 | } 122 | if (datagramHeader.userPayloadSize > 0 && userPayloadBytes != nullptr) 123 | { 124 | std::copy( 125 | userPayloadBytes, userPayloadBytes + datagramHeader.userPayloadSize, std::back_inserter(chunk.payload())); 126 | } 127 | 128 | if (!m_writer->write(&chunk)) 129 | { 130 | IOX_LOG(ERROR, "[FastDataWriter] Failed to write chunk"); 131 | } 132 | } 133 | 134 | iox::capro::IdString_t iox::dds::FastDataWriter::getServiceId() const noexcept 135 | { 136 | return m_serviceId; 137 | } 138 | 139 | iox::capro::IdString_t iox::dds::FastDataWriter::getInstanceId() const noexcept 140 | { 141 | return m_instanceId; 142 | } 143 | 144 | iox::capro::IdString_t iox::dds::FastDataWriter::getEventId() const noexcept 145 | { 146 | return m_eventId; 147 | } 148 | -------------------------------------------------------------------------------- /source/iceoryx_dds/dds/iox_chunk_datagram_header.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "iceoryx_dds/dds/iox_chunk_datagram_header.hpp" 18 | #include "iox/assertions.hpp" 19 | 20 | namespace iox 21 | { 22 | namespace dds 23 | { 24 | Endianess getEndianess() 25 | { 26 | uint32_t endianDetector{0x01020304}; 27 | switch (reinterpret_cast(&endianDetector)[0U]) 28 | { 29 | case 1U: 30 | return Endianess::BIG; 31 | case 4U: 32 | return Endianess::LITTLE; 33 | case 2U: 34 | return Endianess::MIXED; 35 | default: 36 | return Endianess::UNDEFINED; 37 | } 38 | 39 | return Endianess::UNDEFINED; 40 | } 41 | 42 | IoxChunkDatagramHeader::Serialized_t IoxChunkDatagramHeader::serialize(const IoxChunkDatagramHeader& datagramHeader) 43 | { 44 | Serialized_t serializedDatagram; 45 | 46 | serializedDatagram.emplace_back(datagramHeader.datagramVersion); 47 | serializedDatagram.emplace_back(static_cast(datagramHeader.endianness)); 48 | serializedDatagram.emplace_back(static_cast((datagramHeader.userHeaderId >> 8U) & 0xFF)); 49 | serializedDatagram.emplace_back(static_cast(datagramHeader.userHeaderId & 0xFF)); 50 | serializedDatagram.emplace_back(static_cast((datagramHeader.userHeaderSize >> 24U) & 0xFF)); 51 | serializedDatagram.emplace_back(static_cast((datagramHeader.userHeaderSize >> 16U) & 0xFF)); 52 | serializedDatagram.emplace_back(static_cast((datagramHeader.userHeaderSize >> 8U) & 0xFF)); 53 | serializedDatagram.emplace_back(static_cast(datagramHeader.userHeaderSize & 0xFF)); 54 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadSize >> 24U) & 0xFF)); 55 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadSize >> 16U) & 0xFF)); 56 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadSize >> 8U) & 0xFF)); 57 | serializedDatagram.emplace_back(static_cast(datagramHeader.userPayloadSize & 0xFF)); 58 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadAlignment >> 24U) & 0xFF)); 59 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadAlignment >> 16U) & 0xFF)); 60 | serializedDatagram.emplace_back(static_cast((datagramHeader.userPayloadAlignment >> 8U) & 0xFF)); 61 | auto successfullyPushed = 62 | serializedDatagram.emplace_back(static_cast(datagramHeader.userPayloadAlignment & 0xFF)); 63 | 64 | IOX_ENFORCE(successfullyPushed, "Expected to successfully serialize IoxChunkDatagramHeader!"); 65 | 66 | return serializedDatagram; 67 | } 68 | 69 | IoxChunkDatagramHeader 70 | IoxChunkDatagramHeader::deserialize(const IoxChunkDatagramHeader::Serialized_t& serializedDatagramHeader) 71 | { 72 | IOX_ENFORCE(serializedDatagramHeader.size() == 16U, "Expects valid IoxChunkDatagramHeader serialization!"); 73 | 74 | IoxChunkDatagramHeader datagramHeader; 75 | 76 | datagramHeader.datagramVersion = serializedDatagramHeader[0U]; 77 | datagramHeader.endianness = static_cast(serializedDatagramHeader[1U]); 78 | datagramHeader.userHeaderId = static_cast((static_cast(serializedDatagramHeader[2U]) << 8U) 79 | | static_cast(serializedDatagramHeader[3U])); 80 | datagramHeader.userHeaderSize = (static_cast(serializedDatagramHeader[4U]) << 24U) 81 | | (static_cast(serializedDatagramHeader[5U]) << 16U) 82 | | (static_cast(serializedDatagramHeader[6U]) << 8U) 83 | | static_cast(serializedDatagramHeader[7U]); 84 | datagramHeader.userPayloadSize = (static_cast(serializedDatagramHeader[8U]) << 24U) 85 | | (static_cast(serializedDatagramHeader[9U]) << 16U) 86 | | (static_cast(serializedDatagramHeader[10U]) << 8U) 87 | | static_cast(serializedDatagramHeader[11U]); 88 | datagramHeader.userPayloadAlignment = (static_cast(serializedDatagramHeader[12U]) << 24U) 89 | | (static_cast(serializedDatagramHeader[13U]) << 16U) 90 | | (static_cast(serializedDatagramHeader[14U]) << 8U) 91 | | static_cast(serializedDatagramHeader[15U]); 92 | 93 | return datagramHeader; 94 | } 95 | 96 | } // namespace dds 97 | } // namespace iox 98 | -------------------------------------------------------------------------------- /test/.clang-tidy: -------------------------------------------------------------------------------- 1 | # Symlinked to: 2 | # currently no symlinks 3 | 4 | InheritParentConfig: true 5 | 6 | Checks: ' 7 | -cert-err58-cpp, 8 | -cppcoreguidelines-avoid-non-const-global-variables, 9 | -cppcoreguidelines-owning-memory, 10 | -cppcoreguidelines-special-member-functions, 11 | -hicpp-special-member-functions, 12 | -readability-identifier-naming, 13 | ' 14 | 15 | ## Justifications for rule deactivation ## 16 | # 17 | # * rule: cert-err58-cpp 18 | # justification: caused by TEST_F in gtest with internal macro generated construct: test_info_ 19 | # 20 | # * rule: cppcoreguidelines-avoid-non-const-global-variables 21 | # justification: same as for 'cert-err58-cpp' 22 | # 23 | # * rule: cppcoreguidelines-owning-memory 24 | # justification: caused by TEST_F in gtest with internal macro generated construct: testing::internal::TestFactoryBase * 25 | # 26 | # * rule: cppcoreguidelines-special-member-functions 27 | # justification: structs and classes in tests do not all follow the rule of five 28 | # 29 | # * rule: hicpp-special-member-functions 30 | # justification: same as for 'cppcoreguidelines-special-member-functions' 31 | # 32 | # * rule: readability-identifier-naming 33 | # justification: structs and classes in tests do not obey the same naming convention like in production code 34 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | # Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. 3 | # Copyright (c) 2024 by Wei Long Meng. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # SPDX-License-Identifier: Apache-2.0 18 | cmake_minimum_required(VERSION 3.16) 19 | project(test_iox_to_dds VERSION 0) 20 | 21 | find_package(iceoryx_hoofs_testing REQUIRED) 22 | find_package(iceoryx_posh_testing REQUIRED) 23 | find_package(GTest CONFIG REQUIRED) 24 | 25 | set(PROJECT_PREFIX "dds_gateway") 26 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJECT_PREFIX}/test) 27 | 28 | set(MODULETESTS_SRC 29 | "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/main.cpp" 30 | "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/test_dds_to_iox.cpp" 31 | "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/test_iox_to_dds.cpp" 32 | ) 33 | 34 | if(${DDS_STACK} STREQUAL "CYCLONE_DDS") 35 | list(APPEND MODULETESTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/test_cyclone_data_reader.cpp") 36 | elseif(${DDS_STACK} STREQUAL "FAST_DDS") 37 | list(APPEND MODULETESTS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/moduletests/test_fast_data_reader.cpp") 38 | endif() 39 | 40 | set(TEST_LINK_LIBS 41 | ${CODE_COVERAGE_LIBS} 42 | GTest::gtest 43 | GTest::gmock 44 | iceoryx_hoofs::iceoryx_hoofs 45 | iceoryx_hoofs_testing::iceoryx_hoofs_testing 46 | iceoryx_posh::iceoryx_posh 47 | iceoryx_posh_testing::iceoryx_posh_testing 48 | iceoryx_dds::iceoryx_dds 49 | ) 50 | 51 | iox_add_executable( 52 | TARGET ${PROJECT_PREFIX}_moduletests 53 | INCLUDE_DIRECTORIES . 54 | FILES ${MODULETESTS_SRC} 55 | LIBS ${TEST_LINK_LIBS} 56 | LIBS_LINUX dl 57 | LIBS_APPLE dl 58 | ) 59 | -------------------------------------------------------------------------------- /test/helpers/fixture_dds_gateway.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef TEST_HELPERS_FIXTURE_DDS_GATEWAY_H 19 | #define TEST_HELPERS_FIXTURE_DDS_GATEWAY_H 20 | 21 | #include "iceoryx_posh/gateway/channel.hpp" 22 | #include "iox/std_string_support.hpp" 23 | 24 | #include "mocks/google_mocks.hpp" 25 | #include "test.hpp" 26 | 27 | template 28 | class DDSGatewayTestFixture : public Test 29 | { 30 | public: 31 | // Holds mocks created by tests to be used by the channel factory. 32 | std::vector> m_stagedMockIceoryxTerminal; 33 | std::vector> m_stagedMockDDSTerminal; 34 | 35 | // Marks where in the array to look for a valid mock. 36 | // Indexes lower than the marker are assumed to have been moved out and thus undefined. 37 | size_t m_mockIceoryxTerminalCursor = 0; 38 | size_t m_mockDDSTerminalMarker = 0; 39 | 40 | void TearDown() 41 | { 42 | m_stagedMockIceoryxTerminal.clear(); 43 | m_mockIceoryxTerminalCursor = 0; 44 | m_stagedMockDDSTerminal.clear(); 45 | m_mockDDSTerminalMarker = 0; 46 | }; 47 | 48 | // Create a new dds mock 49 | std::shared_ptr createMockDDSTerminal(const iox::capro::ServiceDescription& sd) 50 | { 51 | return std::shared_ptr(new DDSTerminal(sd)); 52 | } 53 | // Stage the given mock to be used in the channel factory 54 | void stageMockDDSTerminal(std::shared_ptr&& mock) 55 | { 56 | // Pass ownership - do not hold a reference here. 57 | m_stagedMockDDSTerminal.emplace_back(std::move(mock)); 58 | }; 59 | // Create a new iceoryx mock 60 | template 61 | std::shared_ptr createMockIceoryxTerminal(const iox::capro::ServiceDescription& sd, 62 | const IceoryxPubSubOptions& options) 63 | { 64 | return std::shared_ptr(new IceoryxTerminal(sd, options)); 65 | } 66 | // Stage the given mock to be used in the channel factory 67 | void stageMockIceoryxTerminal(std::shared_ptr&& mock) 68 | { 69 | m_stagedMockIceoryxTerminal.emplace_back(std::move(mock)); 70 | }; 71 | 72 | // Creates channels to be used in tests. 73 | // Channels will contain staged mocks, or empty mocks if none are staged. 74 | // The factory method can be passed to test gateways, allowing injection of mocks. 75 | template 76 | iox::expected, iox::gw::GatewayError> 77 | channelFactory(iox::capro::ServiceDescription sd, const IceoryxPubSubOptions& options) noexcept 78 | { 79 | // Get or create a mock iceoryx terminal 80 | std::shared_ptr mockIceoryxTerminal; 81 | if (m_mockIceoryxTerminalCursor < m_stagedMockIceoryxTerminal.size()) 82 | { 83 | // Important - must pass ownership to receiver so object is deleted when the receiver is done with it. 84 | mockIceoryxTerminal = std::move(m_stagedMockIceoryxTerminal.at(m_mockIceoryxTerminalCursor++)); 85 | } 86 | else 87 | { 88 | mockIceoryxTerminal = createMockIceoryxTerminal(sd, options); 89 | } 90 | 91 | // Get or create a mock dds terminal 92 | std::shared_ptr mockDataWriter; 93 | if (m_mockDDSTerminalMarker < m_stagedMockDDSTerminal.size()) 94 | { 95 | // Important - must pass ownership to receiver so object is deleted when the receiver is done with it. 96 | mockDataWriter = std::move(m_stagedMockDDSTerminal.at(m_mockDDSTerminalMarker++)); 97 | } 98 | else 99 | { 100 | mockDataWriter = createMockDDSTerminal(sd); 101 | } 102 | 103 | return iox::ok(iox::gw::Channel( 104 | sd, std::move(mockIceoryxTerminal), std::move(mockDataWriter))); 105 | } 106 | }; 107 | 108 | #endif // TEST_HELPERS_FIXTURE_DDS_GATEWAY_H 109 | -------------------------------------------------------------------------------- /test/mocks/google_mocks.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #ifndef IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP 19 | #define IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP 20 | 21 | #include "iceoryx_dds/dds/data_reader.hpp" 22 | #include "iceoryx_dds/dds/data_writer.hpp" 23 | #include "iceoryx_dds/dds/dds_types.hpp" 24 | #include "iceoryx_posh/gateway/channel.hpp" 25 | #include "iceoryx_posh/gateway/gateway_generic.hpp" 26 | #include "iceoryx_posh/iceoryx_posh_types.hpp" 27 | #include "iceoryx_posh/internal/popo/base_publisher.hpp" 28 | #include "iceoryx_posh/internal/popo/base_subscriber.hpp" 29 | #include "iceoryx_posh/popo/publisher_options.hpp" 30 | #include "iceoryx_posh/popo/subscriber_options.hpp" 31 | #include "iox/expected.hpp" 32 | #include "iox/function_ref.hpp" 33 | #include "iox/optional.hpp" 34 | #include "test.hpp" 35 | 36 | #include 37 | 38 | using namespace ::testing; 39 | using ::testing::_; 40 | 41 | class MockPublisher 42 | { 43 | public: 44 | MockPublisher(const iox::capro::ServiceDescription&, const iox::popo::PublisherOptions&) 45 | { 46 | } 47 | virtual ~MockPublisher() = default; 48 | MOCK_CONST_METHOD0(getUid, iox::popo::uid_t()); 49 | MOCK_METHOD0(offer, void(void)); 50 | MOCK_METHOD0(stopOffer, void(void)); 51 | MOCK_CONST_METHOD0(isOffered, bool(void)); 52 | MOCK_CONST_METHOD0(hasSubscribers, bool(void)); 53 | }; 54 | 55 | class MockSubscriber 56 | { 57 | public: 58 | MockSubscriber(const iox::capro::ServiceDescription&, const iox::popo::SubscriberOptions&) 59 | { 60 | } 61 | MOCK_CONST_METHOD0(getUid, iox::popo::uid_t()); 62 | MOCK_CONST_METHOD0(getServiceDescription, iox::capro::ServiceDescription()); 63 | MOCK_METHOD0(subscribe, void()); 64 | MOCK_CONST_METHOD0(getSubscriptionState, iox::SubscribeState()); 65 | MOCK_METHOD0(unsubscribe, void()); 66 | MOCK_CONST_METHOD0(hasData, bool()); 67 | MOCK_METHOD0(hasMissedData, bool()); 68 | MOCK_METHOD0(releaseQueuedData, void()); 69 | MOCK_METHOD1(setConditionVariable, bool(iox::popo::ConditionVariableData*)); 70 | MOCK_METHOD0(unsetConditionVariable, bool(void)); 71 | MOCK_METHOD0(hasTriggered, bool(void)); 72 | }; 73 | 74 | class MockDataReader 75 | { 76 | public: 77 | MockDataReader(const iox::capro::ServiceDescription&) 78 | { 79 | } 80 | MOCK_METHOD0(connect, void(void)); 81 | MOCK_METHOD0(peekNextIoxChunkDatagramHeader, iox::optional(void)); 82 | MOCK_METHOD3(takeNext, 83 | iox::expected(const iox::dds::IoxChunkDatagramHeader, 84 | uint8_t* const, 85 | uint8_t* const)); 86 | MOCK_CONST_METHOD0(getServiceId, std::string(void)); 87 | MOCK_CONST_METHOD0(getInstanceId, std::string(void)); 88 | MOCK_CONST_METHOD0(getEventId, std::string(void)); 89 | }; 90 | 91 | class MockDataWriter 92 | { 93 | public: 94 | MockDataWriter(const iox::capro::ServiceDescription&) 95 | { 96 | } 97 | MOCK_METHOD0(connect, void(void)); 98 | MOCK_METHOD3(write, bool(iox::dds::IoxChunkDatagramHeader, const uint8_t* const, const uint8_t* const)); 99 | MOCK_CONST_METHOD0(getServiceId, std::string(void)); 100 | MOCK_CONST_METHOD0(getInstanceId, std::string(void)); 101 | MOCK_CONST_METHOD0(getEventId, std::string(void)); 102 | }; 103 | 104 | template 105 | class MockGenericGateway 106 | { 107 | public: 108 | MockGenericGateway() = default; 109 | MockGenericGateway(const iox::capro::Interfaces, iox::units::Duration, iox::units::Duration) 110 | { 111 | } 112 | MOCK_METHOD2_T(addChannel, 113 | iox::expected(const iox::capro::ServiceDescription&, 114 | const IceoryxPubSubOptions&)); 115 | MOCK_METHOD1(discardChannel, iox::expected(const iox::capro::ServiceDescription&)); 116 | MOCK_CONST_METHOD1_T(findChannel, iox::optional(const iox::capro::ServiceDescription&)); 117 | }; 118 | 119 | 120 | // NOTE: For some reasons, with the update to gTest 1.14, the streaming operators are required to make the mocks work 121 | template 122 | std::ostream& operator<<(std::ostream& stream, const iox::optional& channel) 123 | { 124 | if (channel.has_value()) 125 | { 126 | stream << "iox::optional has value"; 127 | } 128 | else 129 | { 130 | stream << "iox::optional has no value"; 131 | } 132 | return stream; 133 | } 134 | 135 | template 136 | std::ostream& operator<<(std::ostream& stream, const iox::expected& channel) 137 | { 138 | if (channel.has_value()) 139 | { 140 | stream << "iox::expected has value"; 141 | } 142 | else 143 | { 144 | stream << "iox::expected has error"; 145 | } 146 | return stream; 147 | } 148 | 149 | #endif // IOX_DDS_GATEWAY_TEST_GOOGLE_MOCKS_HPP 150 | -------------------------------------------------------------------------------- /test/moduletests/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "test.hpp" 19 | 20 | using namespace ::testing; 21 | using ::testing::_; 22 | 23 | int main(int argc, char* argv[]) 24 | { 25 | ::testing::InitGoogleTest(&argc, argv); 26 | return RUN_ALL_TESTS(); 27 | } 28 | -------------------------------------------------------------------------------- /test/moduletests/test_cyclone_data_reader.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "Mempool.hpp" 19 | #include "iceoryx_dds/dds/cyclone_data_reader.hpp" 20 | #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" 21 | #include "test.hpp" 22 | 23 | #include 24 | 25 | namespace 26 | { 27 | using namespace ::testing; 28 | using ::testing::_; 29 | using namespace iox::dds; 30 | 31 | // ======================================== Helpers ======================================== // 32 | using TestDataReader = CycloneDataReader; 33 | 34 | struct DummyPayload 35 | { 36 | uint64_t a; 37 | uint64_t b; 38 | uint64_t c; 39 | }; 40 | struct DummyUserHeader 41 | { 42 | uint64_t a; 43 | }; 44 | 45 | // ======================================== Fixture ======================================== // 46 | class CycloneDataReaderTest : public Test 47 | { 48 | public: 49 | void SetUp(){}; 50 | void TearDown(){}; 51 | }; 52 | 53 | // ======================================== Tests ======================================== // 54 | TEST_F(CycloneDataReaderTest, DoesNotAttemptToReadWhenDisconnected) 55 | { 56 | ::testing::Test::RecordProperty("TEST_ID", "46fc99d7-9f7b-4b77-94c7-06778e3461f7"); 57 | // ===== Setup 58 | ChunkMock chunkMock; 59 | iox::dds::IoxChunkDatagramHeader datagramHeader; 60 | datagramHeader.endianness = getEndianess(); 61 | datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize(); 62 | datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment(); 63 | 64 | // ===== Test 65 | TestDataReader reader{"", "", ""}; 66 | 67 | auto takeNextResult = reader.takeNext(datagramHeader, 68 | static_cast(chunkMock.chunkHeader()->userHeader()), 69 | static_cast(chunkMock.chunkHeader()->userPayload())); 70 | ASSERT_EQ(true, takeNextResult.has_error()); 71 | EXPECT_EQ(iox::dds::DataReaderError::NOT_CONNECTED, takeNextResult.get_error()); 72 | } 73 | 74 | TEST_F(CycloneDataReaderTest, ReturnsErrorWhenAttemptingToReadIntoANullBuffer) 75 | { 76 | ::testing::Test::RecordProperty("TEST_ID", "ddd6e55a-b4ca-4e10-838e-5a532ccadb50"); 77 | // ===== Setup 78 | ChunkMock chunkMock; 79 | iox::dds::IoxChunkDatagramHeader datagramHeader; 80 | datagramHeader.endianness = getEndianess(); 81 | datagramHeader.userHeaderId = iox::mepoo::ChunkHeader::UNKNOWN_USER_HEADER; 82 | datagramHeader.userHeaderSize = chunkMock.chunkHeader()->userHeaderSize(); 83 | datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize(); 84 | datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment(); 85 | 86 | // ===== Test 87 | TestDataReader reader{"", "", ""}; 88 | reader.connect(); 89 | 90 | auto takeNextResult1 = 91 | reader.takeNext(datagramHeader, nullptr, static_cast(chunkMock.chunkHeader()->userPayload())); 92 | ASSERT_EQ(true, takeNextResult1.has_error()); 93 | EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_HEADER, takeNextResult1.get_error()); 94 | 95 | auto takeNextResult2 = 96 | reader.takeNext(datagramHeader, static_cast(chunkMock.chunkHeader()->userHeader()), nullptr); 97 | ASSERT_EQ(true, takeNextResult2.has_error()); 98 | EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD, takeNextResult2.get_error()); 99 | } 100 | 101 | } // namespace 102 | -------------------------------------------------------------------------------- /test/moduletests/test_dds_to_iox.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "helpers/fixture_dds_gateway.hpp" 19 | 20 | #include "iceoryx_dds/gateway/dds_to_iox.hpp" 21 | #include "iceoryx_posh/gateway/channel.hpp" 22 | 23 | #include "mocks/google_mocks.hpp" 24 | #include "test.hpp" 25 | 26 | namespace 27 | { 28 | using namespace ::testing; 29 | using ::testing::_; 30 | 31 | // ======================================== Helpers ======================================== // 32 | using TestChannel = iox::gw::Channel; 33 | using TestGateway = 34 | iox::dds::DDS2IceoryxGateway>; 35 | 36 | // ======================================== Fixture ======================================== // 37 | class DDS2IceoryxGatewayTest : public DDSGatewayTestFixture 38 | { 39 | }; 40 | 41 | // ======================================== Tests ======================================== // 42 | TEST_F(DDS2IceoryxGatewayTest, ChannelsAreCreatedForConfiguredServices) 43 | { 44 | ::testing::Test::RecordProperty("TEST_ID", "8c439c96-4777-47a2-aebf-a01898b39c1d"); 45 | // === Setup 46 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 47 | iox::config::GatewayConfig config{}; 48 | config.m_configuredServices.push_back(iox::config::GatewayConfig::ServiceEntry{testService}); 49 | 50 | auto mockPublisher = createMockIceoryxTerminal(testService, iox::popo::PublisherOptions()); 51 | EXPECT_CALL(*mockPublisher, offer).Times(1); 52 | stageMockIceoryxTerminal(std::move(mockPublisher)); 53 | 54 | auto mockDataReader = createMockDDSTerminal(testService); 55 | EXPECT_CALL(*mockDataReader, connect).Times(1); 56 | stageMockDDSTerminal(std::move(mockDataReader)); 57 | 58 | TestGateway gw{}; 59 | EXPECT_CALL(gw, findChannel).WillOnce(Return(iox::nullopt)); 60 | EXPECT_CALL(gw, addChannel(testService, _)) 61 | .WillOnce(Return(channelFactory(testService, iox::popo::PublisherOptions()))); 62 | 63 | // === Test 64 | gw.loadConfiguration(config); 65 | } 66 | 67 | /// @ todo #376 68 | #if 0 69 | TEST_F(DDS2IceoryxGatewayTest, PublishesMemoryChunksContainingSamplesToNetwork) 70 | { 71 | ::testing::Test::RecordProperty("TEST_ID", "1024b7c2-c2ed-4371-a1df-5990dc913a97"); 72 | // === Setup 73 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 74 | 75 | // Setup data reader to provide a sample 76 | auto mockDataReader = createMockDDSTerminal(testService); 77 | auto mockPublisher = createMockIceoryxTerminal(testService); 78 | 79 | ON_CALL(*mockDataReader, peekNextSize) 80 | .WillByDefault(Return(ByMove(iox::make_optional(static_cast(8u))))); 81 | ON_CALL(*mockDataReader, takeNext).WillByDefault(Return(ByMove(iox::ok()))); 82 | EXPECT_CALL(*mockPublisher, sendChunk).Times(1); 83 | 84 | stageMockDDSTerminal(std::move(mockDataReader)); 85 | stageMockIceoryxTerminal(std::move(mockPublisher)); 86 | 87 | TestGateway gw{}; 88 | 89 | // === Test 90 | auto testChannel = channelFactory(testService, iox::popo::PublisherOptions()).value(); 91 | gw.forward(testChannel); 92 | } 93 | #endif 94 | 95 | } // namespace 96 | -------------------------------------------------------------------------------- /test/moduletests/test_fast_data_reader.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2021 by Apex.AI Inc. All rights reserved. 3 | // Copyright (c) 2024 by Wei Long Meng. All rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | // SPDX-License-Identifier: Apache-2.0 18 | 19 | #include "iceoryx_dds/dds/fast_data_reader.hpp" 20 | #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" 21 | #include "test.hpp" 22 | 23 | namespace 24 | { 25 | using namespace ::testing; 26 | using ::testing::_; 27 | using namespace iox::dds; 28 | 29 | // ======================================== Helpers ======================================== // 30 | using TestDataReader = FastDataReader; 31 | 32 | struct DummyPayload 33 | { 34 | uint64_t a; 35 | uint64_t b; 36 | uint64_t c; 37 | }; 38 | struct DummyUserHeader 39 | { 40 | uint64_t a; 41 | }; 42 | 43 | // ======================================== Fixture ======================================== // 44 | class FastDataReaderTest : public Test 45 | { 46 | public: 47 | void SetUp() {}; 48 | void TearDown() {}; 49 | }; 50 | 51 | // ======================================== Tests ======================================== // 52 | TEST_F(FastDataReaderTest, DoesNotAttemptToReadWhenDisconnected) 53 | { 54 | ::testing::Test::RecordProperty("TEST_ID", "46fc99d7-9f7b-4b77-94c7-06778e3461f7"); 55 | // ===== Setup 56 | ChunkMock chunkMock; 57 | iox::dds::IoxChunkDatagramHeader datagramHeader; 58 | datagramHeader.endianness = getEndianess(); 59 | datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize(); 60 | datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment(); 61 | 62 | // ===== Test 63 | TestDataReader reader{"", "", ""}; 64 | 65 | auto takeNextResult = reader.takeNext(datagramHeader, 66 | static_cast(chunkMock.chunkHeader()->userHeader()), 67 | static_cast(chunkMock.chunkHeader()->userPayload())); 68 | ASSERT_EQ(true, takeNextResult.has_error()); 69 | EXPECT_EQ(iox::dds::DataReaderError::NOT_CONNECTED, takeNextResult.get_error()); 70 | } 71 | 72 | TEST_F(FastDataReaderTest, ReturnsErrorWhenAttemptingToReadIntoANullBuffer) 73 | { 74 | ::testing::Test::RecordProperty("TEST_ID", "ddd6e55a-b4ca-4e10-838e-5a532ccadb50"); 75 | // ===== Setup 76 | ChunkMock chunkMock; 77 | iox::dds::IoxChunkDatagramHeader datagramHeader; 78 | datagramHeader.endianness = getEndianess(); 79 | datagramHeader.userHeaderId = iox::mepoo::ChunkHeader::UNKNOWN_USER_HEADER; 80 | datagramHeader.userHeaderSize = chunkMock.chunkHeader()->userHeaderSize(); 81 | datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize(); 82 | datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment(); 83 | 84 | // ===== Test 85 | TestDataReader reader{"", "", ""}; 86 | reader.connect(); 87 | 88 | auto takeNextResult1 = 89 | reader.takeNext(datagramHeader, nullptr, static_cast(chunkMock.chunkHeader()->userPayload())); 90 | ASSERT_EQ(true, takeNextResult1.has_error()); 91 | EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_HEADER, takeNextResult1.get_error()); 92 | 93 | auto takeNextResult2 = 94 | reader.takeNext(datagramHeader, static_cast(chunkMock.chunkHeader()->userHeader()), nullptr); 95 | ASSERT_EQ(true, takeNextResult2.has_error()); 96 | EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD, takeNextResult2.get_error()); 97 | } 98 | 99 | } // namespace 100 | -------------------------------------------------------------------------------- /test/moduletests/test_iox_to_dds.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | // SPDX-License-Identifier: Apache-2.0 17 | 18 | #include "helpers/fixture_dds_gateway.hpp" 19 | 20 | #include "iceoryx_dds/dds/data_writer.hpp" 21 | #include "iceoryx_dds/gateway/iox_to_dds.hpp" 22 | #include "iceoryx_posh/gateway/channel.hpp" 23 | #include "iceoryx_posh/gateway/gateway_config.hpp" 24 | #include "iceoryx_posh/internal/capro/capro_message.hpp" 25 | #include "iceoryx_posh/mepoo/chunk_header.hpp" 26 | #include "iox/expected.hpp" 27 | #include "iox/optional.hpp" 28 | 29 | #include "iceoryx_posh/testing/mocks/chunk_mock.hpp" 30 | #include "mocks/google_mocks.hpp" 31 | #include "test.hpp" 32 | 33 | #include 34 | 35 | namespace 36 | { 37 | using namespace ::testing; 38 | using ::testing::_; 39 | using ::testing::InSequence; 40 | using ::testing::SetArgPointee; 41 | 42 | // ======================================== Helpers ======================================== // 43 | using TestChannel = iox::gw::Channel; 44 | using TestGateway = 45 | iox::dds::Iceoryx2DDSGateway>; 46 | 47 | // ======================================== Fixture ======================================== // 48 | class Iceoryx2DDSGatewayTest : public DDSGatewayTestFixture 49 | { 50 | }; 51 | 52 | // ======================================== Tests ======================================== // 53 | TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForConfiguredServices) 54 | { 55 | ::testing::Test::RecordProperty("TEST_ID", "9e5b3965-2d27-4ec9-a708-5a0c17b47040"); 56 | // === Setup 57 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 58 | iox::config::GatewayConfig config{}; 59 | config.m_configuredServices.push_back(iox::config::GatewayConfig::ServiceEntry{testService}); 60 | 61 | auto mockSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 62 | EXPECT_CALL(*mockSubscriber, subscribe()).Times(1); 63 | stageMockIceoryxTerminal(std::move(mockSubscriber)); 64 | 65 | auto mockWriter = createMockDDSTerminal(testService); 66 | EXPECT_CALL(*mockWriter, connect()).Times(1); 67 | stageMockDDSTerminal(std::move(mockWriter)); 68 | 69 | TestGateway gw{}; 70 | EXPECT_CALL(gw, findChannel(_)).WillOnce(Return(iox::nullopt)); 71 | EXPECT_CALL(gw, addChannel(_, _)).WillOnce(Return(channelFactory(testService, iox::popo::SubscriberOptions()))); 72 | 73 | // === Test 74 | gw.loadConfiguration(config); 75 | } 76 | 77 | TEST_F(Iceoryx2DDSGatewayTest, IgnoresIntrospectionPorts) 78 | { 79 | ::testing::Test::RecordProperty("TEST_ID", "46a4fd43-721c-4c69-a2e2-014ad794cc78"); 80 | // === Setup 81 | TestGateway gw{}; 82 | auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Introspection", "Foo", "Bar"}); 83 | msg.m_serviceType = iox::capro::CaproServiceType::PUBLISHER; 84 | 85 | EXPECT_CALL(gw, addChannel(_, _)).Times(0); 86 | 87 | // === Test 88 | gw.discover(msg); 89 | } 90 | 91 | TEST_F(Iceoryx2DDSGatewayTest, IgnoresServerMessages) 92 | { 93 | ::testing::Test::RecordProperty("TEST_ID", "6894e3f2-6f41-4b8e-95e0-e375ab294d19"); 94 | // === Setup 95 | TestGateway gw{}; 96 | auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, {"Foo", "Bar", "Baz"}); 97 | msg.m_serviceType = iox::capro::CaproServiceType::SERVER; 98 | 99 | EXPECT_CALL(gw, addChannel(_, _)).Times(0); 100 | 101 | // === Test 102 | gw.discover(msg); 103 | } 104 | 105 | TEST_F(Iceoryx2DDSGatewayTest, ChannelsAreCreatedForDiscoveredServices) 106 | { 107 | ::testing::Test::RecordProperty("TEST_ID", "0f356ca7-8f0f-442e-8888-592578145e59"); 108 | // === Setup 109 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 110 | 111 | auto mockSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 112 | EXPECT_CALL(*mockSubscriber, subscribe()).Times(1); 113 | stageMockIceoryxTerminal(std::move(mockSubscriber)); 114 | 115 | auto mockWriter = createMockDDSTerminal(testService); 116 | EXPECT_CALL(*mockWriter, connect()).Times(1); 117 | stageMockDDSTerminal(std::move(mockWriter)); 118 | 119 | TestGateway gw{}; 120 | auto msg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); 121 | msg.m_serviceType = iox::capro::CaproServiceType::PUBLISHER; 122 | 123 | EXPECT_CALL(gw, findChannel(_)).WillOnce(Return(iox::nullopt)); 124 | EXPECT_CALL(gw, addChannel(_, _)).WillOnce(Return(channelFactory(testService, iox::popo::SubscriberOptions()))); 125 | 126 | // === Test 127 | gw.discover(msg); 128 | } 129 | 130 | /// @ todo #376 131 | #if 0 132 | TEST_F(Iceoryx2DDSGatewayTest, ForwardsChunkFromSubscriberToDataWriter) 133 | { 134 | ::testing::Test::RecordProperty("TEST_ID", "51527674-ccc7-4817-bae9-64eebe766fff"); 135 | // === Setup 136 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 137 | 138 | // Prepare a mock mempool chunk 139 | ChunkMock mockChunk{42}; 140 | 141 | // Set up subscriber to provide the chunk 142 | auto mockSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 143 | EXPECT_CALL(*mockSubscriber, hasNewChunks()).WillOnce(Return(true)).WillRepeatedly(Return(false)); 144 | EXPECT_CALL(*mockSubscriber, getChunk(_)).WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), 145 | Return(true))); stageMockIceoryxTerminal(std::move(mockSubscriber)); 146 | 147 | // Verify expected write to the data writer 148 | auto mockWriter = createMockDDSTerminal(testService); 149 | EXPECT_CALL(*mockWriter, 150 | write(SafeMatcherCast(Pointee(Eq(42))), mockChunk.chunkHeader()->m_payloadSize)) 151 | .Times(1); 152 | stageMockDDSTerminal(std::move(mockWriter)); 153 | 154 | auto testChannel = channelFactory(testService, iox::popo::SubscriberOptions()); 155 | TestGateway gw{}; 156 | 157 | // === Test 158 | gw.forward(testChannel.value()); 159 | } 160 | 161 | TEST_F(Iceoryx2DDSGatewayTest, IgnoresMemoryChunksWithNoPayload) 162 | { 163 | ::testing::Test::RecordProperty("TEST_ID", "e73d405e-a8a5-43d7-bc5e-6130b1fa2747"); 164 | // === Setup 165 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 166 | 167 | // Prepare a mock mempool chunk 168 | ChunkMock mockChunk{0}; 169 | mockChunk.chunkHeader()->m_info.m_payloadSize = 0; 170 | 171 | // Set up subscriber to provide the chunk 172 | auto mockSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 173 | EXPECT_CALL(*mockSubscriber, hasNewChunks()).WillOnce(Return(true)).WillRepeatedly(Return(false)); 174 | EXPECT_CALL(*mockSubscriber, getChunk(_)).WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), 175 | Return(true))); stageMockIceoryxTerminal(std::move(mockSubscriber)); 176 | 177 | // Verify expected write to the data writer 178 | auto mockWriter = createMockDDSTerminal(testService); 179 | EXPECT_CALL(*mockWriter, write(_, _)).Times(Exactly(0)); 180 | stageMockDDSTerminal(std::move(mockWriter)); 181 | 182 | auto testChannel = channelFactory(testService, iox::popo::SubscriberOptions()); 183 | TestGateway gw{}; 184 | 185 | // === Test 186 | gw.forward(testChannel.value()); 187 | } 188 | 189 | TEST_F(Iceoryx2DDSGatewayTest, ReleasesReferenceToMemoryChunkAfterSend) 190 | { 191 | ::testing::Test::RecordProperty("TEST_ID", "39f081c9-2ce7-4e00-b6c4-5cc1596fa699"); 192 | // === Setup 193 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 194 | 195 | // Prepare a mock mempool chunk 196 | ChunkMock mockChunk{42}; 197 | 198 | // Set up expect sequence of interactions with subscriber and data writer 199 | auto mockSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 200 | auto mockWriter = createMockDDSTerminal(testService); 201 | { 202 | InSequence seq; 203 | EXPECT_CALL(*mockSubscriber, hasNewChunks()).WillOnce(Return(true)); 204 | EXPECT_CALL(*mockSubscriber, getChunk(_)) 205 | .WillOnce(DoAll(SetArgPointee<0>(mockChunk.chunkHeader()), Return(true))); 206 | EXPECT_CALL(*mockWriter, write(_, _)).Times(1); 207 | EXPECT_CALL(*mockSubscriber, releaseChunk(_)).Times(1); 208 | EXPECT_CALL(*mockSubscriber, hasNewChunks()) 209 | .WillRepeatedly(Return(false)); // No more chunks after the first one 210 | } 211 | 212 | stageMockIceoryxTerminal(std::move(mockSubscriber)); 213 | stageMockDDSTerminal(std::move(mockWriter)); 214 | 215 | auto testChannel = channelFactory(testService, iox::popo::SubscriberOptions()); 216 | TestGateway gw{}; 217 | 218 | // === Test 219 | gw.forward(testChannel.value()); 220 | } 221 | 222 | TEST_F(Iceoryx2DDSGatewayTest, DestroysCorrespondingSubscriberWhenAPublisherStopsOffering) 223 | { 224 | ::testing::Test::RecordProperty("TEST_ID", "a0150430-c947-4735-8474-aea14d2cadbd"); 225 | // === Setup 226 | auto testService = iox::capro::ServiceDescription({"Radar", "Front-Right", "Reflections"}); 227 | 228 | // Subscribers 229 | auto firstCreatedSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 230 | auto secondCreatedSubscriber = createMockIceoryxTerminal(testService, iox::popo::SubscriberOptions()); 231 | { 232 | InSequence seq; 233 | EXPECT_CALL(*firstCreatedSubscriber, subscribe()).Times(1); 234 | EXPECT_CALL(*secondCreatedSubscriber, subscribe()).Times(1); 235 | } 236 | 237 | stageMockIceoryxTerminal(std::move(firstCreatedSubscriber)); 238 | stageMockIceoryxTerminal(std::move(secondCreatedSubscriber)); 239 | 240 | // Messages 241 | auto offerMsg = iox::capro::CaproMessage(iox::capro::CaproMessageType::OFFER, testService); 242 | offerMsg.m_serviceType = iox::capro::CaproServiceType::PUBLISHER; 243 | auto stopOfferMsg = iox::capro::CaproMessage(iox::capro::CaproMessageType::STOP_OFFER, testService); 244 | stopOfferMsg.m_serviceType = iox::capro::CaproServiceType::PUBLISHER; 245 | 246 | // Get the test channels here as we need to use them in expectations 247 | auto testChannelOne = channelFactory(testService, iox::popo::SubscriberOptions()); 248 | auto testChannelTwo = channelFactory(testService, iox::popo::SubscriberOptions()); 249 | 250 | TestGateway gw{}; 251 | EXPECT_CALL(gw, findChannel(_)) 252 | .WillOnce(Return(iox::nullopt)) 253 | .WillOnce( 254 | Return(iox::make_optional>(testChannelOne.value()))) 256 | .WillOnce(Return(iox::nullopt)); 257 | EXPECT_CALL(gw, addChannel(_, _)).WillOnce(Return(testChannelOne)).WillOnce(Return(testChannelTwo)); 258 | EXPECT_CALL(gw, discardChannel(_)).WillOnce(Return(iox::ok())); 259 | 260 | // === Test 261 | gw.discover(offerMsg); 262 | gw.discover(stopOfferMsg); // first subscriber must be deleted here 263 | gw.discover(offerMsg); 264 | } 265 | #endif 266 | 267 | } // namespace 268 | -------------------------------------------------------------------------------- /test/test.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef IOX_DDS_GATEWAY_TEST_TEST_HPP 18 | #define IOX_DDS_GATEWAY_TEST_TEST_HPP 19 | 20 | #include 21 | #include 22 | 23 | #endif // IOX_DDS_GATEWAY_TEST_TEST_HPP 24 | --------------------------------------------------------------------------------