diff --git a/.github/dco.yml b/.github/dco.yml new file mode 100644 index 000000000..37e411e1b --- /dev/null +++ b/.github/dco.yml @@ -0,0 +1,2 @@ +require: + members: false \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 000000000..098ed6e75 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master, develop ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '24 2 * * *' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + #strategy: + #fail-fast: false + #matrix: + # language: [ 'c' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + # with: + # languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/CMakeLists.txt b/CMakeLists.txt index d7f22c5a7..622ebec10 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,14 +42,30 @@ if((CMAKE_SYSTEM_NAME STREQUAL "") AND (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") endif() option(UCLIENT_BIG_ENDIANNESS "Set the machine endianness to big endianness (by default is little endianness)." OFF) - -set(UCLIENT_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/client.config" CACHE PATH "Configuration client file.") +option(UCLIENT_PROFILE_DISCOVERY "Enable discovery profile." ON) +option(UCLIENT_PROFILE_UDP "Enable UDP transport." ON) +option(UCLIENT_PROFILE_TCP "Enable TCP transport." ON) +option(UCLIENT_PROFILE_SERIAL "Enable Serial transport." ON) +option(UCLIENT_PROFILE_STREAM_FRAMING "Enable stream framing protocol." ON) +set(UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS 1 CACHE STRING "Set the maximum number of output best-effort streams for session.") +set(UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS 1 CACHE STRING "Set the maximum number of output reliable streams for session.") +set(UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS 1 CACHE STRING "Set the maximum number of input best-effort streams for session.") +set(UCLIENT_MAX_INPUT_RELIABLE_STREAMS 1 CACHE STRING "Set the maximum number of input reliable streams for session.") +set(UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS 10 CACHE STRING "Set the number of connection attemps.") +set(UCLIENT_MIN_SESSION_CONNECTION_INTERVAL 1000 CACHE STRING "Set the connection interval in milliseconds.") +set(UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL 1 CACHE STRING "Set the time interval between heartbeats in milliseconds.") +set(UCLIENT_UDP_TRANSPORT_MTU 512 CACHE STRING "Set the UDP transport MTU.") +set(UCLIENT_TCP_TRANSPORT_MTU 512 CACHE STRING "Set the TCP transport MTU.") +set(UCLIENT_SERIAL_TRANSPORT_MTU 512 CACHE STRING "Set the Serial transport MTU.") + +option(UCLIENT_PROFILE_CUSTOM_TRANSPORT "Enable Custom transport." ON) +set(UCLIENT_CUSTOM_TRANSPORT_MTU 512 CACHE STRING "Set the Custom transport MTU.") ############################################################################### # Dependencies ############################################################################### -set(_microcdr_version 1.2.0) -set(_microcdr_tag v1.2.0) +set(_microcdr_version 1.2.1) +set(_microcdr_tag v1.2.1) set(_deps "") list(APPEND _deps "microcdr\;${_microcdr_version}") @@ -59,7 +75,7 @@ list(APPEND _deps "microcdr\;${_microcdr_version}") ############################################################################### set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) if(NOT UCLIENT_SUPERBUILD) - project(microxrcedds_client VERSION "1.2.5" LANGUAGES C) + project(microxrcedds_client VERSION "2.0.0" LANGUAGES C) else() project(uclient_superbuild NONE) include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake) @@ -78,13 +94,12 @@ endif() ############################################################################### # Client configuration options ############################################################################### +set(UCLIENT_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/client.config" CACHE PATH "Optional configuration client file.") # Load configuration file. if(EXISTS ${UCLIENT_CONFIG}) configure_file(${UCLIENT_CONFIG} ${PROJECT_SOURCE_DIR}/CMakeCache.txt COPYONLY) load_cache(${PROJECT_SOURCE_DIR}) file(REMOVE ${PROJECT_SOURCE_DIR}/CMakeCache.txt) -else() - message(FATAL_ERROR "No client.config found.") endif() ############################################################################### @@ -117,19 +132,87 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") elseif(CMAKE_SYSTEM_NAME STREQUAL "Generic") if(PLATFORM_NAME STREQUAL "nuttx") set(UCLIENT_PLATFORM_NUTTX ON) + elseif(PLATFORM_NAME STREQUAL "zephyr") + set(UCLIENT_PLATFORM_ZEPHYR ON) elseif(PLATFORM_NAME STREQUAL "LwIP") set(UCLIENT_PLATFORM_POSIX_NOPOLL ON) + elseif(PLATFORM_NAME STREQUAL "FreeRTOS_Plus_TCP") + set(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP ON) endif() endif() -if(UCLIENT_PLATFORM_LINUX OR UCLIENT_PLATFORM_NUTTX) +if(UCLIENT_PLATFORM_LINUX OR UCLIENT_PLATFORM_NUTTX OR UCLIENT_PLATFORM_ZEPHYR) set(UCLIENT_PLATFORM_POSIX ON) endif() -# Check external transport. -option(UCLIENT_EXTERNAL_TCP "Enable external TCP transport." OFF) -option(UCLIENT_EXTERNAL_UDP "Enable external UDP transport." OFF) -option(UCLIENT_EXTERNAL_SERIAL "Enable external serial transport." OFF) +# Transport sources. +set(_transport_src) + +if(UCLIENT_PROFILE_UDP) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport.c) + if(UCLIENT_PLATFORM_POSIX) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport_posix.c) + elseif(UCLIENT_PLATFORM_POSIX_NOPOLL) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c) + elseif(UCLIENT_PLATFORM_WINDOWS) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport_windows.c) + elseif(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.c) + endif() +endif() + +if(UCLIENT_PROFILE_TCP) + list(APPEND _transport_src src/c/profile/transport/ip/tcp/tcp_transport.c) + if(UCLIENT_PLATFORM_POSIX) + list(APPEND _transport_src src/c/profile/transport/ip/tcp/tcp_transport_posix.c) + elseif(UCLIENT_PLATFORM_WINDOWS) + list(APPEND _transport_src src/c/profile/transport/ip/tcp/tcp_transport_windows.c) + elseif(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) + list(APPEND _transport_src src/c/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.c) + endif() +endif() + +if(UCLIENT_PLATFORM_WINDOWS) +set(UCLIENT_PROFILE_SERIAL OFF) +endif() + +if(UCLIENT_PROFILE_SERIAL) + set(UCLIENT_PROFILE_STREAM_FRAMING ON) + list(APPEND _transport_src src/c/profile/transport/serial/serial_transport.c) + if(UCLIENT_PLATFORM_POSIX) + list(APPEND _transport_src src/c/profile/transport/serial/serial_transport_posix.c) + endif() +endif() + +if(UCLIENT_PROFILE_DISCOVERY OR UCLIENT_PROFILE_UDP OR UCLIENT_PROFILE_TCP) + if(UCLIENT_PLATFORM_POSIX) + list(APPEND _transport_src src/c/profile/transport/ip/ip_posix.c) + elseif(UCLIENT_PLATFORM_POSIX_NOPOLL) + list(APPEND _transport_src src/c/profile/transport/ip/ip_posix.c) + elseif(UCLIENT_PLATFORM_WINDOWS) + list(APPEND _transport_src src/c/profile/transport/ip/ip_windows.c) + elseif(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) + list(APPEND _transport_src src/c/profile/transport/ip/ip_freertos_plus_tcp.c) + endif() +endif() + +if(UCLIENT_PROFILE_DISCOVERY) + list(APPEND _transport_src src/c/profile/discovery/discovery.c) + list(APPEND _transport_src src/c/profile/transport/ip/udp/udp_transport.c) + if(UCLIENT_PLATFORM_POSIX) + list(APPEND _transport_src src/c/profile/discovery/transport/udp_transport_datagram_posix.c) + elseif(UCLIENT_PLATFORM_POSIX_NOPOLL) + list(APPEND _transport_src src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c) + elseif(UCLIENT_PLATFORM_WINDOWS) + list(APPEND _transport_src src/c/profile/discovery/transport/udp_transport_datagram_windows.c) + elseif(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) + list(APPEND _transport_src src/c/profile/discovery/transport/udp_transport_datagram_freertos_plus_tcp.c) + endif() +endif() + +if(UCLIENT_PROFILE_CUSTOM_TRANSPORT) + list(APPEND _transport_src src/c/profile/transport/custom/custom_transport.c) +endif() # Other sources set(SRCS @@ -148,31 +231,15 @@ set(SRCS src/c/core/serialization/xrce_header.c src/c/core/serialization/xrce_subheader.c src/c/util/time.c + src/c/util/ping.c src/c/core/session/common_create_entities.c src/c/core/session/create_entities_ref.c src/c/core/session/create_entities_xml.c src/c/core/session/read_access.c src/c/core/session/write_access.c + $<$:src/c/profile/transport/stream_framing/stream_framing_protocol.c> $<$,$>:src/c/core/log/log.c> - $<$:src/c/profile/discovery/discovery.c> - $<$:src/c/profile/transport/ip/udp/udp_transport.c> - $<$,$>:src/c/profile/discovery/transport/udp_transport_datagram_posix.c> - $<$,$>:src/c/profile/discovery/transport/udp_transport_datagram_windows.c> - $<$:src/c/profile/transport/ip/udp/udp_transport.c> - $<$,$>:src/c/profile/transport/ip/udp/udp_transport_posix.c> - $<$,$>:src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c> - $<$,$>:src/c/profile/transport/ip/udp/udp_transport_windows.c> - $<$:src/c/profile/transport/ip/tcp/tcp_transport.c> - $<$,$>:src/c/profile/transport/ip/tcp/tcp_transport_posix.c> - $<$,$>:src/c/profile/transport/ip/tcp/tcp_transport_windows.c> - $<$,$,$>>:src/c/profile/transport/serial/serial_transport.c> - $<$,$,$>>:src/c/profile/transport/serial/serial_protocol.c> - $<$,$>:src/c/profile/transport/serial/serial_transport_posix.c> - $<$:src/c/profile/transport/ip/tcp/tcp_transport_external.c> - $<$:src/c/profile/transport/ip/udp/udp_transport_external.c> - $<$:src/c/profile/transport/serial/serial_transport_external.c> - $<$,$>:src/c/profile/transport/ip/ip_posix.c> - $<$>:src/c/profile/transport/ip/ip_windows.c> + ${_transport_src} ) ############################################################################### @@ -289,6 +356,15 @@ if(UCLIENT_BUILD_EXAMPLES) add_subdirectory(examples/ShapesDemo) add_subdirectory(examples/SubscribeHelloWorld) add_subdirectory(examples/SubscribeHelloWorldP2P) + add_subdirectory(examples/TimeSync) + add_subdirectory(examples/TimeSyncWithCb) + add_subdirectory(examples/PingAgent) + add_subdirectory(examples/ContinuousFragment) + add_subdirectory(examples/PublishHelloWorldBestEffort) + add_subdirectory(examples/SubscribeHelloWorldBestEffort) + if(UCLIENT_PLATFORM_LINUX) + add_subdirectory(examples/CustomTransports) + endif() endif() ############################################################################### @@ -309,6 +385,7 @@ if(UCLIENT_BUILD_TESTS) add_subdirectory(test/unitary) if(UCLIENT_PLATFORM_LINUX) + add_subdirectory(test/transport/custom_comm) add_subdirectory(test/transport/serial_comm) endif() endif() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..0312453af --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contribution Guidelines + +The present document provides a set of guidelines to which contributors must adhere. + + +- [Contribution Guidelines](#contribution-guidelines) + - [Contributions Licensing](#contributions-licensing) + - [Developer Certificate of Origin](#developer-certificate-of-origin) + - [Code Coverage](#code-coverage) + - [General considerations](#general-considerations) + +## Contributions Licensing + +Any contribution that you make to this repository will be under the Apache 2 License, as dictated by that [license](http://www.apache.org/licenses/LICENSE-2.0.html): + +~~~ +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. +~~~ + +## Developer Certificate of Origin + +Contributors must sign-off each commit by adding a `Signed-off-by: ...` line to commit messages to certify that they have the right to submit the code they are contributing to the project according to the [Developer Certificate of Origin (DCO)](https://developercertificate.org/). + +## Code Coverage + +As stated in [QUALITY.md](QUALITY.md), all contributions to the project must increase line code coverage. +Because of this, contributors are asked to locally run a coverage assessment that ensures that code coverage has increased when compared to the latest execution of the [nightly coverage CI job](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/coverage/). + +## General considerations + +Any other contributing policy can be found in [eProsima general guidelines](https://github.com/eProsima/policies/blob/main/CONTRIBUTING.md). diff --git a/CTestConfig.cmake b/CTestConfig.cmake index aecb4819e..64957226d 100644 --- a/CTestConfig.cmake +++ b/CTestConfig.cmake @@ -15,7 +15,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") # MemoryCheck configuration. find_program(MEMORYCHECK_COMMAND NAMES valgrind) - set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --quiet --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=50 --xml=yes --xml-file=test_%p_memcheck.xml \"--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/ci/valgrind.supp\"") + set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --log-fd=2 --quiet --tool=memcheck --leak-check=yes --show-reachable=yes --error-exitcode=1 --num-callers=50 \"--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/ci/valgrind.supp\"") # Coverage configuration. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/PLATFORM_SUPPORT.md b/PLATFORM_SUPPORT.md new file mode 100644 index 000000000..94b8b14fc --- /dev/null +++ b/PLATFORM_SUPPORT.md @@ -0,0 +1,47 @@ +# Platform Support + +This document reflects the level of support offered by **eProsima Micro XRCE-DDS Client** on different platforms as per the following +definitions: + +## Tier 1 + +Tier 1 platforms are subjected to our unit test suite and other testing tools on a frequent basis including continuous +integration jobs and nightly jobs. +Errors or bugs discovered in these platforms are prioritized for correction by the development team. +Significant errors discovered in Tier 1 platforms can impact release dates and we strive to resolve all known high +priority errors in Tier 1 platforms prior to new version releases. + +## Tier 2 + +Tier 2 platforms are subject to periodic CI testing which runs both builds and tests with publicly accessible results. +The CI is expected to be run at least within a week from the last relevant changes for the current release of the **Micro XRCE-DDS Client**. +Installation instructions should be available and up-to-date in order for a platform to be listed in this category. +Package-level binary packages may not be provided but providing a downloadable archive of the built workspace is +encouraged. +Errors may be present in released product versions for Tier 2 platforms. +Known errors in Tier 2 platforms will be addressed subject to resource availability on a best effort basis and may or +may not be corrected prior to new version releases. +One or more entities should be committed to continuing support of the platform. + +## Tier 3 + +Tier 3 platforms are those for which community reports indicate that the release is functional. +The development team does not run the unit test suite nor perform any other tests on platforms in Tier 3. +Community members may provide assistance with these platforms. + +## Platforms + +| Architecture | Ubuntu Focal (20.04) | Windows 10 (VS2019) | Debian Buster (10) | +| ------------ | -------------------- | ------------------- | ------------------ | +| amd64 | Tier 1 [s] | Tier 1 [s] | Tier 3 [s] | +| amd32 | | Tier 1 [s] | | +| arm64 | Tier 3 [s] | | Tier 3 [s] | +| arm32 | Tier 3 [s] | | Tier 3 [s] | + +" [s] " Compilation from source. + +Other Tier 3 OS: + +* FreeRTOS +* Zephyr RTOS +* NuttX diff --git a/QUALITY.md b/QUALITY.md new file mode 100644 index 000000000..e62147930 --- /dev/null +++ b/QUALITY.md @@ -0,0 +1,197 @@ +This document is a declaration of software quality for the **eProsima Micro XRCE-DDS Client** based on the guidelines provided in the [ROS 2 REP-2004 document](https://www.ros.org/reps/rep-2004.html). + +# Quality Declaration + +**eProsima Micro XRCE-DDS Client** is a C99 library that provides a DDS-XRCE implementation for using DDS in eXtreme Resources Constrained Devices. It follows the [DDS-XRCE standard](https://www.omg.org/spec/DDS-XRCE/About-DDS-XRCE/). + +**eProsima Micro XRCE-DDS Client** claims to be in the **Quality Level 1** category. + +Below are the rationales, notes and caveats for this claim, organized by each requirement listed in the [Package Requirements for Quality Level 1 in REP-2004](https://www.ros.org/reps/rep-2004.html#package-requirements). + +## Version Policy [1] + +### Version Scheme [1.i] + +The **Versioning Policy Declaration** for **eProsima Micro XRCE-DDS Client** can be found [here](VERSIONING.md) and it adheres to [`semver`](https://semver.org/). + +### Version Stability [1.ii] + +**eProsima Micro XRCE-DDS Client** is at a stable version, i.e. `>=1.0.0`. +The latest version and the release notes can be found [here](https://github.com/eProsima/Micro-XRCE-DDS-Client/releases). + +### Public API Declaration [1.iii] + +The public API is documented [in oficial documentation Read the Docs](https://micro-xrce-dds.docs.eprosima.com/en/latest/client.html#api). + +### API Stability Policy [1.iv] + +**eProsima Micro XRCE-DDS Client** will only break public API between major releases. + +### ABI Stability Policy [1.v] + +Any ABI break in **eProsima Micro XRCE-DDS Client** will be done between minor versions and it should be clearly stated in the release notes. + +## Change Control Process [2] + +The stability of **eProsima Micro XRCE-DDS Client** is ensured through reviews, CI and tests. +The change control process can be found in [CONTRIBUTING](CONTRIBUTING.md) + +All changes to **eProsima Micro XRCE-DDS Client** occur through pull requests that are required to pass all CI tests. +In case of failure, only maintainers can merge the pull request, and only when there is enough evidence that the failure is unrelated to the change. +Additionally, all pull requests must have at least one positive review from another contributor that did not author the pull request. + +### Change Requests [2.i] + +All changes will occur through a pull request. + +### Contributor Origin [2.ii] + +**eProsima Micro XRCE-DDS Client** uses the [Developer Certificate of Origin (DCO)](https://developercertificate.org/) as its confirmation of contributor origin policy since version 2.0.0. +More information can be found in [CONTRIBUTING](CONTRIBUTING.md) + +### Peer Review Policy [2.iii] + +All pull requests will be peer-reviewed by at least one other contributor who did not author the pull request. Approval is required before merging. + +### Continuous Integration [2.iv] + +All pull requests must pass CI to be considered for merging, unless maintainers consider that there is enough evidence that the failure is unrelated to the changes. +CI testing is automatically triggered by incoming pull requests. +Current nightly results for all supported platforms can be checked at the links: + +* Linux [![Linux ci](http://jenkins.eprosima.com:8080/view/Nightly/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/badge/icon?subject=%20%20%20Linux%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/) +* Windows [![Windows ci](http://jenkins.eprosima.com:8080/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/badge/icon?subject=%20%20%20%20Windows%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/) + +### Documentation Policy [2.v] + +All pull requests must resolve related documentation changes before merging as stated in [CONTRIBUTING](CONTRIBUTING.md). + +## Documentation [3] + +### Feature Documentation [3.i] + +**eProsima Micro XRCE-DDS Client** has a documented features list hosted by [Read the Docs](https://micro-xrce-dds.docs.eprosima.com/en/latest/client.html). + +### Public API Documentation [3.ii] + +**eProsima Micro XRCE-DDS Client** includes a complete API Reference which is hosted in [Read the Docs](https://micro-xrce-dds.docs.eprosima.com/en/latest/client.html#api). + +### License [3.iii] + +The license for **eProsima Micro XRCE-DDS Client** is Apache 2.0, and a summary can be found in each source file. +A full copy of the license can be found [here](LICENSE). + +### Copyright Statements [3.iv] + +The **eProsima Micro XRCE-DDS Client** copyright holder provides a statement of copyright in each source file. + +## Testing [4] + +### Feature Testing [4.i] + +**eProsima Micro XRCE-DDS Client** provides tests which simulate typical usage, and they are located in the [`test` directory](test). +New features are required to have tests before being added as stated in [CONTRIBUTING](CONTRIBUTING.md). +Current nightly results can be found here: + +* Linux [![Linux ci](http://jenkins.eprosima.com:8080/view/Nightly/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/badge/icon?subject=%20%20%20Linux%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/) +* Windows [![Windows ci](http://jenkins.eprosima.com:8080/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/badge/icon?subject=%20%20%20%20Windows%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/) +### Public API Testing [4.ii] + +Each part of the public API has tests, and new additions or changes to the public API require tests before being added. +The tests aim to cover typical usage and corner cases. + +### Coverage [4.iii] + +[![Coverage](https://img.shields.io/jenkins/coverage/cobertura?jobUrl=http%3A%2F%2Fjenkins.eprosima.com%3A8080%2Fview%2FMicro%2520XRCE%2Fjob%2FMicro-XRCE-DDS-Client%2520Nightly%2520Master%2520Linux)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/coverage/) + +*eProsima Micro XRCE-DDS Client* aims to provide a line coverage **above 90%**. +*Micro XRCE-DDS Client* code coverage policy comprises: +1. All contributions to *Micro XRCE-DDS Client* must increase (or at least keep) the current line coverage. + This is done to ensure that the **90%** line coverage goal is eventually met. +2. Line coverage regressions are only permitted if properly justified and accepted by maintainers. +3. If the CI system reports a coverage regression after a pull request has been merged, the maintainers must study the case and decide how to proceed, most often reverting the changes and asking for a more thorough testing of the committed changes. +4. This policy is enforced through the [nightly Micro XRCE-DDS Client CI job](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/). + +As stated in [CONTRIBUTING.md](CONTRIBUTING.md), developers and contributors are required to run a line coverage assessment locally before submitting a PR. + +### Performance [4.iv] + +**eProsima Micro XRCE-DDS Client** does provide performance tests regarding memory consumption due to the nature of the library. +These memory consuption tests are under `test/memory` and evaluates the static size (`text`, `bss` and `data` sections) of the library built with different configuration profiles. +Also, a `stack` consumption analysis is provided by using [Valgrind Massif tool](https://valgrind.org/docs/manual/ms-manual.html). + +All these results are available in [Micro-XRCE-DDS-Client Nightly Master Performance job](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Performance/plot/) + +Any performance regression detected in *eProsima Micro XRCE-DDS Client* would be analysed and, in case it is related to **eProsima Micro XRCE-DDS Client** or could be solved by modifying this library, changes can be made to the library in order to revert the performance regression. + +### Linters and Static Analysis [4.v] + +**eProsima Micro XRCE-DDS Client** [code style](https://github.com/eProsima/cpp-style) is enforced using [*uncrustify*](https://github.com/uncrustify/uncrustify). +Among the CI tests, there are tests that ensure that every pull request is compliant with the code style. +The latest pull request results can be seen [here](http://jenkins.eprosima.com:8080/job/Micro-XRCE-DDS-Client%20Manual%20Linux/lastBuild/). + +**eProsima Micro XRCE-DDS Client** uses [Synopsis Coverity static code analysis](https://scan.coverity.com/projects/eprosima-micro-xrce-dds-client). + +**eProsima Micro XRCE-DDS Client** uses [CodeQL](https://github.com/eProsima/Micro-XRCE-DDS-Client/security/code-scanning?query=tool%3ACodeQL) to find security issues on the code. + +## Dependencies [5] + +### Direct Runtime Dependencies [5.iii] + +**eProsima Micro XRCE-DDS Client** depends on the following packages: +- `eProsima Micro CDR` + +**eProsima Micro CDR** Quality Declaration can be found [here](https://github.com/eProsima/Micro-CDR/blob/master/QUALITY.md). Currently, **eProsima Micro CDR** claims to be in the **Quality Level 1** category. + +## Platform Support [6] + +**eProsima Micro XRCE-DDS Client** supports the following platforms and tests each change against all of them as can be seen in the current nightly results: + +* Linux [![Linux ci](http://jenkins.eprosima.com:8080/view/Nightly/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/badge/icon?subject=%20%20%20Linux%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Linux/) +* Windows [![Windows ci](http://jenkins.eprosima.com:8080/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/badge/icon?subject=%20%20%20%20Windows%20CI%20)](http://jenkins.eprosima.com:8080/view/Micro%20XRCE/job/Micro-XRCE-DDS-Client%20Nightly%20Master%20Windows/) + +More information about the supported platforms can be found in [PLATFORM_SUPPORT](PLATFORM_SUPPORT.md) + +## Vulnerability Disclosure Policy [7.i] + +**eprosima Micro XRCE-DDS Client** vulnerability Disclosure Policy can be found [here](https://github.com/eProsima/policies/blob/main/VULNERABILITY.md) + +# Current Status Summary + +The chart below compares the requirements in the [REP-2004](https://www.ros.org/reps/rep-2004.html#quality-level-comparison-chart) with the current state of **eprosima Micro XRCE-DDS Client** +| Number | Requirement | Current State | +| ------- | ------------------------------------------------- | ------------- | +| 1 | **Version policy** | --- | +| 1.i | Version Policy available | ✓ | +| 1.ii | Stable version | ✓ | +| 1.iii | Declared public API | ✓ | +| 1.iv | API stability policy | ✓ | +| 1.v | ABI stability policy | ✓ | +| 2 | **Change control process** | --- | +| 2.i | All changes occur on change request | ✓ | +| 2.ii | Contributor origin (DCO, CLA, etc) | ✓ | +| 2.iii | Peer review policy | ✓ | +| 2.iv | CI policy for change requests | ✓ | +| 2.v | Documentation policy for change requests | ✓ | +| 3 | **Documentation** | --- | +| 3.i | Per feature documentation | ✓ | +| 3.ii | Per public API item documentation | ✓ | +| 3.iii | Declared License(s) | ✓ | +| 3.iv | Copyright in source files | ✓ | +| 3.v.a | Quality declaration linked to README | ✓ | +| 3.v.b | Centralized declaration available for peer review | ✓ | +| 4 | **Testing** | --- | +| 4.i | Feature items tests | ✓ | +| 4.ii | Public API tests | ✓ | +| 4.iii.a | Using coverage | ✓ | +| 4.iii.b | Coverage policy | ✓ | +| 4.iv.a | Performance tests (if applicable) | ✓ | +| 4.iv.b | Performance tests policy | ✓ | +| 4.v.a | Code style enforcement (linters) | ✓ | +| 4.v.b | Use of static analysis tools | ✓ | +| 5 | **Dependencies** | --- | +| 5.iii | Justifies quality use of dependencies | ✓ | +| 6 | **Platform support** | --- | +| 6.i | Support targets Tier1 ROS platforms | ✓ | +| 7 | **Security** | --- | +| 7.i | Vulnerability Disclosure Policy | ✓ | diff --git a/README.md b/README.md index ba3c54358..31f1350e3 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,38 @@ [![Forks](https://img.shields.io/github/forks/eProsima/Micro-XRCE-DDS-Client.svg)](https://github.com/eProsima/Micro-XRCE-DDS-Client/network/members) [![Stars](https://img.shields.io/github/stars/eProsima/Micro-XRCE-DDS-Client.svg)](https://github.com/eProsima/Micro-XRCE-DDS-Client/stargazers) +[![Docker Build Status](https://img.shields.io/docker/cloud/build/eprosima/micro-xrce-dds-client)](https://hub.docker.com/r/eprosima/micro-xrce-dds-client/) + -In *Micro XRCE-DDS* a *Micro XRCE-DDS Client* can communicate with DDS Network as any other DDS actor could do. -Clients can publish and subscribe to data topics in *DDS Global Data Space*. *Micro XRCE-DDS* provides you with a C API to create *Micro XRCE-DDS Clients*. +*eProsima Micro XRCE-DDS* is a library implementing the [DDS-XRCE protocol](https://www.omg.org/spec/DDS-XRCE/About-DDS-XRCE/) as defined and maintained by the OMG, whose aim is to allow resource constrained devices such as microcontrollers to communicate with the [DDS](https://www.omg.org/spec/DDS/About-DDS/>) world as any other DDS actor would do. +It follows a client/server paradigm and is composed by two libraries, the *Micro XRCE-DDS Client* and the *Micro XRCE-DDS Agent*. The *Micro XRCE-DDS Clients* are lightweight entities meant to be compiled on e**X**tremely **R**esource **C**onstrained **E**nvironments, while the *Micro XRCE-DDS Agent* is a broker which bridges the *Clients* with the DDS world. + +

Image

+ +The *Micro XRCE-DDS Clients* request operations to the *Agent* to publish and/or subscribe to topics in the DDS global dataspace. Remote procedure calls, as defined by the [DDS-RPC standard](https://www.omg.org/spec/DDS-RPC/About-DDS-RPC/), are also supported, allowing *Clients* to communicate in the DDS dataspace according to a request/reply paradigm. +The *Agents* process these requests and send back a response with the operation status result and with the requested data, in the case of subscribe/reply operations. +The communication in the DDS world is mediated by a dedicated `ProxyClient` in charge of creating the *DDS Entities* requested by the *Clients*, such as *Participants*, *Topics*, *Publishers*, and *Subscribers*, which can interact with the DDS Global dataspace. +

Image

-

Image

+*eProsima Micro XRCE-DDS* provides the user with a C API to create *Micro XRCE-DDS Clients* applications. The library can be configured at compile-time via a set of CMake flags allowing to enable or disable some profiles before compilation, and to manipulate several parameters controlling some of the library's functionalities, which in turn allow tuning the library size. + +The communication between a *Micro XRCE-DDS Client* and a *Micro XRCE-DDS Agent* is achieved by means of several kinds of built-in transports: **UDPv4**, **UDPv6**, **TCPv4**, **TCPv6** and **Serial** communication. In addition, there is the possibility for the user to generate its own **Custom** transport. ## Documentation -You can access *Micro XRCE-DDS* documentation online, which is hosted on Read the Docs. +You can access the *eProsima Micro XRCE-DDS* user documentation online, which is hosted on Read the Docs. * [Start Page](http://micro-xrce-dds.readthedocs.io) * [Installation manual](http://micro-xrce-dds.readthedocs.io/en/latest/installation.html) * [User manual](http://micro-xrce-dds.readthedocs.io/en/latest/introduction.html) +## Quality Declaration + +**eProsima Micro XRCE-DDS Client** claims to be in the **Quality Level 1** category based on the guidelines provided by [ROS 2](https://ros.org/reps/rep-2004.html). +See the [Quality Declaration](QUALITY.md) for more details. ## Getting Help If you need support you can reach us by mail at `support@eProsima.com` or by phone at `+34 91 804 34 48`. + diff --git a/VERSIONING.md b/VERSIONING.md new file mode 100644 index 000000000..bbe81b4b3 --- /dev/null +++ b/VERSIONING.md @@ -0,0 +1,9 @@ +Versioning policy declaration +============================= + +Starting on v1.0.0, the version numbers for this library will adhere to the versioning policies defined by [Semantic Versioning](https://semver.org/). + +This means that API breaks should only happen between major version changes. +If an ABI break is required, it should be done between minor versions, and it should be clearly stated in the release notes. + +The changes included on each version can be found in the [release notes](https://github.com/eProsima/Micro-XRCE-DDS-Client/releases) diff --git a/ci/linux/CMakeLists.txt b/ci/linux/CMakeLists.txt index 929d8037c..c46d7cccb 100644 --- a/ci/linux/CMakeLists.txt +++ b/ci/linux/CMakeLists.txt @@ -24,10 +24,10 @@ include(ExternalProject) include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) -set(_c_flags "-fwrapv -fprofile-arcs -ftest-coverage") -set(_cxx_flags "-fwrapv -fprofile-arcs -ftest-coverage") -set(_exe_linker_flags "-fprofile-arcs -ftest-coverage") -set(_shared_linker_flags "-fprofile-arcs -ftest-coverage") +set(_c_flags "-fwrapv -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") +set(_cxx_flags "-fwrapv -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") +set(_exe_linker_flags "-fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") +set(_shared_linker_flags "-fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline") check_cxx_compiler_flag("-fprofile-abs-path" _have_cxx_fprofile_abs_path) if(_have_cxx_fprofile_abs_path) diff --git a/client.config b/client.config deleted file mode 100644 index 273d9ef26..000000000 --- a/client.config +++ /dev/null @@ -1,19 +0,0 @@ -PROFILE_DISCOVERY=TRUE -PROFILE_UDP_TRANSPORT=TRUE -PROFILE_TCP_TRANSPORT=TRUE -PROFILE_SERIAL_TRANSPORT=TRUE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=25 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_BIG_ENDIANNESS=FALSE - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 diff --git a/docs/Client.png b/docs/Client.png new file mode 100644 index 000000000..2e705340d Binary files /dev/null and b/docs/Client.png differ diff --git a/docs/General.png b/docs/General.png new file mode 100644 index 000000000..f07336411 Binary files /dev/null and b/docs/General.png differ diff --git a/docs/client_architecture.png b/docs/client_architecture.png deleted file mode 100644 index 315c2c2cc..000000000 Binary files a/docs/client_architecture.png and /dev/null differ diff --git a/examples/ContinuousFragment/CMakeLists.txt b/examples/ContinuousFragment/CMakeLists.txt new file mode 100644 index 000000000..1a578ee9d --- /dev/null +++ b/examples/ContinuousFragment/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(ContinuousFragment) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/ContinuousFragment/main.c b/examples/ContinuousFragment/main.c new file mode 100644 index 000000000..b41bb1ce0 --- /dev/null +++ b/examples/ContinuousFragment/main.c @@ -0,0 +1,127 @@ +// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include //printf +#include //strcmp +#include //atoi + +#define STREAM_HISTORY 4 +#define BUFFER_SIZE 100 * STREAM_HISTORY + +bool flush_session( + uxrSession* session) +{ + return uxr_run_session_until_confirm_delivery(session, 1000); +} + +int main( + int args, + char** argv) +{ + // CLI + if (3 > args || 0 == atoi(argv[2])) + { + printf("usage: program [-h | --help] | ip port\n"); + return 0; + } + + char* ip = argv[1]; + char* port = argv[2]; + + // Transport + uxrUDPTransport transport; + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xAAAABBBB); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + uxr_run_session_until_confirm_delivery(&session, 100); + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + uxr_run_session_until_confirm_delivery(&session, 100); + uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); + const char* publisher_xml = ""; + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); + + uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); + const char* datawriter_xml = "" + "" + "PREALLOCATED_WITH_REALLOC" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); + uxr_run_session_until_confirm_delivery(&session, 100); + + // Write topic + uint8_t buf[20000]; + memset(buf, 'A', sizeof(buf)); + + ucdrBuffer ub; + uxr_prepare_output_stream_fragmented(&session, reliable_out, datawriter_id, &ub, sizeof(buf), flush_session); + ucdr_serialize_array_char(&ub, buf, sizeof(buf)); + + uxr_run_session_until_confirm_delivery(&session, 1000); + + // Delete resources + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +} diff --git a/examples/CustomTransports/CMakeLists.txt b/examples/CustomTransports/CMakeLists.txt new file mode 100644 index 000000000..224583613 --- /dev/null +++ b/examples/CustomTransports/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(CustomTransports) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c HelloWorld.c my_custom_transport.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/CustomTransports/HelloWorld.c b/examples/CustomTransports/HelloWorld.c new file mode 100644 index 000000000..069529011 --- /dev/null +++ b/examples/CustomTransports/HelloWorld.c @@ -0,0 +1,59 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.c + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#include "HelloWorld.h" + +#include +#include + +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) +{ + (void) ucdr_serialize_uint32_t(writer, topic->index); + + (void) ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) +{ + (void) ucdr_deserialize_uint32_t(reader, &topic->index); + + (void) ucdr_deserialize_string(reader, topic->message, 255); + + return !reader->error; +} + +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) +{ + uint32_t previousSize = size; + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + 1); + + return size - previousSize; +} diff --git a/examples/CustomTransports/HelloWorld.h b/examples/CustomTransports/HelloWorld.h new file mode 100644 index 000000000..21cb3964e --- /dev/null +++ b/examples/CustomTransports/HelloWorld.h @@ -0,0 +1,61 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _HelloWorld_H_ +#define _HelloWorld_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include + +/*! + * @brief This struct represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +typedef struct HelloWorld +{ + uint32_t index; + char message[255]; + +} HelloWorld; + +struct ucdrBuffer; + +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // _HelloWorld_H_ diff --git a/examples/CustomTransports/HelloWorld.idl b/examples/CustomTransports/HelloWorld.idl new file mode 100644 index 000000000..0fd2c355a --- /dev/null +++ b/examples/CustomTransports/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/examples/CustomTransports/main.c b/examples/CustomTransports/main.c new file mode 100644 index 000000000..abaf72a78 --- /dev/null +++ b/examples/CustomTransports/main.c @@ -0,0 +1,140 @@ +// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "HelloWorld.h" +#include "my_custom_transport.h" + +#include +#include + +#include //printf +#include //strcmp +#include //atoi + +#define STREAM_HISTORY 8 +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY + +int main( + int args, + char** argv) +{ + // Transport + uxrCustomTransport transport; + uxr_set_custom_transport_callbacks( + &transport, + false, + my_custom_transport_open, + my_custom_transport_close, + my_custom_transport_write, + my_custom_transport_read); + + if (!uxr_init_custom_transport(&transport, NULL)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xAAAABBBB); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + + uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); + const char* publisher_xml = ""; + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); + + uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); + const char* datawriter_xml = "" + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); + + // Send create entities message and wait its status + uint8_t status[4]; + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %i topic: %i publisher: %i darawriter: %i\n", status[0], + status[1], status[2], status[3]); + return 1; + } + + // Write topics + bool connected = true; + uint32_t count = 0; + while (connected) + { + HelloWorld topic = { + ++count, "Hello DDS world!" + }; + + ucdrBuffer ub; + uint32_t topic_size = HelloWorld_size_of_topic(&topic, 0); + uxr_prepare_output_stream(&session, reliable_out, datawriter_id, &ub, topic_size); + HelloWorld_serialize_topic(&ub, &topic); + + printf("Send topic: %s, id: %i\n", topic.message, topic.index); + connected = uxr_run_session_time(&session, 1000); + } + + // Delete resources + uxr_delete_session(&session); + uxr_close_custom_transport(&transport); + + return 0; +} diff --git a/examples/CustomTransports/my_custom_transport.c b/examples/CustomTransports/my_custom_transport.c new file mode 100644 index 000000000..48cd507a5 --- /dev/null +++ b/examples/CustomTransports/my_custom_transport.c @@ -0,0 +1,110 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +static struct pollfd poll_fd; + +bool my_custom_transport_open( + uxrCustomTransport* transport) +{ + printf("Micro XRCE-DDS Client Custom transport: opening\n"); + + bool rv = false; + + poll_fd.fd = socket(AF_INET, SOCK_DGRAM, 0); + + if (-1 != poll_fd.fd) + { + struct addrinfo hints; + struct addrinfo* result; + struct addrinfo* ptr; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_DGRAM; + + if (0 == getaddrinfo("localhost", "8888", &hints, &result)) + { + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) + { + if (0 == connect(poll_fd.fd, ptr->ai_addr, ptr->ai_addrlen)) + { + poll_fd.events = POLLIN; + rv = true; + break; + } + } + } + freeaddrinfo(result); + } + return rv; +} + +bool my_custom_transport_close( + uxrCustomTransport* transport) +{ + printf("Micro XRCE-DDS Client Custom transport: closing\n"); + + return (-1 == poll_fd.fd) ? true : (0 == close(poll_fd.fd)); +} + +size_t my_custom_transport_write( + uxrCustomTransport* transport, + const uint8_t* buf, + size_t len, + uint8_t* errcode) +{ + size_t rv = 0; + ssize_t bytes_sent = send(poll_fd.fd, (void*)buf, len, 0); + if (-1 != bytes_sent) + { + rv = (size_t)bytes_sent; + *errcode = 0; + } + else + { + *errcode = 1; + } + + printf("Micro XRCE-DDS Client Custom transport: wrote %ld B\n", rv); + + return rv; +} + +size_t my_custom_transport_read( + uxrCustomTransport* transport, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode) +{ + size_t rv = 0; + int poll_rv = poll(&poll_fd, 1, timeout); + if (0 < poll_rv) + { + ssize_t bytes_received = recv(poll_fd.fd, (void*)buf, len, 0); + if (-1 != bytes_received) + { + rv = (size_t)bytes_received; + *errcode = 0; + } + else + { + *errcode = 1; + } + } + else + { + *errcode = (0 == poll_rv) ? 0 : 1; + } + + printf("Micro XRCE-DDS Client Custom transport: read %ld B\n", rv); + + return rv; +} diff --git a/examples/CustomTransports/my_custom_transport.h b/examples/CustomTransports/my_custom_transport.h new file mode 100644 index 000000000..8364e7e1d --- /dev/null +++ b/examples/CustomTransports/my_custom_transport.h @@ -0,0 +1,37 @@ + +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _my_custom_transport_H_ +#define _my_custom_transport_H_ + +#include + +bool my_custom_transport_open( + uxrCustomTransport* transport); +bool my_custom_transport_close( + uxrCustomTransport* transport); +size_t my_custom_transport_write( + uxrCustomTransport* transport, + const uint8_t* buf, + size_t len, + uint8_t* errcode); +size_t my_custom_transport_read( + uxrCustomTransport* transport, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode); + +#endif // ifndef _my_custom_transport_H_ \ No newline at end of file diff --git a/examples/Deployment/CMakeLists.txt b/examples/Deployment/CMakeLists.txt index cc8d7f0b0..9ca0a3d05 100644 --- a/examples/Deployment/CMakeLists.txt +++ b/examples/Deployment/CMakeLists.txt @@ -18,8 +18,8 @@ if (${CMAKE_VERSION} VERSION_GREATER 3.0) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() ############################################################# diff --git a/examples/Deployment/HelloWorld.c b/examples/Deployment/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/Deployment/HelloWorld.c +++ b/examples/Deployment/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/Deployment/HelloWorld.h b/examples/Deployment/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/Deployment/HelloWorld.h +++ b/examples/Deployment/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/Deployment/README.md b/examples/Deployment/README.md index b6541eab1..df200983e 100644 --- a/examples/Deployment/README.md +++ b/examples/Deployment/README.md @@ -5,13 +5,13 @@ The goal of this example is to create a minimal publisher and subscriber that ca To archive this minimal examples, it is necessary to split some logic. This implies that the publisher and subscriber will be configured previously with another application: the configurator client. The configurator client will create the necessary entities in the agent for a specific session. -In order to compile this example, it is necessary to have the following profiles enabled in `client.config` file: +In order to compile this example, the following profiles should be enabled: -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *ConfiguratorClient* example to create both, a publisher and a subscriber. 1. Configure the publisher: `ConfiguratorClient --key 1000 create pub --id 1`. This will create a publisher with the session key `1000`, all necessary entities to create the publisher will have `1` as id. diff --git a/examples/Deployment/configurator_client.c b/examples/Deployment/configurator_client.c index a2603abe1..5c1dcb1b2 100644 --- a/examples/Deployment/configurator_client.c +++ b/examples/Deployment/configurator_client.c @@ -18,7 +18,7 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY #define ACTION_CREATE 1 #define ACTION_DELETE 2 @@ -26,16 +26,33 @@ #define TARGET_PUBLISHER 1 << 8 #define TARGET_SUBSCRIBER 2 << 8 -static void on_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status, void* args); - -static void create_publisher(uxrSession* session, uint16_t ids); -static void create_subscriber(uxrSession* session, uint16_t ids); -static void delete_publisher(uxrSession* session, uint16_t ids); -static void delete_subscriber(uxrSession* session, uint16_t ids); - -static void wait_status(uxrSession* session, uint16_t* requests); - -int main(int args, char** argv) +static void on_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status, + void* args); + +static void create_publisher( + uxrSession* session, + uint16_t ids); +static void create_subscriber( + uxrSession* session, + uint16_t ids); +static void delete_publisher( + uxrSession* session, + uint16_t ids); +static void delete_subscriber( + uxrSession* session, + uint16_t ids); + +static void wait_status( + uxrSession* session, + uint16_t* requests); + +int main( + int args, + char** argv) { // Check args uint32_t key; @@ -43,33 +60,33 @@ int main(int args, char** argv) int pub_sub = 0; uint16_t ids = 0; - if(args == 7) + if (args == 7) { key = atoi(argv[2]); - if(0 == strcmp(argv[3], "create")) + if (0 == strcmp(argv[3], "create")) { create_delete = ACTION_CREATE; } - else if(0 == strcmp(argv[3], "delete")) + else if (0 == strcmp(argv[3], "delete")) { create_delete = ACTION_DELETE; } - if(0 == strcmp(argv[4], "pub")) + if (0 == strcmp(argv[4], "pub")) { pub_sub = TARGET_PUBLISHER; } - else if(0 == strcmp(argv[4], "sub")) + else if (0 == strcmp(argv[4], "sub")) { pub_sub = TARGET_SUBSCRIBER; } ids = atoi(argv[6]); } - if(args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) - || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[5]) - || 0 == atoi(argv[2]) || 0 == atoi(argv[6]) - || !create_delete || !pub_sub) + if (args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) + || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[5]) + || 0 == atoi(argv[2]) || 0 == atoi(argv[6]) + || !create_delete || !pub_sub) { printf("usage: program [-h | --help] | --key <'create'/'delete'> <'pub'/'sub'> --id ]\n"); return 0; @@ -77,8 +94,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, "127.0.0.1", "2018")) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, "127.0.0.1", "2018")) { printf("Error at create transport.\n"); return 1; @@ -88,7 +104,7 @@ int main(int args, char** argv) uxrSession session; uxr_init_session(&session, &transport.comm, key); uxr_set_status_callback(&session, on_status, NULL); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -101,9 +117,9 @@ int main(int args, char** argv) uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); - switch(create_delete | pub_sub) + switch (create_delete | pub_sub) { - case ACTION_CREATE | TARGET_PUBLISHER: + case ACTION_CREATE | TARGET_PUBLISHER: create_publisher(&session, ids); break; @@ -125,93 +141,109 @@ int main(int args, char** argv) return 0; } -void create_publisher(uxrSession* session, uint16_t id) +void create_publisher( + uxrSession* session, + uint16_t id) { uxrStreamId output = uxr_stream_id(0, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); uxrObjectId participant_id = uxr_object_id(id, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(session, output, participant_id, 0, participant_xml, 0); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = + uxr_buffer_create_participant_xml(session, output, participant_id, 0, participant_xml, 0); uxrObjectId topic_id = uxr_object_id(id, UXR_TOPIC_ID); const char* topic_xml = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; uint16_t topic_req = uxr_buffer_create_topic_xml(session, output, topic_id, participant_id, topic_xml, 0); uxrObjectId publisher_id = uxr_object_id(id, UXR_PUBLISHER_ID); const char* publisher_xml = ""; - uint16_t publisher_req = uxr_buffer_create_publisher_xml(session, output, publisher_id, participant_id, publisher_xml, 0); + uint16_t publisher_req = uxr_buffer_create_publisher_xml(session, output, publisher_id, participant_id, + publisher_xml, 0); uxrObjectId datawriter_id = uxr_object_id(id, UXR_DATAWRITER_ID); const char* datawriter_xml = "" - "" - "" - "NO_KEY" - "HelloWorldTopic" - "HelloWorld" - "" - "" - ""; - uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(session, output, datawriter_id, publisher_id, datawriter_xml, 0); - - uint16_t requests[4] = {participant_req, topic_req, publisher_req, datawriter_req}; + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(session, output, datawriter_id, publisher_id, + datawriter_xml, 0); + + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; wait_status(session, requests); } -void create_subscriber(uxrSession* session, uint16_t id) +void create_subscriber( + uxrSession* session, + uint16_t id) { uxrStreamId output = uxr_stream_id(0, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); uxrObjectId participant_id = uxr_object_id(id, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(session, output, participant_id, 0, participant_xml, 0); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = + uxr_buffer_create_participant_xml(session, output, participant_id, 0, participant_xml, 0); uxrObjectId topic_id = uxr_object_id(id, UXR_TOPIC_ID); const char* topic_xml = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; uint16_t topic_req = uxr_buffer_create_topic_xml(session, output, topic_id, participant_id, topic_xml, 0); uxrObjectId subscriber_id = uxr_object_id(id, UXR_SUBSCRIBER_ID); const char* subscriber_xml = ""; - uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(session, output, subscriber_id, participant_id, subscriber_xml, 0); + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(session, output, subscriber_id, participant_id, + subscriber_xml, 0); uxrObjectId datareader_id = uxr_object_id(id, UXR_DATAREADER_ID); const char* datareader_xml = "" - "" - "" - "NO_KEY" - "HelloWorldTopic" - "HelloWorld" - "" - "" - ""; - uint16_t datareader_req = uxr_buffer_create_datareader_xml(session, output, datareader_id, subscriber_id, datareader_xml, 0); - - uint16_t requests[4] = {participant_req, topic_req, subscriber_req, datareader_req}; + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datareader_req = uxr_buffer_create_datareader_xml(session, output, datareader_id, subscriber_id, + datareader_xml, 0); + + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; wait_status(session, requests); } -void delete_publisher(uxrSession* session, uint16_t id) +void delete_publisher( + uxrSession* session, + uint16_t id) { uxrStreamId output = uxr_stream_id(0, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); @@ -220,11 +252,15 @@ void delete_publisher(uxrSession* session, uint16_t id) uint16_t topic_req = uxr_buffer_delete_entity(session, output, uxr_object_id(id, UXR_TOPIC_ID)); uint16_t participant_req = uxr_buffer_delete_entity(session, output, uxr_object_id(id, UXR_PARTICIPANT_ID)); - uint16_t requests[4] = {participant_req, topic_req, publisher_req, datawriter_req}; + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; wait_status(session, requests); } -void delete_subscriber(uxrSession* session, uint16_t id) +void delete_subscriber( + uxrSession* session, + uint16_t id) { uxrStreamId output = uxr_stream_id(0, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); @@ -233,14 +269,18 @@ void delete_subscriber(uxrSession* session, uint16_t id) uint16_t topic_req = uxr_buffer_delete_entity(session, output, uxr_object_id(id, UXR_TOPIC_ID)); uint16_t participant_req = uxr_buffer_delete_entity(session, output, uxr_object_id(id, UXR_PARTICIPANT_ID)); - uint16_t requests[4] = {participant_req, topic_req, subscriber_req, datareader_req}; + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; wait_status(session, requests); } -void wait_status(uxrSession* session, uint16_t* requests) +void wait_status( + uxrSession* session, + uint16_t* requests) { uint8_t status[4]; - if(uxr_run_session_until_all_status(session, 3000, requests, status, 4)) + if (uxr_run_session_until_all_status(session, 3000, requests, status, 4)) { printf("Ok\n"); } @@ -250,11 +290,16 @@ void wait_status(uxrSession* session, uint16_t* requests) } } -void on_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status, void* args) +void on_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status, + void* args) { (void) session; (void) request_id; (void) args; - if(status != UXR_STATUS_OK && status != UXR_STATUS_OK_MATCHED) + if (status != UXR_STATUS_OK && status != UXR_STATUS_OK_MATCHED) { printf("Status error: 0x%02X at entity id '%u' of object type '%u'\n", status, object_id.id, object_id.type); } diff --git a/examples/Deployment/publisher.c b/examples/Deployment/publisher.c index 92a3c9d25..3223c96e3 100644 --- a/examples/Deployment/publisher.c +++ b/examples/Deployment/publisher.c @@ -22,14 +22,16 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY -int main(int args, char** argv) +int main( + int args, + char** argv) { // Args - if(args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) - || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[3]) - || 0 == atoi(argv[2]) || 0 == atoi(argv[4])) + if (args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) + || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[3]) + || 0 == atoi(argv[2]) || 0 == atoi(argv[4])) { printf("usage: program [-h | --help | --key --id ]\n"); return 0; @@ -37,8 +39,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, "127.0.0.1", "2018")) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, "127.0.0.1", "2018")) { printf("Error at create transport.\n"); return 1; @@ -47,7 +48,7 @@ int main(int args, char** argv) // Session uxrSession session; uxr_init_session(&session, &transport.comm, (uint32_t)atoi(argv[2])); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -55,7 +56,8 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); @@ -65,9 +67,11 @@ int main(int args, char** argv) // Write topics bool connected = true; uint32_t count = 0; - while(connected) + while (connected) { - HelloWorld topic = {count++, "Hello DDS world!"}; + HelloWorld topic = { + count++, "Hello DDS world!" + }; ucdrBuffer ub; uint32_t topic_size = HelloWorld_size_of_topic(&topic, 0); @@ -75,7 +79,7 @@ int main(int args, char** argv) HelloWorld_serialize_topic(&ub, &topic); connected = uxr_run_session_time(&session, 1000); - if(connected) + if (connected) { printf("Sent topic: %s, index: %i\n", topic.message, topic.index); } diff --git a/examples/Deployment/subscriber.c b/examples/Deployment/subscriber.c index 5b0553fac..0ad47e6f1 100644 --- a/examples/Deployment/subscriber.c +++ b/examples/Deployment/subscriber.c @@ -20,7 +20,7 @@ #include #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY void on_topic( uxrSession* session, @@ -39,12 +39,14 @@ void on_topic( printf("Received topic: %s, index: %i\n", topic.message, topic.index); } -int main(int args, char** argv) +int main( + int args, + char** argv) { // Args - if(args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) - || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[3]) - || 0 == atoi(argv[2]) || 0 == atoi(argv[4])) + if (args < 5 || 0 == strcmp("-h", argv[1]) || 0 == strcmp("--help", argv[1]) + || 0 != strcmp("--key", argv[1]) || 0 != strcmp("--id", argv[3]) + || 0 == atoi(argv[2]) || 0 == atoi(argv[4])) { printf("usage: program [-h | --help | --key --id ]\n"); return 0; @@ -52,8 +54,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, "127.0.0.1", "2018")) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, "127.0.0.1", "2018")) { printf("Error at create transport.\n"); return 1; @@ -63,7 +64,7 @@ int main(int args, char** argv) uxrSession session; uxr_init_session(&session, &transport.comm, (uint32_t)atoi(argv[2])); uxr_set_topic_callback(&session, on_topic, NULL); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -71,21 +72,26 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); // Request topics - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; uxrObjectId datareader_id = uxr_object_id((uint16_t)atoi(argv[4]), UXR_DATAREADER_ID); - uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, &delivery_control); + uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, + &delivery_control); // Read topics bool connected = true; - while(connected) + while (connected) { uint8_t read_data_status; connected = uxr_run_session_until_all_status(&session, UXR_TIMEOUT_INF, &read_data_req, &read_data_status, 1); diff --git a/examples/Discovery/CMakeLists.txt b/examples/Discovery/CMakeLists.txt index 01bfc2bb8..11316ce4c 100644 --- a/examples/Discovery/CMakeLists.txt +++ b/examples/Discovery/CMakeLists.txt @@ -18,8 +18,8 @@ if (${CMAKE_VERSION} VERSION_GREATER 3.0) endif() -if(NOT PROFILE_DISCOVERY) - message(WARNING "Can not compile example: The profile PROFILE_DISCOVERY must be enabled.") +if(NOT UCLIENT_PROFILE_DISCOVERY) + message(WARNING "Can not compile example: The profile UCLIENT_PROFILE_DISCOVERY must be enabled.") else() ############################################################# diff --git a/examples/Discovery/main.c b/examples/Discovery/main.c index f88b8cd7e..c7f9bcbeb 100644 --- a/examples/Discovery/main.c +++ b/examples/Discovery/main.c @@ -19,7 +19,9 @@ #define MAX_AGENTS 10 -bool on_agent_found(const TransportLocator* locator, void* args) +bool on_agent_found( + const TransportLocator* locator, + void* args) { (void) args; switch (locator->format) @@ -48,12 +50,14 @@ bool on_agent_found(const TransportLocator* locator, void* args) return false; } -int main(int args, char** argv) +int main( + int args, + char** argv) { - if(args < 1 || (args >= 2 && (0 == strcmp("-h", argv[1]) || - 0 == strcmp("--help", argv[1]) || - 0 == args % 2 || - MAX_AGENTS * 2 < args + 2))) + if (args < 1 || (args >= 2 && (0 == strcmp("-h", argv[1]) || + 0 == strcmp("--help", argv[1]) || + 0 == args % 2 || + MAX_AGENTS * 2 < args + 2))) { printf("usage: program [ -h | --help | [ ...] ]\n"); return 0; @@ -67,7 +71,7 @@ int main(int args, char** argv) { size_t size = 0; TransportLocator agent_list[MAX_AGENTS]; - for(int i = 1; i < args; i += 2, size++) + for (int i = 1; i < args; i += 2, size++) { uxr_ip_to_locator(argv[i], (uint16_t)atoi(argv[i + 1]), UXR_IPv4, &agent_list[i++]); } @@ -77,4 +81,3 @@ int main(int args, char** argv) return 0; } - diff --git a/examples/MultiSessionHelloWorld/CMakeLists.txt b/examples/MultiSessionHelloWorld/CMakeLists.txt index ea437d152..0dd6aaa7e 100644 --- a/examples/MultiSessionHelloWorld/CMakeLists.txt +++ b/examples/MultiSessionHelloWorld/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c HelloWorld.c) if(MSVC OR MSVC_IDE) diff --git a/examples/MultiSessionHelloWorld/HelloWorld.c b/examples/MultiSessionHelloWorld/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/MultiSessionHelloWorld/HelloWorld.c +++ b/examples/MultiSessionHelloWorld/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/MultiSessionHelloWorld/HelloWorld.h b/examples/MultiSessionHelloWorld/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/MultiSessionHelloWorld/HelloWorld.h +++ b/examples/MultiSessionHelloWorld/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/MultiSessionHelloWorld/README.md b/examples/MultiSessionHelloWorld/README.md index f1e619df4..f2172f192 100644 --- a/examples/MultiSessionHelloWorld/README.md +++ b/examples/MultiSessionHelloWorld/README.md @@ -2,14 +2,14 @@ This example will show how to create multiple sessions on the same program. Both session will have a publisher and a subscriber communicating each other. -In order to compile this example, it is necessary to have the following profiles enabled in `client.config` file: +In order to compile this example, the following profiles should be enabled: - `PROFILE_CREATE_ENTITIES_XML` - `PROFILE_WRITE_ACCESS` -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *MultiSessionHelloWorld* example. diff --git a/examples/MultiSessionHelloWorld/main.c b/examples/MultiSessionHelloWorld/main.c index 4b7009319..2c20a6f47 100644 --- a/examples/MultiSessionHelloWorld/main.c +++ b/examples/MultiSessionHelloWorld/main.c @@ -22,7 +22,7 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY void on_topic( uxrSession* session, @@ -37,30 +37,31 @@ void on_topic( HelloWorld topic; HelloWorld_deserialize_topic(ub, &topic); - + char key[20]; - snprintf(key, 20, "0x%X%X%X%X", session->info.key[0], session->info.key[1], session->info.key[2], session->info.key[3]); + snprintf(key, 20, "0x%X%X%X%X", session->info.key[0], session->info.key[1], session->info.key[2], + session->info.key[3]); printf("Session %s: %s (%i)\n", key, topic.message, topic.index); } -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { - printf("usage: program [-h | --help] | ip port []\n"); + printf("usage: program [-h | --help] | ip port\n"); return 0; } char* ip = argv[1]; char* port = argv[2]; - uint32_t max_topics = (args == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; // ------ SESSION 1 ------ // Transport uxrUDPTransport transport_1; - uxrUDPPlatform udp_platform_1; - if(!uxr_init_udp_transport(&transport_1, &udp_platform_1, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport_1, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -70,7 +71,7 @@ int main(int args, char** argv) uxrSession session_1; uxr_init_session(&session_1, &transport_1.comm, 0x11111111); uxr_set_topic_callback(&session_1, on_topic, NULL); - if(!uxr_create_session(&session_1)) + if (!uxr_create_session(&session_1)) { printf("Error at create session 1.\n"); return 1; @@ -78,67 +79,89 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer_1[BUFFER_SIZE]; - uxrStreamId reliable_out_1 = uxr_create_output_reliable_stream(&session_1, output_reliable_stream_buffer_1, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out_1 = uxr_create_output_reliable_stream(&session_1, output_reliable_stream_buffer_1, + BUFFER_SIZE, STREAM_HISTORY); uint8_t input_reliable_stream_buffer_1[BUFFER_SIZE]; - uxrStreamId reliable_in_1 = uxr_create_input_reliable_stream(&session_1, input_reliable_stream_buffer_1, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in_1 = uxr_create_input_reliable_stream(&session_1, input_reliable_stream_buffer_1, + BUFFER_SIZE, STREAM_HISTORY); // Create entities uxrObjectId participant_id_1 = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml_1 = "" - "" - "" - "default_xrce_participant_1" - "" - "" - ""; - uint16_t participant_req_1 = uxr_buffer_create_participant_xml(&session_1, reliable_out_1, participant_id_1, 0, participant_xml_1, UXR_REPLACE); - - uxrObjectId topic_id_1 = uxr_object_id(0x01, UXR_TOPIC_ID); - const char* topic_xml_1 = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; - uint16_t topic_req_1 = uxr_buffer_create_topic_xml(&session_1, reliable_out_1, topic_id_1, participant_id_1, topic_xml_1, UXR_REPLACE); + "" + "" + "default_xrce_participant_1" + "" + "" + ""; + uint16_t participant_req_1 = uxr_buffer_create_participant_xml(&session_1, reliable_out_1, participant_id_1, 0, + participant_xml_1, UXR_REPLACE); + + uxrObjectId topic_id_1_1 = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml_1_1 = "" + "" + "HelloWorldTopic_1_to_2" + "HelloWorld" + "" + ""; + uint16_t topic_req_1_1 = uxr_buffer_create_topic_xml(&session_1, reliable_out_1, topic_id_1_1, participant_id_1, + topic_xml_1_1, UXR_REPLACE); + + uxrObjectId topic_id_1_2 = uxr_object_id(0x02, UXR_TOPIC_ID); + const char* topic_xml_1_2 = "" + "" + "HelloWorldTopic_2_to_1" + "HelloWorld" + "" + ""; + uint16_t topic_req_1_2 = uxr_buffer_create_topic_xml(&session_1, reliable_out_1, topic_id_1_2, participant_id_1, + topic_xml_1_2, UXR_REPLACE); uxrObjectId publisher_id_1 = uxr_object_id(0x01, UXR_PUBLISHER_ID); const char* publisher_xml_1 = ""; - uint16_t publisher_req_1 = uxr_buffer_create_publisher_xml(&session_1, reliable_out_1, publisher_id_1, participant_id_1, publisher_xml_1, UXR_REPLACE); + uint16_t publisher_req_1 = uxr_buffer_create_publisher_xml(&session_1, reliable_out_1, publisher_id_1, + participant_id_1, publisher_xml_1, UXR_REPLACE); uxrObjectId datawriter_id_1 = uxr_object_id(0x01, UXR_DATAWRITER_ID); const char* datawriter_xml_1 = "" - "" - "" - "NO_KEY" - "HelloWorldTopic_1_to_2" - "HelloWorld" - "" - "" - ""; - uint16_t datawriter_req_1 = uxr_buffer_create_datawriter_xml(&session_1, reliable_out_1, datawriter_id_1, publisher_id_1, datawriter_xml_1, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic_1_to_2" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req_1 = uxr_buffer_create_datawriter_xml(&session_1, reliable_out_1, datawriter_id_1, + publisher_id_1, datawriter_xml_1, UXR_REPLACE); uxrObjectId subscriber_id_1 = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); const char* subscriber_xml_1 = ""; - uint16_t subscriber_req_1 = uxr_buffer_create_subscriber_xml(&session_1, reliable_out_1, subscriber_id_1, participant_id_1, subscriber_xml_1, UXR_REPLACE); + uint16_t subscriber_req_1 = uxr_buffer_create_subscriber_xml(&session_1, reliable_out_1, subscriber_id_1, + participant_id_1, subscriber_xml_1, UXR_REPLACE); uxrObjectId datareader_id_1 = uxr_object_id(0x01, UXR_DATAREADER_ID); const char* datareader_xml_1 = "" - "" - "" - "NO_KEY" - "HelloWorldTopic_2_to_1" - "HelloWorld" - "" - "" - ""; - uint16_t datareader_req_1 = uxr_buffer_create_datareader_xml(&session_1, reliable_out_1, datareader_id_1, subscriber_id_1, datareader_xml_1, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic_2_to_1" + "HelloWorld" + "" + "" + ""; + uint16_t datareader_req_1 = uxr_buffer_create_datareader_xml(&session_1, reliable_out_1, datareader_id_1, + subscriber_id_1, datareader_xml_1, UXR_REPLACE); // Send create entities message and wait its status - uint8_t status_1[6]; - uint16_t requests_1[6] = {participant_req_1, topic_req_1, publisher_req_1, datawriter_req_1, subscriber_req_1, datareader_req_1}; - if(!uxr_run_session_until_all_status(&session_1, 1000, requests_1, status_1, 6)) + uint16_t requests_1[] = { + participant_req_1, topic_req_1_1, topic_req_1_2, publisher_req_1, datawriter_req_1, subscriber_req_1, + datareader_req_1 + }; + uint8_t status_1[sizeof(requests_1) / 2]; + + if (!uxr_run_session_until_all_status(&session_1, 1000, requests_1, status_1, sizeof(status_1))) { printf("Error at create entities session 1\n"); return 1; @@ -147,8 +170,7 @@ int main(int args, char** argv) // ------ SESSION 2 ------ // Transport uxrUDPTransport transport_2; - uxrUDPPlatform udp_platform_2; - if(!uxr_init_udp_transport(&transport_2, &udp_platform_2, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport_2, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -158,7 +180,7 @@ int main(int args, char** argv) uxrSession session_2; uxr_init_session(&session_2, &transport_2.comm, 0x22222222); uxr_set_topic_callback(&session_2, on_topic, NULL); - if(!uxr_create_session(&session_2)) + if (!uxr_create_session(&session_2)) { printf("Error at create session 2.\n"); return 1; @@ -166,93 +188,123 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer_2[BUFFER_SIZE]; - uxrStreamId reliable_out_2 = uxr_create_output_reliable_stream(&session_2, output_reliable_stream_buffer_2, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out_2 = uxr_create_output_reliable_stream(&session_2, output_reliable_stream_buffer_2, + BUFFER_SIZE, STREAM_HISTORY); uint8_t input_reliable_stream_buffer_2[BUFFER_SIZE]; - uxrStreamId reliable_in_2 = uxr_create_input_reliable_stream(&session_2, input_reliable_stream_buffer_2, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in_2 = uxr_create_input_reliable_stream(&session_2, input_reliable_stream_buffer_2, + BUFFER_SIZE, STREAM_HISTORY); // Create entities uxrObjectId participant_id_2 = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml_2 = "" - "" - "" - "default_xrce_participant_2" - "" - "" - ""; - uint16_t participant_req_2 = uxr_buffer_create_participant_xml(&session_2, reliable_out_2, participant_id_2, 0, participant_xml_2, UXR_REPLACE); - - uxrObjectId topic_id_2 = uxr_object_id(0x01, UXR_TOPIC_ID); - const char* topic_xml_2 = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; - uint16_t topic_req_2 = uxr_buffer_create_topic_xml(&session_2, reliable_out_2, topic_id_2, participant_id_2, topic_xml_2, UXR_REPLACE); + "" + "" + "default_xrce_participant_2" + "" + "" + ""; + uint16_t participant_req_2 = uxr_buffer_create_participant_xml(&session_2, reliable_out_2, participant_id_2, 0, + participant_xml_2, UXR_REPLACE); + + uxrObjectId topic_id_2_1 = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml_2_1 = "" + "" + "HelloWorldTopic_2_to_1" + "HelloWorld" + "" + ""; + uint16_t topic_req_2_1 = uxr_buffer_create_topic_xml(&session_2, reliable_out_2, topic_id_2_1, participant_id_2, + topic_xml_2_1, UXR_REPLACE); + + uxrObjectId topic_id_2_2 = uxr_object_id(0x02, UXR_TOPIC_ID); + const char* topic_xml_2_2 = "" + "" + "HelloWorldTopic_1_to_2" + "HelloWorld" + "" + ""; + uint16_t topic_req_2_2 = uxr_buffer_create_topic_xml(&session_2, reliable_out_2, topic_id_2_2, participant_id_2, + topic_xml_2_2, UXR_REPLACE); uxrObjectId publisher_id_2 = uxr_object_id(0x01, UXR_PUBLISHER_ID); const char* publisher_xml_2 = ""; - uint16_t publisher_req_2 = uxr_buffer_create_publisher_xml(&session_2, reliable_out_2, publisher_id_2, participant_id_2, publisher_xml_2, UXR_REPLACE); + uint16_t publisher_req_2 = uxr_buffer_create_publisher_xml(&session_2, reliable_out_2, publisher_id_2, + participant_id_2, publisher_xml_2, UXR_REPLACE); uxrObjectId datawriter_id_2 = uxr_object_id(0x01, UXR_DATAWRITER_ID); const char* datawriter_xml_2 = "" - "" - "" - "NO_KEY" - "HelloWorldTopic_2_to_1" - "HelloWorld" - "" - "" - ""; - uint16_t datawriter_req_2 = uxr_buffer_create_datawriter_xml(&session_2, reliable_out_2, datawriter_id_2, publisher_id_2, datawriter_xml_2, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic_2_to_1" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req_2 = uxr_buffer_create_datawriter_xml(&session_2, reliable_out_2, datawriter_id_2, + publisher_id_2, datawriter_xml_2, UXR_REPLACE); uxrObjectId subscriber_id_2 = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); const char* subscriber_xml_2 = ""; - uint16_t subscriber_req_2 = uxr_buffer_create_subscriber_xml(&session_2, reliable_out_2, subscriber_id_2, participant_id_2, subscriber_xml_2, UXR_REPLACE); + uint16_t subscriber_req_2 = uxr_buffer_create_subscriber_xml(&session_2, reliable_out_2, subscriber_id_2, + participant_id_2, subscriber_xml_2, UXR_REPLACE); uxrObjectId datareader_id_2 = uxr_object_id(0x01, UXR_DATAREADER_ID); const char* datareader_xml_2 = "" - "" - "" - "NO_KEY" - "HelloWorldTopic_1_to_2" - "HelloWorld" - "" - "" - ""; - uint16_t datareader_req_2 = uxr_buffer_create_datareader_xml(&session_2, reliable_out_2, datareader_id_2, subscriber_id_2, datareader_xml_2, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic_1_to_2" + "HelloWorld" + "" + "" + ""; + uint16_t datareader_req_2 = uxr_buffer_create_datareader_xml(&session_2, reliable_out_2, datareader_id_2, + subscriber_id_2, datareader_xml_2, UXR_REPLACE); // Send create entities message and wait its status - uint8_t status_2[6]; - uint16_t requests_2[6] = {participant_req_2, topic_req_2, publisher_req_2, datawriter_req_2, subscriber_req_2, datareader_req_2}; - if(!uxr_run_session_until_all_status(&session_2, 1000, requests_2, status_2, 6)) + uint16_t requests_2[] = { + participant_req_2, topic_req_2_1, topic_req_2_2, publisher_req_2, datawriter_req_2, subscriber_req_2, + datareader_req_2 + }; + uint8_t status_2[sizeof(requests_2) / 2]; + + if (!uxr_run_session_until_all_status(&session_2, 1000, requests_2, status_2, sizeof(status_2))) { printf("Error at create entities session 2\n"); return 1; - } + } // Request topics of both sessions - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; - uint16_t read_data_req_1 = uxr_buffer_request_data(&session_1, reliable_out_1, datareader_id_1, reliable_in_1, &delivery_control); - uint16_t read_data_req_2 = uxr_buffer_request_data(&session_2, reliable_out_2, datareader_id_2, reliable_in_2, &delivery_control); + uint16_t read_data_req_1 = uxr_buffer_request_data(&session_1, reliable_out_1, datareader_id_1, reliable_in_1, + &delivery_control); + uint16_t read_data_req_2 = uxr_buffer_request_data(&session_2, reliable_out_2, datareader_id_2, reliable_in_2, + &delivery_control); // Write topics uint32_t count = 0; bool connected = true; - while(connected) - { + while (connected) + { // Session 1 publication - HelloWorld topic_1 = {count, "Publisher 1 says hello"}; + HelloWorld topic_1 = { + count, "Publisher 1 says hello" + }; ucdrBuffer ub_1; uint32_t topic_size_1 = HelloWorld_size_of_topic(&topic_1, 0); uxr_prepare_output_stream(&session_1, reliable_out_1, datawriter_id_1, &ub_1, topic_size_1); HelloWorld_serialize_topic(&ub_1, &topic_1); // Session 2 publication - HelloWorld topic_2 = {count, "Publisher 2 says hello"}; + HelloWorld topic_2 = { + count, "Publisher 2 says hello" + }; ucdrBuffer ub_2; uint32_t topic_size_2 = HelloWorld_size_of_topic(&topic_2, 0); uxr_prepare_output_stream(&session_2, reliable_out_2, datawriter_id_2, &ub_2, topic_size_2); diff --git a/examples/PingAgent/CMakeLists.txt b/examples/PingAgent/CMakeLists.txt new file mode 100644 index 000000000..3f3c57140 --- /dev/null +++ b/examples/PingAgent/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +add_subdirectory(UDP) +add_subdirectory(TCP) +add_subdirectory(Serial) diff --git a/examples/PingAgent/Serial/CMakeLists.txt b/examples/PingAgent/Serial/CMakeLists.txt new file mode 100644 index 000000000..4d6ab8d67 --- /dev/null +++ b/examples/PingAgent/Serial/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(PingAgentSerial) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_SERIAL) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_SERIAL must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/PingAgent/Serial/main.c b/examples/PingAgent/Serial/main.c new file mode 100644 index 000000000..c5d12be9e --- /dev/null +++ b/examples/PingAgent/Serial/main.c @@ -0,0 +1,61 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include // O_RDWR, O_NOCTTY, O_NONBLOCK +#include + +int main( + int argc, + char** argv) +{ +#ifdef WIN32 + printf("Sorry, this example is not available for Windows platforms."); + return 0; +#else + // CLI + if (2 != argc) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + char* dev = argv[1]; + + uxrSerialTransport transport; + int fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK); + + + if (!uxr_init_serial_transport(&transport, fd, 0, 1)) + { + printf("Error during transport creation\n"); + return 1; + } + + if (uxr_ping_agent_attempts(&transport.comm, 1000, 10)) + { + printf("Success! Agent is up on device '%s'\n", dev); + } + else + { + printf("Sorry, no agent available at device '%s'\n", dev); + } + + uxr_close_serial_transport(&transport); + + return 0; +#endif // WIN32 +} \ No newline at end of file diff --git a/examples/PingAgent/TCP/CMakeLists.txt b/examples/PingAgent/TCP/CMakeLists.txt new file mode 100644 index 000000000..9b6e342a4 --- /dev/null +++ b/examples/PingAgent/TCP/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(PingAgentTCP) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_TCP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_TCP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/PingAgent/TCP/main.c b/examples/PingAgent/TCP/main.c new file mode 100644 index 000000000..791921909 --- /dev/null +++ b/examples/PingAgent/TCP/main.c @@ -0,0 +1,54 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include + +int main( + int argc, + char** argv) +{ + // CLI + if (3 != argc) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + char* ip = argv[1]; + char* port = argv[2]; + + uxrTCPTransport transport; + + if (!uxr_init_tcp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error during transport creation\n"); + return 1; + } + + if (uxr_ping_agent_attempts(&transport.comm, 1000, 10)) + { + printf("Success! Agent is up on %s:%s\n", ip, port); + } + else + { + printf("Sorry, no agent available at %s:%s\n", ip, port); + } + + uxr_close_tcp_transport(&transport); + + return 0; +} \ No newline at end of file diff --git a/examples/PingAgent/UDP/CMakeLists.txt b/examples/PingAgent/UDP/CMakeLists.txt new file mode 100644 index 000000000..6ecf9b4c2 --- /dev/null +++ b/examples/PingAgent/UDP/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(PingAgentUDP) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/PingAgent/UDP/main.c b/examples/PingAgent/UDP/main.c new file mode 100644 index 000000000..08f3db91a --- /dev/null +++ b/examples/PingAgent/UDP/main.c @@ -0,0 +1,54 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include + +int main( + int argc, + char** argv) +{ + // CLI + if (3 != argc) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + char* ip = argv[1]; + char* port = argv[2]; + + uxrUDPTransport transport; + + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error during transport creation\n"); + return 1; + } + + if (uxr_ping_agent_attempts(&transport.comm, 1000, 10)) + { + printf("Success! Agent is up on %s:%s\n", ip, port); + } + else + { + printf("Sorry, no agent available at %s:%s\n", ip, port); + } + + uxr_close_udp_transport(&transport); + + return 0; +} \ No newline at end of file diff --git a/examples/PublishHelloWorld/CMakeLists.txt b/examples/PublishHelloWorld/CMakeLists.txt index e4fb80746..a003d21c7 100644 --- a/examples/PublishHelloWorld/CMakeLists.txt +++ b/examples/PublishHelloWorld/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c HelloWorld.c) if(MSVC OR MSVC_IDE) diff --git a/examples/PublishHelloWorld/HelloWorld.c b/examples/PublishHelloWorld/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/PublishHelloWorld/HelloWorld.c +++ b/examples/PublishHelloWorld/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/PublishHelloWorld/HelloWorld.h b/examples/PublishHelloWorld/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/PublishHelloWorld/HelloWorld.h +++ b/examples/PublishHelloWorld/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/PublishHelloWorld/README.md b/examples/PublishHelloWorld/README.md index 7b4fd19b9..e5e3280b6 100644 --- a/examples/PublishHelloWorld/README.md +++ b/examples/PublishHelloWorld/README.md @@ -1,15 +1,16 @@ # PublishHelloWorld example This example will show how to send data to the DDS World creating a client publisher. -In order to compile this example, it is necessary to have the following profiles enabled in `client.config` file: +In order to compile this example, the following profiles should be enabled: -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *SubscriberHelloWorld* example or some subscriber that can read the *HelloWorld* topic. 3. Run the *PublisherHelloWorld* example. - The example can be parameterized with the number of topics that will be sent. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the number of topics that will be sent. + If no number is given, the subscriber will listen indefinitely. ## Topic diff --git a/examples/PublishHelloWorld/main.c b/examples/PublishHelloWorld/main.c index aeed1679a..f1ae81c9b 100644 --- a/examples/PublishHelloWorld/main.c +++ b/examples/PublishHelloWorld/main.c @@ -22,12 +22,14 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port []\n"); return 0; @@ -39,8 +41,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -49,7 +50,7 @@ int main(int args, char** argv) // Session uxrSession session; uxr_init_session(&session, &transport.comm, 0xAAAABBBB); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -57,7 +58,8 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); @@ -65,54 +67,63 @@ int main(int args, char** argv) // Create entities uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, participant_xml, UXR_REPLACE); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); const char* topic_xml = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; - uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, UXR_REPLACE); + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); const char* publisher_xml = ""; - uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, publisher_xml, UXR_REPLACE); + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); const char* datawriter_xml = "" - "" - "" - "NO_KEY" - "HelloWorldTopic" - "HelloWorld" - "" - "" - ""; - uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, datawriter_xml, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[4]; - uint16_t requests[4] = {participant_req, topic_req, publisher_req, datawriter_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) { - printf("Error at create entities: participant: %i topic: %i publisher: %i darawriter: %i\n", status[0], status[1], status[2], status[3]); + printf("Error at create entities: participant: %i topic: %i publisher: %i datawriter: %i\n", status[0], + status[1], status[2], status[3]); return 1; } // Write topics bool connected = true; uint32_t count = 0; - while(connected && count < max_topics) + while (connected && count < max_topics) { - HelloWorld topic = {++count, "Hello DDS world!"}; + HelloWorld topic = { + ++count, "Hello DDS world!" + }; ucdrBuffer ub; uint32_t topic_size = HelloWorld_size_of_topic(&topic, 0); diff --git a/examples/PublishHelloWorldBestEffort/CMakeLists.txt b/examples/PublishHelloWorldBestEffort/CMakeLists.txt new file mode 100644 index 000000000..00d14a1b0 --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(PublishHelloWorldClientBestEffort) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c HelloWorld.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/PublishHelloWorldBestEffort/HelloWorld.c b/examples/PublishHelloWorldBestEffort/HelloWorld.c new file mode 100644 index 000000000..6461b04cf --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/HelloWorld.c @@ -0,0 +1,59 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.c + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#include "HelloWorld.h" + +#include +#include + +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) +{ + (void) ucdr_serialize_uint32_t(writer, topic->index); + + (void) ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) +{ + (void) ucdr_deserialize_uint32_t(reader, &topic->index); + + (void) ucdr_deserialize_string(reader, topic->message, 255); + + return !reader->error; +} + +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) +{ + uint32_t previousSize = size; + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + 1); + + return size - previousSize; +} diff --git a/examples/PublishHelloWorldBestEffort/HelloWorld.h b/examples/PublishHelloWorldBestEffort/HelloWorld.h new file mode 100644 index 000000000..07079a01f --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/HelloWorld.h @@ -0,0 +1,61 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _HelloWorld_H_ +#define _HelloWorld_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include + +/*! + * @brief This struct represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +typedef struct HelloWorld +{ + uint32_t index; + char message[255]; + +} HelloWorld; + +struct ucdrBuffer; + +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // _HelloWorld_H_ diff --git a/examples/PublishHelloWorldBestEffort/HelloWorld.idl b/examples/PublishHelloWorldBestEffort/HelloWorld.idl new file mode 100644 index 000000000..0fd2c355a --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/examples/PublishHelloWorldBestEffort/README.md b/examples/PublishHelloWorldBestEffort/README.md new file mode 100644 index 000000000..dce084701 --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/README.md @@ -0,0 +1,26 @@ +# PublishHelloWorldBestEffort example + +This example will show how to send data to the DDS World creating a client publisher in best effort mode. +In order to compile this example, the following profiles should be enabled: + +- `UCLIENT_PROFILE_UDP` + +## Usage +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. +2. Run the *SubscribeHelloWorldBestEffort* example or some subscriber that can read the *HelloWorld* topic. +3. Run the *PublishHelloWorldBestEffort* example. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the number of topics that will be sent. + + If no number is given, the publisher will send data indefinitely. + +## Topic + +The *HelloWorld* topic has the following *IDL* representation: + +``` +struct HelloWorld +{ + unsigned long index; + string message; +}; +``` diff --git a/examples/PublishHelloWorldBestEffort/main.c b/examples/PublishHelloWorldBestEffort/main.c new file mode 100644 index 000000000..ace94d726 --- /dev/null +++ b/examples/PublishHelloWorldBestEffort/main.c @@ -0,0 +1,146 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "HelloWorld.h" + +#include +#include + +#include //printf +#include //strcmp +#include //atoi + +#define STREAM_HISTORY 8 +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY + +int main( + int args, + char** argv) +{ + // CLI + if (3 > args || 0 == atoi(argv[2])) + { + printf("usage: program [-h | --help] | ip port []\n"); + return 0; + } + + char* ip = argv[1]; + char* port = argv[2]; + uint32_t max_topics = (args == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; + + // Transport + uxrUDPTransport transport; + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xAAAABBBB); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + + uint8_t output_besteffort_stream_buffer[BUFFER_SIZE]; + uxrStreamId besteffort_out = uxr_create_output_best_effort_stream(&session, output_besteffort_stream_buffer, + BUFFER_SIZE); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + + uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); + const char* publisher_xml = ""; + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); + + uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); + const char* datawriter_xml = "" + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); + + // Send create entities message and wait its status + uint8_t status[4]; + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %i topic: %i publisher: %i darawriter: %i\n", status[0], + status[1], status[2], status[3]); + return 1; + } + + // Write topics + bool connected = true; + uint32_t count = 0; + while (connected && count < max_topics) + { + HelloWorld topic = { + ++count, "Hello DDS world!" + }; + + ucdrBuffer ub; + uint32_t topic_size = HelloWorld_size_of_topic(&topic, 0); + uxr_prepare_output_stream(&session, besteffort_out, datawriter_id, &ub, topic_size); + HelloWorld_serialize_topic(&ub, &topic); + + printf("Send topic: %s, id: %i\n", topic.message, topic.index); + connected = uxr_run_session_time(&session, 1000); + } + + // Delete resources + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +} diff --git a/examples/PublishHelloWorldP2P/CMakeLists.txt b/examples/PublishHelloWorldP2P/CMakeLists.txt index b8aa4c3bb..011149dba 100644 --- a/examples/PublishHelloWorldP2P/CMakeLists.txt +++ b/examples/PublishHelloWorldP2P/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c HelloWorld.c) if(MSVC OR MSVC_IDE) diff --git a/examples/PublishHelloWorldP2P/HelloWorld.c b/examples/PublishHelloWorldP2P/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/PublishHelloWorldP2P/HelloWorld.c +++ b/examples/PublishHelloWorldP2P/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/PublishHelloWorldP2P/HelloWorld.h b/examples/PublishHelloWorldP2P/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/PublishHelloWorldP2P/HelloWorld.h +++ b/examples/PublishHelloWorldP2P/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/PublishHelloWorldP2P/README.md b/examples/PublishHelloWorldP2P/README.md index 01dbd8396..2d37a08e8 100644 --- a/examples/PublishHelloWorldP2P/README.md +++ b/examples/PublishHelloWorldP2P/README.md @@ -1,15 +1,16 @@ # PublishHelloWorldP2P example This example will show how to publish data creating a client publisher. -It is necessary to have the following profiles enabled in `client.config` file to compile this example: +It is necessary to have the following profiles enabled to compile this example: -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *SubscriberHelloWorldP2P* example or some subscriber that can read the *HelloWorld* topic. 3. Run the *PublisherHelloWorldP2P* example. - The example can be parameterized with the number of topics that will be sent. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the number of topics that will be sent. + If no number is given, the subscriber will listen indefinitely. ## Topic diff --git a/examples/PublishHelloWorldP2P/main.c b/examples/PublishHelloWorldP2P/main.c index 1b0383b33..58eee2966 100644 --- a/examples/PublishHelloWorldP2P/main.c +++ b/examples/PublishHelloWorldP2P/main.c @@ -22,12 +22,14 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port []\n"); return 0; @@ -39,8 +41,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -49,7 +50,7 @@ int main(int args, char** argv) // Session uxrSession session; uxr_init_session(&session, &transport.comm, 0xAAAABBBB); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -57,7 +58,8 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); @@ -65,35 +67,44 @@ int main(int args, char** argv) // Create entities uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_ref = "participant_name"; - uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, participant_ref, UXR_REPLACE); + uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, + participant_ref, UXR_REPLACE); uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); const char* topic_ref = "topic_name"; - uint16_t topic_req = uxr_buffer_create_topic_ref(&session, reliable_out, topic_id, participant_id, topic_ref, UXR_REPLACE); + uint16_t topic_req = uxr_buffer_create_topic_ref(&session, reliable_out, topic_id, participant_id, topic_ref, + UXR_REPLACE); uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); const char* publisher_xml = ""; - uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, publisher_xml, UXR_REPLACE); + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); const char* datawriter_ref = topic_ref; - uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, datawriter_ref, UXR_REPLACE); + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_ref, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[4]; - uint16_t requests[4] = {participant_req, topic_req, publisher_req, datawriter_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + uint16_t requests[4] = { + participant_req, topic_req, publisher_req, datawriter_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) { - printf("Error at create entities: participant: %i topic: %i publisher: %i darawriter: %i\n", status[0], status[1], status[2], status[3]); + printf("Error at create entities: participant: %i topic: %i publisher: %i datawriter: %i\n", status[0], + status[1], status[2], status[3]); return 1; } // Write topics bool connected = true; uint32_t count = 0; - while(connected && count < max_topics) + while (connected && count < max_topics) { - HelloWorld topic = {++count, "Hello DDS world!"}; + HelloWorld topic = { + ++count, "Hello DDS world!" + }; ucdrBuffer ub; uint32_t topic_size = HelloWorld_size_of_topic(&topic, 0); diff --git a/examples/ReplyAdder/CMakeLists.txt b/examples/ReplyAdder/CMakeLists.txt index 0d923ac23..4adde8d2a 100644 --- a/examples/ReplyAdder/CMakeLists.txt +++ b/examples/ReplyAdder/CMakeLists.txt @@ -16,8 +16,8 @@ cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) project(ReplyAdder) -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: the PROFILE_UDP_TRANSPORT must be enables.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: the UCLIENT_PROFILE_UDP must be enables.") else() add_executable(${PROJECT_NAME} main.c) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/examples/ReplyAdder/main.c b/examples/ReplyAdder/main.c index 3c5d3938f..501e689d0 100644 --- a/examples/ReplyAdder/main.c +++ b/examples/ReplyAdder/main.c @@ -20,7 +20,7 @@ #include #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY static uxrStreamId reliable_out; static uxrStreamId reliable_in; @@ -48,7 +48,9 @@ void on_request( printf("Request received: (%d + %d)\n", rhs, lhs); - uint8_t reply_buffer[8] = {0}; + uint8_t reply_buffer[8] = { + 0 + }; ucdrBuffer reply_ub; ucdr_init_buffer(&reply_ub, reply_buffer, sizeof(reply_buffer)); ucdr_serialize_uint64_t(&reply_ub, rhs + lhs); @@ -59,12 +61,14 @@ void on_request( printf("Reply send: %I64u\n", (uint64_t)(rhs + lhs)); #else printf("Reply send: %" PRIu64 "\n", (uint64_t)(rhs + lhs)); -#endif +#endif /* ifdef WIN32 */ } -int main(int args, char** argv) +int main( + int args, + char** argv) { - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port [key]\n"); return 0; @@ -76,8 +80,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if (!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at init transport.\n"); return 1; @@ -95,7 +98,8 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); @@ -103,37 +107,44 @@ int main(int args, char** argv) // Create entities participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, participant_xml, UXR_REPLACE); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); replier_id = uxr_object_id(0x01, UXR_REPLIER_ID); const char* replier_xml = "" - "" - "" - ""; - uint16_t replier_req = uxr_buffer_create_replier_xml(&session, reliable_out, replier_id, participant_id, replier_xml, UXR_REPLACE); + "" + "" + ""; + uint16_t replier_req = uxr_buffer_create_replier_xml(&session, reliable_out, replier_id, participant_id, + replier_xml, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[2]; - uint16_t requests[2] = {participant_req, replier_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 2)) + uint16_t requests[2] = { + participant_req, replier_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 2)) { printf("Error at create entities: participant: %i requester: %i\n", status[0], status[1]); return 1; } // Request requests - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; - uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, replier_id, reliable_in, &delivery_control); + uint16_t read_data_req = + uxr_buffer_request_data(&session, reliable_out, replier_id, reliable_in, &delivery_control); // Read request bool connected = true; diff --git a/examples/RequestAdder/CMakeLists.txt b/examples/RequestAdder/CMakeLists.txt index 9d0552c82..a4a9c71da 100644 --- a/examples/RequestAdder/CMakeLists.txt +++ b/examples/RequestAdder/CMakeLists.txt @@ -16,8 +16,8 @@ cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) project(RequestAdder) -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: the PROFILE_UDP_TRANSPORT must be enables.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: the UCLIENT_PROFILE_UDP must be enables.") else() add_executable(${PROJECT_NAME} main.c) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/examples/RequestAdder/main.c b/examples/RequestAdder/main.c index 160f94ce8..f9364bccb 100644 --- a/examples/RequestAdder/main.c +++ b/examples/RequestAdder/main.c @@ -20,7 +20,7 @@ #include #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY void on_reply( uxrSession* session, @@ -42,12 +42,14 @@ void on_reply( printf("Reply received: %I64u [id: %d]\n", result, reply_id); #else printf("Reply received: %" PRIu64 " [id: %d]\n", result, reply_id); -#endif +#endif /* ifdef WIN32 */ } -int main(int args, char** argv) +int main( + int args, + char** argv) { - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port [key]\n"); return 0; @@ -59,8 +61,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if (!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at init transport.\n"); return 1; @@ -78,52 +79,63 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); // Create entities uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, participant_xml, UXR_REPLACE); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); uxrObjectId requester_id = uxr_object_id(0x01, UXR_REQUESTER_ID); const char* requester_xml = "" - "" - "" - ""; - uint16_t requester_req = uxr_buffer_create_requester_xml(&session, reliable_out, requester_id, participant_id, requester_xml, UXR_REPLACE); + "" + "" + ""; + uint16_t requester_req = uxr_buffer_create_requester_xml(&session, reliable_out, requester_id, participant_id, + requester_xml, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[2]; - uint16_t requests[2] = {participant_req, requester_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 2)) + uint16_t requests[2] = { + participant_req, requester_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 2)) { printf("Error at create entities: participant: %i requester: %i\n", status[0], status[1]); return 1; } // Request replies - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; - uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, requester_id, reliable_in, &delivery_control); + uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, requester_id, reliable_in, + &delivery_control); // Write requests bool connected = true; uint32_t count = 0; while (connected) { - uint8_t request[2 * 4] = {0}; + uint8_t request[2 * 4] = { + 0 + }; ucdrBuffer ub; ucdr_init_buffer(&ub, request, sizeof(request)); diff --git a/examples/ShapesDemo/CMakeLists.txt b/examples/ShapesDemo/CMakeLists.txt index f6e2c05d5..3fd424c18 100644 --- a/examples/ShapesDemo/CMakeLists.txt +++ b/examples/ShapesDemo/CMakeLists.txt @@ -23,10 +23,10 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT OR - NOT PROFILE_TCP_TRANSPORT OR - NOT PROFILE_SERIAL_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT, PROFILE_TCP_TRANSPORT and PROFILE_SERIAL_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP OR + NOT UCLIENT_PROFILE_TCP OR + NOT UCLIENT_PROFILE_SERIAL) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP, UCLIENT_PROFILE_TCP and UCLIENT_PROFILE_SERIAL must be enabled.") else() add_executable(${PROJECT_NAME} main.c ShapeType.c) if(MSVC OR MSVC_IDE) diff --git a/examples/ShapesDemo/ShapeType.c b/examples/ShapesDemo/ShapeType.c index adf631ad5..a50045462 100644 --- a/examples/ShapesDemo/ShapeType.c +++ b/examples/ShapesDemo/ShapeType.c @@ -24,7 +24,9 @@ #include #include -bool ShapeType_serialize_topic(ucdrBuffer* writer, const ShapeType* topic) +bool ShapeType_serialize_topic( + ucdrBuffer* writer, + const ShapeType* topic) { (void) ucdr_serialize_string(writer, topic->color); @@ -37,7 +39,9 @@ bool ShapeType_serialize_topic(ucdrBuffer* writer, const ShapeType* topic) return !writer->error; } -bool ShapeType_deserialize_topic(ucdrBuffer* reader, ShapeType* topic) +bool ShapeType_deserialize_topic( + ucdrBuffer* reader, + ShapeType* topic) { (void) ucdr_deserialize_string(reader, topic->color, 255); @@ -50,7 +54,9 @@ bool ShapeType_deserialize_topic(ucdrBuffer* reader, ShapeType* topic) return !reader->error; } -uint32_t ShapeType_size_of_topic(const ShapeType* topic, uint32_t size) +uint32_t ShapeType_size_of_topic( + const ShapeType* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->color) + 1); diff --git a/examples/ShapesDemo/ShapeType.h b/examples/ShapesDemo/ShapeType.h index beca5408c..d52591a58 100644 --- a/examples/ShapesDemo/ShapeType.h +++ b/examples/ShapesDemo/ShapeType.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -45,13 +45,19 @@ typedef struct ShapeType struct ucdrBuffer; -bool ShapeType_serialize_topic(struct ucdrBuffer* writer, const ShapeType* topic); -bool ShapeType_deserialize_topic(struct ucdrBuffer* reader, ShapeType* topic); -uint32_t ShapeType_size_of_topic(const ShapeType* topic, uint32_t size); +bool ShapeType_serialize_topic( + struct ucdrBuffer* writer, + const ShapeType* topic); +bool ShapeType_deserialize_topic( + struct ucdrBuffer* reader, + ShapeType* topic); +uint32_t ShapeType_size_of_topic( + const ShapeType* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _ShapeType_H_ diff --git a/examples/ShapesDemo/main.c b/examples/ShapesDemo/main.c index 23f268b3a..e420bf2ce 100644 --- a/examples/ShapesDemo/main.c +++ b/examples/ShapesDemo/main.c @@ -29,7 +29,7 @@ #include #else #include -#endif +#endif /* ifdef _WIN32 */ // Colors for highlight the print #define GREEN_CONSOLE_COLOR "\x1B[1;32m" @@ -37,49 +37,88 @@ #define RESTORE_COLOR "\x1B[0m" // Getting the max MTU at compile time. -#define MAX_UDP_TCP_MTU ((UXR_CONFIG_UDP_TRANSPORT_MTU > UXR_CONFIG_TCP_TRANSPORT_MTU) ? UXR_CONFIG_UDP_TRANSPORT_MTU : UXR_CONFIG_UDP_TRANSPORT_MTU) -#define MAX_TRANSPORT_MTU ((UXR_CONFIG_SERIAL_TRANSPORT_MTU > MAX_UDP_TCP_MTU) ? UXR_CONFIG_SERIAL_TRANSPORT_MTU : MAX_UDP_TCP_MTU) +#define MAX_UDP_TCP_MTU ((UXR_CONFIG_UDP_TRANSPORT_MTU > \ + UXR_CONFIG_TCP_TRANSPORT_MTU) ? UXR_CONFIG_UDP_TRANSPORT_MTU : UXR_CONFIG_UDP_TRANSPORT_MTU) +#define MAX_TRANSPORT_MTU ((UXR_CONFIG_SERIAL_TRANSPORT_MTU > \ + MAX_UDP_TCP_MTU) ? UXR_CONFIG_SERIAL_TRANSPORT_MTU : MAX_UDP_TCP_MTU) // Stream buffers #define MAX_HISTORY 16 -#define MAX_BUFFER_SIZE MAX_TRANSPORT_MTU * MAX_HISTORY +#define MAX_BUFFER_SIZE MAX_TRANSPORT_MTU* MAX_HISTORY static int shapes_demo_error = 0; -static bool run_command(const char* command, uxrSession* session, uxrStreamId* stream_id); -static bool compute_command(uxrSession* session, uxrStreamId* stream_id, int length, const char* name, - uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, const char* topic_color); -static bool compute_print_command(uxrSession* session, uxrStreamId* stream_id, int length, const char* name, - uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, const char* topic_color); -static void on_topic(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uxrStreamId stream_id, struct ucdrBuffer* serialization, uint16_t length, void* args); -static void on_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status, void* args); -static void print_ShapeType_topic(const ShapeType* topic); -static void print_status(uint8_t status); -static void print_help(void); -static void print_commands(void); -static int check_input(void); - -int main(int args, char** argv) +static bool run_command( + const char* command, + uxrSession* session, + uxrStreamId* stream_id); +static bool compute_command( + uxrSession* session, + uxrStreamId* stream_id, + int length, + const char* name, + uint32_t arg1, + uint32_t arg2, + uint32_t arg3, + uint32_t arg4, + uint32_t arg5, + const char* topic_color); +static bool compute_print_command( + uxrSession* session, + uxrStreamId* stream_id, + int length, + const char* name, + uint32_t arg1, + uint32_t arg2, + uint32_t arg3, + uint32_t arg4, + uint32_t arg5, + const char* topic_color); +static void on_topic( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* serialization, + uint16_t length, + void* args); +static void on_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status, + void* args); +static void print_ShapeType_topic( + const ShapeType* topic); +static void print_status( + uint8_t status); +static void print_help( + void); +static void print_commands( + void); +static int check_input( + void); + +int main( + int args, + char** argv) { uxrSession session; #if !defined(WIN32) uxrSerialTransport serial; - uxrSerialPlatform serial_platform; -#endif +#endif /* if !defined(WIN32) */ uxrUDPTransport udp; - uxrUDPPlatform udp_platform; uxrTCPTransport tcp; - uxrTCPPlatform tcp_platform; uxrCommunication* comm; int args_index = 0; - if(args >= 4 && strcmp(argv[1], "--udp4") == 0) + if (args >= 4 && strcmp(argv[1], "--udp4") == 0) { char* ip = argv[2]; char* port = argv[3]; - if(!uxr_init_udp_transport(&udp, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&udp, UXR_IPv4, ip, port)) { printf("%sCan not create an udp connection%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); return 1; @@ -88,11 +127,11 @@ int main(int args, char** argv) printf("Running in UDP/IPv4 mode => ip: %s, port: %s\n", ip, port); args_index = 4; } - else if(args >= 4 && strcmp(argv[1], "--udp6") == 0) + else if (args >= 4 && strcmp(argv[1], "--udp6") == 0) { char* ip = argv[2]; char* port = argv[3]; - if(!uxr_init_udp_transport(&udp, &udp_platform, UXR_IPv6, ip, port)) + if (!uxr_init_udp_transport(&udp, UXR_IPv6, ip, port)) { printf("%sCan not create an udp connection%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); return 1; @@ -101,11 +140,11 @@ int main(int args, char** argv) printf("Running in UDP/IPv6 mode => ip: %s, port: %s\n", ip, port); args_index = 4; } - else if(args >= 4 && strcmp(argv[1], "--tcp4") == 0) + else if (args >= 4 && strcmp(argv[1], "--tcp4") == 0) { char* ip = argv[2]; char* port = argv[3]; - if(!uxr_init_tcp_transport(&tcp, &tcp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_tcp_transport(&tcp, UXR_IPv4, ip, port)) { printf("%sCan not create a tcp connection%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); return 1; @@ -114,11 +153,11 @@ int main(int args, char** argv) printf("Running TCP mode => ip: %s, port: %s\n", ip, port); args_index = 4; } - else if(args >= 4 && strcmp(argv[1], "--tcp6") == 0) + else if (args >= 4 && strcmp(argv[1], "--tcp6") == 0) { char* ip = argv[2]; char* port = argv[3]; - if(!uxr_init_tcp_transport(&tcp, &tcp_platform, UXR_IPv6, ip, port)) + if (!uxr_init_tcp_transport(&tcp, UXR_IPv6, ip, port)) { printf("%sCan not create a tcp connection%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); return 1; @@ -128,11 +167,11 @@ int main(int args, char** argv) args_index = 4; } #if !defined(WIN32) - else if(args >= 3 && strcmp(argv[1], "--serial") == 0) + else if (args >= 3 && strcmp(argv[1], "--serial") == 0) { char* device = argv[2]; int fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); - if(!uxr_init_serial_transport(&serial, &serial_platform, fd, 0, 1)) + if (!uxr_init_serial_transport(&serial, fd, 0, 1)) { printf("%sCan not create a serial connection%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); return 1; @@ -141,7 +180,7 @@ int main(int args, char** argv) printf("Running in serial mode => dev: %s\n", device); args_index = 3; } -#endif +#endif /* if !defined(WIN32) */ else { print_help(); @@ -149,9 +188,9 @@ int main(int args, char** argv) } uint32_t key = 0xAABBCCDD; - if(args_index < args && 0 == strcmp(argv[args_index++], "--key")) + if (args_index < args && 0 == strcmp(argv[args_index++], "--key")) { - if(args_index < args) + if (args_index < args) { key = atoi(argv[args_index++]); } @@ -162,12 +201,12 @@ int main(int args, char** argv) } uint16_t history = 8; - if(args_index < args && 0 == strcmp(argv[args_index++], "--history")) + if (args_index < args && 0 == strcmp(argv[args_index++], "--history")) { - if(args_index < args) + if (args_index < args) { size_t request_history = atoi(argv[args_index++]); - if(MAX_HISTORY >= request_history) + if (MAX_HISTORY >= request_history) { history = (uint16_t)request_history; } @@ -187,21 +226,24 @@ int main(int args, char** argv) uint8_t output_reliable_stream_buffer[MAX_BUFFER_SIZE * UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS]; uint8_t input_reliable_stream_buffer[MAX_BUFFER_SIZE * UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS]; - for(int i = 0; i < UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS; ++i) + for (int i = 0; i < UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS; ++i) { - (void) uxr_create_output_best_effort_stream(&session, output_best_effort_stream_buffer + MAX_TRANSPORT_MTU * i, comm->mtu); + (void) uxr_create_output_best_effort_stream(&session, output_best_effort_stream_buffer + MAX_TRANSPORT_MTU * i, + comm->mtu); } - for(int i = 0; i < UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS; ++i) + for (int i = 0; i < UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS; ++i) { (void) uxr_create_input_best_effort_stream(&session); } - for(int i = 0; i < UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS; ++i) + for (int i = 0; i < UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS; ++i) { - (void) uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer + MAX_BUFFER_SIZE * i, comm->mtu * history, history); + (void) uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer + MAX_BUFFER_SIZE * i, + comm->mtu * history, history); } - for(int i = 0; i < UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS; ++i) + for (int i = 0; i < UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS; ++i) { - (void) uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer + MAX_BUFFER_SIZE * i, comm->mtu * history, history); + (void) uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer + MAX_BUFFER_SIZE * i, + comm->mtu * history, history); } uxrStreamId default_output = uxr_stream_id(0, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); @@ -219,25 +261,28 @@ int main(int args, char** argv) } } - if(&udp.comm == comm) + if (&udp.comm == comm) { uxr_close_udp_transport(&udp); } - else if(&tcp.comm == comm) + else if (&tcp.comm == comm) { uxr_close_tcp_transport(&tcp); } #if !defined(WIN32) - else if(&serial.comm == comm) + else if (&serial.comm == comm) { uxr_close_serial_transport(&serial); } -#endif +#endif /* if !defined(WIN32) */ return shapes_demo_error; } -bool run_command(const char* command, uxrSession* session, uxrStreamId* stream_id) +bool run_command( + const char* command, + uxrSession* session, + uxrStreamId* stream_id) { char name[128]; uint32_t arg1 = 0; @@ -247,7 +292,7 @@ bool run_command(const char* command, uxrSession* session, uxrStreamId* stream_i uint32_t arg5 = 0; char topic_color[128] = ""; int length = sscanf(command, "%s %u %u %u %u %u %s", name, &arg1, &arg2, &arg3, &arg4, &arg5, topic_color); - if(length == 7 && topic_color[0] == '\0') + if (length == 7 && topic_color[0] == '\0') { length = length - 1; //some implementations of sscanfs add 1 to length if color is empty. } @@ -255,59 +300,70 @@ bool run_command(const char* command, uxrSession* session, uxrStreamId* stream_i return compute_command(session, stream_id, length, name, arg1, arg2, arg3, arg4, arg5, topic_color); } -bool compute_command(uxrSession* session, uxrStreamId* stream_id, int length, const char* name, - uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, const char* topic_color) +bool compute_command( + uxrSession* session, + uxrStreamId* stream_id, + int length, + const char* name, + uint32_t arg1, + uint32_t arg2, + uint32_t arg3, + uint32_t arg4, + uint32_t arg5, + const char* topic_color) { - if(0 == strcmp(name, "create_session") && 1 == length) + if (0 == strcmp(name, "create_session") && 1 == length) { (void) uxr_create_session(session); print_status(session->info.last_requested_status); } - else if(0 == strcmp(name, "create_participant") && 2 == length) + else if (0 == strcmp(name, "create_participant") && 2 == length) { uxrObjectId participant_id = uxr_object_id((uint16_t)arg1, UXR_PARTICIPANT_ID); const char* participant_ref = "default_xrce_participant"; (void) uxr_buffer_create_participant_ref(session, *stream_id, participant_id, 0, participant_ref, 0); } - else if(0 == strcmp(name, "create_topic") && 3 == length) + else if (0 == strcmp(name, "create_topic") && 3 == length) { uxrObjectId topic_id = uxr_object_id((uint16_t)arg1, UXR_TOPIC_ID); uxrObjectId participant_id = uxr_object_id((uint16_t)arg2, UXR_PARTICIPANT_ID); const char* topic_ref = "shapetype_topic"; (void) uxr_buffer_create_topic_ref(session, *stream_id, topic_id, participant_id, topic_ref, 0); } - else if(0 == strcmp(name, "create_publisher") && 3 == length) + else if (0 == strcmp(name, "create_publisher") && 3 == length) { uxrObjectId publisher_id = uxr_object_id((uint16_t)arg1, UXR_PUBLISHER_ID); uxrObjectId participant_id = uxr_object_id((uint16_t)arg2, UXR_PARTICIPANT_ID); const char* publisher_xml = ""; (void) uxr_buffer_create_publisher_xml(session, *stream_id, publisher_id, participant_id, publisher_xml, 0); } - else if(0 == strcmp(name, "create_subscriber") && 3 == length) + else if (0 == strcmp(name, "create_subscriber") && 3 == length) { uxrObjectId subscriber_id = uxr_object_id((uint16_t)arg1, UXR_SUBSCRIBER_ID); uxrObjectId participant_id = uxr_object_id((uint16_t)arg2, UXR_PARTICIPANT_ID); const char* subscriber_xml = ""; (void) uxr_buffer_create_subscriber_xml(session, *stream_id, subscriber_id, participant_id, subscriber_xml, 0); } - else if(0 == strcmp(name, "create_datawriter") && 3 == length) + else if (0 == strcmp(name, "create_datawriter") && 3 == length) { uxrObjectId datawriter_id = uxr_object_id((uint16_t)arg1, UXR_DATAWRITER_ID); uxrObjectId publisher_id = uxr_object_id((uint16_t)arg2, UXR_PUBLISHER_ID); const char* datawriter_ref = "shapetype_data_writer"; (void) uxr_buffer_create_datawriter_ref(session, *stream_id, datawriter_id, publisher_id, datawriter_ref, 0); } - else if(0 == strcmp(name, "create_datareader") && 3 == length) + else if (0 == strcmp(name, "create_datareader") && 3 == length) { uxrObjectId datareader_id = uxr_object_id((uint16_t)arg1, UXR_DATAREADER_ID); uxrObjectId subscriber_id = uxr_object_id((uint16_t)arg2, UXR_SUBSCRIBER_ID); const char* datareader_ref = "shapetype_data_reader"; (void) uxr_buffer_create_datareader_ref(session, *stream_id, datareader_id, subscriber_id, datareader_ref, 0); } - else if(0 == strcmp(name, "write_data") && 3 <= length) + else if (0 == strcmp(name, "write_data") && 3 <= length) { - ShapeType topic = {"GREEN", 100 , 100, 50}; - if(3 < length) + ShapeType topic = { + "GREEN", 100, 100, 50 + }; + if (3 < length) { strncpy(topic.color, topic_color, sizeof(topic.color)); topic.x = arg3; @@ -326,7 +382,7 @@ bool compute_command(uxrSession* session, uxrStreamId* stream_id, int length, co printf("Sending... "); print_ShapeType_topic(&topic); } - else if(0 == strcmp(name, "request_data") && 4 == length) + else if (0 == strcmp(name, "request_data") && 4 == length) { uxrDeliveryControl delivery_control; delivery_control.max_samples = (uint16_t)arg3; @@ -338,66 +394,80 @@ bool compute_command(uxrSession* session, uxrStreamId* stream_id, int length, co uxrStreamId input_stream_id = uxr_stream_id_from_raw((uint8_t)arg2, UXR_INPUT_STREAM); (void) uxr_buffer_request_data(session, *stream_id, datareader_id, input_stream_id, &delivery_control); } - else if(0 == strcmp(name, "cancel_data") && 2 == length) + else if (0 == strcmp(name, "cancel_data") && 2 == length) { uxrObjectId datareader_id = uxr_object_id((uint16_t)arg1, UXR_DATAREADER_ID); (void) uxr_buffer_cancel_data(session, *stream_id, datareader_id); } - else if(0 == strcmp(name, "delete") && 3 == length) + else if (0 == strcmp(name, "delete") && 3 == length) { uxrObjectId entity_id = uxr_object_id((uint16_t)arg1, (uint8_t)arg2); (void) uxr_buffer_delete_entity(session, *stream_id, entity_id); } - else if((0 == strcmp(name, "default_output_stream") || 0 == strcmp(name, "stream")) && 2 == length) + else if ((0 == strcmp(name, "default_output_stream") || 0 == strcmp(name, "stream")) && 2 == length) { *stream_id = uxr_stream_id_from_raw((uint8_t)arg1, UXR_OUTPUT_STREAM); } - else if(0 == strcmp(name, "delete_session") && 1 == length) + else if (0 == strcmp(name, "delete_session") && 1 == length) { (void) uxr_delete_session(session); print_status(session->info.last_requested_status); } - else if(0 == strcmp(name, "exit") && 1 == length) + else if (0 == strcmp(name, "exit") && 1 == length) { return false; } - else if((0 == strcmp(name, "entity_tree") || 0 == strcmp(name, "tree")) && 2 == length) + else if ((0 == strcmp(name, "entity_tree") || 0 == strcmp(name, "tree")) && 2 == length) { (void) compute_print_command(session, stream_id, 2, "create_participant", arg1, 0, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); - (void) compute_print_command(session, stream_id, 3, "create_topic" , arg1, arg1, 0, 0, 0, ""); + (void) compute_print_command(session, stream_id, 3, "create_topic", arg1, arg1, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); - (void) compute_print_command(session, stream_id, 3, "create_publisher" , arg1, arg1, 0, 0, 0, ""); + (void) compute_print_command(session, stream_id, 3, "create_publisher", arg1, arg1, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); - (void) compute_print_command(session, stream_id, 3, "create_subscriber" , arg1, arg1, 0, 0, 0, ""); + (void) compute_print_command(session, stream_id, 3, "create_subscriber", arg1, arg1, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); - (void) compute_print_command(session, stream_id, 3, "create_datawriter" , arg1, arg1, 0, 0, 0, ""); + (void) compute_print_command(session, stream_id, 3, "create_datawriter", arg1, arg1, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); - (void) compute_print_command(session, stream_id, 3, "create_datareader" , arg1, arg1, 0, 0, 0, ""); + (void) compute_print_command(session, stream_id, 3, "create_datareader", arg1, arg1, 0, 0, 0, ""); (void) uxr_run_session_time(session, 20); } - else if(0 == strcmp(name, "list") || 0 == strcmp(name, "l")) + else if (0 == strcmp(name, "list") || 0 == strcmp(name, "l")) { print_commands(); } else { - printf("%sUnknown command error, write 'l' or 'list' to show the command list.%s\n", RED_CONSOLE_COLOR, RESTORE_COLOR); + printf("%sUnknown command error, write 'l' or 'list' to show the command list.%s\n", RED_CONSOLE_COLOR, + RESTORE_COLOR); shapes_demo_error = 2; } return true; } - -static bool compute_print_command(uxrSession* session, uxrStreamId* stream_id, int length, const char* name, - uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4, uint32_t arg5, const char* topic_color) +static bool compute_print_command( + uxrSession* session, + uxrStreamId* stream_id, + int length, + const char* name, + uint32_t arg1, + uint32_t arg2, + uint32_t arg3, + uint32_t arg4, + uint32_t arg5, + const char* topic_color) { printf("%s\n", name); return compute_command(session, stream_id, length, name, arg1, arg2, arg3, arg4, arg5, topic_color); } -void on_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status, void* args) +void on_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status, + void* args) { (void) session; (void) object_id; (void) request_id; (void) args; print_status(status); @@ -412,7 +482,8 @@ void on_topic( uint16_t length, void* args) { - (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) serialization; (void) args; (void) length; + (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) serialization; (void) args; + (void) length; ShapeType topic; ShapeType_deserialize_topic(serialization, &topic); @@ -421,75 +492,79 @@ void on_topic( print_ShapeType_topic(&topic); } -void print_ShapeType_topic(const ShapeType* shape_topic) +void print_ShapeType_topic( + const ShapeType* shape_topic) { printf("%s[SHAPE_TYPE | color: %s | x: %u | y: %u | size: %u]%s\n", - "\x1B[1;34m", - shape_topic->color, - shape_topic->x, - shape_topic->y, - shape_topic->shapesize, - "\x1B[0m"); + "\x1B[1;34m", + shape_topic->color, + shape_topic->x, + shape_topic->y, + shape_topic->shapesize, + "\x1B[0m"); } -void print_status(uint8_t status) +void print_status( + uint8_t status) { char status_name[128]; - if(UXR_STATUS_OK == status) + if (UXR_STATUS_OK == status) { strcpy(status_name, "OK"); } - else if(UXR_STATUS_OK_MATCHED == status) + else if (UXR_STATUS_OK_MATCHED == status) { strcpy(status_name, "OK_MATCHED"); } - else if(UXR_STATUS_ERR_DDS_ERROR == status) + else if (UXR_STATUS_ERR_DDS_ERROR == status) { strcpy(status_name, "ERR_DDS_ERROR"); } - else if(UXR_STATUS_ERR_MISMATCH == status) + else if (UXR_STATUS_ERR_MISMATCH == status) { strcpy(status_name, "ERR_MISMATCH"); } - else if(UXR_STATUS_ERR_ALREADY_EXISTS == status) + else if (UXR_STATUS_ERR_ALREADY_EXISTS == status) { strcpy(status_name, "ERR_ALREADY_EXISTS"); } - else if(UXR_STATUS_ERR_DENIED == status) + else if (UXR_STATUS_ERR_DENIED == status) { strcpy(status_name, "ERR_DDS_DENIED"); } - else if(UXR_STATUS_ERR_UNKNOWN_REFERENCE == status) + else if (UXR_STATUS_ERR_UNKNOWN_REFERENCE == status) { strcpy(status_name, "UNKNOWN_REFERENCE"); } - else if(UXR_STATUS_ERR_INVALID_DATA == status) + else if (UXR_STATUS_ERR_INVALID_DATA == status) { strcpy(status_name, "ERR_INVALID_DATA"); } - else if(UXR_STATUS_ERR_INCOMPATIBLE == status) + else if (UXR_STATUS_ERR_INCOMPATIBLE == status) { strcpy(status_name, "ERR_INCOMPATIBLE"); } - else if(UXR_STATUS_ERR_RESOURCES == status) + else if (UXR_STATUS_ERR_RESOURCES == status) { strcpy(status_name, "ERR_RESOURCES"); } - else if(UXR_STATUS_NONE == status) + else if (UXR_STATUS_NONE == status) { strcpy(status_name, "NONE"); } - const char* color = (UXR_STATUS_OK == status || UXR_STATUS_OK_MATCHED == status) ? GREEN_CONSOLE_COLOR : RED_CONSOLE_COLOR; + const char* color = + (UXR_STATUS_OK == status || UXR_STATUS_OK_MATCHED == status) ? GREEN_CONSOLE_COLOR : RED_CONSOLE_COLOR; printf("%sStatus: %s%s\n", color, status_name, RESTORE_COLOR); - if(UXR_STATUS_OK != status && UXR_STATUS_OK_MATCHED != status) + if (UXR_STATUS_OK != status && UXR_STATUS_OK_MATCHED != status) { shapes_demo_error = 2; } } -void print_help(void) +void print_help( + void) { printf("Usage: program --help\n"); printf(" program [--key ] [--history ]\n"); @@ -501,7 +576,8 @@ void print_help(void) printf(" --tcp6 \n"); } -void print_commands(void) +void print_commands( + void) { printf("usage: []\n"); printf(" create_session\n"); @@ -539,16 +615,21 @@ void print_commands(void) printf(" Shows this message.\n"); } -int check_input(void) +int check_input( + void) { #ifdef _WIN32 return _kbhit(); #else - struct timeval tv = {0, 0}; - fd_set fds = {0}; + struct timeval tv = { + 0, 0 + }; + fd_set fds = { + 0 + }; FD_ZERO(&fds); FD_SET(0, &fds); //STDIN 0 select(1, &fds, NULL, NULL, &tv); return FD_ISSET(0, &fds); -#endif +#endif /* ifdef _WIN32 */ } diff --git a/examples/SubscribeHelloWorld/CMakeLists.txt b/examples/SubscribeHelloWorld/CMakeLists.txt index 06f9dbbe9..9a33d1777 100644 --- a/examples/SubscribeHelloWorld/CMakeLists.txt +++ b/examples/SubscribeHelloWorld/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c HelloWorld.c) if(MSVC OR MSVC_IDE) diff --git a/examples/SubscribeHelloWorld/HelloWorld.c b/examples/SubscribeHelloWorld/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/SubscribeHelloWorld/HelloWorld.c +++ b/examples/SubscribeHelloWorld/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/SubscribeHelloWorld/HelloWorld.h b/examples/SubscribeHelloWorld/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/SubscribeHelloWorld/HelloWorld.h +++ b/examples/SubscribeHelloWorld/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/SubscribeHelloWorld/README.md b/examples/SubscribeHelloWorld/README.md index bf6aa00c7..d3e2ed20a 100644 --- a/examples/SubscribeHelloWorld/README.md +++ b/examples/SubscribeHelloWorld/README.md @@ -1,15 +1,15 @@ # SubscribeHelloWorld example This example will show how to receive data from the DDS World creating a client subscriber. -In order to compile this example, it is necessary to have the following profiles enabled in `client.config` file: +In order to compile this example, the following profiles should be enabled: -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *PublisherHelloWorld* example or some publisher that can send the *HelloWorld* topic. 3. Run the *SubscriberHelloWorld* example. - The example can be parameterized with the number of topics that will be listened. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the amount of times that the topic will be listened. If no number is given, the publisher will publish indefinitely. ## Topic diff --git a/examples/SubscribeHelloWorld/main.c b/examples/SubscribeHelloWorld/main.c index cae845274..2e21f8c07 100644 --- a/examples/SubscribeHelloWorld/main.c +++ b/examples/SubscribeHelloWorld/main.c @@ -21,7 +21,7 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY void on_topic( uxrSession* session, @@ -43,10 +43,12 @@ void on_topic( (*count_ptr)++; } -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port []\n"); return 0; @@ -61,8 +63,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -72,7 +73,7 @@ int main(int args, char** argv) uxrSession session; uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); uxr_set_topic_callback(&session, on_topic, &count); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -80,64 +81,76 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); // Create entities uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_xml = "" - "" - "" - "default_xrce_participant" - "" - "" - ""; - uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, participant_xml, UXR_REPLACE); + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); const char* topic_xml = "" - "" - "HelloWorldTopic" - "HelloWorld" - "" - ""; - uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, UXR_REPLACE); + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); uxrObjectId subscriber_id = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); const char* subscriber_xml = ""; - uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, subscriber_xml, UXR_REPLACE); + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, + subscriber_xml, UXR_REPLACE); uxrObjectId datareader_id = uxr_object_id(0x01, UXR_DATAREADER_ID); const char* datareader_xml = "" - "" - "" - "NO_KEY" - "HelloWorldTopic" - "HelloWorld" - "" - "" - ""; - uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, datareader_xml, UXR_REPLACE); + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, + datareader_xml, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[4]; - uint16_t requests[4] = {participant_req, topic_req, subscriber_req, datareader_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) { - printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], status[1], status[2], status[3]); + printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], + status[1], status[2], status[3]); return 1; } // Request topics - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; - uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, &delivery_control); + uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, + &delivery_control); // Read topics bool connected = true; - while(connected && count < max_topics) + while (connected && count < max_topics) { uint8_t read_data_status; connected = uxr_run_session_until_all_status(&session, UXR_TIMEOUT_INF, &read_data_req, &read_data_status, 1); diff --git a/examples/SubscribeHelloWorldBestEffort/CMakeLists.txt b/examples/SubscribeHelloWorldBestEffort/CMakeLists.txt new file mode 100644 index 000000000..c42546e3a --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 2.8.12) +if (${CMAKE_VERSION} VERSION_GREATER 3.0) + cmake_policy(SET CMP0048 NEW) +endif() + +project(SubscribeHelloWorldClientBestEffort) + +if(NOT UCLIENT_BUILD_EXAMPLES) + find_package(microxrcedds_client REQUIRED) +endif() + +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") +else() + add_executable(${PROJECT_NAME} main.c HelloWorld.c) + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + set_target_properties(${PROJECT_NAME} PROPERTIES + C_STANDARD 99 + C_STANDARD_REQUIRED YES + ) + + + target_link_libraries(${PROJECT_NAME} microxrcedds_client $<$:-Wl,--gc-section,--no-export-dynamic>) + + if(UCLIENT_INSTALL_EXAMPLES) + install( + TARGETS + ${PROJECT_NAME} + RUNTIME DESTINATION + ${BIN_INSTALL_DIR} + ) + endif() +endif() diff --git a/examples/SubscribeHelloWorldBestEffort/HelloWorld.c b/examples/SubscribeHelloWorldBestEffort/HelloWorld.c new file mode 100644 index 000000000..6461b04cf --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/HelloWorld.c @@ -0,0 +1,59 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.c + * This source file contains the definition of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#include "HelloWorld.h" + +#include +#include + +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) +{ + (void) ucdr_serialize_uint32_t(writer, topic->index); + + (void) ucdr_serialize_string(writer, topic->message); + + return !writer->error; +} + +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) +{ + (void) ucdr_deserialize_uint32_t(reader, &topic->index); + + (void) ucdr_deserialize_string(reader, topic->message, 255); + + return !reader->error; +} + +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) +{ + uint32_t previousSize = size; + size += (uint32_t)(ucdr_alignment(size, 4) + 4); + + size += (uint32_t)(ucdr_alignment(size, 4) + 4 + strlen(topic->message) + 1); + + return size - previousSize; +} diff --git a/examples/SubscribeHelloWorldBestEffort/HelloWorld.h b/examples/SubscribeHelloWorldBestEffort/HelloWorld.h new file mode 100644 index 000000000..07079a01f --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/HelloWorld.h @@ -0,0 +1,61 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/*! + * @file HelloWorld.h + * This header file contains the declaration of the described types in the IDL file. + * + * This file was generated by the tool gen. + */ + +#ifndef _HelloWorld_H_ +#define _HelloWorld_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include + +/*! + * @brief This struct represents the structure HelloWorld defined by the user in the IDL file. + * @ingroup HELLOWORLD + */ +typedef struct HelloWorld +{ + uint32_t index; + char message[255]; + +} HelloWorld; + +struct ucdrBuffer; + +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // _HelloWorld_H_ diff --git a/examples/SubscribeHelloWorldBestEffort/HelloWorld.idl b/examples/SubscribeHelloWorldBestEffort/HelloWorld.idl new file mode 100644 index 000000000..0fd2c355a --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/HelloWorld.idl @@ -0,0 +1,5 @@ +struct HelloWorld +{ + unsigned long index; + string message; +}; diff --git a/examples/SubscribeHelloWorldBestEffort/README.md b/examples/SubscribeHelloWorldBestEffort/README.md new file mode 100644 index 000000000..e52f8a580 --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/README.md @@ -0,0 +1,25 @@ +# SubscribeHelloWorldBestEffort example + +This example will show how to receive data from the DDS World creating a client subscriber in best effort mode. +In order to compile this example, the following profiles should be enabled: + +- `UCLIENT_PROFILE_UDP` + +## Usage +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. +2. Run the *PublisherHelloWorldBestEffort* example or some publisher that can send the *HelloWorld* topic. +3. Run the *SubscriberHelloWorldBestEffort* example. + The example expects first and second argument to be IP address and port where the Micro XRCE-DDS Agent is running. It can also be parameterized with the amount of times that the topic will be listened. + If no number is given, the subscriber will listen indefinitely. + +## Topic + +The *HelloWorld* topic has the following *IDL* representation: + +``` +struct HelloWorld +{ + unsigned long index; + string message; +}; +``` diff --git a/examples/SubscribeHelloWorldBestEffort/main.c b/examples/SubscribeHelloWorldBestEffort/main.c new file mode 100644 index 000000000..95d56dad0 --- /dev/null +++ b/examples/SubscribeHelloWorldBestEffort/main.c @@ -0,0 +1,163 @@ +// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "HelloWorld.h" + +#include + +#include //printf +#include //strcmp +#include //atoi + +#define STREAM_HISTORY 8 +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY + +void on_topic( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) +{ + (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) length; + + HelloWorld topic; + HelloWorld_deserialize_topic(ub, &topic); + + printf("Received topic: %s, id: %i\n", topic.message, topic.index); + + uint32_t* count_ptr = (uint32_t*) args; + (*count_ptr)++; +} + +int main( + int args, + char** argv) +{ + // CLI + if (3 > args || 0 == atoi(argv[2])) + { + printf("usage: program [-h | --help] | ip port []\n"); + return 0; + } + + char* ip = argv[1]; + char* port = argv[2]; + uint32_t max_topics = (args == 4) ? (uint32_t)atoi(argv[3]) : UINT32_MAX; + + // State + uint32_t count = 0; + + // Transport + uxrUDPTransport transport; + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) + { + printf("Error at create transport.\n"); + return 1; + } + + // Session + uxrSession session; + uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); + uxr_set_topic_callback(&session, on_topic, &count); + if (!uxr_create_session(&session)) + { + printf("Error at create session.\n"); + return 1; + } + + // Streams + uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; + uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + + uxrStreamId besteffort_in = uxr_create_input_best_effort_stream(&session); + + // Create entities + uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); + const char* participant_xml = "" + "" + "" + "default_xrce_participant" + "" + "" + ""; + uint16_t participant_req = uxr_buffer_create_participant_xml(&session, reliable_out, participant_id, 0, + participant_xml, UXR_REPLACE); + + uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); + const char* topic_xml = "" + "" + "HelloWorldTopic" + "HelloWorld" + "" + ""; + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); + + uxrObjectId subscriber_id = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); + const char* subscriber_xml = ""; + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, + subscriber_xml, UXR_REPLACE); + + uxrObjectId datareader_id = uxr_object_id(0x01, UXR_DATAREADER_ID); + const char* datareader_xml = "" + "" + "" + "NO_KEY" + "HelloWorldTopic" + "HelloWorld" + "" + "" + ""; + uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, + datareader_xml, UXR_REPLACE); + + // Send create entities message and wait its status + uint8_t status[4]; + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + { + printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], + status[1], status[2], status[3]); + return 1; + } + + // Request topics + uxrDeliveryControl delivery_control = { + 0 + }; + delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; + uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, besteffort_in, + &delivery_control); + + // Read topics + while (count < max_topics) + { + uxr_run_session_time(&session, 1000); + } + + // Delete resources + uxr_delete_session(&session); + uxr_close_udp_transport(&transport); + + return 0; +} diff --git a/examples/SubscribeHelloWorldP2P/CMakeLists.txt b/examples/SubscribeHelloWorldP2P/CMakeLists.txt index 72aecc5ad..d7299d41f 100644 --- a/examples/SubscribeHelloWorldP2P/CMakeLists.txt +++ b/examples/SubscribeHelloWorldP2P/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c HelloWorld.c) if(MSVC OR MSVC_IDE) diff --git a/examples/SubscribeHelloWorldP2P/HelloWorld.c b/examples/SubscribeHelloWorldP2P/HelloWorld.c index 7ebb8253e..069529011 100644 --- a/examples/SubscribeHelloWorldP2P/HelloWorld.c +++ b/examples/SubscribeHelloWorldP2P/HelloWorld.c @@ -24,7 +24,9 @@ #include #include -bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) +bool HelloWorld_serialize_topic( + ucdrBuffer* writer, + const HelloWorld* topic) { (void) ucdr_serialize_uint32_t(writer, topic->index); @@ -33,7 +35,9 @@ bool HelloWorld_serialize_topic(ucdrBuffer* writer, const HelloWorld* topic) return !writer->error; } -bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) +bool HelloWorld_deserialize_topic( + ucdrBuffer* reader, + HelloWorld* topic) { (void) ucdr_deserialize_uint32_t(reader, &topic->index); @@ -42,7 +46,9 @@ bool HelloWorld_deserialize_topic(ucdrBuffer* reader, HelloWorld* topic) return !reader->error; } -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size) +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size) { uint32_t previousSize = size; size += (uint32_t)(ucdr_alignment(size, 4) + 4); diff --git a/examples/SubscribeHelloWorldP2P/HelloWorld.h b/examples/SubscribeHelloWorldP2P/HelloWorld.h index 0e718021e..21cb3964e 100644 --- a/examples/SubscribeHelloWorldP2P/HelloWorld.h +++ b/examples/SubscribeHelloWorldP2P/HelloWorld.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,13 +43,19 @@ typedef struct HelloWorld struct ucdrBuffer; -bool HelloWorld_serialize_topic(struct ucdrBuffer* writer, const HelloWorld* topic); -bool HelloWorld_deserialize_topic(struct ucdrBuffer* reader, HelloWorld* topic); -uint32_t HelloWorld_size_of_topic(const HelloWorld* topic, uint32_t size); +bool HelloWorld_serialize_topic( + struct ucdrBuffer* writer, + const HelloWorld* topic); +bool HelloWorld_deserialize_topic( + struct ucdrBuffer* reader, + HelloWorld* topic); +uint32_t HelloWorld_size_of_topic( + const HelloWorld* topic, + uint32_t size); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _HelloWorld_H_ diff --git a/examples/SubscribeHelloWorldP2P/README.md b/examples/SubscribeHelloWorldP2P/README.md index 020c63150..7c7862945 100644 --- a/examples/SubscribeHelloWorldP2P/README.md +++ b/examples/SubscribeHelloWorldP2P/README.md @@ -1,12 +1,12 @@ # SubscribeHelloWorldP2P example This example will show how to subscribe to data creating a client subscriber. -It is necessary to have the following profiles enabled in `client.config` file to compile this example: +It is necessary to have the following profiles enabled to compile this example: -- `PROFILE_UDP_TRANSPORT` +- `UCLIENT_PROFILE_UDP` ## Usage -1. Run an agent in port *2018*. +1. Run an agent in a certain port, for example, *2018*: `MicroXRCEAgent udp4 -p 2018`. 2. Run the *PublisherHelloWorldP2P* example or some publisher that can send the *HelloWorld* topic. 3. Run the *SubscriberHelloWorldP2P* example. The example can be parameterized with the number of topics that will be listened to. diff --git a/examples/SubscribeHelloWorldP2P/main.c b/examples/SubscribeHelloWorldP2P/main.c index 973d6c3d2..4c4ce3a27 100644 --- a/examples/SubscribeHelloWorldP2P/main.c +++ b/examples/SubscribeHelloWorldP2P/main.c @@ -21,7 +21,7 @@ #include //atoi #define STREAM_HISTORY 8 -#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU * STREAM_HISTORY +#define BUFFER_SIZE UXR_CONFIG_UDP_TRANSPORT_MTU* STREAM_HISTORY void on_topic( uxrSession* session, @@ -43,10 +43,12 @@ void on_topic( (*count_ptr)++; } -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port []\n"); return 0; @@ -61,8 +63,7 @@ int main(int args, char** argv) // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, UXR_IPv4, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -72,7 +73,7 @@ int main(int args, char** argv) uxrSession session; uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); uxr_set_topic_callback(&session, on_topic, &count); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -80,45 +81,57 @@ int main(int args, char** argv) // Streams uint8_t output_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); uint8_t input_reliable_stream_buffer[BUFFER_SIZE]; - uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); // Create entities uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_ref = "participant_name"; - uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, participant_ref, UXR_REPLACE); + uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, + participant_ref, UXR_REPLACE); uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); const char* topic_ref = "topic_name"; - uint16_t topic_req = uxr_buffer_create_topic_ref(&session, reliable_out, topic_id, participant_id, topic_ref, UXR_REPLACE); + uint16_t topic_req = uxr_buffer_create_topic_ref(&session, reliable_out, topic_id, participant_id, topic_ref, + UXR_REPLACE); uxrObjectId subscriber_id = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); const char* subscriber_xml = ""; - uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, subscriber_xml, UXR_REPLACE); + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, + subscriber_xml, UXR_REPLACE); uxrObjectId datareader_id = uxr_object_id(0x01, UXR_DATAREADER_ID); const char* datareader_ref = topic_ref; - uint16_t datareader_req = uxr_buffer_create_datareader_ref(&session, reliable_out, datareader_id, subscriber_id, datareader_ref, UXR_REPLACE); + uint16_t datareader_req = uxr_buffer_create_datareader_ref(&session, reliable_out, datareader_id, subscriber_id, + datareader_ref, UXR_REPLACE); // Send create entities message and wait its status uint8_t status[4]; - uint16_t requests[4] = {participant_req, topic_req, subscriber_req, datareader_req}; - if(!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) + uint16_t requests[4] = { + participant_req, topic_req, subscriber_req, datareader_req + }; + if (!uxr_run_session_until_all_status(&session, 1000, requests, status, 4)) { - printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], status[1], status[2], status[3]); + printf("Error at create entities: participant: %i topic: %i subscriber: %i datareader: %i\n", status[0], + status[1], status[2], status[3]); return 1; } // Request topics - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; - uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, &delivery_control); + uint16_t read_data_req = uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, + &delivery_control); // Read topics bool connected = true; - while(connected && count < max_topics) + while (connected && count < max_topics) { uint8_t read_data_status; connected = uxr_run_session_until_all_status(&session, UXR_TIMEOUT_INF, &read_data_req, &read_data_status, 1); diff --git a/examples/TimeSync/CMakeLists.txt b/examples/TimeSync/CMakeLists.txt index f65424aa1..f6e0b0108 100644 --- a/examples/TimeSync/CMakeLists.txt +++ b/examples/TimeSync/CMakeLists.txt @@ -23,8 +23,8 @@ if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c) if(MSVC OR MSVC_IDE) diff --git a/examples/TimeSync/main.c b/examples/TimeSync/main.c index 66c71b7b9..a0851aba1 100644 --- a/examples/TimeSync/main.c +++ b/examples/TimeSync/main.c @@ -21,24 +21,44 @@ #include #else #include -#endif +#endif /* ifdef WIN32 */ -int main(int args, char** argv) +int64_t avg_time_offset = 0; +size_t sample_id = 0; + +void on_time( + uxrSession* session, + int64_t current_time, + int64_t transmit_timestamp, + int64_t received_timestamp, + int64_t originate_timestamp, + void* args) +{ + (void) args; + int64_t current_time_offset = ((current_time - originate_timestamp) - (transmit_timestamp - received_timestamp)) / + 2; + avg_time_offset = (avg_time_offset * sample_id + current_time_offset) / (sample_id + 1); + ++sample_id; + session->time_offset = avg_time_offset; +} + +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port\n"); return 0; } char* ip = argv[1]; - uint16_t port = (uint16_t)atoi(argv[2]); + char* port = argv[2]; // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -47,12 +67,15 @@ int main(int args, char** argv) // Session uxrSession session; uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; } + // This is optional + uxr_set_time_callback(&session, on_time, NULL); + // Synchronize with the Agent bool synchronized = false; do @@ -62,12 +85,12 @@ int main(int args, char** argv) printf("synchronized with time offset %-4I64d us\n", session.time_offset / 1000); Sleep(1); #else - printf("synchronized with time offset %-4" PRId64 "us\n", session.time_offset / 1000); + printf("synchronized with time offset %" PRId64 " us\n", session.time_offset / 1000); sleep(1); -#endif +#endif /* ifdef WIN32 */ } while (synchronized); - + // Delete resources uxr_delete_session(&session); uxr_close_udp_transport(&transport); diff --git a/examples/TimeSyncWithCb/CMakeLists.txt b/examples/TimeSyncWithCb/CMakeLists.txt index d6d5c3720..4a8b774a3 100644 --- a/examples/TimeSyncWithCb/CMakeLists.txt +++ b/examples/TimeSyncWithCb/CMakeLists.txt @@ -17,14 +17,14 @@ if (${CMAKE_VERSION} VERSION_GREATER 3.0) cmake_policy(SET CMP0048 NEW) endif() -project(time-sync-with-cb) +project(TimeSyncWithCb) if(NOT UCLIENT_BUILD_EXAMPLES) find_package(microxrcedds_client REQUIRED) endif() -if(NOT PROFILE_UDP_TRANSPORT) - message(WARNING "Can not compile example: The PROFILE_UDP_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_UDP) + message(WARNING "Can not compile example: The UCLIENT_PROFILE_UDP must be enabled.") else() add_executable(${PROJECT_NAME} main.c) if(MSVC OR MSVC_IDE) diff --git a/examples/TimeSyncWithCb/main.c b/examples/TimeSyncWithCb/main.c index 286e12a9c..9bac2fb2e 100644 --- a/examples/TimeSyncWithCb/main.c +++ b/examples/TimeSyncWithCb/main.c @@ -21,7 +21,7 @@ #include #else #include -#endif +#endif /* ifdef WIN32 */ int64_t avg_time_offset = 0; size_t sample_id = 0; @@ -35,28 +35,30 @@ void on_time( void* args) { (void) args; - int64_t current_time_offset = ((current_time - originate_timestamp) - (transmit_timestamp - received_timestamp)) / 2; + int64_t current_time_offset = ((current_time - originate_timestamp) - (transmit_timestamp - received_timestamp)) / + 2; avg_time_offset = (avg_time_offset * sample_id + current_time_offset) / (sample_id + 1); ++sample_id; session->time_offset = avg_time_offset; } -int main(int args, char** argv) +int main( + int args, + char** argv) { // CLI - if(3 > args || 0 == atoi(argv[2])) + if (3 > args || 0 == atoi(argv[2])) { printf("usage: program [-h | --help] | ip port\n"); return 0; } char* ip = argv[1]; - uint16_t port = (uint16_t)atoi(argv[2]); + char* port = argv[2]; // Transport uxrUDPTransport transport; - uxrUDPPlatform udp_platform; - if(!uxr_init_udp_transport(&transport, &udp_platform, ip, port)) + if (!uxr_init_udp_transport(&transport, UXR_IPv4, ip, port)) { printf("Error at create transport.\n"); return 1; @@ -65,7 +67,7 @@ int main(int args, char** argv) // Session uxrSession session; uxr_init_session(&session, &transport.comm, 0xCCCCDDDD); - if(!uxr_create_session(&session)) + if (!uxr_create_session(&session)) { printf("Error at create session.\n"); return 1; @@ -85,10 +87,10 @@ int main(int args, char** argv) #else printf("synchronized with time offset %-5" PRId64 "us\n", session.time_offset / 1000); sleep(1); -#endif +#endif /* ifdef WIN32 */ } while (synchronized); - + // Delete resources uxr_delete_session(&session); uxr_close_udp_transport(&transport); diff --git a/include/uxr/client/client.h b/include/uxr/client/client.h index 184745093..ac070b182 100644 --- a/include/uxr/client/client.h +++ b/include/uxr/client/client.h @@ -17,9 +17,9 @@ #include -#ifdef PROFILE_DISCOVERY +#ifdef UCLIENT_PROFILE_DISCOVERY #include -#endif //PROFILE_DISCOVERY +#endif //UCLIENT_PROFILE_DISCOVERY #include #include diff --git a/include/uxr/client/config.h.in b/include/uxr/client/config.h.in index 2bec7e7a8..8eb73dc65 100644 --- a/include/uxr/client/config.h.in +++ b/include/uxr/client/config.h.in @@ -20,42 +20,43 @@ #define UXR_CLIENT_VERSION_MICRO @PROJECT_VERSION_PATCH@ #define UXR_CLIENT_VERSION_STR "@PROJECT_VERSION@" -#cmakedefine PROFILE_DISCOVERY +#cmakedefine UCLIENT_PROFILE_DISCOVERY -#cmakedefine PROFILE_UDP_TRANSPORT -#cmakedefine PROFILE_TCP_TRANSPORT -#cmakedefine PROFILE_SERIAL_TRANSPORT +#cmakedefine UCLIENT_PROFILE_UDP +#cmakedefine UCLIENT_PROFILE_TCP +#cmakedefine UCLIENT_PROFILE_SERIAL +#cmakedefine UCLIENT_PROFILE_CUSTOM_TRANSPORT -#cmakedefine UCLIENT_PLATFORM_LINUX -#cmakedefine UCLIENT_PLATFORM_WINDOWS -#cmakedefine UCLIENT_PLATFORM_NUTTX +#cmakedefine UCLIENT_PLATFORM_POSIX #cmakedefine UCLIENT_PLATFORM_POSIX_NOPOLL +#cmakedefine UCLIENT_PLATFORM_WINDOWS +#cmakedefine UCLIENT_PLATFORM_FREERTOS_PLUS_TCP +#cmakedefine UCLIENT_PLATFORM_ZEPHYR #cmakedefine UCLIENT_EXTERNAL_TCP #cmakedefine UCLIENT_EXTERNAL_UDP #cmakedefine UCLIENT_EXTERNAL_SERIAL -#if defined(UCLIENT_PLATFORM_LINUX) || defined(UCLIENT_PLATFORM_NUTTX) -#define UCLIENT_PLATFORM_POSIX -#endif +#define UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS @UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS@ +#define UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS @UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS@ +#define UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS @UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS@ +#define UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS @UCLIENT_MAX_INPUT_RELIABLE_STREAMS@ -#define UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS @CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS@ -#define UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS @CONFIG_MAX_OUTPUT_RELIABLE_STREAMS@ -#define UXR_CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS @CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS@ -#define UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS @CONFIG_MAX_INPUT_RELIABLE_STREAMS@ +#define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS @UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS@ +#define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL @UCLIENT_MIN_SESSION_CONNECTION_INTERVAL@ +#define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL @UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL@ -#define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS @CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS@ -#define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL @CONFIG_MIN_SESSION_CONNECTION_INTERVAL@ -#define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL @CONFIG_MIN_HEARTBEAT_TIME_INTERVAL@ - -#ifdef PROFILE_UDP_TRANSPORT -#define UXR_CONFIG_UDP_TRANSPORT_MTU @CONFIG_UDP_TRANSPORT_MTU@ +#ifdef UCLIENT_PROFILE_UDP +#define UXR_CONFIG_UDP_TRANSPORT_MTU @UCLIENT_UDP_TRANSPORT_MTU@ +#endif +#ifdef UCLIENT_PROFILE_TCP +#define UXR_CONFIG_TCP_TRANSPORT_MTU @UCLIENT_TCP_TRANSPORT_MTU@ #endif -#ifdef PROFILE_TCP_TRANSPORT -#define UXR_CONFIG_TCP_TRANSPORT_MTU @CONFIG_TCP_TRANSPORT_MTU@ +#ifdef UCLIENT_PROFILE_SERIAL +#define UXR_CONFIG_SERIAL_TRANSPORT_MTU @UCLIENT_SERIAL_TRANSPORT_MTU@ #endif -#ifdef PROFILE_SERIAL_TRANSPORT -#define UXR_CONFIG_SERIAL_TRANSPORT_MTU @CONFIG_SERIAL_TRANSPORT_MTU@ +#ifdef UCLIENT_PROFILE_CUSTOM_TRANSPORT +#define UXR_CONFIG_CUSTOM_TRANSPORT_MTU @UCLIENT_CUSTOM_TRANSPORT_MTU@ #endif #endif // _UXR_CLIENT_CONFIG_H_ diff --git a/include/uxr/client/core/communication/communication.h b/include/uxr/client/core/communication/communication.h index 4e8c87d44..3b4303407 100644 --- a/include/uxr/client/core/communication/communication.h +++ b/include/uxr/client/core/communication/communication.h @@ -18,15 +18,23 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include #include -typedef bool (*send_msg_func)(void* instance, const uint8_t* buf, size_t len); -typedef bool (*recv_msg_func)(void* instance, uint8_t** buf, size_t* len, int timeout); -typedef uint8_t (*comm_error_func)(void); +typedef bool (* send_msg_func)( + void* instance, + const uint8_t* buf, + size_t len); +typedef bool (* recv_msg_func)( + void* instance, + uint8_t** buf, + size_t* len, + int timeout); +typedef uint8_t (* comm_error_func)( + void); typedef struct uxrCommunication { @@ -40,6 +48,6 @@ typedef struct uxrCommunication #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif //_UXR_CLIENT_CORE_COMMUNICATION_COMMUNICATION_H_ diff --git a/include/uxr/client/core/session/common_create_entities.h b/include/uxr/client/core/session/common_create_entities.h index 9d580b6df..55319f624 100644 --- a/include/uxr/client/core/session/common_create_entities.h +++ b/include/uxr/client/core/session/common_create_entities.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -39,6 +39,6 @@ UXRDLLAPI uint16_t uxr_buffer_delete_entity( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_COMMON_CREATE_ENTITIES_H_ diff --git a/include/uxr/client/core/session/create_entities_ref.h b/include/uxr/client/core/session/create_entities_ref.h index 89254d691..9b0e89949 100644 --- a/include/uxr/client/core/session/create_entities_ref.h +++ b/include/uxr/client/core/session/create_entities_ref.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -123,7 +123,7 @@ UXRDLLAPI uint16_t uxr_buffer_create_datareader_ref( * The submessage will be sent when `uxr_flag_output_streams` or `uxr_run_session` functions are called. * As a result of the reception of this submessage, the Agent will create an XRCE Requester according to * the reference provided in the CREATE submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the CREATE submessage will be buffered. * @param object_id The identifier of the XRCE Requester. @@ -148,7 +148,7 @@ UXRDLLAPI uint16_t uxr_buffer_create_requester_ref( * The submessage will be sent when `uxr_flag_output_streams` or `uxr_run_session` functions are called. * As a result of the reception of this submessage, the Agent will create an XRCE Replier according to * the reference provided in the CREATE submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the CREATE submessage will be buffered. * @param object_id The identifier of the XRCE Requester. @@ -170,6 +170,6 @@ UXRDLLAPI uint16_t uxr_buffer_create_replier_ref( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_CREATE_ENTITIES_REF_H_ diff --git a/include/uxr/client/core/session/create_entities_xml.h b/include/uxr/client/core/session/create_entities_xml.h index 20b287dd7..18d2726df 100644 --- a/include/uxr/client/core/session/create_entities_xml.h +++ b/include/uxr/client/core/session/create_entities_xml.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -171,7 +171,7 @@ UXRDLLAPI uint16_t uxr_buffer_create_datareader_xml( * The submessage will be sent when `uxr_flag_output_streams` or `uxr_run_session` functions are called. * As a result of the reception of this submessage, the Agent will create an XRCE Requester according to * the reference provided in the CREATE submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the CREATE submessage will be buffered. * @param object_id The identifier of the XRCE Requester. @@ -196,7 +196,7 @@ UXRDLLAPI uint16_t uxr_buffer_create_requester_xml( * The submessage will be sent when `uxr_flag_output_streams` or `uxr_run_session` functions are called. * As a result of the reception of this submessage, the Agent will create an XRCE Replier according to * the reference provided in the CREATE submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the CREATE submessage will be buffered. * @param object_id The identifier of the XRCE Requester. @@ -218,6 +218,6 @@ UXRDLLAPI uint16_t uxr_buffer_create_replier_xml( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_CREATE_ENTITIES_XML_H_ diff --git a/include/uxr/client/core/session/object_id.h b/include/uxr/client/core/session/object_id.h index 781eda146..47cbace33 100644 --- a/include/uxr/client/core/session/object_id.h +++ b/include/uxr/client/core/session/object_id.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -41,13 +41,18 @@ typedef struct uxrObjectId } uxrObjectId; -UXRDLLAPI uxrObjectId uxr_object_id(uint16_t id, uint8_t type); +UXRDLLAPI uxrObjectId uxr_object_id( + uint16_t id, + uint8_t type); -UXRDLLAPI uxrObjectId uxr_object_id_from_raw(const uint8_t* raw); -UXRDLLAPI void uxr_object_id_to_raw(uxrObjectId object_id, uint8_t* raw); +UXRDLLAPI uxrObjectId uxr_object_id_from_raw( + const uint8_t* raw); +UXRDLLAPI void uxr_object_id_to_raw( + uxrObjectId object_id, + uint8_t* raw); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif //_UXR_CLIENT_CORE_SESSION_OBJECT_ID_H_ diff --git a/include/uxr/client/core/session/read_access.h b/include/uxr/client/core/session/read_access.h index fbac7c83a..7304096df 100644 --- a/include/uxr/client/core/session/read_access.h +++ b/include/uxr/client/core/session/read_access.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -68,7 +68,7 @@ UXRDLLAPI uint16_t uxr_buffer_request_data( uxrStreamId stream_id, uxrObjectId datareader_id, uxrStreamId data_stream_id, - const uxrDeliveryControl * const delivery_control); + const uxrDeliveryControl* const delivery_control); /** * @brief Buffers into the stream identified by `stream_id` an XRCE READ_DATA submessage. @@ -87,6 +87,6 @@ UXRDLLAPI uint16_t uxr_buffer_cancel_data( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_READ_ACCESS_H_ diff --git a/include/uxr/client/core/session/session.h b/include/uxr/client/core/session/session.h index 8a63c14f0..74ba923aa 100644 --- a/include/uxr/client/core/session/session.h +++ b/include/uxr/client/core/session/session.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -29,14 +29,14 @@ extern "C" struct uxrSession; struct uxrCommunication; -typedef void (*uxrOnStatusFunc) ( +typedef void (* uxrOnStatusFunc) ( struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status, void* args); -typedef void (*uxrOnTopicFunc) ( +typedef void (* uxrOnTopicFunc) ( struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, @@ -45,7 +45,7 @@ typedef void (*uxrOnTopicFunc) ( uint16_t length, void* args); -typedef void (*uxrOnTimeFunc) ( +typedef void (* uxrOnTimeFunc) ( struct uxrSession* session, int64_t current_timestamp, int64_t transmit_timestamp, @@ -53,7 +53,7 @@ typedef void (*uxrOnTimeFunc) ( int64_t originate_timestamp, void* args); -typedef void (*uxrOnRequestFunc) ( +typedef void (* uxrOnRequestFunc) ( struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, @@ -62,7 +62,7 @@ typedef void (*uxrOnRequestFunc) ( uint16_t length, void* args); -typedef void (*uxrOnReplyFunc) ( +typedef void (* uxrOnReplyFunc) ( struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, @@ -71,9 +71,22 @@ typedef void (*uxrOnReplyFunc) ( uint16_t length, void* args); +typedef bool (* uxrOnBuffersFull) ( + struct uxrSession* session); + #ifdef PERFORMANCE_TESTING -typedef void (*uxrOnPerformanceFunc) (struct uxrSession* session, struct ucdrBuffer* mb, void* args); -#endif +typedef void (* uxrOnPerformanceFunc) ( + struct uxrSession* session, + struct ucdrBuffer* mb, + void* args); +#endif // ifdef PERFORMANCE_TESTING + +typedef struct uxrContinuousArgs +{ + uxrOnBuffersFull flush_callback; + uxrStreamId stream_id; + size_t data_size; +} uxrContinuousArgs; typedef struct uxrSession { @@ -102,10 +115,13 @@ typedef struct uxrSession uxrOnReplyFunc on_reply; void* on_reply_args; + bool on_data_flag; + uxrContinuousArgs continuous_args; + #ifdef PERFORMANCE_TESTING uxrOnPerformanceFunc on_performance; void* on_performance_args; -#endif +#endif // ifdef PERFORMANCE_TESTING } uxrSession; /** @@ -163,7 +179,7 @@ UXRDLLAPI void uxr_set_time_callback( * @brief Sets the request callback. * It will be called when a request is received from the Agent. * The requests will be received only if a `request_data` function has been called with a `Requester` object id. - * + * * @param session A uxrSession structure previously initialized. * @param on_request_func The function that will be called when a valid request message arrives from the Agent. * @param args User pointer data. The args will be provided to the `on_request_func` callback. @@ -177,11 +193,11 @@ UXRDLLAPI void uxr_set_request_callback( * @brief Sets the reply callback. * It will be called when a reply is received from the Agent. * The reply will be received only if a `request_data` function has been called with a `Replier` object id. - * + * * @param session A uxrSession structure previosly initialized. * @param on_reply_func The function that will be called when a valid reply message arrives from the Agent. * @param args User pointer data. The args will be provided to the `on_reply_func` callback. - * @return UXRDLLAPI uxr_set_reply_callback + * @return UXRDLLAPI uxr_set_reply_callback */ UXRDLLAPI void uxr_set_reply_callback( uxrSession* session, @@ -189,8 +205,11 @@ UXRDLLAPI void uxr_set_reply_callback( void* args); #ifdef PERFORMANCE_TESTING -UXRDLLAPI void uxr_set_performance_callback(uxrSession* session, uxrOnPerformanceFunc on_performance_func, void* args); -#endif +UXRDLLAPI void uxr_set_performance_callback( + uxrSession* session, + uxrOnPerformanceFunc on_performance_func, + void* args); +#endif // ifdef PERFORMANCE_TESTING /** * @brief Creates a new session with the Agent. @@ -198,21 +217,45 @@ UXRDLLAPI void uxr_set_performance_callback(uxrSession* session, uxrOnPerformanc * @param session A uxrSesssion structure previously initialized. * @return true in case of successful session establishment, and false in other case. */ -UXRDLLAPI bool uxr_create_session(uxrSession* session); +UXRDLLAPI bool uxr_create_session( + uxrSession* session); + +/** + * @brief Creates a new session with the Agent. + * This function logs in a session, enabling any other XRCE communication with the Agent. + * @param session A uxrSesssion structure previously initialized. + * @param retries Max attempts for creating the session. + * @return true in case of successful session establishment, and false in other case. + */ +UXRDLLAPI bool uxr_create_session_retries( + uxrSession* session, + size_t retries); + +/** + * @brief Deletes a session previously created. + * All XRCE entities created within the session will be removed. + * This function logs out a session, disabling any other XRCE communication with the Agent. + * @param session A uxrSession structure previously initialized. + * @return true in case of successful session deletion, and false in other case. + */ +UXRDLLAPI bool uxr_delete_session( + uxrSession* session); /** * @brief Deletes a session previously created. * All XRCE entities created within the session will be removed. * This function logs out a session, disabling any other XRCE communication with the Agent. * @param session A uxrSession structure previously initialized. + * @param retries Max attempts for deleting the session. * @return true in case of successful session deletion, and false in other case. */ -UXRDLLAPI bool uxr_delete_session(uxrSession* session); +UXRDLLAPI bool uxr_delete_session_retries( + uxrSession* session, + size_t retries); /** * @brief Creates and initializes an output best-effort stream. - * The maximum number of output best-effort streams is set by the `CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS` - * variable at `client.config` file. + * The maximum number of output best-effort streams is set by the `UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS`. * @param session A uxrSession structure previously initialized. * @param buffer The memory block where the messages will be written. * @param size The buffer size. @@ -225,8 +268,7 @@ UXRDLLAPI uxrStreamId uxr_create_output_best_effort_stream( /** * @brief Creates and initializes an output reliable stream. - * The maximum number of output reliable streams is set by the `CONFIG_MAX_OUTPUT_RELIABLE_STREAMS` - * variable at `client.config` file. + * The maximum number of output reliable streams is set by the `UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS`. * @param session A uxrSession structure previously initialized. * @param buffer The memory block where the messages will be written. * @param size The buffer size. @@ -243,17 +285,16 @@ UXRDLLAPI uxrStreamId uxr_create_output_reliable_stream( /** * @brief Creates and initializes an input best-effort stream. - * The maximum number of input best-effort streams is set by the `CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS` - * variable at `client.config` file. + * The maximum number of input best-effort streams is set by the `UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS`. * @param session A uxrSession structure previously initialized. * @return A uxrStreamId which could by used for managing the stream. */ -UXRDLLAPI uxrStreamId uxr_create_input_best_effort_stream(uxrSession* session); +UXRDLLAPI uxrStreamId uxr_create_input_best_effort_stream( + uxrSession* session); /** * @brief Creates and initializes an input reliable stream. - * The maximum number of input reliable streams is set by the `CONFIG_MAX_INPUT_RELIABLE_STREAMS` - * variable at `client.config` file. + * The maximum number of input reliable streams is set by the `UCLIENT_MAX_INPUT_RELIABLE_STREAMS`. * @param session A uxrSession structure previously initialized. * @param buffer The memory block where the messages will be written. * @param size The buffer size. @@ -272,7 +313,8 @@ UXRDLLAPI uxrStreamId uxr_create_input_reliable_stream( * @brief Flashes all the output streams seding the data through the transport. * @param session A uxrSession structure previously initialized. */ -UXRDLLAPI void uxr_flash_output_streams(uxrSession* session); +UXRDLLAPI void uxr_flash_output_streams( + uxrSession* session); /** * @brief Keeps communication between the Client and the Agent. @@ -303,6 +345,21 @@ UXRDLLAPI bool uxr_run_session_timeout( uxrSession* session, int timeout); +/** + * @brief Keeps communication between the Client and the Agent. + * This function involves the following actions: + * 1. flashing all the output streams sending the data through the transport, + * 2. listening messages from the Agent calling the associated callback (topic, status, request and replies). + * The aforementioned actions will be performed in a loop until a data message is received + * or the `timeout` is exceeded. + * @param session A uxrSession structure previously initialized. + * @param timeout The waiting time in milliseconds. + * @return `true` in case of a data message is received before the timeout. `false` in other case. + */ +UXRDLLAPI bool uxr_run_session_until_data( + uxrSession* session, + int timeout); + /** * @brief Keeps communication between the Client and the Agent. * This function involves the following actions: @@ -393,26 +450,29 @@ UXRDLLAPI bool uxr_sync_session( * @param session A uxrSession structure previosly initialized. * @return The epoch time in milliseconds. */ -UXRDLLAPI int64_t uxr_epoch_millis(uxrSession* session); +UXRDLLAPI int64_t uxr_epoch_millis( + uxrSession* session); /** * @brief Returns the epoch time in nanoseconds taking into account the offset computed during the time synchronization. * @param session A uxrSession structure previosly initialized. * @return The epoch time in nanoseconds. */ -UXRDLLAPI int64_t uxr_epoch_nanos(uxrSession* session); +UXRDLLAPI int64_t uxr_epoch_nanos( + uxrSession* session); #ifdef PERFORMANCE_TESTING -UXRDLLAPI bool uxr_buffer_performance(uxrSession* session, - uxrStreamId stream_id, - uint64_t epoch_time, - uint8_t* buf, - uint16_t len, - bool echo); -#endif +UXRDLLAPI bool uxr_buffer_performance( + uxrSession* session, + uxrStreamId stream_id, + uint64_t epoch_time, + uint8_t* buf, + uint16_t len, + bool echo); +#endif // ifdef PERFORMANCE_TESTING #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_SESSION_H diff --git a/include/uxr/client/core/session/session_info.h b/include/uxr/client/core/session/session_info.h index e901f7aa9..8777cd4bf 100644 --- a/include/uxr/client/core/session/session_info.h +++ b/include/uxr/client/core/session/session_info.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -40,7 +40,7 @@ extern "C" #define UXR_REPLACE 0x01 << 2 #ifdef PERFORMANCE_TESTING #define UXR_ECHO 0x01 << 7 -#endif +#endif // ifdef PERFORMANCE_TESTING #define UXR_INVALID_REQUEST_ID 0 @@ -59,6 +59,6 @@ typedef struct uxrSessionInfo #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_CORE_SESSION_SESSION_INFO_H diff --git a/include/uxr/client/core/session/stream/input_best_effort_stream.h b/include/uxr/client/core/session/stream/input_best_effort_stream.h index 4f12b43df..0241b1352 100644 --- a/include/uxr/client/core/session/stream/input_best_effort_stream.h +++ b/include/uxr/client/core/session/stream/input_best_effort_stream.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -33,6 +33,6 @@ typedef struct uxrInputBestEffortStream #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_CORE_SESSION_STREAM_INPUT_BEST_EFFORT_STREAM_H_ diff --git a/include/uxr/client/core/session/stream/input_reliable_stream.h b/include/uxr/client/core/session/stream/input_reliable_stream.h index c92f9048c..f9aa5d7f4 100644 --- a/include/uxr/client/core/session/stream/input_reliable_stream.h +++ b/include/uxr/client/core/session/stream/input_reliable_stream.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -35,7 +35,8 @@ typedef enum FragmentationInfo } FragmentationInfo; -typedef FragmentationInfo (*OnGetFragmentationInfo)(uint8_t* buffer); +typedef FragmentationInfo (* OnGetFragmentationInfo)( + uint8_t* buffer); typedef struct uxrInputReliableStream { @@ -52,6 +53,6 @@ typedef struct uxrInputReliableStream #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR__CLIENT__CORE__SESSION__STREAM__INPUT_RELIABLE_STREAM_H_ diff --git a/include/uxr/client/core/session/stream/output_best_effort_stream.h b/include/uxr/client/core/session/stream/output_best_effort_stream.h index 907d3b701..d72056bb2 100644 --- a/include/uxr/client/core/session/stream/output_best_effort_stream.h +++ b/include/uxr/client/core/session/stream/output_best_effort_stream.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -39,6 +39,6 @@ typedef struct uxrOutputBestEffortStream #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_H diff --git a/include/uxr/client/core/session/stream/output_reliable_stream.h b/include/uxr/client/core/session/stream/output_reliable_stream.h index 6f124b6bf..d392a35d1 100644 --- a/include/uxr/client/core/session/stream/output_reliable_stream.h +++ b/include/uxr/client/core/session/stream/output_reliable_stream.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -28,7 +28,9 @@ extern "C" struct ucdrBuffer; struct uxrOutputReliableStream; -typedef void (*OnNewFragment)(struct ucdrBuffer* ub, struct uxrOutputReliableStream* stream); +typedef void (* OnNewFragment)( + struct ucdrBuffer* ub, + struct uxrOutputReliableStream* stream); typedef struct uxrOutputReliableStream { @@ -47,6 +49,6 @@ typedef struct uxrOutputReliableStream #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR__CLIENT__CORE__SESSION__STREAM__OUTPUT_RELIABLE_STREAM_H_ diff --git a/include/uxr/client/core/session/stream/reliable_stream.h b/include/uxr/client/core/session/stream/reliable_stream.h index 8461f6c63..0da6e1000 100644 --- a/include/uxr/client/core/session/stream/reliable_stream.h +++ b/include/uxr/client/core/session/stream/reliable_stream.h @@ -18,14 +18,14 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include typedef struct uxrReliableStream { - uint8_t * buffer; + uint8_t* buffer; size_t size; uint16_t history; @@ -33,6 +33,6 @@ typedef struct uxrReliableStream #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR__CLIENT__CORE__SESSION__STREAM__RELIABLE_STREAM_H_ diff --git a/include/uxr/client/core/session/stream/seq_num.h b/include/uxr/client/core/session/stream/seq_num.h index 28cde6cbe..9f889a657 100644 --- a/include/uxr/client/core/session/stream/seq_num.h +++ b/include/uxr/client/core/session/stream/seq_num.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -26,6 +26,6 @@ typedef uint16_t uxrSeqNum; #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_CORE_SESSION_STREAM_SEQ_NUM_H_ diff --git a/include/uxr/client/core/session/stream/stream_id.h b/include/uxr/client/core/session/stream/stream_id.h index bd8e41575..b335734e3 100644 --- a/include/uxr/client/core/session/stream/stream_id.h +++ b/include/uxr/client/core/session/stream/stream_id.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -100,6 +100,6 @@ UXRDLLAPI uxrStreamId uxr_stream_id_from_raw( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_STREAM_STREAM_ID_H diff --git a/include/uxr/client/core/session/stream/stream_storage.h b/include/uxr/client/core/session/stream/stream_storage.h index d8b1993a0..d4712d1d3 100644 --- a/include/uxr/client/core/session/stream/stream_storage.h +++ b/include/uxr/client/core/session/stream/stream_storage.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -42,6 +42,6 @@ typedef struct uxrStreamStorage #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_CORE_SESSION_STREAM_STREAM_STORAGE_H diff --git a/include/uxr/client/core/session/write_access.h b/include/uxr/client/core/session/write_access.h index 0552d1371..5bc97b148 100644 --- a/include/uxr/client/core/session/write_access.h +++ b/include/uxr/client/core/session/write_access.h @@ -18,14 +18,14 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include /** * @brief Buffers into the stream identified by `stream_id` an XRCE WRITE_DATA submessage. * As a consequence, an XRCE request is generated associated to the WRITE_DATA submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered. * @param requester_id The identifier of the XRCE Requester that will write the request into the DDS GDS. @@ -44,13 +44,13 @@ uint16_t uxr_buffer_request( /** * @brief Buffers into the stream identified by `stream_id` an XRCE WRITE_DATA submessage. * As a consequence, an XRCE request is generated associated to the WRITE_DATA submessage. - * + * * @param session A uxrSession structure previously initialized. * @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered. - * @param replier_id The identifier of the XRCE Replier that will write the reply into the DDS GDS. + * @param replier_id The identifier of the XRCE Replier that will write the reply into the DDS GDS. * @param sample_id The `SampleIdentity` that identifies the request. * It will be read by the Requester to filter and identify the reply. - * @param buffer The pointer to the reply data. + * @param buffer The pointer to the reply data. * @param len The length of the reply data. * @return A `request_id` that identifies the XRCE request made by the Client. * This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions. @@ -63,6 +63,25 @@ uint16_t uxr_buffer_reply( uint8_t* buffer, size_t len); +/** + * @brief Buffers into the stream identified by `stream_id` an XRCE WRITE_DATA submessage. + * As a consequence, an XRCE request is generated associated to the WRITE_DATA submessage. + * + * @param session A uxrSession structure previously initialized. + * @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered. + * @param datawriter_id The identifier of the XRCE Datawriter that will write the topic into the DDS GDS. + * @param buffer The pointer to the topic data. + * @param len The length of the topic data. + * @return A `request_id` that identifies the XRCE request made by the Publisher. + * This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions. + */ +uint16_t uxr_buffer_topic( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId datawriter_id, + uint8_t* buffer, + size_t len); + /** * @brief Buffers into the stream identified by `stream_id` an XRCE WRITE_DATA submessage. * The submessage will be sent when `uxr_flash_output_stream` or `uxr_run_session` function are called. @@ -72,18 +91,42 @@ uint16_t uxr_buffer_reply( * @param datawriter_id The identifier of the XRCE DataWriter that will write the topic into the DDS GDS. * @param ub_topic The ucdrBuffer structure used for serializing the topic. * @param topic_size The size of the topic in bytes. - * @return A `request_id` that identifies the request made by the Client. + * @return A `request_id` that identifies the XRCE request made by the Entity. * This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions. - */ -UXRDLLAPI bool uxr_prepare_output_stream( + * */ +UXRDLLAPI uint16_t uxr_prepare_output_stream( uxrSession* session, uxrStreamId stream_id, - uxrObjectId datawriter_id, + uxrObjectId entity_id, struct ucdrBuffer* ub_topic, uint32_t topic_size); + +/** + * @brief Buffers into the stream identified by `stream_id` an XRCE WRITE_DATA submessage. + * The submessage will be sent when `uxr_flash_output_stream` or `uxr_run_session` function are called. + * This function handles the buffer flush by means of `uxrOnBuffersFull` callback. + * As a result of the reception of this submessage, the Agent will write a topic into the DDS Global-Data-Space. + * @param session A uxrSession structure previously initialized. + * @param stream_id The output stream identifier where the WRITE_DATA submessage will be buffered. + * @param datawriter_id The identifier of the XRCE DataWriter that will write the topic into the DDS GDS. + * @param ub The ucdrBuffer structure used for serializing the topic. + * @param topic_size The size of the topic in bytes. + * @param flush_callback Callback that is call by the library when user should flush output buffers. + * @return A `request_id` that identifies the XRCE request made by the Entity. + * This could be used in the `uxr_run_session_until_one_status` or `uxr_run_session_until_all_status` functions. + * */ + +UXRDLLAPI uint16_t uxr_prepare_output_stream_fragmented( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId datawriter_id, + ucdrBuffer* ub, + size_t topic_size, + uxrOnBuffersFull flush_callback); + #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_SESSION_WRITE_ACCESS_H_ diff --git a/include/uxr/client/core/type/xrce_types.h b/include/uxr/client/core/type/xrce_types.h index 6e78f34dd..d62a5d751 100644 --- a/include/uxr/client/core/type/xrce_types.h +++ b/include/uxr/client/core/type/xrce_types.h @@ -21,7 +21,7 @@ extern "C" #define INLINE_STRUCT(x) (x) #else #define INLINE_STRUCT(x) x -#endif +#endif // ifdef __cplusplus #include @@ -603,7 +603,7 @@ typedef enum InfoMask typedef struct AGENT_ActivityInfo { - int16_t availibility; + int16_t availability; TransportLocatorSeq address_seq; } AGENT_ActivityInfo; @@ -1052,318 +1052,726 @@ typedef struct PERFORMANCE_Payload uint16_t len; } PERFORMANCE_Payload; -#endif - -bool uxr_serialize_Time_t(ucdrBuffer* buffer, const Time_t* input); -bool uxr_deserialize_Time_t(ucdrBuffer* buffer, Time_t* output); - -bool uxr_serialize_BinarySequence_t(ucdrBuffer* buffer, const BinarySequence_t* input); -bool uxr_deserialize_BinarySequence_t(ucdrBuffer* buffer, BinarySequence_t* output); - -bool uxr_serialize_StringSequence_t(ucdrBuffer* buffer, const StringSequence_t* input); -bool uxr_deserialize_StringSequence_t(ucdrBuffer* buffer, StringSequence_t* output); - -bool uxr_serialize_ClientKey(ucdrBuffer* buffer, const ClientKey* input); -bool uxr_deserialize_ClientKey(ucdrBuffer* buffer, ClientKey* output); - -bool uxr_serialize_ObjectId(ucdrBuffer* buffer, const ObjectId* input); -bool uxr_deserialize_ObjectId(ucdrBuffer* buffer, ObjectId* output); - -bool uxr_serialize_ObjectPrefix(ucdrBuffer* buffer, const ObjectPrefix* input); -bool uxr_deserialize_ObjectPrefix(ucdrBuffer* buffer, ObjectPrefix* output); - -bool uxr_serialize_XrceCookie(ucdrBuffer* buffer, const XrceCookie* input); -bool uxr_deserialize_XrceCookie(ucdrBuffer* buffer, XrceCookie* output); - -bool uxr_serialize_XrceVersion(ucdrBuffer* buffer, const XrceVersion* input); -bool uxr_deserialize_XrceVersion(ucdrBuffer* buffer, XrceVersion* output); - -bool uxr_serialize_XrceVendorId(ucdrBuffer* buffer, const XrceVendorId* input); -bool uxr_deserialize_XrceVendorId(ucdrBuffer* buffer, XrceVendorId* output); - -bool uxr_serialize_TransportLocatorSmall(ucdrBuffer* buffer, const TransportLocatorSmall* input); -bool uxr_deserialize_TransportLocatorSmall(ucdrBuffer* buffer, TransportLocatorSmall* output); - -bool uxr_serialize_TransportLocatorMedium(ucdrBuffer* buffer, const TransportLocatorMedium* input); -bool uxr_deserialize_TransportLocatorMedium(ucdrBuffer* buffer, TransportLocatorMedium* output); - -bool uxr_serialize_TransportLocatorLarge(ucdrBuffer* buffer, const TransportLocatorLarge* input); -bool uxr_deserialize_TransportLocatorLarge(ucdrBuffer* buffer, TransportLocatorLarge* output); - -bool uxr_serialize_TransportLocatorString(ucdrBuffer* buffer, const TransportLocatorString* input); -bool uxr_deserialize_TransportLocatorString(ucdrBuffer* buffer, TransportLocatorString* output); - -bool uxr_serialize_TransportLocator(ucdrBuffer* buffer, const TransportLocator* input); -bool uxr_deserialize_TransportLocator(ucdrBuffer* buffer, TransportLocator* output); - -bool uxr_serialize_TransportLocatorSeq(ucdrBuffer* buffer, const TransportLocatorSeq* input); -bool uxr_deserialize_TransportLocatorSeq(ucdrBuffer* buffer, TransportLocatorSeq* output); - -bool uxr_serialize_Property(ucdrBuffer* buffer, const Property* input); -bool uxr_deserialize_Property(ucdrBuffer* buffer, Property* output); - -bool uxr_serialize_PropertySeq(ucdrBuffer* buffer, const PropertySeq* input); -bool uxr_deserialize_PropertySeq(ucdrBuffer* buffer, PropertySeq* output); - -bool uxr_serialize_CLIENT_Representation(ucdrBuffer* buffer, const CLIENT_Representation* input); -bool uxr_deserialize_CLIENT_Representation(ucdrBuffer* buffer, CLIENT_Representation* output); - -bool uxr_serialize_AGENT_Representation(ucdrBuffer* buffer, const AGENT_Representation* input); -bool uxr_deserialize_AGENT_Representation(ucdrBuffer* buffer, AGENT_Representation* output); - -bool uxr_serialize_OBJK_Representation3Formats(ucdrBuffer* buffer, const OBJK_Representation3Formats* input); -bool uxr_deserialize_OBJK_Representation3Formats(ucdrBuffer* buffer, OBJK_Representation3Formats* output); - -bool uxr_serialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, const OBJK_RepresentationRefAndXMLFormats* input); -bool uxr_deserialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, OBJK_RepresentationRefAndXMLFormats* output); - -bool uxr_serialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, const OBJK_RepresentationBinAndXMLFormats* input); -bool uxr_deserialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, OBJK_RepresentationBinAndXMLFormats* output); - -bool uxr_serialize_OBJK_RepresentationRefAndXML_Base(ucdrBuffer* buffer, const OBJK_RepresentationRefAndXML_Base* input); -bool uxr_deserialize_OBJK_RepresentationRefAndXML_Base(ucdrBuffer* buffer, OBJK_RepresentationRefAndXML_Base* output); - -bool uxr_serialize_OBJK_RepresentationBinAndXML_Base(ucdrBuffer* buffer, const OBJK_RepresentationBinAndXML_Base* input); -bool uxr_deserialize_OBJK_RepresentationBinAndXML_Base(ucdrBuffer* buffer, OBJK_RepresentationBinAndXML_Base* output); - -bool uxr_serialize_OBJK_Representation3_Base(ucdrBuffer* buffer, const OBJK_Representation3_Base* input); -bool uxr_deserialize_OBJK_Representation3_Base(ucdrBuffer* buffer, OBJK_Representation3_Base* output); - -bool uxr_serialize_OBJK_QOSPROFILE_Representation(ucdrBuffer* buffer, const OBJK_QOSPROFILE_Representation* input); -bool uxr_deserialize_OBJK_QOSPROFILE_Representation(ucdrBuffer* buffer, OBJK_QOSPROFILE_Representation* output); - -bool uxr_serialize_OBJK_TYPE_Representation(ucdrBuffer* buffer, const OBJK_TYPE_Representation* input); -bool uxr_deserialize_OBJK_TYPE_Representation(ucdrBuffer* buffer, OBJK_TYPE_Representation* output); - -bool uxr_serialize_OBJK_DOMAIN_Representation(ucdrBuffer* buffer, const OBJK_DOMAIN_Representation* input); -bool uxr_deserialize_OBJK_DOMAIN_Representation(ucdrBuffer* buffer, OBJK_DOMAIN_Representation* output); - -bool uxr_serialize_OBJK_APPLICATION_Representation(ucdrBuffer* buffer, const OBJK_APPLICATION_Representation* input); -bool uxr_deserialize_OBJK_APPLICATION_Representation(ucdrBuffer* buffer, OBJK_APPLICATION_Representation* output); - -bool uxr_serialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, const OBJK_PUBLISHER_Representation* input); -bool uxr_deserialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, OBJK_PUBLISHER_Representation* output); - -bool uxr_serialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, const OBJK_SUBSCRIBER_Representation* input); -bool uxr_deserialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, OBJK_SUBSCRIBER_Representation* output); - -bool uxr_serialize_DATAWRITER_Representation(ucdrBuffer* buffer, const DATAWRITER_Representation* input); -bool uxr_deserialize_DATAWRITER_Representation(ucdrBuffer* buffer, DATAWRITER_Representation* output); - -bool uxr_serialize_DATAREADER_Representation(ucdrBuffer* buffer, const DATAREADER_Representation* input); -bool uxr_deserialize_DATAREADER_Representation(ucdrBuffer* buffer, DATAREADER_Representation* output); - -bool uxr_serialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, const OBJK_PARTICIPANT_Representation* input); -bool uxr_deserialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, OBJK_PARTICIPANT_Representation* output); - -bool uxr_serialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, const OBJK_TOPIC_Representation* input); -bool uxr_deserialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, OBJK_TOPIC_Representation* output); - -bool uxr_serialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, const OBJK_REQUESTER_Representation* input); -bool uxr_deserialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, OBJK_REQUESTER_Representation* output); - -bool uxr_serialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, const OBJK_REPLIER_Representation* input); -bool uxr_deserialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, OBJK_REPLIER_Representation* output); - -bool uxr_serialize_OBJK_DomainParticipant_Binary(ucdrBuffer* buffer, const OBJK_DomainParticipant_Binary* input); -bool uxr_deserialize_OBJK_DomainParticipant_Binary(ucdrBuffer* buffer, OBJK_DomainParticipant_Binary* output); - -bool uxr_serialize_OBJK_Topic_Binary(ucdrBuffer* buffer, const OBJK_Topic_Binary* input); -bool uxr_deserialize_OBJK_Topic_Binary(ucdrBuffer* buffer, OBJK_Topic_Binary* output); - -bool uxr_serialize_OBJK_Publisher_Binary_Qos(ucdrBuffer* buffer, const OBJK_Publisher_Binary_Qos* input); -bool uxr_deserialize_OBJK_Publisher_Binary_Qos(ucdrBuffer* buffer, OBJK_Publisher_Binary_Qos* output); - -bool uxr_serialize_OBJK_Publisher_Binary(ucdrBuffer* buffer, const OBJK_Publisher_Binary* input); -bool uxr_deserialize_OBJK_Publisher_Binary(ucdrBuffer* buffer, OBJK_Publisher_Binary* output); - -bool uxr_serialize_OBJK_Subscriber_Binary_Qos(ucdrBuffer* buffer, const OBJK_Subscriber_Binary_Qos* input); -bool uxr_deserialize_OBJK_Subscriber_Binary_Qos(ucdrBuffer* buffer, OBJK_Subscriber_Binary_Qos* output); - -bool uxr_serialize_OBJK_Subscriber_Binary(ucdrBuffer* buffer, const OBJK_Subscriber_Binary* input); -bool uxr_deserialize_OBJK_Subscriber_Binary(ucdrBuffer* buffer, OBJK_Subscriber_Binary* output); - -bool uxr_serialize_OBJK_Endpoint_QosBinary(ucdrBuffer* buffer, const OBJK_Endpoint_QosBinary* input); -bool uxr_deserialize_OBJK_Endpoint_QosBinary(ucdrBuffer* buffer, OBJK_Endpoint_QosBinary* output); - -bool uxr_serialize_OBJK_DataWriter_Binary_Qos(ucdrBuffer* buffer, const OBJK_DataWriter_Binary_Qos* input); -bool uxr_deserialize_OBJK_DataWriter_Binary_Qos(ucdrBuffer* buffer, OBJK_DataWriter_Binary_Qos* output); - -bool uxr_serialize_OBJK_DataReader_Binary_Qos(ucdrBuffer* buffer, const OBJK_DataReader_Binary_Qos* input); -bool uxr_deserialize_OBJK_DataReader_Binary_Qos(ucdrBuffer* buffer, OBJK_DataReader_Binary_Qos* output); - -bool uxr_serialize_OBJK_DataReader_Binary(ucdrBuffer* buffer, const OBJK_DataReader_Binary* input); -bool uxr_deserialize_OBJK_DataReader_Binary(ucdrBuffer* buffer, OBJK_DataReader_Binary* output); - -bool uxr_serialize_OBJK_DataWriter_Binary(ucdrBuffer* buffer, const OBJK_DataWriter_Binary* input); -bool uxr_deserialize_OBJK_DataWriter_Binary(ucdrBuffer* buffer, OBJK_DataWriter_Binary* output); - -bool uxr_serialize_ObjectVariant(ucdrBuffer* buffer, const ObjectVariant* input); -bool uxr_deserialize_ObjectVariant(ucdrBuffer* buffer, ObjectVariant* output); - -bool uxr_serialize_CreationMode(ucdrBuffer* buffer, const CreationMode* input); -bool uxr_deserialize_CreationMode(ucdrBuffer* buffer, CreationMode* output); - -bool uxr_serialize_RequestId(ucdrBuffer* buffer, const RequestId* input); -bool uxr_deserialize_RequestId(ucdrBuffer* buffer, RequestId* output); - -bool uxr_serialize_ResultStatus(ucdrBuffer* buffer, const ResultStatus* input); -bool uxr_deserialize_ResultStatus(ucdrBuffer* buffer, ResultStatus* output); - -bool uxr_serialize_BaseObjectRequest(ucdrBuffer* buffer, const BaseObjectRequest* input); -bool uxr_deserialize_BaseObjectRequest(ucdrBuffer* buffer, BaseObjectRequest* output); - -bool uxr_serialize_AGENT_ActivityInfo(ucdrBuffer* buffer, const AGENT_ActivityInfo* input); -bool uxr_deserialize_AGENT_ActivityInfo(ucdrBuffer* buffer, AGENT_ActivityInfo* output); - -bool uxr_serialize_DATAREADER_ActivityInfo(ucdrBuffer* buffer, const DATAREADER_ActivityInfo* input); -bool uxr_deserialize_DATAREADER_ActivityInfo(ucdrBuffer* buffer, DATAREADER_ActivityInfo* output); - -bool uxr_serialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, const DATAWRITER_ActivityInfo* input); -bool uxr_deserialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, DATAWRITER_ActivityInfo* output); - -bool uxr_serialize_ActivityInfoVariant(ucdrBuffer* buffer, const ActivityInfoVariant* input); -bool uxr_deserialize_ActivityInfoVariant(ucdrBuffer* buffer, ActivityInfoVariant* output); - -bool uxr_serialize_ObjectInfo(ucdrBuffer* buffer, const ObjectInfo* input); -bool uxr_deserialize_ObjectInfo(ucdrBuffer* buffer, ObjectInfo* output); - -bool uxr_serialize_BaseObjectReply(ucdrBuffer* buffer, const BaseObjectReply* input); -bool uxr_deserialize_BaseObjectReply(ucdrBuffer* buffer, BaseObjectReply* output); - -bool uxr_serialize_DataDeliveryControl(ucdrBuffer* buffer, const DataDeliveryControl* input); -bool uxr_deserialize_DataDeliveryControl(ucdrBuffer* buffer, DataDeliveryControl* output); - -bool uxr_serialize_ReadSpecification(ucdrBuffer* buffer, const ReadSpecification* input); -bool uxr_deserialize_ReadSpecification(ucdrBuffer* buffer, ReadSpecification* output); - -bool uxr_serialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, const SeqNumberAndTimestamp* input); -bool uxr_deserialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, SeqNumberAndTimestamp* output); - -bool uxr_serialize_SampleInfoDetail(ucdrBuffer* buffer, const SampleInfoDetail* input); -bool uxr_deserialize_SampleInfoDetail(ucdrBuffer* buffer, SampleInfoDetail* output); - -bool uxr_serialize_SampleInfo(ucdrBuffer* buffer, const SampleInfo* input); -bool uxr_deserialize_SampleInfo(ucdrBuffer* buffer, SampleInfo* output); - -bool uxr_serialize_SampleInfoDelta(ucdrBuffer* buffer, const SampleInfoDelta* input); -bool uxr_deserialize_SampleInfoDelta(ucdrBuffer* buffer, SampleInfoDelta* output); - -bool uxr_serialize_SampleData(ucdrBuffer* buffer, const SampleData* input); -bool uxr_deserialize_SampleData(ucdrBuffer* buffer, SampleData* output); - -bool uxr_serialize_SampleDataSeq(ucdrBuffer* buffer, const SampleDataSeq* input); -bool uxr_deserialize_SampleDataSeq(ucdrBuffer* buffer, SampleDataSeq* output); - -bool uxr_serialize_Sample(ucdrBuffer* buffer, const Sample* input); -bool uxr_deserialize_Sample(ucdrBuffer* buffer, Sample* output); - -bool uxr_serialize_SampleSeq(ucdrBuffer* buffer, const SampleSeq* input); -bool uxr_deserialize_SampleSeq(ucdrBuffer* buffer, SampleSeq* output); - -bool uxr_serialize_SampleDelta(ucdrBuffer* buffer, const SampleDelta* input); -bool uxr_deserialize_SampleDelta(ucdrBuffer* buffer, SampleDelta* output); - -bool uxr_serialize_SampleDeltaSequence(ucdrBuffer* buffer, const SampleDeltaSequence* input); -bool uxr_deserialize_SampleDeltaSequence(ucdrBuffer* buffer, SampleDeltaSequence* output); - -bool uxr_serialize_PackedSamples(ucdrBuffer* buffer, const PackedSamples* input); -bool uxr_deserialize_PackedSamples(ucdrBuffer* buffer, PackedSamples* output); - -bool uxr_serialize_SamplePackedSeq(ucdrBuffer* buffer, const SamplePackedSeq* input); -bool uxr_deserialize_SamplePackedSeq(ucdrBuffer* buffer, SamplePackedSeq* output); - -bool uxr_serialize_DataRepresentation(ucdrBuffer* buffer, const DataRepresentation* input); -bool uxr_deserialize_DataRepresentation(ucdrBuffer* buffer, DataRepresentation* output); - -bool uxr_serialize_CREATE_CLIENT_Payload(ucdrBuffer* buffer, const CREATE_CLIENT_Payload* input); -bool uxr_deserialize_CREATE_CLIENT_Payload(ucdrBuffer* buffer, CREATE_CLIENT_Payload* output); - -bool uxr_serialize_CREATE_Payload(ucdrBuffer* buffer, const CREATE_Payload* input); -bool uxr_deserialize_CREATE_Payload(ucdrBuffer* buffer, CREATE_Payload* output); - -bool uxr_serialize_GET_INFO_Payload(ucdrBuffer* buffer, const GET_INFO_Payload* input); -bool uxr_deserialize_GET_INFO_Payload(ucdrBuffer* buffer, GET_INFO_Payload* output); - -bool uxr_serialize_DELETE_Payload(ucdrBuffer* buffer, const DELETE_Payload* input); -bool uxr_deserialize_DELETE_Payload(ucdrBuffer* buffer, DELETE_Payload* output); - -bool uxr_serialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, const STATUS_AGENT_Payload* input); -bool uxr_deserialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, STATUS_AGENT_Payload* output); - -bool uxr_serialize_STATUS_Payload(ucdrBuffer* buffer, const STATUS_Payload* input); -bool uxr_deserialize_STATUS_Payload(ucdrBuffer* buffer, STATUS_Payload* output); - -bool uxr_serialize_INFO_Payload(ucdrBuffer* buffer, const INFO_Payload* input); -bool uxr_deserialize_INFO_Payload(ucdrBuffer* buffer, INFO_Payload* output); - -bool uxr_serialize_READ_DATA_Payload(ucdrBuffer* buffer, const READ_DATA_Payload* input); -bool uxr_deserialize_READ_DATA_Payload(ucdrBuffer* buffer, READ_DATA_Payload* output); - -bool uxr_serialize_WRITE_DATA_Payload_Data(ucdrBuffer* buffer, const WRITE_DATA_Payload_Data* input); -bool uxr_deserialize_WRITE_DATA_Payload_Data(ucdrBuffer* buffer, WRITE_DATA_Payload_Data* output); - -bool uxr_serialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, const WRITE_DATA_Payload_Sample* input); -bool uxr_deserialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, WRITE_DATA_Payload_Sample* output); - -bool uxr_serialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, const WRITE_DATA_Payload_DataSeq* input); -bool uxr_deserialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, WRITE_DATA_Payload_DataSeq* output); - -bool uxr_serialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const WRITE_DATA_Payload_SampleSeq* input); -bool uxr_deserialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, WRITE_DATA_Payload_SampleSeq* output); - -bool uxr_serialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const WRITE_DATA_Payload_PackedSamples* input); -bool uxr_deserialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, WRITE_DATA_Payload_PackedSamples* output); - -bool uxr_serialize_DATA_Payload_Data(ucdrBuffer* buffer, const DATA_Payload_Data* input); -bool uxr_deserialize_DATA_Payload_Data(ucdrBuffer* buffer, DATA_Payload_Data* output); - -bool uxr_serialize_DATA_Payload_Sample(ucdrBuffer* buffer, const DATA_Payload_Sample* input); -bool uxr_deserialize_DATA_Payload_Sample(ucdrBuffer* buffer, DATA_Payload_Sample* output); - -bool uxr_serialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, const DATA_Payload_DataSeq* input); -bool uxr_deserialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, DATA_Payload_DataSeq* output); - -bool uxr_serialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const DATA_Payload_SampleSeq* input); -bool uxr_deserialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, DATA_Payload_SampleSeq* output); - -bool uxr_serialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const DATA_Payload_PackedSamples* input); -bool uxr_deserialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, DATA_Payload_PackedSamples* output); - -bool uxr_serialize_ACKNACK_Payload(ucdrBuffer* buffer, const ACKNACK_Payload* input); -bool uxr_deserialize_ACKNACK_Payload(ucdrBuffer* buffer, ACKNACK_Payload* output); - -bool uxr_serialize_HEARTBEAT_Payload(ucdrBuffer* buffer, const HEARTBEAT_Payload* input); -bool uxr_deserialize_HEARTBEAT_Payload(ucdrBuffer* buffer, HEARTBEAT_Payload* output); - -bool uxr_serialize_TIMESTAMP_Payload(ucdrBuffer* buffer, const TIMESTAMP_Payload* input); -bool uxr_deserialize_TIMESTAMP_Payload(ucdrBuffer* buffer, TIMESTAMP_Payload* output); - -bool uxr_serialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, const TIMESTAMP_REPLY_Payload* input); -bool uxr_deserialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, TIMESTAMP_REPLY_Payload* output); - -bool uxr_serialize_GuidPrefix_t(ucdrBuffer* buffer, const GuidPrefix_t* input); -bool uxr_deserialize_GuidPrefix_t(ucdrBuffer* buffer, GuidPrefix_t* output); - -bool uxr_serialize_EntityId_t(ucdrBuffer* buffer, const EntityId_t* input); -bool uxr_deserialize_EntityId_t(ucdrBuffer* buffer, EntityId_t* output); - -bool uxr_serialize_GUID_t(ucdrBuffer* buffer, const GUID_t* input); -bool uxr_deserialize_GUID_t(ucdrBuffer* buffer, GUID_t* output); - -bool uxr_serialize_SequenceNumber_t(ucdrBuffer* buffer, const SequenceNumber_t* input); -bool uxr_deserialize_SequenceNumber_t(ucdrBuffer* buffer, SequenceNumber_t* output); - -bool uxr_serialize_SampleIdentity(ucdrBuffer* buffer, const SampleIdentity* input); -bool uxr_deserialize_SampleIdentity(ucdrBuffer* buffer, SampleIdentity* output); +#endif // ifdef PERFORMANCE_TESTING + +bool uxr_serialize_Time_t( + ucdrBuffer* buffer, + const Time_t* input); +bool uxr_deserialize_Time_t( + ucdrBuffer* buffer, + Time_t* output); + +bool uxr_serialize_BinarySequence_t( + ucdrBuffer* buffer, + const BinarySequence_t* input); +bool uxr_deserialize_BinarySequence_t( + ucdrBuffer* buffer, + BinarySequence_t* output); + +bool uxr_serialize_StringSequence_t( + ucdrBuffer* buffer, + const StringSequence_t* input); +bool uxr_deserialize_StringSequence_t( + ucdrBuffer* buffer, + StringSequence_t* output); + +bool uxr_serialize_ClientKey( + ucdrBuffer* buffer, + const ClientKey* input); +bool uxr_deserialize_ClientKey( + ucdrBuffer* buffer, + ClientKey* output); + +bool uxr_serialize_ObjectId( + ucdrBuffer* buffer, + const ObjectId* input); +bool uxr_deserialize_ObjectId( + ucdrBuffer* buffer, + ObjectId* output); + +bool uxr_serialize_ObjectPrefix( + ucdrBuffer* buffer, + const ObjectPrefix* input); +bool uxr_deserialize_ObjectPrefix( + ucdrBuffer* buffer, + ObjectPrefix* output); + +bool uxr_serialize_XrceCookie( + ucdrBuffer* buffer, + const XrceCookie* input); +bool uxr_deserialize_XrceCookie( + ucdrBuffer* buffer, + XrceCookie* output); + +bool uxr_serialize_XrceVersion( + ucdrBuffer* buffer, + const XrceVersion* input); +bool uxr_deserialize_XrceVersion( + ucdrBuffer* buffer, + XrceVersion* output); + +bool uxr_serialize_XrceVendorId( + ucdrBuffer* buffer, + const XrceVendorId* input); +bool uxr_deserialize_XrceVendorId( + ucdrBuffer* buffer, + XrceVendorId* output); + +bool uxr_serialize_TransportLocatorSmall( + ucdrBuffer* buffer, + const TransportLocatorSmall* input); +bool uxr_deserialize_TransportLocatorSmall( + ucdrBuffer* buffer, + TransportLocatorSmall* output); + +bool uxr_serialize_TransportLocatorMedium( + ucdrBuffer* buffer, + const TransportLocatorMedium* input); +bool uxr_deserialize_TransportLocatorMedium( + ucdrBuffer* buffer, + TransportLocatorMedium* output); + +bool uxr_serialize_TransportLocatorLarge( + ucdrBuffer* buffer, + const TransportLocatorLarge* input); +bool uxr_deserialize_TransportLocatorLarge( + ucdrBuffer* buffer, + TransportLocatorLarge* output); + +bool uxr_serialize_TransportLocatorString( + ucdrBuffer* buffer, + const TransportLocatorString* input); +bool uxr_deserialize_TransportLocatorString( + ucdrBuffer* buffer, + TransportLocatorString* output); + +bool uxr_serialize_TransportLocator( + ucdrBuffer* buffer, + const TransportLocator* input); +bool uxr_deserialize_TransportLocator( + ucdrBuffer* buffer, + TransportLocator* output); + +bool uxr_serialize_TransportLocatorSeq( + ucdrBuffer* buffer, + const TransportLocatorSeq* input); +bool uxr_deserialize_TransportLocatorSeq( + ucdrBuffer* buffer, + TransportLocatorSeq* output); + +bool uxr_serialize_Property( + ucdrBuffer* buffer, + const Property* input); +bool uxr_deserialize_Property( + ucdrBuffer* buffer, + Property* output); + +bool uxr_serialize_PropertySeq( + ucdrBuffer* buffer, + const PropertySeq* input); +bool uxr_deserialize_PropertySeq( + ucdrBuffer* buffer, + PropertySeq* output); + +bool uxr_serialize_CLIENT_Representation( + ucdrBuffer* buffer, + const CLIENT_Representation* input); +bool uxr_deserialize_CLIENT_Representation( + ucdrBuffer* buffer, + CLIENT_Representation* output); + +bool uxr_serialize_AGENT_Representation( + ucdrBuffer* buffer, + const AGENT_Representation* input); +bool uxr_deserialize_AGENT_Representation( + ucdrBuffer* buffer, + AGENT_Representation* output); + +bool uxr_serialize_OBJK_Representation3Formats( + ucdrBuffer* buffer, + const OBJK_Representation3Formats* input); +bool uxr_deserialize_OBJK_Representation3Formats( + ucdrBuffer* buffer, + OBJK_Representation3Formats* output); + +bool uxr_serialize_OBJK_RepresentationRefAndXMLFormats( + ucdrBuffer* buffer, + const OBJK_RepresentationRefAndXMLFormats* input); +bool uxr_deserialize_OBJK_RepresentationRefAndXMLFormats( + ucdrBuffer* buffer, + OBJK_RepresentationRefAndXMLFormats* output); + +bool uxr_serialize_OBJK_RepresentationBinAndXMLFormats( + ucdrBuffer* buffer, + const OBJK_RepresentationBinAndXMLFormats* input); +bool uxr_deserialize_OBJK_RepresentationBinAndXMLFormats( + ucdrBuffer* buffer, + OBJK_RepresentationBinAndXMLFormats* output); + +bool uxr_serialize_OBJK_RepresentationRefAndXML_Base( + ucdrBuffer* buffer, + const OBJK_RepresentationRefAndXML_Base* input); +bool uxr_deserialize_OBJK_RepresentationRefAndXML_Base( + ucdrBuffer* buffer, + OBJK_RepresentationRefAndXML_Base* output); + +bool uxr_serialize_OBJK_RepresentationBinAndXML_Base( + ucdrBuffer* buffer, + const OBJK_RepresentationBinAndXML_Base* input); +bool uxr_deserialize_OBJK_RepresentationBinAndXML_Base( + ucdrBuffer* buffer, + OBJK_RepresentationBinAndXML_Base* output); + +bool uxr_serialize_OBJK_Representation3_Base( + ucdrBuffer* buffer, + const OBJK_Representation3_Base* input); +bool uxr_deserialize_OBJK_Representation3_Base( + ucdrBuffer* buffer, + OBJK_Representation3_Base* output); + +bool uxr_serialize_OBJK_QOSPROFILE_Representation( + ucdrBuffer* buffer, + const OBJK_QOSPROFILE_Representation* input); +bool uxr_deserialize_OBJK_QOSPROFILE_Representation( + ucdrBuffer* buffer, + OBJK_QOSPROFILE_Representation* output); + +bool uxr_serialize_OBJK_TYPE_Representation( + ucdrBuffer* buffer, + const OBJK_TYPE_Representation* input); +bool uxr_deserialize_OBJK_TYPE_Representation( + ucdrBuffer* buffer, + OBJK_TYPE_Representation* output); + +bool uxr_serialize_OBJK_DOMAIN_Representation( + ucdrBuffer* buffer, + const OBJK_DOMAIN_Representation* input); +bool uxr_deserialize_OBJK_DOMAIN_Representation( + ucdrBuffer* buffer, + OBJK_DOMAIN_Representation* output); + +bool uxr_serialize_OBJK_APPLICATION_Representation( + ucdrBuffer* buffer, + const OBJK_APPLICATION_Representation* input); +bool uxr_deserialize_OBJK_APPLICATION_Representation( + ucdrBuffer* buffer, + OBJK_APPLICATION_Representation* output); + +bool uxr_serialize_OBJK_PUBLISHER_Representation( + ucdrBuffer* buffer, + const OBJK_PUBLISHER_Representation* input); +bool uxr_deserialize_OBJK_PUBLISHER_Representation( + ucdrBuffer* buffer, + OBJK_PUBLISHER_Representation* output); + +bool uxr_serialize_OBJK_SUBSCRIBER_Representation( + ucdrBuffer* buffer, + const OBJK_SUBSCRIBER_Representation* input); +bool uxr_deserialize_OBJK_SUBSCRIBER_Representation( + ucdrBuffer* buffer, + OBJK_SUBSCRIBER_Representation* output); + +bool uxr_serialize_DATAWRITER_Representation( + ucdrBuffer* buffer, + const DATAWRITER_Representation* input); +bool uxr_deserialize_DATAWRITER_Representation( + ucdrBuffer* buffer, + DATAWRITER_Representation* output); + +bool uxr_serialize_DATAREADER_Representation( + ucdrBuffer* buffer, + const DATAREADER_Representation* input); +bool uxr_deserialize_DATAREADER_Representation( + ucdrBuffer* buffer, + DATAREADER_Representation* output); + +bool uxr_serialize_OBJK_PARTICIPANT_Representation( + ucdrBuffer* buffer, + const OBJK_PARTICIPANT_Representation* input); +bool uxr_deserialize_OBJK_PARTICIPANT_Representation( + ucdrBuffer* buffer, + OBJK_PARTICIPANT_Representation* output); + +bool uxr_serialize_OBJK_TOPIC_Representation( + ucdrBuffer* buffer, + const OBJK_TOPIC_Representation* input); +bool uxr_deserialize_OBJK_TOPIC_Representation( + ucdrBuffer* buffer, + OBJK_TOPIC_Representation* output); + +bool uxr_serialize_OBJK_REQUESTER_Representation( + ucdrBuffer* buffer, + const OBJK_REQUESTER_Representation* input); +bool uxr_deserialize_OBJK_REQUESTER_Representation( + ucdrBuffer* buffer, + OBJK_REQUESTER_Representation* output); + +bool uxr_serialize_OBJK_REPLIER_Representation( + ucdrBuffer* buffer, + const OBJK_REPLIER_Representation* input); +bool uxr_deserialize_OBJK_REPLIER_Representation( + ucdrBuffer* buffer, + OBJK_REPLIER_Representation* output); + +bool uxr_serialize_OBJK_DomainParticipant_Binary( + ucdrBuffer* buffer, + const OBJK_DomainParticipant_Binary* input); +bool uxr_deserialize_OBJK_DomainParticipant_Binary( + ucdrBuffer* buffer, + OBJK_DomainParticipant_Binary* output); + +bool uxr_serialize_OBJK_Topic_Binary( + ucdrBuffer* buffer, + const OBJK_Topic_Binary* input); +bool uxr_deserialize_OBJK_Topic_Binary( + ucdrBuffer* buffer, + OBJK_Topic_Binary* output); + +bool uxr_serialize_OBJK_Publisher_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_Publisher_Binary_Qos* input); +bool uxr_deserialize_OBJK_Publisher_Binary_Qos( + ucdrBuffer* buffer, + OBJK_Publisher_Binary_Qos* output); + +bool uxr_serialize_OBJK_Publisher_Binary( + ucdrBuffer* buffer, + const OBJK_Publisher_Binary* input); +bool uxr_deserialize_OBJK_Publisher_Binary( + ucdrBuffer* buffer, + OBJK_Publisher_Binary* output); + +bool uxr_serialize_OBJK_Subscriber_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_Subscriber_Binary_Qos* input); +bool uxr_deserialize_OBJK_Subscriber_Binary_Qos( + ucdrBuffer* buffer, + OBJK_Subscriber_Binary_Qos* output); + +bool uxr_serialize_OBJK_Subscriber_Binary( + ucdrBuffer* buffer, + const OBJK_Subscriber_Binary* input); +bool uxr_deserialize_OBJK_Subscriber_Binary( + ucdrBuffer* buffer, + OBJK_Subscriber_Binary* output); + +bool uxr_serialize_OBJK_Endpoint_QosBinary( + ucdrBuffer* buffer, + const OBJK_Endpoint_QosBinary* input); +bool uxr_deserialize_OBJK_Endpoint_QosBinary( + ucdrBuffer* buffer, + OBJK_Endpoint_QosBinary* output); + +bool uxr_serialize_OBJK_DataWriter_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_DataWriter_Binary_Qos* input); +bool uxr_deserialize_OBJK_DataWriter_Binary_Qos( + ucdrBuffer* buffer, + OBJK_DataWriter_Binary_Qos* output); + +bool uxr_serialize_OBJK_DataReader_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_DataReader_Binary_Qos* input); +bool uxr_deserialize_OBJK_DataReader_Binary_Qos( + ucdrBuffer* buffer, + OBJK_DataReader_Binary_Qos* output); + +bool uxr_serialize_OBJK_DataReader_Binary( + ucdrBuffer* buffer, + const OBJK_DataReader_Binary* input); +bool uxr_deserialize_OBJK_DataReader_Binary( + ucdrBuffer* buffer, + OBJK_DataReader_Binary* output); + +bool uxr_serialize_OBJK_DataWriter_Binary( + ucdrBuffer* buffer, + const OBJK_DataWriter_Binary* input); +bool uxr_deserialize_OBJK_DataWriter_Binary( + ucdrBuffer* buffer, + OBJK_DataWriter_Binary* output); + +bool uxr_serialize_ObjectVariant( + ucdrBuffer* buffer, + const ObjectVariant* input); +bool uxr_deserialize_ObjectVariant( + ucdrBuffer* buffer, + ObjectVariant* output); + +bool uxr_serialize_CreationMode( + ucdrBuffer* buffer, + const CreationMode* input); +bool uxr_deserialize_CreationMode( + ucdrBuffer* buffer, + CreationMode* output); + +bool uxr_serialize_RequestId( + ucdrBuffer* buffer, + const RequestId* input); +bool uxr_deserialize_RequestId( + ucdrBuffer* buffer, + RequestId* output); + +bool uxr_serialize_ResultStatus( + ucdrBuffer* buffer, + const ResultStatus* input); +bool uxr_deserialize_ResultStatus( + ucdrBuffer* buffer, + ResultStatus* output); + +bool uxr_serialize_BaseObjectRequest( + ucdrBuffer* buffer, + const BaseObjectRequest* input); +bool uxr_deserialize_BaseObjectRequest( + ucdrBuffer* buffer, + BaseObjectRequest* output); + +bool uxr_serialize_AGENT_ActivityInfo( + ucdrBuffer* buffer, + const AGENT_ActivityInfo* input); +bool uxr_deserialize_AGENT_ActivityInfo( + ucdrBuffer* buffer, + AGENT_ActivityInfo* output); + +bool uxr_serialize_DATAREADER_ActivityInfo( + ucdrBuffer* buffer, + const DATAREADER_ActivityInfo* input); +bool uxr_deserialize_DATAREADER_ActivityInfo( + ucdrBuffer* buffer, + DATAREADER_ActivityInfo* output); + +bool uxr_serialize_DATAWRITER_ActivityInfo( + ucdrBuffer* buffer, + const DATAWRITER_ActivityInfo* input); +bool uxr_deserialize_DATAWRITER_ActivityInfo( + ucdrBuffer* buffer, + DATAWRITER_ActivityInfo* output); + +bool uxr_serialize_ActivityInfoVariant( + ucdrBuffer* buffer, + const ActivityInfoVariant* input); +bool uxr_deserialize_ActivityInfoVariant( + ucdrBuffer* buffer, + ActivityInfoVariant* output); + +bool uxr_serialize_ObjectInfo( + ucdrBuffer* buffer, + const ObjectInfo* input); +bool uxr_deserialize_ObjectInfo( + ucdrBuffer* buffer, + ObjectInfo* output); + +bool uxr_serialize_BaseObjectReply( + ucdrBuffer* buffer, + const BaseObjectReply* input); +bool uxr_deserialize_BaseObjectReply( + ucdrBuffer* buffer, + BaseObjectReply* output); + +bool uxr_serialize_DataDeliveryControl( + ucdrBuffer* buffer, + const DataDeliveryControl* input); +bool uxr_deserialize_DataDeliveryControl( + ucdrBuffer* buffer, + DataDeliveryControl* output); + +bool uxr_serialize_ReadSpecification( + ucdrBuffer* buffer, + const ReadSpecification* input); +bool uxr_deserialize_ReadSpecification( + ucdrBuffer* buffer, + ReadSpecification* output); + +bool uxr_serialize_SeqNumberAndTimestamp( + ucdrBuffer* buffer, + const SeqNumberAndTimestamp* input); +bool uxr_deserialize_SeqNumberAndTimestamp( + ucdrBuffer* buffer, + SeqNumberAndTimestamp* output); + +bool uxr_serialize_SampleInfoDetail( + ucdrBuffer* buffer, + const SampleInfoDetail* input); +bool uxr_deserialize_SampleInfoDetail( + ucdrBuffer* buffer, + SampleInfoDetail* output); + +bool uxr_serialize_SampleInfo( + ucdrBuffer* buffer, + const SampleInfo* input); +bool uxr_deserialize_SampleInfo( + ucdrBuffer* buffer, + SampleInfo* output); + +bool uxr_serialize_SampleInfoDelta( + ucdrBuffer* buffer, + const SampleInfoDelta* input); +bool uxr_deserialize_SampleInfoDelta( + ucdrBuffer* buffer, + SampleInfoDelta* output); + +bool uxr_serialize_SampleData( + ucdrBuffer* buffer, + const SampleData* input); +bool uxr_deserialize_SampleData( + ucdrBuffer* buffer, + SampleData* output); + +bool uxr_serialize_SampleDataSeq( + ucdrBuffer* buffer, + const SampleDataSeq* input); +bool uxr_deserialize_SampleDataSeq( + ucdrBuffer* buffer, + SampleDataSeq* output); + +bool uxr_serialize_Sample( + ucdrBuffer* buffer, + const Sample* input); +bool uxr_deserialize_Sample( + ucdrBuffer* buffer, + Sample* output); + +bool uxr_serialize_SampleSeq( + ucdrBuffer* buffer, + const SampleSeq* input); +bool uxr_deserialize_SampleSeq( + ucdrBuffer* buffer, + SampleSeq* output); + +bool uxr_serialize_SampleDelta( + ucdrBuffer* buffer, + const SampleDelta* input); +bool uxr_deserialize_SampleDelta( + ucdrBuffer* buffer, + SampleDelta* output); + +bool uxr_serialize_SampleDeltaSequence( + ucdrBuffer* buffer, + const SampleDeltaSequence* input); +bool uxr_deserialize_SampleDeltaSequence( + ucdrBuffer* buffer, + SampleDeltaSequence* output); + +bool uxr_serialize_PackedSamples( + ucdrBuffer* buffer, + const PackedSamples* input); +bool uxr_deserialize_PackedSamples( + ucdrBuffer* buffer, + PackedSamples* output); + +bool uxr_serialize_SamplePackedSeq( + ucdrBuffer* buffer, + const SamplePackedSeq* input); +bool uxr_deserialize_SamplePackedSeq( + ucdrBuffer* buffer, + SamplePackedSeq* output); + +bool uxr_serialize_DataRepresentation( + ucdrBuffer* buffer, + const DataRepresentation* input); +bool uxr_deserialize_DataRepresentation( + ucdrBuffer* buffer, + DataRepresentation* output); + +bool uxr_serialize_CREATE_CLIENT_Payload( + ucdrBuffer* buffer, + const CREATE_CLIENT_Payload* input); +bool uxr_deserialize_CREATE_CLIENT_Payload( + ucdrBuffer* buffer, + CREATE_CLIENT_Payload* output); + +bool uxr_serialize_CREATE_Payload( + ucdrBuffer* buffer, + const CREATE_Payload* input); +bool uxr_deserialize_CREATE_Payload( + ucdrBuffer* buffer, + CREATE_Payload* output); + +bool uxr_serialize_GET_INFO_Payload( + ucdrBuffer* buffer, + const GET_INFO_Payload* input); +bool uxr_deserialize_GET_INFO_Payload( + ucdrBuffer* buffer, + GET_INFO_Payload* output); + +bool uxr_serialize_DELETE_Payload( + ucdrBuffer* buffer, + const DELETE_Payload* input); +bool uxr_deserialize_DELETE_Payload( + ucdrBuffer* buffer, + DELETE_Payload* output); + +bool uxr_serialize_STATUS_AGENT_Payload( + ucdrBuffer* buffer, + const STATUS_AGENT_Payload* input); +bool uxr_deserialize_STATUS_AGENT_Payload( + ucdrBuffer* buffer, + STATUS_AGENT_Payload* output); + +bool uxr_serialize_STATUS_Payload( + ucdrBuffer* buffer, + const STATUS_Payload* input); +bool uxr_deserialize_STATUS_Payload( + ucdrBuffer* buffer, + STATUS_Payload* output); + +bool uxr_serialize_INFO_Payload( + ucdrBuffer* buffer, + const INFO_Payload* input); +bool uxr_deserialize_INFO_Payload( + ucdrBuffer* buffer, + INFO_Payload* output); + +bool uxr_serialize_READ_DATA_Payload( + ucdrBuffer* buffer, + const READ_DATA_Payload* input); +bool uxr_deserialize_READ_DATA_Payload( + ucdrBuffer* buffer, + READ_DATA_Payload* output); + +bool uxr_serialize_WRITE_DATA_Payload_Data( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_Data* input); +bool uxr_deserialize_WRITE_DATA_Payload_Data( + ucdrBuffer* buffer, + WRITE_DATA_Payload_Data* output); + +bool uxr_serialize_WRITE_DATA_Payload_Sample( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_Sample* input); +bool uxr_deserialize_WRITE_DATA_Payload_Sample( + ucdrBuffer* buffer, + WRITE_DATA_Payload_Sample* output); + +bool uxr_serialize_WRITE_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_DataSeq* input); +bool uxr_deserialize_WRITE_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + WRITE_DATA_Payload_DataSeq* output); + +bool uxr_serialize_WRITE_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_SampleSeq* input); +bool uxr_deserialize_WRITE_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + WRITE_DATA_Payload_SampleSeq* output); + +bool uxr_serialize_WRITE_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_PackedSamples* input); +bool uxr_deserialize_WRITE_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + WRITE_DATA_Payload_PackedSamples* output); + +bool uxr_serialize_DATA_Payload_Data( + ucdrBuffer* buffer, + const DATA_Payload_Data* input); +bool uxr_deserialize_DATA_Payload_Data( + ucdrBuffer* buffer, + DATA_Payload_Data* output); + +bool uxr_serialize_DATA_Payload_Sample( + ucdrBuffer* buffer, + const DATA_Payload_Sample* input); +bool uxr_deserialize_DATA_Payload_Sample( + ucdrBuffer* buffer, + DATA_Payload_Sample* output); + +bool uxr_serialize_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + const DATA_Payload_DataSeq* input); +bool uxr_deserialize_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + DATA_Payload_DataSeq* output); + +bool uxr_serialize_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + const DATA_Payload_SampleSeq* input); +bool uxr_deserialize_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + DATA_Payload_SampleSeq* output); + +bool uxr_serialize_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + const DATA_Payload_PackedSamples* input); +bool uxr_deserialize_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + DATA_Payload_PackedSamples* output); + +bool uxr_serialize_ACKNACK_Payload( + ucdrBuffer* buffer, + const ACKNACK_Payload* input); +bool uxr_deserialize_ACKNACK_Payload( + ucdrBuffer* buffer, + ACKNACK_Payload* output); + +bool uxr_serialize_HEARTBEAT_Payload( + ucdrBuffer* buffer, + const HEARTBEAT_Payload* input); +bool uxr_deserialize_HEARTBEAT_Payload( + ucdrBuffer* buffer, + HEARTBEAT_Payload* output); + +bool uxr_serialize_TIMESTAMP_Payload( + ucdrBuffer* buffer, + const TIMESTAMP_Payload* input); +bool uxr_deserialize_TIMESTAMP_Payload( + ucdrBuffer* buffer, + TIMESTAMP_Payload* output); + +bool uxr_serialize_TIMESTAMP_REPLY_Payload( + ucdrBuffer* buffer, + const TIMESTAMP_REPLY_Payload* input); +bool uxr_deserialize_TIMESTAMP_REPLY_Payload( + ucdrBuffer* buffer, + TIMESTAMP_REPLY_Payload* output); + +bool uxr_serialize_GuidPrefix_t( + ucdrBuffer* buffer, + const GuidPrefix_t* input); +bool uxr_deserialize_GuidPrefix_t( + ucdrBuffer* buffer, + GuidPrefix_t* output); + +bool uxr_serialize_EntityId_t( + ucdrBuffer* buffer, + const EntityId_t* input); +bool uxr_deserialize_EntityId_t( + ucdrBuffer* buffer, + EntityId_t* output); + +bool uxr_serialize_GUID_t( + ucdrBuffer* buffer, + const GUID_t* input); +bool uxr_deserialize_GUID_t( + ucdrBuffer* buffer, + GUID_t* output); + +bool uxr_serialize_SequenceNumber_t( + ucdrBuffer* buffer, + const SequenceNumber_t* input); +bool uxr_deserialize_SequenceNumber_t( + ucdrBuffer* buffer, + SequenceNumber_t* output); + +bool uxr_serialize_SampleIdentity( + ucdrBuffer* buffer, + const SampleIdentity* input); +bool uxr_deserialize_SampleIdentity( + ucdrBuffer* buffer, + SampleIdentity* output); #ifdef PERFORMANCE_TESTING -bool uxr_serialize_PERFORMANCE_Payload(ucdrBuffer* buffer, const PERFORMANCE_Payload* input); -bool uxr_deserialize_PERFORMANCE_Payload(ucdrBuffer* buffer, PERFORMANCE_Payload* input); -#endif +bool uxr_serialize_PERFORMANCE_Payload( + ucdrBuffer* buffer, + const PERFORMANCE_Payload* input); +bool uxr_deserialize_PERFORMANCE_Payload( + ucdrBuffer* buffer, + PERFORMANCE_Payload* input); +#endif // ifdef PERFORMANCE_TESTING #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_CORE_TYPE_XRCETYPES_H_ diff --git a/include/uxr/client/defines.h b/include/uxr/client/defines.h index fa808ff38..506d6593b 100644 --- a/include/uxr/client/defines.h +++ b/include/uxr/client/defines.h @@ -19,6 +19,6 @@ #define COMPOUND_LITERAL(x) x #else #define COMPOUND_LITERAL(x) (x) -#endif +#endif // ifdef __cplusplus #endif // _UXR_CLIENT_DEFINES_H_ diff --git a/include/uxr/client/profile/discovery/discovery.h b/include/uxr/client/profile/discovery/discovery.h index 761272bbf..318d91708 100644 --- a/include/uxr/client/profile/discovery/discovery.h +++ b/include/uxr/client/profile/discovery/discovery.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -28,7 +28,9 @@ extern "C" #include #include -typedef bool (*uxrOnAgentFound) (const TransportLocator* locator, void* args); +typedef bool (* uxrOnAgentFound) ( + const TransportLocator* locator, + void* args); /** * @brief Discovers Agents within the network using UDP/IP multicast with address "239.255.0.2" and port 7400. @@ -62,6 +64,6 @@ UXRDLLAPI void uxr_discovery_agents( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_DISCOVERY_DISCOVERY_H_ diff --git a/include/uxr/client/profile/transport/custom/custom_transport.h b/include/uxr/client/profile/transport/custom/custom_transport.h new file mode 100644 index 000000000..74fced06b --- /dev/null +++ b/include/uxr/client/profile/transport/custom/custom_transport.h @@ -0,0 +1,102 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef UXR_CLIENT_CUSTOM_TRANSPORT_H_ +#define UXR_CLIENT_CUSTOM_TRANSPORT_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include +#include +#include + +struct uxrCustomTransport; + +typedef bool (* open_custom_func) ( + struct uxrCustomTransport* transport); + +typedef bool (* close_custom_func) ( + struct uxrCustomTransport* transport); + +typedef size_t (* write_custom_func) ( + struct uxrCustomTransport* transport, + const uint8_t* buffer, + size_t length, + uint8_t* error_code); + +typedef size_t (* read_custom_func) ( + struct uxrCustomTransport* transport, + uint8_t* buffer, + size_t length, + int timeout, + uint8_t* error_code); + +typedef struct uxrCustomTransport +{ + uint8_t buffer[UXR_CONFIG_CUSTOM_TRANSPORT_MTU]; + bool framing; + uxrFramingIO framing_io; + open_custom_func open; + close_custom_func close; + write_custom_func write; + read_custom_func read; + uxrCommunication comm; + void* args; +} uxrCustomTransport; + + +/** + * @brief Set a Custom transport callbacks. + * @param transport The uninitialized transport structure used for managing the transport. + * @param open Open callback. + * @param close Close callback. + * @param write Write callback. + * @param read Read callback. + */ +UXRDLLAPI void uxr_set_custom_transport_callbacks( + uxrCustomTransport* transport, + bool framing, + open_custom_func open, + close_custom_func close, + write_custom_func write, + read_custom_func read); + +/** + * @brief Initializes a Custom transport. + * @param transport The transport structure used for managing the transport. + * Callbacks must be set. + * @param open_args Arguments for the open function. + * @return `true` in case of successful initialization. `false` in other case. + */ +UXRDLLAPI bool uxr_init_custom_transport( + uxrCustomTransport* transport, + void* args); + +/** + * @brief Closes a Custom transport. + * @param transport The transport structure. + * @return `true` in case of successful closing. `false` in other case. + */ +UXRDLLAPI bool uxr_close_custom_transport( + uxrCustomTransport* transport); + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // UXR_CLIENT_CUSTOM_TRANSPORT_H_ diff --git a/include/uxr/client/profile/transport/ip/ip.h b/include/uxr/client/profile/transport/ip/ip.h index 55ef46671..b1f9907a7 100644 --- a/include/uxr/client/profile/transport/ip/ip.h +++ b/include/uxr/client/profile/transport/ip/ip.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -43,10 +43,10 @@ typedef enum uxrIpProtocol * @return false In other case. */ UXRDLLAPI bool uxr_ip_to_locator( - char const * ip, + char const* ip, uint16_t port, uxrIpProtocol ip_protocol, - TransportLocator * locator); + TransportLocator* locator); /** * @brief Converts a TrasnportLocator to an IPv4/IPv6 address + port. @@ -61,14 +61,14 @@ UXRDLLAPI bool uxr_ip_to_locator( * @return false In other case. */ UXRDLLAPI bool uxr_locator_to_ip( - TransportLocator const * locator, - char * ip, + TransportLocator const* locator, + char* ip, size_t size, - uint16_t * port, - uxrIpProtocol * ip_protocol); + uint16_t* port, + uxrIpProtocol* ip_protocol); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_IP_H_ diff --git a/include/uxr/client/profile/transport/ip/tcp/tcp_transport.h b/include/uxr/client/profile/transport/ip/tcp/tcp_transport.h index c83838fe0..a5cf4bcd4 100644 --- a/include/uxr/client/profile/transport/ip/tcp/tcp_transport.h +++ b/include/uxr/client/profile/transport/ip/tcp/tcp_transport.h @@ -18,13 +18,13 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include #include #include - +#include typedef enum uxrTCPInputBufferState { UXR_TCP_BUFFER_EMPTY, @@ -44,13 +44,11 @@ typedef struct uxrTCPInputBuffer } uxrTCPInputBuffer; -struct uxrTCPPlatform; - typedef struct uxrTCPTransport { uxrTCPInputBuffer input_buffer; uxrCommunication comm; - struct uxrTCPPlatform* platform; + struct uxrTCPPlatform platform; } uxrTCPTransport; @@ -66,7 +64,6 @@ typedef struct uxrTCPTransport */ UXRDLLAPI bool uxr_init_tcp_transport( uxrTCPTransport* transport, - struct uxrTCPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port); @@ -81,6 +78,6 @@ UXRDLLAPI bool uxr_close_tcp_transport( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_TCP_TRANSPORT_H_ diff --git a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_external.h.template b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_external.h.template deleted file mode 100644 index 8c74efc94..000000000 --- a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_external.h.template +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ -#define UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Place here your includes - -typedef struct uxrTCPPlatform -{ - // Place here your platform data -} uxrTCPPlatform; - -#ifdef __cplusplus -} -#endif - -#endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_EXTERNAL_H_ \ No newline at end of file diff --git a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.h b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.h new file mode 100644 index 000000000..623b94a4b --- /dev/null +++ b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.h @@ -0,0 +1,40 @@ +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _UXR_CLIENT_TCP_TRANSPORT_FREERTOS_H_ +#define _UXR_CLIENT_TCP_TRANSPORT_FREERTOS_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include "FreeRTOS.h" +#include "list.h" +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" + +typedef struct uxrTCPPlatform +{ + struct freertos_sockaddr remote_addr; + SocketSet_t poll_fd; + Socket_t fd; + uint8_t use_ethernet; +} uxrTCPPlatform; + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif //_UXR_CLIENT_TCP_TRANSPORT_FREERTOS_H_ diff --git a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_posix.h b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_posix.h index c111308de..3a5733cb3 100644 --- a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_posix.h +++ b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_posix.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -32,6 +32,6 @@ typedef struct uxrTCPPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_TCP_TCPTRANSPORTPOSIX_H_ \ No newline at end of file diff --git a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_windows.h b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_windows.h index 987a3a38e..980260f45 100644 --- a/include/uxr/client/profile/transport/ip/tcp/tcp_transport_windows.h +++ b/include/uxr/client/profile/transport/ip/tcp/tcp_transport_windows.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -30,6 +30,6 @@ typedef struct uxrTCPPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_TCP_TRANSPORT_WINDOWS_H_ diff --git a/include/uxr/client/profile/transport/ip/udp/udp_transport.h b/include/uxr/client/profile/transport/ip/udp/udp_transport.h index 792136768..6c9193e52 100644 --- a/include/uxr/client/profile/transport/ip/udp/udp_transport.h +++ b/include/uxr/client/profile/transport/ip/udp/udp_transport.h @@ -18,21 +18,19 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include #include #include - -struct uxrUDPPlatform; +#include typedef struct uxrUDPTransport { uint8_t buffer[UXR_CONFIG_UDP_TRANSPORT_MTU]; uxrCommunication comm; - struct uxrUDPPlatform* platform; - + struct uxrUDPPlatform platform; } uxrUDPTransport; /** @@ -47,7 +45,6 @@ typedef struct uxrUDPTransport */ UXRDLLAPI bool uxr_init_udp_transport( uxrUDPTransport* transport, - struct uxrUDPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port); @@ -63,6 +60,6 @@ UXRDLLAPI bool uxr_close_udp_transport( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_UDP_TRANSPORT_H_ diff --git a/include/uxr/client/profile/transport/ip/udp/udp_transport_external.h.template b/include/uxr/client/profile/transport/ip/udp/udp_transport_external.h.template deleted file mode 100644 index b61409a55..000000000 --- a/include/uxr/client/profile/transport/ip/udp/udp_transport_external.h.template +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ -#define UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Place here your includes - -typedef struct uxrUDPPlatform -{ - // Place here your platform data -} uxrUDPPlatform; - -#ifdef __cplusplus -} -#endif - -#endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_EXTERNAL_H_ \ No newline at end of file diff --git a/include/uxr/client/profile/transport/serial/serial_transport_windows.h b/include/uxr/client/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.h similarity index 53% rename from include/uxr/client/profile/transport/serial/serial_transport_windows.h rename to include/uxr/client/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.h index a09cda195..a923e1a42 100644 --- a/include/uxr/client/profile/transport/serial/serial_transport_windows.h +++ b/include/uxr/client/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.h @@ -1,45 +1,41 @@ -// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _UXR_CLIENT_SERIAL_TRANSPORT_H_ -#define _UXR_CLIENT_SERIAL_TRANSPORT_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include - -#include -#include -#include - -struct SerialProperties; - -typedef struct SerialTransport -{ - intmax_t (*send_data)(struct SerialTransport* transport, char* buf, size_t len); - intmax_t (*recv_data)(struct SerialTransport* transport, char** buf, size_t* len); - struct SerialProperties* properties; -} SerialTransport; - -UXRDLLAPI bool uxr_init_uart_transport(SerialTransport* transport, const char* device); - -#ifdef __cplusplus -} -#endif - -#endif //_UXR_CLIENT_SERIAL_TRANSPORT_H_ - +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _UXR_CLIENT_UDP_TRANSPORT_FREERTOS_H_ +#define _UXR_CLIENT_UDP_TRANSPORT_FREERTOS_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include "FreeRTOS.h" +#include "list.h" +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" + +typedef struct uxrUDPPlatform +{ + struct freertos_sockaddr remote_addr; + SocketSet_t poll_fd; + Socket_t fd; + uint8_t use_ethernet; + +} uxrUDPPlatform; + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif //_UXR_CLIENT_UDP_TRANSPORT_FREERTOS_H_ diff --git a/include/uxr/client/profile/transport/ip/udp/udp_transport_posix.h b/include/uxr/client/profile/transport/ip/udp/udp_transport_posix.h index b661e44a2..160c59714 100644 --- a/include/uxr/client/profile/transport/ip/udp/udp_transport_posix.h +++ b/include/uxr/client/profile/transport/ip/udp/udp_transport_posix.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -32,6 +32,6 @@ typedef struct uxrUDPPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_UDPTRANSPORTPOSIX_H_ diff --git a/include/uxr/client/profile/transport/ip/udp/udp_transport_posix_nopoll.h b/include/uxr/client/profile/transport/ip/udp/udp_transport_posix_nopoll.h index 22a500e21..57447e596 100644 --- a/include/uxr/client/profile/transport/ip/udp/udp_transport_posix_nopoll.h +++ b/include/uxr/client/profile/transport/ip/udp/udp_transport_posix_nopoll.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus typedef struct uxrUDPPlatform { @@ -27,6 +27,6 @@ typedef struct uxrUDPPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_TRANSPORT_IP_UDP_UDPTRANSPORTPOSIXNOPOLL_H_ \ No newline at end of file diff --git a/include/uxr/client/profile/transport/ip/udp/udp_transport_windows.h b/include/uxr/client/profile/transport/ip/udp/udp_transport_windows.h index 9afb9590c..40a52c105 100644 --- a/include/uxr/client/profile/transport/ip/udp/udp_transport_windows.h +++ b/include/uxr/client/profile/transport/ip/udp/udp_transport_windows.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -30,6 +30,6 @@ typedef struct uxrUDPPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_UDP_TRANSPORT_WINDOWS_H_ diff --git a/include/uxr/client/profile/transport/serial/serial_transport.h b/include/uxr/client/profile/transport/serial/serial_transport.h index dc2268b02..add08b80e 100644 --- a/include/uxr/client/profile/transport/serial/serial_transport.h +++ b/include/uxr/client/profile/transport/serial/serial_transport.h @@ -18,22 +18,21 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include -#include +#include #include #include - -struct uxrSerialPlatform; +#include typedef struct uxrSerialTransport { uint8_t buffer[UXR_CONFIG_SERIAL_TRANSPORT_MTU]; - uxrSerialIO serial_io; + uxrFramingIO framing_io; uint8_t remote_addr; uxrCommunication comm; - struct uxrSerialPlatform* platform; + struct uxrSerialPlatform platform; } uxrSerialTransport; @@ -52,7 +51,6 @@ typedef struct uxrSerialTransport */ UXRDLLAPI bool uxr_init_serial_transport( uxrSerialTransport* transport, - struct uxrSerialPlatform* platform, const int fd, uint8_t remote_addr, uint8_t local_addr); @@ -62,10 +60,11 @@ UXRDLLAPI bool uxr_init_serial_transport( * @param transport The transport structure. * @return `true` in case of successful closing. `false` in other case. */ -UXRDLLAPI bool uxr_close_serial_transport(uxrSerialTransport* transport); +UXRDLLAPI bool uxr_close_serial_transport( + uxrSerialTransport* transport); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_SERIAL_TRANSPORT_H_ diff --git a/include/uxr/client/profile/transport/serial/serial_transport_external.h.template b/include/uxr/client/profile/transport/serial/serial_transport_external.h.template deleted file mode 100644 index ad8661c84..000000000 --- a/include/uxr/client/profile/transport/serial/serial_transport_external.h.template +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ -#define UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Place here your includes - -typedef struct uxrSerialPlatform -{ - // Place here your platform data -} uxrSerialPlatform; - -#ifdef __cplusplus -} -#endif - -#endif // UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_EXTERNAL_H_ \ No newline at end of file diff --git a/include/uxr/client/profile/transport/serial/serial_transport_platform.h b/include/uxr/client/profile/transport/serial/serial_transport_platform.h index 3dfc4a795..96b7e45a6 100644 --- a/include/uxr/client/profile/transport/serial/serial_transport_platform.h +++ b/include/uxr/client/profile/transport/serial/serial_transport_platform.h @@ -18,26 +18,33 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include -bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, const int fd, uint8_t remote_addr, uint8_t local_addr); -bool uxr_close_serial_platform(struct uxrSerialPlatform* platform); - -size_t uxr_write_serial_data_platform(struct uxrSerialPlatform* platform, - uint8_t* buf, - size_t len, - uint8_t* errcode); - -size_t uxr_read_serial_data_platform(struct uxrSerialPlatform* platform, - uint8_t* buf, - size_t len, - int timeout, - uint8_t* errcode); +bool uxr_init_serial_platform( + void* args, + const int fd, + uint8_t remote_addr, + uint8_t local_addr); +bool uxr_close_serial_platform( + void* args); + +size_t uxr_write_serial_data_platform( + void* args, + const uint8_t* buf, + size_t len, + uint8_t* errcode); + +size_t uxr_read_serial_data_platform( + void* args, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif //_SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_TRANSPORT_PLATFORM_H_ diff --git a/include/uxr/client/profile/transport/serial/serial_transport_posix.h b/include/uxr/client/profile/transport/serial/serial_transport_posix.h index 6a0545c5f..55eba063b 100644 --- a/include/uxr/client/profile/transport/serial/serial_transport_posix.h +++ b/include/uxr/client/profile/transport/serial/serial_transport_posix.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -30,6 +30,6 @@ typedef struct uxrSerialPlatform #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIALTRANSPORTPOSIX_H_ diff --git a/include/uxr/client/profile/transport/serial/serial_protocol.h b/include/uxr/client/profile/transport/stream_framing/stream_framing_protocol.h similarity index 61% rename from include/uxr/client/profile/transport/serial/serial_protocol.h rename to include/uxr/client/profile/transport/stream_framing/stream_framing_protocol.h index a3195311e..66d6f55ef 100644 --- a/include/uxr/client/profile/transport/serial/serial_protocol.h +++ b/include/uxr/client/profile/transport/stream_framing/stream_framing_protocol.h @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ -#define _UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ +#ifndef _UXR_CLIENT_PROFILE_TRANSPORT_STREAM_FRAMING_PROTOCOL_H_ +#define _UXR_CLIENT_PROFILE_TRANSPORT_STREAM_FRAMING_PROTOCOL_H_ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -25,22 +25,22 @@ extern "C" #define UXR_FRAMING_ESC_FLAG 0x7D #define UXR_FRAMING_XOR_FLAG 0x20 -typedef enum uxrSerialInputState +typedef enum uxrFramingInputState { - UXR_SERIAL_UNINITIALIZED, - UXR_SERIAL_READING_SRC_ADDR, - UXR_SERIAL_READING_DST_ADDR, - UXR_SERIAL_READING_LEN_LSB, - UXR_SERIAL_READING_LEN_MSB, - UXR_SERIAL_READING_PAYLOAD, - UXR_SERIAL_READING_CRC_LSB, - UXR_SERIAL_READING_CRC_MSB, - -} uxrSerialInputState; - -typedef struct uxrSerialIO + UXR_FRAMING_UNINITIALIZED, + UXR_FRAMING_READING_SRC_ADDR, + UXR_FRAMING_READING_DST_ADDR, + UXR_FRAMING_READING_LEN_LSB, + UXR_FRAMING_READING_LEN_MSB, + UXR_FRAMING_READING_PAYLOAD, + UXR_FRAMING_READING_CRC_LSB, + UXR_FRAMING_READING_CRC_MSB, + +} uxrFramingInputState; + +typedef struct uxrFramingIO { - uxrSerialInputState state; + uxrFramingInputState state; uint8_t local_addr; uint8_t rb[42]; uint8_t rb_head; @@ -53,10 +53,10 @@ typedef struct uxrSerialIO uint8_t wb[42]; uint8_t wb_pos; -} uxrSerialIO; +} uxrFramingIO; #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus -#endif //_UXR_CLIENT_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ +#endif //_UXR_CLIENT_PROFILE_TRANSPORT_STREAM_FRAMING_PROTOCOL_H_ diff --git a/include/uxr/client/transport.h b/include/uxr/client/transport.h index f006416e4..502f60ce7 100644 --- a/include/uxr/client/transport.h +++ b/include/uxr/client/transport.h @@ -17,8 +17,7 @@ #include -#ifdef PROFILE_UDP_TRANSPORT -#include +#ifdef UCLIENT_PROFILE_UDP #if defined(UCLIENT_EXTERNAL_UDP) #include #elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) @@ -27,28 +26,34 @@ #include #elif defined(UCLIENT_PLATFORM_WINDOWS) #include -#endif -#endif //PROFILE_UDP_TRANSPORT +#elif defined(UCLIENT_PLATFORM_FREERTOS_PLUS_TCP) +#include +#endif // if defined(UCLIENT_EXTERNAL_UDP) +#include +#endif //UCLIENT_PROFILE_UDP -#ifdef PROFILE_TCP_TRANSPORT -#include +#ifdef UCLIENT_PROFILE_TCP #if defined(UCLIENT_EXTERNAL_TCP) #include #elif defined(UCLIENT_PLATFORM_POSIX) #include #elif defined(UCLIENT_PLATFORM_WINDOWS) #include -#endif -#endif //PROFILE_TCP_TRANSPORT +#endif // if defined(UCLIENT_EXTERNAL_TCP) +#include +#endif //UCLIENT_PROFILE_TCP -#ifdef PROFILE_SERIAL_TRANSPORT -#include +#ifdef UCLIENT_PROFILE_SERIAL #if defined(UCLIENT_EXTERNAL_SERIAL) #include #elif defined(UCLIENT_PLATFORM_POSIX) #include -#elif defined(UCLIENT_PLATFORM_WINDOWS) -#endif -#endif //PROFILE_SERIAL_TRANSPORT +#endif // if defined(UCLIENT_EXTERNAL_SERIAL) +#include +#endif //UCLIENT_PROFILE_SERIAL + +#ifdef UCLIENT_PROFILE_CUSTOM_TRANSPORT +#include +#endif //UCLIENT_PROFILE_CUSTOM_TRANSPORT #endif // UXR_CLIENT_TRANSPORT_H_ diff --git a/include/uxr/client/util/ping.h b/include/uxr/client/util/ping.h new file mode 100644 index 000000000..b749fdcce --- /dev/null +++ b/include/uxr/client/util/ping.h @@ -0,0 +1,71 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef UXR_CLIENT_UTIL_PING_H_ +#define UXR_CLIENT_UTIL_PING_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include +#include + +#include + +#define UXR_PING_BUF 16 // 4 (HEADER SIZE) + 4 (SUBHEADER_SIZE) + 8 (GET_Info payload) + +#define GET_INFO_MSG_SIZE 8 +#define GET_INFO_REQUEST_ID 9 + +/** + * @brief Checks the availability status of a valid connection with an agent. + * This methods performs a single attempt. + * Transport must be properly initialized before calling this method. + * This method does not take care of init/fini the transport struct. + * @param comm Pointer to the uxrCommunication struct holding the transport + * information and callback methods. + * @param timeout Time, in milliseconds, for a ping attempt. + * @return `true` in case of a successful ping to the agent, `false` otherwise. + */ +UXRDLLAPI bool uxr_ping_agent( + const uxrCommunication* comm, + const int timeout); + +/** + * @brief Checks the availability status of a valid connection with an agent. + * Additionally, this method allows the user to specify the number + * of attempts to be performed. This number will not be reached if a + * successful ping occurs. + * Transport must be properly initialized before calling this method. + * This method does not take care of init/fini the transport struct. + * @param comm Pointer to the uxrCommunication struct holding the transport + * information and callback methods. + * @param timeout Time, in milliseconds, for a ping attempt. + * @param attempts Maximum number of ping attempts to be performed. + * @return `true` in case of a successful ping to the agent, `false` otherwise. + */ +UXRDLLAPI bool uxr_ping_agent_attempts( + const uxrCommunication* comm, + const int timeout, + const uint8_t attempts); + + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif // UXR_CLIENT_UTIL_PING_H_ \ No newline at end of file diff --git a/include/uxr/client/util/time.h b/include/uxr/client/util/time.h index 1945fe624..1dc04f1ec 100644 --- a/include/uxr/client/util/time.h +++ b/include/uxr/client/util/time.h @@ -18,17 +18,19 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include -UXRDLLAPI int64_t uxr_millis(void); +UXRDLLAPI int64_t uxr_millis( + void); -UXRDLLAPI int64_t uxr_nanos(void); +UXRDLLAPI int64_t uxr_nanos( + void); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // UXR_CLIENT_UTIL_TIME_H_ diff --git a/src/c/core/log/log.c b/src/c/core/log/log.c index b68637d77..fb041d6d2 100644 --- a/src/c/core/log/log.c +++ b/src/c/core/log/log.c @@ -48,52 +48,95 @@ /* Compute output buffer size. */ #if !defined(UXR_CONFIG_SERIAL_TRANSPORT_MTU) #define UXR_CONFIG_SERIAL_TRANSPORT_MTU 0 -#endif +#endif /* if !defined(UXR_CONFIG_SERIAL_TRANSPORT_MTU) */ #if !defined(UXR_CONFIG_UDP_TRANSPORT_MTU) #define UXR_CONFIG_UDP_TRANSPORT_MTU 0 -#endif +#endif /* if !defined(UXR_CONFIG_UDP_TRANSPORT_MTU) */ #if !defined(UXR_CONFIG_TCP_TRANSPORT_MTU) #define UXR_CONFIG_TCP_TRANSPORT_MTU 0 -#endif +#endif /* if !defined(UXR_CONFIG_TCP_TRANSPORT_MTU) */ #if UXR_CONFIG_UDP_TRANSPORT_MTU > UXR_CONFIG_TCP_TRANSPORT_MTU #define MAX_UDP_TCP_MTU UXR_CONFIG_UDP_TRANSPORT_MTU #else #define MAX_UDP_TCP_MTU UXR_CONFIG_TCP_TRANSPORT_MTU -#endif +#endif /* if UXR_CONFIG_UDP_TRANSPORT_MTU > UXR_CONFIG_TCP_TRANSPORT_MTU */ #if UXR_CONFIG_SERIAL_TRANSPORT_MTU > MAX_UDP_TCP_MTU #define MAX_MTU_CONFIG UXR_CONFIG_SERIAL_TRANSPORT_MTU #else #define MAX_MTU_CONFIG MAX_UDP_TCP_MTU -#endif - -#define DATA_TO_STRING_BUFFER MAX_MTU_CONFIG * 3 + 100 - -static char* print_array_2(const uint8_t* array_2); -static const char* data_to_string(const uint8_t* data, uint32_t size); -static const char* request_to_string(const BaseObjectRequest* request); -static const char* reply_to_string(const BaseObjectReply* reply); -static void print_create_client_submessage(const char* pre, const CREATE_CLIENT_Payload* payload); -static void print_create_submessage(const char* pre, const CREATE_Payload* payload, uint8_t flags); -static void print_get_info_submessage(const char* pre, const GET_INFO_Payload* payload); -static void print_delete_submessage(const char* pre, const DELETE_Payload* payload); -static void print_status_agent_submessage(const char* pre, const STATUS_AGENT_Payload* payload); -static void print_status_submessage(const char* pre, const STATUS_Payload* payload); -static void print_info_submessage(const char* pre, const INFO_Payload* payload); -static void print_read_data_submessage(const char* pre, const READ_DATA_Payload* payload); -static void print_write_data_data_submessage(const char* pre, const WRITE_DATA_Payload_Data* payload); -static void print_data_data_submessage(const char* pre, const DATA_Payload_Data* payload); -static void print_acknack_submessage(const char* pre, const ACKNACK_Payload* payload); -static void print_heartbeat_submessage(const char* pre, const HEARTBEAT_Payload* payload); -static void print_fragment_submessage(const char* pre, uint16_t size, uint8_t flags); -static void print_header(size_t size, int direction, uint8_t stream_id, uint16_t seq_num, const uint8_t* client_key); -static void print_tail(int64_t initial_log_time); +#endif /* if UXR_CONFIG_SERIAL_TRANSPORT_MTU > MAX_UDP_TCP_MTU */ + +#define DATA_TO_STRING_BUFFER MAX_MTU_CONFIG* 3 + 100 + +static char* print_array_2( + const uint8_t* array_2); +static const char* data_to_string( + const uint8_t* data, + uint32_t size); +static const char* request_to_string( + const BaseObjectRequest* request); +static const char* reply_to_string( + const BaseObjectReply* reply); +static void print_create_client_submessage( + const char* pre, + const CREATE_CLIENT_Payload* payload); +static void print_create_submessage( + const char* pre, + const CREATE_Payload* payload, + uint8_t flags); +static void print_get_info_submessage( + const char* pre, + const GET_INFO_Payload* payload); +static void print_delete_submessage( + const char* pre, + const DELETE_Payload* payload); +static void print_status_agent_submessage( + const char* pre, + const STATUS_AGENT_Payload* payload); +static void print_status_submessage( + const char* pre, + const STATUS_Payload* payload); +static void print_info_submessage( + const char* pre, + const INFO_Payload* payload); +static void print_read_data_submessage( + const char* pre, + const READ_DATA_Payload* payload); +static void print_write_data_data_submessage( + const char* pre, + const WRITE_DATA_Payload_Data* payload); +static void print_data_data_submessage( + const char* pre, + const DATA_Payload_Data* payload); +static void print_acknack_submessage( + const char* pre, + const ACKNACK_Payload* payload); +static void print_heartbeat_submessage( + const char* pre, + const HEARTBEAT_Payload* payload); +static void print_fragment_submessage( + const char* pre, + uint16_t size, + uint8_t flags); +static void print_header( + size_t size, + int direction, + uint8_t stream_id, + uint16_t seq_num, + const uint8_t* client_key); +static void print_tail( + int64_t initial_log_time); //================================================================== // PUBLIC //================================================================== -void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_t* client_key) +void uxr_print_message( + int direction, + uint8_t* buffer, + size_t size, + const uint8_t* client_key) { static int64_t initial_log_time = 0; @@ -127,14 +170,14 @@ void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_ size_t submessage_counter = 0; uint8_t submessage_id; uint16_t length; uint8_t flags; - while(uxr_read_submessage_header(&ub, &submessage_id, &length, &flags)) + while (uxr_read_submessage_header(&ub, &submessage_id, &length, &flags)) { - if(submessage_counter != 0) + if (submessage_counter != 0) { printf("\n "); } - switch(submessage_id) + switch (submessage_id) { case SUBMESSAGE_ID_CREATE_CLIENT: { @@ -149,7 +192,8 @@ void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_ { char string_buffer[DATA_TO_STRING_BUFFER]; CREATE_Payload payload; - payload.object_representation._.participant.base.representation._.xml_string_represenatation = string_buffer; + payload.object_representation._.participant.base.representation._.xml_string_represenatation = + string_buffer; payload.object_representation._.publisher.base.representation._.string_represenatation = string_buffer; uxr_deserialize_CREATE_Payload(&ub, &payload); @@ -268,7 +312,10 @@ void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_ printf(" \n"); } -void uxr_print_serialization(int direction, const uint8_t* buffer, size_t size) +void uxr_print_serialization( + int direction, + const uint8_t* buffer, + size_t size) { const char* dir; switch (direction) @@ -301,23 +348,29 @@ void uxr_print_serialization(int direction, const uint8_t* buffer, size_t size) //================================================================== // PRIVATE //================================================================== -char* print_array_2(const uint8_t* array_2) +char* print_array_2( + const uint8_t* array_2) { static char buffer[249]; sprintf(buffer, "%02X%02X", array_2[0], array_2[1]); return buffer; } -const char* data_to_string(const uint8_t* data, uint32_t size) +const char* data_to_string( + const uint8_t* data, + uint32_t size) { static char buffer[DATA_TO_STRING_BUFFER]; - for(uint32_t i = 0; i < size; i++) + for (uint32_t i = 0; i < size; i++) + { sprintf(buffer + 3 * i, "%02X ", data[i]); + } buffer[3 * size] = '\0'; return buffer; } -const char* request_to_string(const BaseObjectRequest* request) +const char* request_to_string( + const BaseObjectRequest* request) { static char buffer[256]; int pos = sprintf(buffer, "req: 0x%s", print_array_2(request->request_id.data)); @@ -326,12 +379,13 @@ const char* request_to_string(const BaseObjectRequest* request) return buffer; } -const char* reply_to_string(const BaseObjectReply* reply) +const char* reply_to_string( + const BaseObjectReply* reply) { static char buffer[256]; char status[64]; - switch(reply->result.status) + switch (reply->result.status) { case UXR_STATUS_OK: sprintf(status, "OK"); @@ -374,7 +428,9 @@ const char* reply_to_string(const BaseObjectReply* reply) return buffer; } -void print_create_client_submessage(const char* pre, const CREATE_CLIENT_Payload* payload) +void print_create_client_submessage( + const char* pre, + const CREATE_CLIENT_Payload* payload) { printf("%s[CREATE CLIENT | session: 0x%02X | key: %s]%s", pre, @@ -383,10 +439,13 @@ void print_create_client_submessage(const char* pre, const CREATE_CLIENT_Payload RESTORE_COLOR); } -void print_create_submessage(const char* pre, const CREATE_Payload* payload, uint8_t flags) +void print_create_submessage( + const char* pre, + const CREATE_Payload* payload, + uint8_t flags) { char type[4]; - switch(payload->object_representation._.participant.base.representation.format) + switch (payload->object_representation._.participant.base.representation.format) { case DDS_XRCE_REPRESENTATION_AS_XML_STRING: strcpy(type, "xml"); @@ -403,42 +462,51 @@ void print_create_submessage(const char* pre, const CREATE_Payload* payload, uin } char content[DATA_TO_STRING_BUFFER]; - switch(payload->object_representation.kind) + switch (payload->object_representation.kind) { case DDS_XRCE_OBJK_PARTICIPANT: sprintf(content, "PARTICIPANT | %s: %zu", type, - strlen(payload->object_representation._.participant.base.representation._.xml_string_represenatation) + 1); + strlen( + payload->object_representation._.participant.base.representation._.xml_string_represenatation) + + 1); break; case DDS_XRCE_OBJK_TOPIC: sprintf(content, "TOPIC | obj: 0x%s | %s: %zu", print_array_2(payload->object_representation._.data_reader.subscriber_id.data), type, - strlen(payload->object_representation._.topic.base.representation._.xml_string_represenatation) + 1); + strlen(payload->object_representation._.topic.base.representation._.xml_string_represenatation) + + 1); break; case DDS_XRCE_OBJK_PUBLISHER: sprintf(content, "PUBLISHER | obj: 0x%s | %s: %zu", print_array_2(payload->object_representation._.publisher.participant_id.data), type, - strlen(payload->object_representation._.publisher.base.representation._.string_represenatation) + 1); + strlen(payload->object_representation._.publisher.base.representation._.string_represenatation) + + 1); break; case DDS_XRCE_OBJK_SUBSCRIBER: sprintf(content, "SUBSCRIBER | obj: 0x%s | %s: %zu", print_array_2(payload->object_representation._.subscriber.participant_id.data), type, - strlen(payload->object_representation._.subscriber.base.representation._.string_represenatation) + 1); + strlen(payload->object_representation._.subscriber.base.representation._.string_represenatation) + + 1); break; case DDS_XRCE_OBJK_DATAWRITER: sprintf(content, "DATAWRITER | obj: 0x%s | %s: %zu", print_array_2(payload->object_representation._.data_writer.publisher_id.data), type, - strlen(payload->object_representation._.data_writer.base.representation._.xml_string_represenatation) + 1); - break; + strlen( + payload->object_representation._.data_writer.base.representation._.xml_string_represenatation) + + 1); + break; case DDS_XRCE_OBJK_DATAREADER: sprintf(content, "DATAREADER | obj: 0x%s | %s: %zu", print_array_2(payload->object_representation._.data_reader.subscriber_id.data), type, - strlen(payload->object_representation._.data_reader.base.representation._.xml_string_represenatation) + 1); + strlen( + payload->object_representation._.data_reader.base.representation._.xml_string_represenatation) + + 1); break; default: sprintf(content, "UNKNOWN"); @@ -446,7 +514,8 @@ void print_create_submessage(const char* pre, const CREATE_Payload* payload, uin const char* reuse_flag = (flags & UXR_REUSE) ? "REUSE" : ""; const char* replace_flag = (flags & UXR_REPLACE) ? "REPLACE" : ""; - const char* separator = ((flags & UXR_REUSE && flags & UXR_REPLACE) || (!(flags & UXR_REUSE) && !(flags & UXR_REPLACE))) ? " " : ""; + const char* separator = + ((flags & UXR_REUSE && flags & UXR_REPLACE) || (!(flags & UXR_REUSE) && !(flags & UXR_REPLACE))) ? " " : ""; printf("%s[CREATE | %s%s%s | %s | %s]%s", pre, @@ -458,7 +527,9 @@ void print_create_submessage(const char* pre, const CREATE_Payload* payload, uin RESTORE_COLOR); } -void print_get_info_submessage(const char* pre, const GET_INFO_Payload* payload) +void print_get_info_submessage( + const char* pre, + const GET_INFO_Payload* payload) { const char* config = (payload->info_mask & 1) ? "CONFIG" : ""; const char* activity = (payload->info_mask & 2) ? "ACTIVITY" : ""; @@ -471,7 +542,9 @@ void print_get_info_submessage(const char* pre, const GET_INFO_Payload* payload) RESTORE_COLOR); } -void print_delete_submessage(const char* pre, const DELETE_Payload* payload) +void print_delete_submessage( + const char* pre, + const DELETE_Payload* payload) { printf("%s[DELETE | %s]%s", pre, @@ -479,7 +552,9 @@ void print_delete_submessage(const char* pre, const DELETE_Payload* payload) RESTORE_COLOR); } -void print_status_agent_submessage(const char* pre, const STATUS_AGENT_Payload* payload) +void print_status_agent_submessage( + const char* pre, + const STATUS_AGENT_Payload* payload) { (void) payload; printf("%s[STATUS AGENT]%s", @@ -487,7 +562,9 @@ void print_status_agent_submessage(const char* pre, const STATUS_AGENT_Payload* RESTORE_COLOR); } -void print_status_submessage(const char* pre, const STATUS_Payload* payload) +void print_status_submessage( + const char* pre, + const STATUS_Payload* payload) { printf("%s[STATUS | %s]%s", pre, @@ -495,7 +572,9 @@ void print_status_submessage(const char* pre, const STATUS_Payload* payload) RESTORE_COLOR); } -void print_info_submessage(const char* pre, const INFO_Payload* payload) +void print_info_submessage( + const char* pre, + const INFO_Payload* payload) { const uint8_t* ip = payload->object_info.activity._.agent.address_seq.data[0]._.medium_locator.address; uint16_t port = payload->object_info.activity._.agent.address_seq.data[0]._.medium_locator.locator_port; @@ -508,10 +587,12 @@ void print_info_submessage(const char* pre, const INFO_Payload* payload) RESTORE_COLOR); } -void print_read_data_submessage(const char* pre, const READ_DATA_Payload* payload) +void print_read_data_submessage( + const char* pre, + const READ_DATA_Payload* payload) { char format[128]; - switch(payload->read_specification.data_format) + switch (payload->read_specification.data_format) { case FORMAT_DATA: sprintf(format, "DATA"); @@ -542,7 +623,9 @@ void print_read_data_submessage(const char* pre, const READ_DATA_Payload* payloa RESTORE_COLOR); } -void print_write_data_data_submessage(const char* pre, const WRITE_DATA_Payload_Data* payload) +void print_write_data_data_submessage( + const char* pre, + const WRITE_DATA_Payload_Data* payload) { printf("%s[WRITE DATA | format: DATA | %s]%s", pre, @@ -550,7 +633,9 @@ void print_write_data_data_submessage(const char* pre, const WRITE_DATA_Payload_ RESTORE_COLOR); } -void print_data_data_submessage(const char* pre, const DATA_Payload_Data* payload) +void print_data_data_submessage( + const char* pre, + const DATA_Payload_Data* payload) { printf("%s[DATA | format: DATA | %s]%s", pre, @@ -558,10 +643,14 @@ void print_data_data_submessage(const char* pre, const DATA_Payload_Data* payloa RESTORE_COLOR); } -void print_acknack_submessage(const char* pre, const ACKNACK_Payload* payload) +void print_acknack_submessage( + const char* pre, + const ACKNACK_Payload* payload) { - char bitmask[17] = {0}; - for(int i = 0; i < 8; i++) + char bitmask[17] = { + 0 + }; + for (int i = 0; i < 8; i++) { bitmask[15 - i] = (payload->nack_bitmap[1] & (1 << i)) ? '1' : '0'; bitmask[7 - i] = (payload->nack_bitmap[0] & (1 << i)) ? '1' : '0'; @@ -575,7 +664,9 @@ void print_acknack_submessage(const char* pre, const ACKNACK_Payload* payload) RESTORE_COLOR); } -void print_heartbeat_submessage(const char* pre, const HEARTBEAT_Payload* payload) +void print_heartbeat_submessage( + const char* pre, + const HEARTBEAT_Payload* payload) { printf("%s[HEARTBEAT | stream: 0x%02X | first: %hu | last: %hu]%s", pre, @@ -585,7 +676,10 @@ void print_heartbeat_submessage(const char* pre, const HEARTBEAT_Payload* payloa RESTORE_COLOR); } -void print_fragment_submessage(const char* pre, uint16_t size, uint8_t flags) +void print_fragment_submessage( + const char* pre, + uint16_t size, + uint8_t flags) { printf("%s[FRAGMENT | size: %hu | %s]%s", pre, @@ -594,7 +688,12 @@ void print_fragment_submessage(const char* pre, uint16_t size, uint8_t flags) RESTORE_COLOR); } -void print_header(size_t size, int direction, uint8_t stream_id, uint16_t seq_num, const uint8_t* client_key) +void print_header( + size_t size, + int direction, + uint8_t stream_id, + uint16_t seq_num, + const uint8_t* client_key) { const char* arrow; const char* color; @@ -623,11 +722,11 @@ void print_header(size_t size, int direction, uint8_t stream_id, uint16_t seq_nu } char stream_representation; - if(0 == stream_id) + if (0 == stream_id) { stream_representation = 'n'; } - else if(0x80 <= stream_id) + else if (0x80 <= stream_id) { stream_representation = 'r'; } @@ -649,13 +748,13 @@ void print_header(size_t size, int direction, uint8_t stream_id, uint16_t seq_nu RESTORE_COLOR); } -void print_tail(int64_t initial_log_time) +void print_tail( + int64_t initial_log_time) { int64_t ms = uxr_millis() - initial_log_time; #ifdef WIN32 printf(" %st: %I64ims%s", BLUE, ms, RESTORE_COLOR); #else printf(" %st: %" PRId64 "ms%s", BLUE, ms, RESTORE_COLOR); -#endif +#endif /* ifdef WIN32 */ } - diff --git a/src/c/core/log/log_internal.h b/src/c/core/log/log_internal.h index 055474feb..19649e8dc 100644 --- a/src/c/core/log/log_internal.h +++ b/src/c/core/log/log_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -32,30 +32,37 @@ extern "C" #define UXR_MESSAGE_LOGS_AVAILABLE 1 #else #define UXR_MESSAGE_LOGS_AVAILABLE 0 -#endif +#endif // ifdef UXR_MESSAGE_LOGS #ifdef UXR_SERIALIZATION_LOGS #define UXR_SERIALIZATION_LOGS_AVAILABLE 1 #else #define UXR_SERIALIZATION_LOGS_AVAILABLE 0 -#endif +#endif // ifdef UXR_SERIALIZATION_LOGS -void uxr_print_message(int direction, uint8_t* buffer, size_t size, const uint8_t* client_key); -void uxr_print_serialization(int direction, const uint8_t* buffer, size_t size); +void uxr_print_message( + int direction, + uint8_t* buffer, + size_t size, + const uint8_t* client_key); +void uxr_print_serialization( + int direction, + const uint8_t* buffer, + size_t size); #if defined(UXR_MESSAGE_LOGS) || defined(UXR_SERIALIZATION_LOGS) #define UXR_DEBUG_PRINT_MESSAGE(direction, buffer, size, client_key) \ do \ { \ - if (UXR_MESSAGE_LOGS_AVAILABLE) uxr_print_message(direction, buffer, size, client_key); \ - if (UXR_SERIALIZATION_LOGS_AVAILABLE) uxr_print_serialization(direction, buffer, size); \ + if (UXR_MESSAGE_LOGS_AVAILABLE)uxr_print_message(direction, buffer, size, client_key); \ + if (UXR_SERIALIZATION_LOGS_AVAILABLE)uxr_print_serialization(direction, buffer, size); \ } while (0) #else -#define UXR_DEBUG_PRINT_MESSAGE(direction, buffer, size, client_key) do {} while(0) -#endif +#define UXR_DEBUG_PRINT_MESSAGE(direction, buffer, size, client_key) do {} while (0) +#endif // if defined(UXR_MESSAGE_LOGS) || defined(UXR_SERIALIZATION_LOGS) #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_LOG_LOG_INTERNAL_H_ diff --git a/src/c/core/serialization/xrce_header.c b/src/c/core/serialization/xrce_header.c index e3cc15fbd..63ee19622 100644 --- a/src/c/core/serialization/xrce_header.c +++ b/src/c/core/serialization/xrce_header.c @@ -3,23 +3,33 @@ //================================================================== // PUBLIC //================================================================== -void uxr_serialize_message_header(ucdrBuffer* ub, uint8_t session_id, uint8_t stream_id, uint16_t seq_num, const uint8_t* key) +void uxr_serialize_message_header( + ucdrBuffer* ub, + uint8_t session_id, + uint8_t stream_id, + uint16_t seq_num, + const uint8_t* key) { (void) ucdr_serialize_uint8_t(ub, session_id); (void) ucdr_serialize_uint8_t(ub, stream_id); (void) ucdr_serialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, seq_num); - if(SESSION_ID_WITHOUT_CLIENT_KEY > session_id) + if (SESSION_ID_WITHOUT_CLIENT_KEY > session_id) { (void) ucdr_serialize_array_uint8_t(ub, key, CLIENT_KEY_SIZE); } } -void uxr_deserialize_message_header(ucdrBuffer* ub, uint8_t* session_id, uint8_t* stream_id, uint16_t* seq_num, uint8_t* key) +void uxr_deserialize_message_header( + ucdrBuffer* ub, + uint8_t* session_id, + uint8_t* stream_id, + uint16_t* seq_num, + uint8_t* key) { (void) ucdr_deserialize_uint8_t(ub, session_id); (void) ucdr_deserialize_uint8_t(ub, stream_id); (void) ucdr_deserialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, seq_num); - if(SESSION_ID_WITHOUT_CLIENT_KEY > *session_id) + if (SESSION_ID_WITHOUT_CLIENT_KEY > *session_id) { (void) ucdr_deserialize_array_uint8_t(ub, key, CLIENT_KEY_SIZE); } diff --git a/src/c/core/serialization/xrce_header_internal.h b/src/c/core/serialization/xrce_header_internal.h index 884c9f19c..82b59471d 100644 --- a/src/c/core/serialization/xrce_header_internal.h +++ b/src/c/core/serialization/xrce_header_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -29,11 +29,21 @@ extern "C" #define SESSION_ID_WITH_CLIENT_KEY 0x00 #define SESSION_ID_WITHOUT_CLIENT_KEY 0x80 -void uxr_serialize_message_header(ucdrBuffer* ub, uint8_t session_id, uint8_t stream_id, uint16_t seq_num, const uint8_t* key); -void uxr_deserialize_message_header(ucdrBuffer* ub, uint8_t* session_id, uint8_t* stream_id, uint16_t* seq_num, uint8_t* key); +void uxr_serialize_message_header( + ucdrBuffer* ub, + uint8_t session_id, + uint8_t stream_id, + uint16_t seq_num, + const uint8_t* key); +void uxr_deserialize_message_header( + ucdrBuffer* ub, + uint8_t* session_id, + uint8_t* stream_id, + uint16_t* seq_num, + uint8_t* key); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SERIALIZATION_XRCE_HEADER_INTERNAL_H_ diff --git a/src/c/core/serialization/xrce_subheader.c b/src/c/core/serialization/xrce_subheader.c index 2c18a3764..468ba64a5 100644 --- a/src/c/core/serialization/xrce_subheader.c +++ b/src/c/core/serialization/xrce_subheader.c @@ -3,14 +3,22 @@ //================================================================== // PUBLIC //================================================================== -void uxr_serialize_submessage_header(ucdrBuffer* ub, uint8_t id, uint8_t flags, uint16_t length) +void uxr_serialize_submessage_header( + ucdrBuffer* ub, + uint8_t id, + uint8_t flags, + uint16_t length) { (void) ucdr_serialize_uint8_t(ub, id); (void) ucdr_serialize_uint8_t(ub, flags); (void) ucdr_serialize_endian_uint16_t(ub, UCDR_LITTLE_ENDIANNESS, length); } -void uxr_deserialize_submessage_header(ucdrBuffer* ub, uint8_t* id, uint8_t* flags, uint16_t* length) +void uxr_deserialize_submessage_header( + ucdrBuffer* ub, + uint8_t* id, + uint8_t* flags, + uint16_t* length) { (void) ucdr_deserialize_uint8_t(ub, id); (void) ucdr_deserialize_uint8_t(ub, flags); diff --git a/src/c/core/serialization/xrce_subheader_internal.h b/src/c/core/serialization/xrce_subheader_internal.h index 651d7ef81..16759e950 100644 --- a/src/c/core/serialization/xrce_subheader_internal.h +++ b/src/c/core/serialization/xrce_subheader_internal.h @@ -18,17 +18,25 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include #include -void uxr_serialize_submessage_header(ucdrBuffer* buffer, uint8_t id, uint8_t flags, uint16_t length); -void uxr_deserialize_submessage_header(ucdrBuffer* buffer, uint8_t* id, uint8_t* flags, uint16_t* length); +void uxr_serialize_submessage_header( + ucdrBuffer* buffer, + uint8_t id, + uint8_t flags, + uint16_t length); +void uxr_deserialize_submessage_header( + ucdrBuffer* buffer, + uint8_t* id, + uint8_t* flags, + uint16_t* length); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SERIALIZATION_SUBHEADER_H_ diff --git a/src/c/core/serialization/xrce_types.c b/src/c/core/serialization/xrce_types.c index 209252770..8aefd43f7 100644 --- a/src/c/core/serialization/xrce_types.c +++ b/src/c/core/serialization/xrce_types.c @@ -4,7 +4,9 @@ //================================================================== // PUBLIC //================================================================== -bool uxr_serialize_Time_t(ucdrBuffer* buffer, const Time_t* input) +bool uxr_serialize_Time_t( + ucdrBuffer* buffer, + const Time_t* input) { bool ret = true; ret &= ucdr_serialize_int32_t(buffer, input->seconds); @@ -12,7 +14,9 @@ bool uxr_serialize_Time_t(ucdrBuffer* buffer, const Time_t* input) return ret; } -bool uxr_deserialize_Time_t(ucdrBuffer* buffer, Time_t* output) +bool uxr_deserialize_Time_t( + ucdrBuffer* buffer, + Time_t* output) { bool ret = true; ret &= ucdr_deserialize_int32_t(buffer, &output->seconds); @@ -20,37 +24,45 @@ bool uxr_deserialize_Time_t(ucdrBuffer* buffer, Time_t* output) return ret; } -bool uxr_serialize_BinarySequence_t(ucdrBuffer* buffer, const BinarySequence_t* input) +bool uxr_serialize_BinarySequence_t( + ucdrBuffer* buffer, + const BinarySequence_t* input) { return ucdr_serialize_sequence_uint8_t(buffer, input->data, input->size); } -bool uxr_deserialize_BinarySequence_t(ucdrBuffer* buffer, BinarySequence_t* output) +bool uxr_deserialize_BinarySequence_t( + ucdrBuffer* buffer, + BinarySequence_t* output) { return ucdr_deserialize_sequence_uint8_t(buffer, output->data, UXR_BINARY_SEQUENCE_MAX, &output->size); } -bool uxr_serialize_StringSequence_t(ucdrBuffer* buffer, const StringSequence_t* input) +bool uxr_serialize_StringSequence_t( + ucdrBuffer* buffer, + const StringSequence_t* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = ucdr_serialize_string(buffer, input->data[i]); } return ret; } -bool uxr_deserialize_StringSequence_t(ucdrBuffer* buffer, StringSequence_t* output) +bool uxr_deserialize_StringSequence_t( + ucdrBuffer* buffer, + StringSequence_t* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_STRING_SEQUENCE_MAX) + if (output->size > UXR_STRING_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = ucdr_deserialize_string(buffer, output->data[i], UXR_STRING_SIZE_MAX); } @@ -58,91 +70,117 @@ bool uxr_deserialize_StringSequence_t(ucdrBuffer* buffer, StringSequence_t* outp return ret; } -bool uxr_serialize_ClientKey(ucdrBuffer* buffer, const ClientKey* input) +bool uxr_serialize_ClientKey( + ucdrBuffer* buffer, + const ClientKey* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 4); return ret; } -bool uxr_deserialize_ClientKey(ucdrBuffer* buffer, ClientKey* output) +bool uxr_deserialize_ClientKey( + ucdrBuffer* buffer, + ClientKey* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 4); return ret; } -bool uxr_serialize_ObjectId(ucdrBuffer* buffer, const ObjectId* input) +bool uxr_serialize_ObjectId( + ucdrBuffer* buffer, + const ObjectId* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 2); return ret; } -bool uxr_deserialize_ObjectId(ucdrBuffer* buffer, ObjectId* output) +bool uxr_deserialize_ObjectId( + ucdrBuffer* buffer, + ObjectId* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 2); return ret; } -bool uxr_serialize_ObjectPrefix(ucdrBuffer* buffer, const ObjectPrefix* input) +bool uxr_serialize_ObjectPrefix( + ucdrBuffer* buffer, + const ObjectPrefix* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 2); return ret; } -bool uxr_deserialize_ObjectPrefix(ucdrBuffer* buffer, ObjectPrefix* output) +bool uxr_deserialize_ObjectPrefix( + ucdrBuffer* buffer, + ObjectPrefix* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 2); return ret; } -bool uxr_serialize_XrceCookie(ucdrBuffer* buffer, const XrceCookie* input) +bool uxr_serialize_XrceCookie( + ucdrBuffer* buffer, + const XrceCookie* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 4); return ret; } -bool uxr_deserialize_XrceCookie(ucdrBuffer* buffer, XrceCookie* output) +bool uxr_deserialize_XrceCookie( + ucdrBuffer* buffer, + XrceCookie* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 4); return ret; } -bool uxr_serialize_XrceVersion(ucdrBuffer* buffer, const XrceVersion* input) +bool uxr_serialize_XrceVersion( + ucdrBuffer* buffer, + const XrceVersion* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 2); return ret; } -bool uxr_deserialize_XrceVersion(ucdrBuffer* buffer, XrceVersion* output) +bool uxr_deserialize_XrceVersion( + ucdrBuffer* buffer, + XrceVersion* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 2); return ret; } -bool uxr_serialize_XrceVendorId(ucdrBuffer* buffer, const XrceVendorId* input) +bool uxr_serialize_XrceVendorId( + ucdrBuffer* buffer, + const XrceVendorId* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 2); return ret; } -bool uxr_deserialize_XrceVendorId(ucdrBuffer* buffer, XrceVendorId* output) +bool uxr_deserialize_XrceVendorId( + ucdrBuffer* buffer, + XrceVendorId* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 2); return ret; } -bool uxr_serialize_TransportLocatorSmall(ucdrBuffer* buffer, const TransportLocatorSmall* input) +bool uxr_serialize_TransportLocatorSmall( + ucdrBuffer* buffer, + const TransportLocatorSmall* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->address, 2); @@ -150,7 +188,9 @@ bool uxr_serialize_TransportLocatorSmall(ucdrBuffer* buffer, const TransportLoca return ret; } -bool uxr_deserialize_TransportLocatorSmall(ucdrBuffer* buffer, TransportLocatorSmall* output) +bool uxr_deserialize_TransportLocatorSmall( + ucdrBuffer* buffer, + TransportLocatorSmall* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->address, 2); @@ -158,7 +198,9 @@ bool uxr_deserialize_TransportLocatorSmall(ucdrBuffer* buffer, TransportLocatorS return ret; } -bool uxr_serialize_TransportLocatorMedium(ucdrBuffer* buffer, const TransportLocatorMedium* input) +bool uxr_serialize_TransportLocatorMedium( + ucdrBuffer* buffer, + const TransportLocatorMedium* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->address, 4); @@ -166,7 +208,9 @@ bool uxr_serialize_TransportLocatorMedium(ucdrBuffer* buffer, const TransportLoc return ret; } -bool uxr_deserialize_TransportLocatorMedium(ucdrBuffer* buffer, TransportLocatorMedium* output) +bool uxr_deserialize_TransportLocatorMedium( + ucdrBuffer* buffer, + TransportLocatorMedium* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->address, 4); @@ -174,7 +218,9 @@ bool uxr_deserialize_TransportLocatorMedium(ucdrBuffer* buffer, TransportLocator return ret; } -bool uxr_serialize_TransportLocatorLarge(ucdrBuffer* buffer, const TransportLocatorLarge* input) +bool uxr_serialize_TransportLocatorLarge( + ucdrBuffer* buffer, + const TransportLocatorLarge* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->address, 16); @@ -182,7 +228,9 @@ bool uxr_serialize_TransportLocatorLarge(ucdrBuffer* buffer, const TransportLoca return ret; } -bool uxr_deserialize_TransportLocatorLarge(ucdrBuffer* buffer, TransportLocatorLarge* output) +bool uxr_deserialize_TransportLocatorLarge( + ucdrBuffer* buffer, + TransportLocatorLarge* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->address, 16); @@ -190,27 +238,33 @@ bool uxr_deserialize_TransportLocatorLarge(ucdrBuffer* buffer, TransportLocatorL return ret; } -bool uxr_serialize_TransportLocatorString(ucdrBuffer* buffer, const TransportLocatorString* input) +bool uxr_serialize_TransportLocatorString( + ucdrBuffer* buffer, + const TransportLocatorString* input) { bool ret = true; ret &= ucdr_serialize_string(buffer, input->value); return ret; } -bool uxr_deserialize_TransportLocatorString(ucdrBuffer* buffer, TransportLocatorString* output) +bool uxr_deserialize_TransportLocatorString( + ucdrBuffer* buffer, + TransportLocatorString* output) { bool ret = true; ret &= ucdr_deserialize_string(buffer, output->value, UXR_STRING_SIZE_MAX); return ret; } -bool uxr_serialize_TransportLocator(ucdrBuffer* buffer, const TransportLocator* input) +bool uxr_serialize_TransportLocator( + ucdrBuffer* buffer, + const TransportLocator* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case ADDRESS_FORMAT_SMALL: ret &= uxr_serialize_TransportLocatorSmall(buffer, &input->_.small_locator); @@ -231,13 +285,15 @@ bool uxr_serialize_TransportLocator(ucdrBuffer* buffer, const TransportLocator* return ret; } -bool uxr_deserialize_TransportLocator(ucdrBuffer* buffer, TransportLocator* output) +bool uxr_deserialize_TransportLocator( + ucdrBuffer* buffer, + TransportLocator* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case ADDRESS_FORMAT_SMALL: ret &= uxr_deserialize_TransportLocatorSmall(buffer, &output->_.small_locator); @@ -258,27 +314,31 @@ bool uxr_deserialize_TransportLocator(ucdrBuffer* buffer, TransportLocator* outp return ret; } -bool uxr_serialize_TransportLocatorSeq(ucdrBuffer* buffer, const TransportLocatorSeq* input) +bool uxr_serialize_TransportLocatorSeq( + ucdrBuffer* buffer, + const TransportLocatorSeq* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_TransportLocator(buffer, &input->data[i]); } return ret; } -bool uxr_deserialize_TransportLocatorSeq(ucdrBuffer* buffer, TransportLocatorSeq* output) +bool uxr_deserialize_TransportLocatorSeq( + ucdrBuffer* buffer, + TransportLocatorSeq* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_TRANSPORT_LOCATOR_SEQUENCE_MAX) + if (output->size > UXR_TRANSPORT_LOCATOR_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_TransportLocator(buffer, &output->data[i]); } @@ -286,7 +346,9 @@ bool uxr_deserialize_TransportLocatorSeq(ucdrBuffer* buffer, TransportLocatorSeq return ret; } -bool uxr_serialize_Property(ucdrBuffer* buffer, const Property* input) +bool uxr_serialize_Property( + ucdrBuffer* buffer, + const Property* input) { bool ret = true; ret &= ucdr_serialize_string(buffer, input->name); @@ -294,7 +356,9 @@ bool uxr_serialize_Property(ucdrBuffer* buffer, const Property* input) return ret; } -bool uxr_deserialize_Property(ucdrBuffer* buffer, Property* output) +bool uxr_deserialize_Property( + ucdrBuffer* buffer, + Property* output) { bool ret = true; ret &= ucdr_deserialize_string(buffer, output->name, UXR_STRING_SIZE_MAX); @@ -302,28 +366,32 @@ bool uxr_deserialize_Property(ucdrBuffer* buffer, Property* output) return ret; } -bool uxr_serialize_PropertySeq(ucdrBuffer* buffer, const PropertySeq* input) +bool uxr_serialize_PropertySeq( + ucdrBuffer* buffer, + const PropertySeq* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_Property(buffer, input->data + i); } return ret; } -bool uxr_deserialize_PropertySeq(ucdrBuffer* buffer, PropertySeq* output) +bool uxr_deserialize_PropertySeq( + ucdrBuffer* buffer, + PropertySeq* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_PROPERTY_SEQUENCE_MAX) + if (output->size > UXR_PROPERTY_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_Property(buffer, &output->data[i]); } @@ -331,7 +399,9 @@ bool uxr_deserialize_PropertySeq(ucdrBuffer* buffer, PropertySeq* output) return ret; } -bool uxr_serialize_CLIENT_Representation(ucdrBuffer* buffer, const CLIENT_Representation* input) +bool uxr_serialize_CLIENT_Representation( + ucdrBuffer* buffer, + const CLIENT_Representation* input) { bool ret = true; ret &= uxr_serialize_XrceCookie(buffer, &input->xrce_cookie); @@ -340,7 +410,7 @@ bool uxr_serialize_CLIENT_Representation(ucdrBuffer* buffer, const CLIENT_Repres ret &= uxr_serialize_ClientKey(buffer, &input->client_key); ret &= ucdr_serialize_uint8_t(buffer, input->session_id); ret &= ucdr_serialize_bool(buffer, input->optional_properties); - if(input->optional_properties == true) + if (input->optional_properties == true) { ret &= uxr_serialize_PropertySeq(buffer, &input->properties); } @@ -349,7 +419,9 @@ bool uxr_serialize_CLIENT_Representation(ucdrBuffer* buffer, const CLIENT_Repres return ret; } -bool uxr_deserialize_CLIENT_Representation(ucdrBuffer* buffer, CLIENT_Representation* output) +bool uxr_deserialize_CLIENT_Representation( + ucdrBuffer* buffer, + CLIENT_Representation* output) { bool ret = true; ret &= uxr_deserialize_XrceCookie(buffer, &output->xrce_cookie); @@ -358,23 +430,25 @@ bool uxr_deserialize_CLIENT_Representation(ucdrBuffer* buffer, CLIENT_Representa ret &= uxr_deserialize_ClientKey(buffer, &output->client_key); ret &= ucdr_deserialize_uint8_t(buffer, &output->session_id); ret &= ucdr_deserialize_bool(buffer, &output->optional_properties); - if(output->optional_properties == true) + if (output->optional_properties == true) { - ret &= uxr_deserialize_PropertySeq(buffer, &output->properties); + ret &= uxr_deserialize_PropertySeq(buffer, &output->properties); } ret &= ucdr_deserialize_uint16_t(buffer, &output->mtu); return ret; } -bool uxr_serialize_AGENT_Representation(ucdrBuffer* buffer, const AGENT_Representation* input) +bool uxr_serialize_AGENT_Representation( + ucdrBuffer* buffer, + const AGENT_Representation* input) { bool ret = true; ret &= uxr_serialize_XrceCookie(buffer, &input->xrce_cookie); ret &= uxr_serialize_XrceVersion(buffer, &input->xrce_version); ret &= uxr_serialize_XrceVendorId(buffer, &input->xrce_vendor_id); ret &= ucdr_serialize_bool(buffer, input->optional_properties); - if(input->optional_properties == true) + if (input->optional_properties == true) { ret &= uxr_serialize_PropertySeq(buffer, &input->properties); } @@ -382,7 +456,9 @@ bool uxr_serialize_AGENT_Representation(ucdrBuffer* buffer, const AGENT_Represen return ret; } -bool uxr_deserialize_AGENT_Representation(ucdrBuffer* buffer, AGENT_Representation* output) +bool uxr_deserialize_AGENT_Representation( + ucdrBuffer* buffer, + AGENT_Representation* output) { bool ret = true; ret &= uxr_deserialize_XrceCookie(buffer, &output->xrce_cookie); @@ -398,13 +474,15 @@ bool uxr_deserialize_AGENT_Representation(ucdrBuffer* buffer, AGENT_Representati return ret; } -bool uxr_serialize_OBJK_Representation3Formats(ucdrBuffer* buffer, const OBJK_Representation3Formats* input) +bool uxr_serialize_OBJK_Representation3Formats( + ucdrBuffer* buffer, + const OBJK_Representation3Formats* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case DDS_XRCE_REPRESENTATION_BY_REFERENCE: ret &= ucdr_serialize_string(buffer, input->_.object_reference); @@ -422,13 +500,15 @@ bool uxr_serialize_OBJK_Representation3Formats(ucdrBuffer* buffer, const OBJK_Re return ret; } -bool uxr_deserialize_OBJK_Representation3Formats(ucdrBuffer* buffer, OBJK_Representation3Formats* output) +bool uxr_deserialize_OBJK_Representation3Formats( + ucdrBuffer* buffer, + OBJK_Representation3Formats* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case DDS_XRCE_REPRESENTATION_BY_REFERENCE: ret &= ucdr_deserialize_string(buffer, output->_.object_reference, UXR_STRING_SIZE_MAX); @@ -446,13 +526,15 @@ bool uxr_deserialize_OBJK_Representation3Formats(ucdrBuffer* buffer, OBJK_Repres return ret; } -bool uxr_serialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, const OBJK_RepresentationRefAndXMLFormats* input) +bool uxr_serialize_OBJK_RepresentationRefAndXMLFormats( + ucdrBuffer* buffer, + const OBJK_RepresentationRefAndXMLFormats* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case DDS_XRCE_REPRESENTATION_BY_REFERENCE: ret &= ucdr_serialize_string(buffer, input->_.object_name); @@ -467,13 +549,15 @@ bool uxr_serialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, const return ret; } -bool uxr_deserialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, OBJK_RepresentationRefAndXMLFormats* output) +bool uxr_deserialize_OBJK_RepresentationRefAndXMLFormats( + ucdrBuffer* buffer, + OBJK_RepresentationRefAndXMLFormats* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case DDS_XRCE_REPRESENTATION_BY_REFERENCE: ret &= ucdr_deserialize_string(buffer, output->_.object_name, UXR_STRING_SIZE_MAX); @@ -488,13 +572,15 @@ bool uxr_deserialize_OBJK_RepresentationRefAndXMLFormats(ucdrBuffer* buffer, OBJ return ret; } -bool uxr_serialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, const OBJK_RepresentationBinAndXMLFormats* input) +bool uxr_serialize_OBJK_RepresentationBinAndXMLFormats( + ucdrBuffer* buffer, + const OBJK_RepresentationBinAndXMLFormats* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case DDS_XRCE_REPRESENTATION_IN_BINARY: ret &= uxr_serialize_BinarySequence_t(buffer, &input->_.binary_representation); @@ -509,13 +595,15 @@ bool uxr_serialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, const return ret; } -bool uxr_deserialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, OBJK_RepresentationBinAndXMLFormats* output) +bool uxr_deserialize_OBJK_RepresentationBinAndXMLFormats( + ucdrBuffer* buffer, + OBJK_RepresentationBinAndXMLFormats* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case DDS_XRCE_REPRESENTATION_IN_BINARY: ret &= uxr_deserialize_BinarySequence_t(buffer, &output->_.binary_representation); @@ -530,105 +618,135 @@ bool uxr_deserialize_OBJK_RepresentationBinAndXMLFormats(ucdrBuffer* buffer, OBJ return ret; } -bool uxr_serialize_OBJK_RepresentationRefAndXML_Base(ucdrBuffer* buffer, const OBJK_RepresentationRefAndXML_Base* input) +bool uxr_serialize_OBJK_RepresentationRefAndXML_Base( + ucdrBuffer* buffer, + const OBJK_RepresentationRefAndXML_Base* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationRefAndXMLFormats(buffer, &input->representation); return ret; } -bool uxr_deserialize_OBJK_RepresentationRefAndXML_Base(ucdrBuffer* buffer, OBJK_RepresentationRefAndXML_Base* output) +bool uxr_deserialize_OBJK_RepresentationRefAndXML_Base( + ucdrBuffer* buffer, + OBJK_RepresentationRefAndXML_Base* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationRefAndXMLFormats(buffer, &output->representation); return ret; } -bool uxr_serialize_OBJK_RepresentationBinAndXML_Base(ucdrBuffer* buffer, const OBJK_RepresentationBinAndXML_Base* input) +bool uxr_serialize_OBJK_RepresentationBinAndXML_Base( + ucdrBuffer* buffer, + const OBJK_RepresentationBinAndXML_Base* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationBinAndXMLFormats(buffer, &input->representation); return ret; } -bool uxr_deserialize_OBJK_RepresentationBinAndXML_Base(ucdrBuffer* buffer, OBJK_RepresentationBinAndXML_Base* output) +bool uxr_deserialize_OBJK_RepresentationBinAndXML_Base( + ucdrBuffer* buffer, + OBJK_RepresentationBinAndXML_Base* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationBinAndXMLFormats(buffer, &output->representation); return ret; } -bool uxr_serialize_OBJK_Representation3_Base(ucdrBuffer* buffer, const OBJK_Representation3_Base* input) +bool uxr_serialize_OBJK_Representation3_Base( + ucdrBuffer* buffer, + const OBJK_Representation3_Base* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3Formats(buffer, &input->representation); return ret; } -bool uxr_deserialize_OBJK_Representation3_Base(ucdrBuffer* buffer, OBJK_Representation3_Base* output) +bool uxr_deserialize_OBJK_Representation3_Base( + ucdrBuffer* buffer, + OBJK_Representation3_Base* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3Formats(buffer, &output->representation); return ret; } -bool uxr_serialize_OBJK_QOSPROFILE_Representation(ucdrBuffer* buffer, const OBJK_QOSPROFILE_Representation* input) +bool uxr_serialize_OBJK_QOSPROFILE_Representation( + ucdrBuffer* buffer, + const OBJK_QOSPROFILE_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationRefAndXML_Base(buffer, &input->base); return ret; } -bool uxr_deserialize_OBJK_QOSPROFILE_Representation(ucdrBuffer* buffer, OBJK_QOSPROFILE_Representation* output) +bool uxr_deserialize_OBJK_QOSPROFILE_Representation( + ucdrBuffer* buffer, + OBJK_QOSPROFILE_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationRefAndXML_Base(buffer, &output->base); return ret; } -bool uxr_serialize_OBJK_TYPE_Representation(ucdrBuffer* buffer, const OBJK_TYPE_Representation* input) +bool uxr_serialize_OBJK_TYPE_Representation( + ucdrBuffer* buffer, + const OBJK_TYPE_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationRefAndXML_Base(buffer, &input->base); return ret; } -bool uxr_deserialize_OBJK_TYPE_Representation(ucdrBuffer* buffer, OBJK_TYPE_Representation* output) +bool uxr_deserialize_OBJK_TYPE_Representation( + ucdrBuffer* buffer, + OBJK_TYPE_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationRefAndXML_Base(buffer, &output->base); return ret; } -bool uxr_serialize_OBJK_DOMAIN_Representation(ucdrBuffer* buffer, const OBJK_DOMAIN_Representation* input) +bool uxr_serialize_OBJK_DOMAIN_Representation( + ucdrBuffer* buffer, + const OBJK_DOMAIN_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationRefAndXML_Base(buffer, &input->base); return ret; } -bool uxr_deserialize_OBJK_DOMAIN_Representation(ucdrBuffer* buffer, OBJK_DOMAIN_Representation* output) +bool uxr_deserialize_OBJK_DOMAIN_Representation( + ucdrBuffer* buffer, + OBJK_DOMAIN_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationRefAndXML_Base(buffer, &output->base); return ret; } -bool uxr_serialize_OBJK_APPLICATION_Representation(ucdrBuffer* buffer, const OBJK_APPLICATION_Representation* input) +bool uxr_serialize_OBJK_APPLICATION_Representation( + ucdrBuffer* buffer, + const OBJK_APPLICATION_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationRefAndXML_Base(buffer, &input->base); return ret; } -bool uxr_deserialize_OBJK_APPLICATION_Representation(ucdrBuffer* buffer, OBJK_APPLICATION_Representation* output) +bool uxr_deserialize_OBJK_APPLICATION_Representation( + ucdrBuffer* buffer, + OBJK_APPLICATION_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationRefAndXML_Base(buffer, &output->base); return ret; } -bool uxr_serialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, const OBJK_PUBLISHER_Representation* input) +bool uxr_serialize_OBJK_PUBLISHER_Representation( + ucdrBuffer* buffer, + const OBJK_PUBLISHER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationBinAndXML_Base(buffer, &input->base); @@ -636,7 +754,9 @@ bool uxr_serialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, const OBJK_ return ret; } -bool uxr_deserialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, OBJK_PUBLISHER_Representation* output) +bool uxr_deserialize_OBJK_PUBLISHER_Representation( + ucdrBuffer* buffer, + OBJK_PUBLISHER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationBinAndXML_Base(buffer, &output->base); @@ -644,7 +764,9 @@ bool uxr_deserialize_OBJK_PUBLISHER_Representation(ucdrBuffer* buffer, OBJK_PUBL return ret; } -bool uxr_serialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, const OBJK_SUBSCRIBER_Representation* input) +bool uxr_serialize_OBJK_SUBSCRIBER_Representation( + ucdrBuffer* buffer, + const OBJK_SUBSCRIBER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_RepresentationBinAndXML_Base(buffer, &input->base); @@ -652,7 +774,9 @@ bool uxr_serialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, const OBJK return ret; } -bool uxr_deserialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, OBJK_SUBSCRIBER_Representation* output) +bool uxr_deserialize_OBJK_SUBSCRIBER_Representation( + ucdrBuffer* buffer, + OBJK_SUBSCRIBER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_RepresentationBinAndXML_Base(buffer, &output->base); @@ -660,7 +784,9 @@ bool uxr_deserialize_OBJK_SUBSCRIBER_Representation(ucdrBuffer* buffer, OBJK_SUB return ret; } -bool uxr_serialize_DATAWRITER_Representation(ucdrBuffer* buffer, const DATAWRITER_Representation* input) +bool uxr_serialize_DATAWRITER_Representation( + ucdrBuffer* buffer, + const DATAWRITER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -668,7 +794,9 @@ bool uxr_serialize_DATAWRITER_Representation(ucdrBuffer* buffer, const DATAWRITE return ret; } -bool uxr_deserialize_DATAWRITER_Representation(ucdrBuffer* buffer, DATAWRITER_Representation* output) +bool uxr_deserialize_DATAWRITER_Representation( + ucdrBuffer* buffer, + DATAWRITER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -676,7 +804,9 @@ bool uxr_deserialize_DATAWRITER_Representation(ucdrBuffer* buffer, DATAWRITER_Re return ret; } -bool uxr_serialize_DATAREADER_Representation(ucdrBuffer* buffer, const DATAREADER_Representation* input) +bool uxr_serialize_DATAREADER_Representation( + ucdrBuffer* buffer, + const DATAREADER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -684,7 +814,9 @@ bool uxr_serialize_DATAREADER_Representation(ucdrBuffer* buffer, const DATAREADE return ret; } -bool uxr_deserialize_DATAREADER_Representation(ucdrBuffer* buffer, DATAREADER_Representation* output) +bool uxr_deserialize_DATAREADER_Representation( + ucdrBuffer* buffer, + DATAREADER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -692,7 +824,9 @@ bool uxr_deserialize_DATAREADER_Representation(ucdrBuffer* buffer, DATAREADER_Re return ret; } -bool uxr_serialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, const OBJK_PARTICIPANT_Representation* input) +bool uxr_serialize_OBJK_PARTICIPANT_Representation( + ucdrBuffer* buffer, + const OBJK_PARTICIPANT_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -700,7 +834,9 @@ bool uxr_serialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, const OBJ return ret; } -bool uxr_deserialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, OBJK_PARTICIPANT_Representation* output) +bool uxr_deserialize_OBJK_PARTICIPANT_Representation( + ucdrBuffer* buffer, + OBJK_PARTICIPANT_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -708,7 +844,9 @@ bool uxr_deserialize_OBJK_PARTICIPANT_Representation(ucdrBuffer* buffer, OBJK_PA return ret; } -bool uxr_serialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, const OBJK_TOPIC_Representation* input) +bool uxr_serialize_OBJK_TOPIC_Representation( + ucdrBuffer* buffer, + const OBJK_TOPIC_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -716,7 +854,9 @@ bool uxr_serialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, const OBJK_TOPI return ret; } -bool uxr_deserialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, OBJK_TOPIC_Representation* output) +bool uxr_deserialize_OBJK_TOPIC_Representation( + ucdrBuffer* buffer, + OBJK_TOPIC_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -724,7 +864,9 @@ bool uxr_deserialize_OBJK_TOPIC_Representation(ucdrBuffer* buffer, OBJK_TOPIC_Re return ret; } -bool uxr_serialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, const OBJK_REQUESTER_Representation* input) +bool uxr_serialize_OBJK_REQUESTER_Representation( + ucdrBuffer* buffer, + const OBJK_REQUESTER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -732,7 +874,9 @@ bool uxr_serialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, const OBJK_ return ret; } -bool uxr_deserialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, OBJK_REQUESTER_Representation* output) +bool uxr_deserialize_OBJK_REQUESTER_Representation( + ucdrBuffer* buffer, + OBJK_REQUESTER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -740,7 +884,9 @@ bool uxr_deserialize_OBJK_REQUESTER_Representation(ucdrBuffer* buffer, OBJK_REQU return ret; } -bool uxr_serialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, const OBJK_REPLIER_Representation* input) +bool uxr_serialize_OBJK_REPLIER_Representation( + ucdrBuffer* buffer, + const OBJK_REPLIER_Representation* input) { bool ret = true; ret &= uxr_serialize_OBJK_Representation3_Base(buffer, &input->base); @@ -748,7 +894,9 @@ bool uxr_serialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, const OBJK_RE return ret; } -bool uxr_deserialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, OBJK_REPLIER_Representation* output) +bool uxr_deserialize_OBJK_REPLIER_Representation( + ucdrBuffer* buffer, + OBJK_REPLIER_Representation* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Representation3_Base(buffer, &output->base); @@ -756,17 +904,19 @@ bool uxr_deserialize_OBJK_REPLIER_Representation(ucdrBuffer* buffer, OBJK_REPLIE return ret; } -bool uxr_serialize_OBJK_DomainParticipant_Binary(ucdrBuffer* buffer, const OBJK_DomainParticipant_Binary* input) +bool uxr_serialize_OBJK_DomainParticipant_Binary( + ucdrBuffer* buffer, + const OBJK_DomainParticipant_Binary* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_domain_reference); - if(input->optional_domain_reference == true) + if (input->optional_domain_reference == true) { ret &= ucdr_serialize_string(buffer, input->domain_reference); } ret &= ucdr_serialize_bool(buffer, input->optional_qos_profile_reference); - if(input->optional_qos_profile_reference == true) + if (input->optional_qos_profile_reference == true) { ret &= ucdr_serialize_string(buffer, input->qos_profile_reference); } @@ -774,36 +924,40 @@ bool uxr_serialize_OBJK_DomainParticipant_Binary(ucdrBuffer* buffer, const OBJK_ return ret; } -bool uxr_deserialize_OBJK_DomainParticipant_Binary(ucdrBuffer* buffer, OBJK_DomainParticipant_Binary* output) +bool uxr_deserialize_OBJK_DomainParticipant_Binary( + ucdrBuffer* buffer, + OBJK_DomainParticipant_Binary* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_domain_reference); - if(output->optional_domain_reference == true) + if (output->optional_domain_reference == true) { - ret &= ucdr_deserialize_string(buffer, output->domain_reference, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->domain_reference, UXR_STRING_SIZE_MAX); } ret &= ucdr_deserialize_bool(buffer, &output->optional_qos_profile_reference); - if(output->optional_qos_profile_reference == true) + if (output->optional_qos_profile_reference == true) { - ret &= ucdr_deserialize_string(buffer, output->qos_profile_reference, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->qos_profile_reference, UXR_STRING_SIZE_MAX); } return ret; } -bool uxr_serialize_OBJK_Topic_Binary(ucdrBuffer* buffer, const OBJK_Topic_Binary* input) +bool uxr_serialize_OBJK_Topic_Binary( + ucdrBuffer* buffer, + const OBJK_Topic_Binary* input) { bool ret = true; ret &= ucdr_serialize_string(buffer, input->topic_name); ret &= ucdr_serialize_bool(buffer, input->optional_type_reference); - if(input->optional_type_reference == true) + if (input->optional_type_reference == true) { ret &= ucdr_serialize_string(buffer, input->type_reference); } ret &= ucdr_serialize_bool(buffer, input->optional_type_name); - if(input->optional_type_name == true) + if (input->optional_type_name == true) { ret &= ucdr_serialize_string(buffer, input->type_name); } @@ -811,36 +965,40 @@ bool uxr_serialize_OBJK_Topic_Binary(ucdrBuffer* buffer, const OBJK_Topic_Binary return ret; } -bool uxr_deserialize_OBJK_Topic_Binary(ucdrBuffer* buffer, OBJK_Topic_Binary* output) +bool uxr_deserialize_OBJK_Topic_Binary( + ucdrBuffer* buffer, + OBJK_Topic_Binary* output) { bool ret = true; ret &= ucdr_deserialize_string(buffer, output->topic_name, UXR_STRING_SIZE_MAX); ret &= ucdr_deserialize_bool(buffer, &output->optional_type_reference); - if(output->optional_type_reference == true) + if (output->optional_type_reference == true) { - ret &= ucdr_deserialize_string(buffer, output->type_reference, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->type_reference, UXR_STRING_SIZE_MAX); } ret &= ucdr_deserialize_bool(buffer, &output->optional_type_name); - if(output->optional_type_name == true) + if (output->optional_type_name == true) { - ret &= ucdr_deserialize_string(buffer, output->type_name, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->type_name, UXR_STRING_SIZE_MAX); } return ret; } -bool uxr_serialize_OBJK_Publisher_Binary_Qos(ucdrBuffer* buffer, const OBJK_Publisher_Binary_Qos* input) +bool uxr_serialize_OBJK_Publisher_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_Publisher_Binary_Qos* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_partitions); - if(input->optional_partitions == true) + if (input->optional_partitions == true) { ret &= uxr_serialize_StringSequence_t(buffer, &input->partitions); } ret &= ucdr_serialize_bool(buffer, input->optional_group_data); - if(input->optional_group_data == true) + if (input->optional_group_data == true) { ret &= uxr_serialize_BinarySequence_t(buffer, &input->group_data); } @@ -848,35 +1006,39 @@ bool uxr_serialize_OBJK_Publisher_Binary_Qos(ucdrBuffer* buffer, const OBJK_Publ return ret; } -bool uxr_deserialize_OBJK_Publisher_Binary_Qos(ucdrBuffer* buffer, OBJK_Publisher_Binary_Qos* output) +bool uxr_deserialize_OBJK_Publisher_Binary_Qos( + ucdrBuffer* buffer, + OBJK_Publisher_Binary_Qos* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_partitions); - if(output->optional_partitions == true) + if (output->optional_partitions == true) { - ret &= uxr_deserialize_StringSequence_t(buffer, &output->partitions); + ret &= uxr_deserialize_StringSequence_t(buffer, &output->partitions); } ret &= ucdr_deserialize_bool(buffer, &output->optional_group_data); - if(output->optional_group_data == true) + if (output->optional_group_data == true) { - ret &= uxr_deserialize_BinarySequence_t(buffer, &output->group_data); + ret &= uxr_deserialize_BinarySequence_t(buffer, &output->group_data); } return ret; } -bool uxr_serialize_OBJK_Publisher_Binary(ucdrBuffer* buffer, const OBJK_Publisher_Binary* input) +bool uxr_serialize_OBJK_Publisher_Binary( + ucdrBuffer* buffer, + const OBJK_Publisher_Binary* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_publisher_name); - if(input->optional_publisher_name == true) + if (input->optional_publisher_name == true) { ret &= ucdr_serialize_string(buffer, input->publisher_name); } ret &= ucdr_serialize_bool(buffer, input->optional_qos); - if(input->optional_qos == true) + if (input->optional_qos == true) { ret &= uxr_serialize_OBJK_Publisher_Binary_Qos(buffer, &input->qos); } @@ -884,35 +1046,39 @@ bool uxr_serialize_OBJK_Publisher_Binary(ucdrBuffer* buffer, const OBJK_Publishe return ret; } -bool uxr_deserialize_OBJK_Publisher_Binary(ucdrBuffer* buffer, OBJK_Publisher_Binary* output) +bool uxr_deserialize_OBJK_Publisher_Binary( + ucdrBuffer* buffer, + OBJK_Publisher_Binary* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_publisher_name); - if(output->optional_publisher_name == true) + if (output->optional_publisher_name == true) { - ret &= ucdr_deserialize_string(buffer, output->publisher_name, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->publisher_name, UXR_STRING_SIZE_MAX); } ret &= ucdr_deserialize_bool(buffer, &output->optional_qos); - if(output->optional_qos == true) + if (output->optional_qos == true) { - ret &= uxr_deserialize_OBJK_Publisher_Binary_Qos(buffer, &output->qos); + ret &= uxr_deserialize_OBJK_Publisher_Binary_Qos(buffer, &output->qos); } return ret; } -bool uxr_serialize_OBJK_Subscriber_Binary_Qos(ucdrBuffer* buffer, const OBJK_Subscriber_Binary_Qos* input) +bool uxr_serialize_OBJK_Subscriber_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_Subscriber_Binary_Qos* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_partitions); - if(input->optional_partitions == true) + if (input->optional_partitions == true) { ret &= uxr_serialize_StringSequence_t(buffer, &input->partitions); } ret &= ucdr_serialize_bool(buffer, input->optional_group_data); - if(input->optional_group_data == true) + if (input->optional_group_data == true) { ret &= uxr_serialize_BinarySequence_t(buffer, &input->group_data); } @@ -920,35 +1086,39 @@ bool uxr_serialize_OBJK_Subscriber_Binary_Qos(ucdrBuffer* buffer, const OBJK_Sub return ret; } -bool uxr_deserialize_OBJK_Subscriber_Binary_Qos(ucdrBuffer* buffer, OBJK_Subscriber_Binary_Qos* output) +bool uxr_deserialize_OBJK_Subscriber_Binary_Qos( + ucdrBuffer* buffer, + OBJK_Subscriber_Binary_Qos* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_partitions); - if(output->optional_partitions == true) + if (output->optional_partitions == true) { - ret &= uxr_deserialize_StringSequence_t(buffer, &output->partitions); + ret &= uxr_deserialize_StringSequence_t(buffer, &output->partitions); } ret &= ucdr_deserialize_bool(buffer, &output->optional_group_data); - if(output->optional_group_data == true) + if (output->optional_group_data == true) { - ret &= uxr_deserialize_BinarySequence_t(buffer, &output->group_data); + ret &= uxr_deserialize_BinarySequence_t(buffer, &output->group_data); } return ret; } -bool uxr_serialize_OBJK_Subscriber_Binary(ucdrBuffer* buffer, const OBJK_Subscriber_Binary* input) +bool uxr_serialize_OBJK_Subscriber_Binary( + ucdrBuffer* buffer, + const OBJK_Subscriber_Binary* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_subscriber_name); - if(input->optional_subscriber_name == true) + if (input->optional_subscriber_name == true) { ret &= ucdr_serialize_string(buffer, input->subscriber_name); } ret &= ucdr_serialize_bool(buffer, input->optional_qos); - if(input->optional_qos == true) + if (input->optional_qos == true) { ret &= uxr_serialize_OBJK_Subscriber_Binary_Qos(buffer, &input->qos); } @@ -956,48 +1126,52 @@ bool uxr_serialize_OBJK_Subscriber_Binary(ucdrBuffer* buffer, const OBJK_Subscri return ret; } -bool uxr_deserialize_OBJK_Subscriber_Binary(ucdrBuffer* buffer, OBJK_Subscriber_Binary* output) +bool uxr_deserialize_OBJK_Subscriber_Binary( + ucdrBuffer* buffer, + OBJK_Subscriber_Binary* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_subscriber_name); - if(output->optional_subscriber_name == true) + if (output->optional_subscriber_name == true) { - ret &= ucdr_deserialize_string(buffer, output->subscriber_name, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->subscriber_name, UXR_STRING_SIZE_MAX); } ret &= ucdr_deserialize_bool(buffer, &output->optional_qos); - if(output->optional_qos == true) + if (output->optional_qos == true) { - ret &= uxr_deserialize_OBJK_Subscriber_Binary_Qos(buffer, &output->qos); + ret &= uxr_deserialize_OBJK_Subscriber_Binary_Qos(buffer, &output->qos); } return ret; } -bool uxr_serialize_OBJK_Endpoint_QosBinary(ucdrBuffer* buffer, const OBJK_Endpoint_QosBinary* input) +bool uxr_serialize_OBJK_Endpoint_QosBinary( + ucdrBuffer* buffer, + const OBJK_Endpoint_QosBinary* input) { bool ret = true; ret &= ucdr_serialize_uint16_t(buffer, input->qos_flags); ret &= ucdr_serialize_bool(buffer, input->optional_history_depth); - if(input->optional_history_depth == true) + if (input->optional_history_depth == true) { ret &= ucdr_serialize_uint16_t(buffer, input->history_depth); } ret &= ucdr_serialize_bool(buffer, input->optional_deadline_msec); - if(input->optional_deadline_msec == true) + if (input->optional_deadline_msec == true) { ret &= ucdr_serialize_uint32_t(buffer, input->deadline_msec); } ret &= ucdr_serialize_bool(buffer, input->optional_lifespan_msec); - if(input->optional_lifespan_msec == true) + if (input->optional_lifespan_msec == true) { ret &= ucdr_serialize_uint32_t(buffer, input->lifespan_msec); } ret &= ucdr_serialize_bool(buffer, input->optional_user_data); - if(input->optional_user_data == true) + if (input->optional_user_data == true) { ret &= uxr_serialize_BinarySequence_t(buffer, &input->user_data); } @@ -1005,43 +1179,47 @@ bool uxr_serialize_OBJK_Endpoint_QosBinary(ucdrBuffer* buffer, const OBJK_Endpoi return ret; } -bool uxr_deserialize_OBJK_Endpoint_QosBinary(ucdrBuffer* buffer, OBJK_Endpoint_QosBinary* output) +bool uxr_deserialize_OBJK_Endpoint_QosBinary( + ucdrBuffer* buffer, + OBJK_Endpoint_QosBinary* output) { bool ret = true; ret &= ucdr_deserialize_uint16_t(buffer, &output->qos_flags); ret &= ucdr_deserialize_bool(buffer, &output->optional_history_depth); - if(output->optional_history_depth == true) + if (output->optional_history_depth == true) { - ret &= ucdr_deserialize_uint16_t(buffer, &output->history_depth); + ret &= ucdr_deserialize_uint16_t(buffer, &output->history_depth); } ret &= ucdr_deserialize_bool(buffer, &output->optional_deadline_msec); - if(output->optional_deadline_msec == true) + if (output->optional_deadline_msec == true) { - ret &= ucdr_deserialize_uint32_t(buffer, &output->deadline_msec); + ret &= ucdr_deserialize_uint32_t(buffer, &output->deadline_msec); } ret &= ucdr_deserialize_bool(buffer, &output->optional_lifespan_msec); - if(output->optional_lifespan_msec == true) + if (output->optional_lifespan_msec == true) { - ret &= ucdr_deserialize_uint32_t(buffer, &output->lifespan_msec); + ret &= ucdr_deserialize_uint32_t(buffer, &output->lifespan_msec); } ret &= ucdr_deserialize_bool(buffer, &output->optional_user_data); - if(output->optional_user_data == true) + if (output->optional_user_data == true) { - ret &= uxr_deserialize_BinarySequence_t(buffer, &output->user_data); + ret &= uxr_deserialize_BinarySequence_t(buffer, &output->user_data); } return ret; } -bool uxr_serialize_OBJK_DataWriter_Binary_Qos(ucdrBuffer* buffer, const OBJK_DataWriter_Binary_Qos* input) +bool uxr_serialize_OBJK_DataWriter_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_DataWriter_Binary_Qos* input) { bool ret = true; ret &= uxr_serialize_OBJK_Endpoint_QosBinary(buffer, &input->base); ret &= ucdr_serialize_bool(buffer, input->optional_ownership_strength); - if(input->optional_ownership_strength == true) + if (input->optional_ownership_strength == true) { ret &= ucdr_serialize_uint64_t(buffer, input->ownership_strength); } @@ -1049,31 +1227,35 @@ bool uxr_serialize_OBJK_DataWriter_Binary_Qos(ucdrBuffer* buffer, const OBJK_Dat return ret; } -bool uxr_deserialize_OBJK_DataWriter_Binary_Qos(ucdrBuffer* buffer, OBJK_DataWriter_Binary_Qos* output) +bool uxr_deserialize_OBJK_DataWriter_Binary_Qos( + ucdrBuffer* buffer, + OBJK_DataWriter_Binary_Qos* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Endpoint_QosBinary(buffer, &output->base); ret &= ucdr_deserialize_bool(buffer, &output->optional_ownership_strength); - if(output->optional_ownership_strength == true) + if (output->optional_ownership_strength == true) { - ret &= ucdr_deserialize_uint64_t(buffer, &output->ownership_strength); + ret &= ucdr_deserialize_uint64_t(buffer, &output->ownership_strength); } return ret; } -bool uxr_serialize_OBJK_DataReader_Binary_Qos(ucdrBuffer* buffer, const OBJK_DataReader_Binary_Qos* input) +bool uxr_serialize_OBJK_DataReader_Binary_Qos( + ucdrBuffer* buffer, + const OBJK_DataReader_Binary_Qos* input) { bool ret = true; ret &= uxr_serialize_OBJK_Endpoint_QosBinary(buffer, &input->base); ret &= ucdr_serialize_bool(buffer, input->optional_timebasedfilter_msec); - if(input->optional_timebasedfilter_msec == true) + if (input->optional_timebasedfilter_msec == true) { ret &= ucdr_serialize_uint64_t(buffer, input->timebasedfilter_msec); } ret &= ucdr_serialize_bool(buffer, input->optional_contentbased_filter); - if(input->optional_contentbased_filter == true) + if (input->optional_contentbased_filter == true) { ret &= ucdr_serialize_string(buffer, input->contentbased_filter); } @@ -1081,31 +1263,35 @@ bool uxr_serialize_OBJK_DataReader_Binary_Qos(ucdrBuffer* buffer, const OBJK_Dat return ret; } -bool uxr_deserialize_OBJK_DataReader_Binary_Qos(ucdrBuffer* buffer, OBJK_DataReader_Binary_Qos* output) +bool uxr_deserialize_OBJK_DataReader_Binary_Qos( + ucdrBuffer* buffer, + OBJK_DataReader_Binary_Qos* output) { bool ret = true; ret &= uxr_deserialize_OBJK_Endpoint_QosBinary(buffer, &output->base); ret &= ucdr_deserialize_bool(buffer, &output->optional_timebasedfilter_msec); - if(output->optional_timebasedfilter_msec == true) + if (output->optional_timebasedfilter_msec == true) { - ret &= ucdr_deserialize_uint64_t(buffer, &output->timebasedfilter_msec); + ret &= ucdr_deserialize_uint64_t(buffer, &output->timebasedfilter_msec); } ret &= ucdr_deserialize_bool(buffer, &output->optional_contentbased_filter); - if(output->optional_contentbased_filter == true) + if (output->optional_contentbased_filter == true) { - ret &= ucdr_deserialize_string(buffer, output->contentbased_filter, UXR_STRING_SIZE_MAX); + ret &= ucdr_deserialize_string(buffer, output->contentbased_filter, UXR_STRING_SIZE_MAX); } return ret; } -bool uxr_serialize_OBJK_DataReader_Binary(ucdrBuffer* buffer, const OBJK_DataReader_Binary* input) +bool uxr_serialize_OBJK_DataReader_Binary( + ucdrBuffer* buffer, + const OBJK_DataReader_Binary* input) { bool ret = true; ret &= ucdr_serialize_string(buffer, input->topic_name); ret &= ucdr_serialize_bool(buffer, input->optional_qos); - if(input->optional_qos == true) + if (input->optional_qos == true) { ret &= uxr_serialize_OBJK_DataReader_Binary_Qos(buffer, &input->qos); } @@ -1113,25 +1299,29 @@ bool uxr_serialize_OBJK_DataReader_Binary(ucdrBuffer* buffer, const OBJK_DataRea return ret; } -bool uxr_deserialize_OBJK_DataReader_Binary(ucdrBuffer* buffer, OBJK_DataReader_Binary* output) +bool uxr_deserialize_OBJK_DataReader_Binary( + ucdrBuffer* buffer, + OBJK_DataReader_Binary* output) { bool ret = true; ret &= ucdr_deserialize_string(buffer, output->topic_name, UXR_STRING_SIZE_MAX); ret &= ucdr_deserialize_bool(buffer, &output->optional_qos); - if(output->optional_qos == true) + if (output->optional_qos == true) { - ret &= uxr_deserialize_OBJK_DataReader_Binary_Qos(buffer, &output->qos); + ret &= uxr_deserialize_OBJK_DataReader_Binary_Qos(buffer, &output->qos); } return ret; } -bool uxr_serialize_OBJK_DataWriter_Binary(ucdrBuffer* buffer, const OBJK_DataWriter_Binary* input) +bool uxr_serialize_OBJK_DataWriter_Binary( + ucdrBuffer* buffer, + const OBJK_DataWriter_Binary* input) { bool ret = true; ret &= ucdr_serialize_string(buffer, input->topic_name); ret &= ucdr_serialize_bool(buffer, input->optional_qos); - if(input->optional_qos == true) + if (input->optional_qos == true) { ret &= uxr_serialize_OBJK_DataWriter_Binary_Qos(buffer, &input->qos); } @@ -1139,26 +1329,30 @@ bool uxr_serialize_OBJK_DataWriter_Binary(ucdrBuffer* buffer, const OBJK_DataWri return ret; } -bool uxr_deserialize_OBJK_DataWriter_Binary(ucdrBuffer* buffer, OBJK_DataWriter_Binary* output) +bool uxr_deserialize_OBJK_DataWriter_Binary( + ucdrBuffer* buffer, + OBJK_DataWriter_Binary* output) { bool ret = true; ret &= ucdr_deserialize_string(buffer, output->topic_name, UXR_STRING_SIZE_MAX); ret &= ucdr_deserialize_bool(buffer, &output->optional_qos); - if(output->optional_qos == true) + if (output->optional_qos == true) { - ret &= uxr_deserialize_OBJK_DataWriter_Binary_Qos(buffer, &output->qos); + ret &= uxr_deserialize_OBJK_DataWriter_Binary_Qos(buffer, &output->qos); } return ret; } -bool uxr_serialize_ObjectVariant(ucdrBuffer* buffer, const ObjectVariant* input) +bool uxr_serialize_ObjectVariant( + ucdrBuffer* buffer, + const ObjectVariant* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->kind); if (ret) { - switch(input->kind) + switch (input->kind) { case DDS_XRCE_OBJK_AGENT: ret &= uxr_serialize_AGENT_Representation(buffer, &input->_.agent); @@ -1206,13 +1400,15 @@ bool uxr_serialize_ObjectVariant(ucdrBuffer* buffer, const ObjectVariant* input) return ret; } -bool uxr_deserialize_ObjectVariant(ucdrBuffer* buffer, ObjectVariant* output) +bool uxr_deserialize_ObjectVariant( + ucdrBuffer* buffer, + ObjectVariant* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->kind); if (ret) { - switch(output->kind) + switch (output->kind) { case DDS_XRCE_OBJK_AGENT: ret &= uxr_deserialize_AGENT_Representation(buffer, &output->_.agent); @@ -1260,7 +1456,9 @@ bool uxr_deserialize_ObjectVariant(ucdrBuffer* buffer, ObjectVariant* output) return ret; } -bool uxr_serialize_CreationMode(ucdrBuffer* buffer, const CreationMode* input) +bool uxr_serialize_CreationMode( + ucdrBuffer* buffer, + const CreationMode* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->reuse); @@ -1268,7 +1466,9 @@ bool uxr_serialize_CreationMode(ucdrBuffer* buffer, const CreationMode* input) return ret; } -bool uxr_deserialize_CreationMode(ucdrBuffer* buffer, CreationMode* output) +bool uxr_deserialize_CreationMode( + ucdrBuffer* buffer, + CreationMode* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->reuse); @@ -1276,21 +1476,27 @@ bool uxr_deserialize_CreationMode(ucdrBuffer* buffer, CreationMode* output) return ret; } -bool uxr_serialize_RequestId(ucdrBuffer* buffer, const RequestId* input) +bool uxr_serialize_RequestId( + ucdrBuffer* buffer, + const RequestId* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, 2); return ret; } -bool uxr_deserialize_RequestId(ucdrBuffer* buffer, RequestId* output) +bool uxr_deserialize_RequestId( + ucdrBuffer* buffer, + RequestId* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, 2); return ret; } -bool uxr_serialize_ResultStatus(ucdrBuffer* buffer, const ResultStatus* input) +bool uxr_serialize_ResultStatus( + ucdrBuffer* buffer, + const ResultStatus* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->status); @@ -1298,7 +1504,9 @@ bool uxr_serialize_ResultStatus(ucdrBuffer* buffer, const ResultStatus* input) return ret; } -bool uxr_deserialize_ResultStatus(ucdrBuffer* buffer, ResultStatus* output) +bool uxr_deserialize_ResultStatus( + ucdrBuffer* buffer, + ResultStatus* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->status); @@ -1306,7 +1514,9 @@ bool uxr_deserialize_ResultStatus(ucdrBuffer* buffer, ResultStatus* output) return ret; } -bool uxr_serialize_BaseObjectRequest(ucdrBuffer* buffer, const BaseObjectRequest* input) +bool uxr_serialize_BaseObjectRequest( + ucdrBuffer* buffer, + const BaseObjectRequest* input) { bool ret = true; ret &= uxr_serialize_RequestId(buffer, &input->request_id); @@ -1314,7 +1524,9 @@ bool uxr_serialize_BaseObjectRequest(ucdrBuffer* buffer, const BaseObjectRequest return ret; } -bool uxr_deserialize_BaseObjectRequest(ucdrBuffer* buffer, BaseObjectRequest* output) +bool uxr_deserialize_BaseObjectRequest( + ucdrBuffer* buffer, + BaseObjectRequest* output) { bool ret = true; ret &= uxr_deserialize_RequestId(buffer, &output->request_id); @@ -1322,37 +1534,47 @@ bool uxr_deserialize_BaseObjectRequest(ucdrBuffer* buffer, BaseObjectRequest* ou return ret; } -bool uxr_serialize_AGENT_ActivityInfo(ucdrBuffer* buffer, const AGENT_ActivityInfo* input) +bool uxr_serialize_AGENT_ActivityInfo( + ucdrBuffer* buffer, + const AGENT_ActivityInfo* input) { bool ret = true; - ret &= ucdr_serialize_int16_t(buffer, input->availibility); + ret &= ucdr_serialize_int16_t(buffer, input->availability); ret &= uxr_serialize_TransportLocatorSeq(buffer, &input->address_seq); return ret; } -bool uxr_deserialize_AGENT_ActivityInfo(ucdrBuffer* buffer, AGENT_ActivityInfo* output) +bool uxr_deserialize_AGENT_ActivityInfo( + ucdrBuffer* buffer, + AGENT_ActivityInfo* output) { bool ret = true; - ret &= ucdr_deserialize_int16_t(buffer, &output->availibility); + ret &= ucdr_deserialize_int16_t(buffer, &output->availability); ret &= uxr_deserialize_TransportLocatorSeq(buffer, &output->address_seq); return ret; } -bool uxr_serialize_DATAREADER_ActivityInfo(ucdrBuffer* buffer, const DATAREADER_ActivityInfo* input) +bool uxr_serialize_DATAREADER_ActivityInfo( + ucdrBuffer* buffer, + const DATAREADER_ActivityInfo* input) { bool ret = true; ret &= ucdr_serialize_int16_t(buffer, input->highest_acked_num); return ret; } -bool uxr_deserialize_DATAREADER_ActivityInfo(ucdrBuffer* buffer, DATAREADER_ActivityInfo* output) +bool uxr_deserialize_DATAREADER_ActivityInfo( + ucdrBuffer* buffer, + DATAREADER_ActivityInfo* output) { bool ret = true; ret &= ucdr_deserialize_int16_t(buffer, &output->highest_acked_num); return ret; } -bool uxr_serialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, const DATAWRITER_ActivityInfo* input) +bool uxr_serialize_DATAWRITER_ActivityInfo( + ucdrBuffer* buffer, + const DATAWRITER_ActivityInfo* input) { bool ret = true; ret &= ucdr_serialize_int16_t(buffer, input->stream_seq_num); @@ -1360,7 +1582,9 @@ bool uxr_serialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, const DATAWRITER_ return ret; } -bool uxr_deserialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, DATAWRITER_ActivityInfo* output) +bool uxr_deserialize_DATAWRITER_ActivityInfo( + ucdrBuffer* buffer, + DATAWRITER_ActivityInfo* output) { bool ret = true; ret &= ucdr_deserialize_int16_t(buffer, &output->stream_seq_num); @@ -1368,13 +1592,15 @@ bool uxr_deserialize_DATAWRITER_ActivityInfo(ucdrBuffer* buffer, DATAWRITER_Acti return ret; } -bool uxr_serialize_ActivityInfoVariant(ucdrBuffer* buffer, const ActivityInfoVariant* input) +bool uxr_serialize_ActivityInfoVariant( + ucdrBuffer* buffer, + const ActivityInfoVariant* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->kind); if (ret) { - switch(input->kind) + switch (input->kind) { case DDS_XRCE_OBJK_AGENT: ret &= uxr_serialize_AGENT_ActivityInfo(buffer, &input->_.agent); @@ -1392,13 +1618,15 @@ bool uxr_serialize_ActivityInfoVariant(ucdrBuffer* buffer, const ActivityInfoVar return ret; } -bool uxr_deserialize_ActivityInfoVariant(ucdrBuffer* buffer, ActivityInfoVariant* output) +bool uxr_deserialize_ActivityInfoVariant( + ucdrBuffer* buffer, + ActivityInfoVariant* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->kind); if (ret) { - switch(output->kind) + switch (output->kind) { case DDS_XRCE_OBJK_AGENT: ret &= uxr_deserialize_AGENT_ActivityInfo(buffer, &output->_.agent); @@ -1416,17 +1644,19 @@ bool uxr_deserialize_ActivityInfoVariant(ucdrBuffer* buffer, ActivityInfoVariant return ret; } -bool uxr_serialize_ObjectInfo(ucdrBuffer* buffer, const ObjectInfo* input) +bool uxr_serialize_ObjectInfo( + ucdrBuffer* buffer, + const ObjectInfo* input) { bool ret = true; ret &= ucdr_serialize_bool(buffer, input->optional_config); - if(input->optional_config == true) + if (input->optional_config == true) { ret &= uxr_serialize_ObjectVariant(buffer, &input->config); } ret &= ucdr_serialize_bool(buffer, input->optional_activity); - if(input->optional_activity == true) + if (input->optional_activity == true) { ret &= uxr_serialize_ActivityInfoVariant(buffer, &input->activity); } @@ -1434,25 +1664,29 @@ bool uxr_serialize_ObjectInfo(ucdrBuffer* buffer, const ObjectInfo* input) return ret; } -bool uxr_deserialize_ObjectInfo(ucdrBuffer* buffer, ObjectInfo* output) +bool uxr_deserialize_ObjectInfo( + ucdrBuffer* buffer, + ObjectInfo* output) { bool ret = true; ret &= ucdr_deserialize_bool(buffer, &output->optional_config); - if(output->optional_config == true) + if (output->optional_config == true) { - ret &= uxr_deserialize_ObjectVariant(buffer, &output->config); + ret &= uxr_deserialize_ObjectVariant(buffer, &output->config); } ret &= ucdr_deserialize_bool(buffer, &output->optional_activity); - if(output->optional_activity == true) + if (output->optional_activity == true) { - ret &= uxr_deserialize_ActivityInfoVariant(buffer, &output->activity); + ret &= uxr_deserialize_ActivityInfoVariant(buffer, &output->activity); } return ret; } -bool uxr_serialize_BaseObjectReply(ucdrBuffer* buffer, const BaseObjectReply* input) +bool uxr_serialize_BaseObjectReply( + ucdrBuffer* buffer, + const BaseObjectReply* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->related_request); @@ -1460,7 +1694,9 @@ bool uxr_serialize_BaseObjectReply(ucdrBuffer* buffer, const BaseObjectReply* in return ret; } -bool uxr_deserialize_BaseObjectReply(ucdrBuffer* buffer, BaseObjectReply* output) +bool uxr_deserialize_BaseObjectReply( + ucdrBuffer* buffer, + BaseObjectReply* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->related_request); @@ -1468,7 +1704,9 @@ bool uxr_deserialize_BaseObjectReply(ucdrBuffer* buffer, BaseObjectReply* output return ret; } -bool uxr_serialize_DataDeliveryControl(ucdrBuffer* buffer, const DataDeliveryControl* input) +bool uxr_serialize_DataDeliveryControl( + ucdrBuffer* buffer, + const DataDeliveryControl* input) { bool ret = true; ret &= ucdr_serialize_uint16_t(buffer, input->max_samples); @@ -1478,7 +1716,9 @@ bool uxr_serialize_DataDeliveryControl(ucdrBuffer* buffer, const DataDeliveryCon return ret; } -bool uxr_deserialize_DataDeliveryControl(ucdrBuffer* buffer, DataDeliveryControl* output) +bool uxr_deserialize_DataDeliveryControl( + ucdrBuffer* buffer, + DataDeliveryControl* output) { bool ret = true; ret &= ucdr_deserialize_uint16_t(buffer, &output->max_samples); @@ -1488,19 +1728,21 @@ bool uxr_deserialize_DataDeliveryControl(ucdrBuffer* buffer, DataDeliveryControl return ret; } -bool uxr_serialize_ReadSpecification(ucdrBuffer* buffer, const ReadSpecification* input) +bool uxr_serialize_ReadSpecification( + ucdrBuffer* buffer, + const ReadSpecification* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->preferred_stream_id); ret &= ucdr_serialize_uint8_t(buffer, input->data_format); ret &= ucdr_serialize_bool(buffer, input->optional_content_filter_expression); - if(input->optional_content_filter_expression == true) + if (input->optional_content_filter_expression == true) { ret &= ucdr_serialize_string(buffer, input->content_filter_expression); } ret &= ucdr_serialize_bool(buffer, input->optional_delivery_control); - if(input->optional_delivery_control == true) + if (input->optional_delivery_control == true) { ret &= uxr_serialize_DataDeliveryControl(buffer, &input->delivery_control); } @@ -1508,19 +1750,21 @@ bool uxr_serialize_ReadSpecification(ucdrBuffer* buffer, const ReadSpecification return ret; } -bool uxr_deserialize_ReadSpecification(ucdrBuffer* buffer, ReadSpecification* output) +bool uxr_deserialize_ReadSpecification( + ucdrBuffer* buffer, + ReadSpecification* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->preferred_stream_id); ret &= ucdr_deserialize_uint8_t(buffer, &output->data_format); ret &= ucdr_deserialize_bool(buffer, &output->optional_content_filter_expression); - if(output->optional_content_filter_expression == true) + if (output->optional_content_filter_expression == true) { ret &= ucdr_deserialize_string(buffer, output->content_filter_expression, UXR_STRING_SIZE_MAX); } ret &= ucdr_deserialize_bool(buffer, &output->optional_delivery_control); - if(output->optional_delivery_control == true) + if (output->optional_delivery_control == true) { ret &= uxr_deserialize_DataDeliveryControl(buffer, &output->delivery_control); } @@ -1528,7 +1772,9 @@ bool uxr_deserialize_ReadSpecification(ucdrBuffer* buffer, ReadSpecification* ou return ret; } -bool uxr_serialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, const SeqNumberAndTimestamp* input) +bool uxr_serialize_SeqNumberAndTimestamp( + ucdrBuffer* buffer, + const SeqNumberAndTimestamp* input) { bool ret = true; ret &= ucdr_serialize_uint32_t(buffer, input->sequence_number); @@ -1536,7 +1782,9 @@ bool uxr_serialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, const SeqNumberAndT return ret; } -bool uxr_deserialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, SeqNumberAndTimestamp* output) +bool uxr_deserialize_SeqNumberAndTimestamp( + ucdrBuffer* buffer, + SeqNumberAndTimestamp* output) { bool ret = true; ret &= ucdr_deserialize_uint32_t(buffer, &output->sequence_number); @@ -1544,13 +1792,15 @@ bool uxr_deserialize_SeqNumberAndTimestamp(ucdrBuffer* buffer, SeqNumberAndTimes return ret; } -bool uxr_serialize_SampleInfoDetail(ucdrBuffer* buffer, const SampleInfoDetail* input) +bool uxr_serialize_SampleInfoDetail( + ucdrBuffer* buffer, + const SampleInfoDetail* input) { bool ret = true; ret &= ucdr_serialize_uint32_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case FORMAT_EMPTY: ret &= ucdr_serialize_uint32_t(buffer, input->_.sequence_number); @@ -1568,13 +1818,15 @@ bool uxr_serialize_SampleInfoDetail(ucdrBuffer* buffer, const SampleInfoDetail* return ret; } -bool uxr_deserialize_SampleInfoDetail(ucdrBuffer* buffer, SampleInfoDetail* output) +bool uxr_deserialize_SampleInfoDetail( + ucdrBuffer* buffer, + SampleInfoDetail* output) { bool ret = true; ret &= ucdr_deserialize_uint32_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case FORMAT_EMPTY: ret &= ucdr_deserialize_uint32_t(buffer, &output->_.sequence_number); @@ -1592,7 +1844,9 @@ bool uxr_deserialize_SampleInfoDetail(ucdrBuffer* buffer, SampleInfoDetail* outp return ret; } -bool uxr_serialize_SampleInfo(ucdrBuffer* buffer, const SampleInfo* input) +bool uxr_serialize_SampleInfo( + ucdrBuffer* buffer, + const SampleInfo* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->state); @@ -1600,7 +1854,9 @@ bool uxr_serialize_SampleInfo(ucdrBuffer* buffer, const SampleInfo* input) return ret; } -bool uxr_deserialize_SampleInfo(ucdrBuffer* buffer, SampleInfo* output) +bool uxr_deserialize_SampleInfo( + ucdrBuffer* buffer, + SampleInfo* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->state); @@ -1608,7 +1864,9 @@ bool uxr_deserialize_SampleInfo(ucdrBuffer* buffer, SampleInfo* output) return ret; } -bool uxr_serialize_SampleInfoDelta(ucdrBuffer* buffer, const SampleInfoDelta* input) +bool uxr_serialize_SampleInfoDelta( + ucdrBuffer* buffer, + const SampleInfoDelta* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->state); @@ -1617,7 +1875,9 @@ bool uxr_serialize_SampleInfoDelta(ucdrBuffer* buffer, const SampleInfoDelta* in return ret; } -bool uxr_deserialize_SampleInfoDelta(ucdrBuffer* buffer, SampleInfoDelta* output) +bool uxr_deserialize_SampleInfoDelta( + ucdrBuffer* buffer, + SampleInfoDelta* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->state); @@ -1626,37 +1886,45 @@ bool uxr_deserialize_SampleInfoDelta(ucdrBuffer* buffer, SampleInfoDelta* output return ret; } -bool uxr_serialize_SampleData(ucdrBuffer* buffer, const SampleData* input) +bool uxr_serialize_SampleData( + ucdrBuffer* buffer, + const SampleData* input) { return ucdr_serialize_sequence_uint8_t(buffer, input->data, input->size); } -bool uxr_deserialize_SampleData(ucdrBuffer* buffer, SampleData* output) +bool uxr_deserialize_SampleData( + ucdrBuffer* buffer, + SampleData* output) { return ucdr_deserialize_sequence_uint8_t(buffer, output->data, UXR_SAMPLE_DATA_SIZE_MAX, &output->size); } -bool uxr_serialize_SampleDataSeq(ucdrBuffer* buffer, const SampleDataSeq* input) +bool uxr_serialize_SampleDataSeq( + ucdrBuffer* buffer, + const SampleDataSeq* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_SampleData(buffer, &input->data[i]); } return ret; } -bool uxr_deserialize_SampleDataSeq(ucdrBuffer* buffer, SampleDataSeq* output) +bool uxr_deserialize_SampleDataSeq( + ucdrBuffer* buffer, + SampleDataSeq* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_SAMPLE_DATA_SEQUENCE_MAX) + if (output->size > UXR_SAMPLE_DATA_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_SampleData(buffer, &output->data[i]); } @@ -1664,7 +1932,9 @@ bool uxr_deserialize_SampleDataSeq(ucdrBuffer* buffer, SampleDataSeq* output) return ret; } -bool uxr_serialize_Sample(ucdrBuffer* buffer, const Sample* input) +bool uxr_serialize_Sample( + ucdrBuffer* buffer, + const Sample* input) { bool ret = true; ret &= uxr_serialize_SampleInfo(buffer, &input->info); @@ -1672,7 +1942,9 @@ bool uxr_serialize_Sample(ucdrBuffer* buffer, const Sample* input) return ret; } -bool uxr_deserialize_Sample(ucdrBuffer* buffer, Sample* output) +bool uxr_deserialize_Sample( + ucdrBuffer* buffer, + Sample* output) { bool ret = true; ret &= uxr_deserialize_SampleInfo(buffer, &output->info); @@ -1680,27 +1952,31 @@ bool uxr_deserialize_Sample(ucdrBuffer* buffer, Sample* output) return ret; } -bool uxr_serialize_SampleSeq(ucdrBuffer* buffer, const SampleSeq* input) +bool uxr_serialize_SampleSeq( + ucdrBuffer* buffer, + const SampleSeq* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_Sample(buffer, &input->data[i]); } return ret; } -bool uxr_deserialize_SampleSeq(ucdrBuffer* buffer, SampleSeq* output) +bool uxr_deserialize_SampleSeq( + ucdrBuffer* buffer, + SampleSeq* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_SAMPLE_SEQUENCE_MAX) + if (output->size > UXR_SAMPLE_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_Sample(buffer, &output->data[i]); } @@ -1708,7 +1984,9 @@ bool uxr_deserialize_SampleSeq(ucdrBuffer* buffer, SampleSeq* output) return ret; } -bool uxr_serialize_SampleDelta(ucdrBuffer* buffer, const SampleDelta* input) +bool uxr_serialize_SampleDelta( + ucdrBuffer* buffer, + const SampleDelta* input) { bool ret = true; ret &= uxr_serialize_SampleInfoDelta(buffer, &input->info_delta); @@ -1716,7 +1994,9 @@ bool uxr_serialize_SampleDelta(ucdrBuffer* buffer, const SampleDelta* input) return ret; } -bool uxr_deserialize_SampleDelta(ucdrBuffer* buffer, SampleDelta* output) +bool uxr_deserialize_SampleDelta( + ucdrBuffer* buffer, + SampleDelta* output) { bool ret = true; ret &= uxr_deserialize_SampleInfoDelta(buffer, &output->info_delta); @@ -1724,27 +2004,31 @@ bool uxr_deserialize_SampleDelta(ucdrBuffer* buffer, SampleDelta* output) return ret; } -bool uxr_serialize_SampleDeltaSequence(ucdrBuffer* buffer, const SampleDeltaSequence* input) +bool uxr_serialize_SampleDeltaSequence( + ucdrBuffer* buffer, + const SampleDeltaSequence* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_SampleDelta(buffer, &input->data[i]); } return ret; } -bool uxr_deserialize_SampleDeltaSequence(ucdrBuffer* buffer, SampleDeltaSequence* output) +bool uxr_deserialize_SampleDeltaSequence( + ucdrBuffer* buffer, + SampleDeltaSequence* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_SAMPLE_DELTA_SEQUENCE_MAX) + if (output->size > UXR_SAMPLE_DELTA_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_SampleDelta(buffer, &output->data[i]); } @@ -1752,7 +2036,9 @@ bool uxr_deserialize_SampleDeltaSequence(ucdrBuffer* buffer, SampleDeltaSequence return ret; } -bool uxr_serialize_PackedSamples(ucdrBuffer* buffer, const PackedSamples* input) +bool uxr_serialize_PackedSamples( + ucdrBuffer* buffer, + const PackedSamples* input) { bool ret = true; ret &= uxr_serialize_SampleInfo(buffer, &input->info_base); @@ -1760,7 +2046,9 @@ bool uxr_serialize_PackedSamples(ucdrBuffer* buffer, const PackedSamples* input) return ret; } -bool uxr_deserialize_PackedSamples(ucdrBuffer* buffer, PackedSamples* output) +bool uxr_deserialize_PackedSamples( + ucdrBuffer* buffer, + PackedSamples* output) { bool ret = true; ret &= uxr_deserialize_SampleInfo(buffer, &output->info_base); @@ -1768,27 +2056,31 @@ bool uxr_deserialize_PackedSamples(ucdrBuffer* buffer, PackedSamples* output) return ret; } -bool uxr_serialize_SamplePackedSeq(ucdrBuffer* buffer, const SamplePackedSeq* input) +bool uxr_serialize_SamplePackedSeq( + ucdrBuffer* buffer, + const SamplePackedSeq* input) { bool ret = ucdr_serialize_uint32_t(buffer, input->size); - for(uint32_t i = 0; i < input->size && ret; i++) + for (uint32_t i = 0; i < input->size && ret; i++) { ret = uxr_serialize_PackedSamples(buffer, &input->data[i]); } return ret; } -bool uxr_deserialize_SamplePackedSeq(ucdrBuffer* buffer, SamplePackedSeq* output) +bool uxr_deserialize_SamplePackedSeq( + ucdrBuffer* buffer, + SamplePackedSeq* output) { bool ret = ucdr_deserialize_uint32_t(buffer, &output->size); - if(output->size > UXR_PACKED_SAMPLES_SEQUENCE_MAX) + if (output->size > UXR_PACKED_SAMPLES_SEQUENCE_MAX) { buffer->error = true; ret = false; } else { - for(uint32_t i = 0; i < output->size && ret; i++) + for (uint32_t i = 0; i < output->size && ret; i++) { ret = uxr_deserialize_PackedSamples(buffer, &output->data[i]); } @@ -1796,13 +2088,15 @@ bool uxr_deserialize_SamplePackedSeq(ucdrBuffer* buffer, SamplePackedSeq* output return ret; } -bool uxr_serialize_DataRepresentation(ucdrBuffer* buffer, const DataRepresentation* input) +bool uxr_serialize_DataRepresentation( + ucdrBuffer* buffer, + const DataRepresentation* input) { bool ret = true; ret &= ucdr_serialize_uint8_t(buffer, input->format); if (ret) { - switch(input->format) + switch (input->format) { case FORMAT_DATA: ret &= uxr_serialize_SampleData(buffer, &input->_.data); @@ -1826,13 +2120,15 @@ bool uxr_serialize_DataRepresentation(ucdrBuffer* buffer, const DataRepresentati return ret; } -bool uxr_deserialize_DataRepresentation(ucdrBuffer* buffer, DataRepresentation* output) +bool uxr_deserialize_DataRepresentation( + ucdrBuffer* buffer, + DataRepresentation* output) { bool ret = true; ret &= ucdr_deserialize_uint8_t(buffer, &output->format); if (ret) { - switch(output->format) + switch (output->format) { case FORMAT_DATA: ret &= uxr_deserialize_SampleData(buffer, &output->_.data); @@ -1856,21 +2152,27 @@ bool uxr_deserialize_DataRepresentation(ucdrBuffer* buffer, DataRepresentation* return ret; } -bool uxr_serialize_CREATE_CLIENT_Payload(ucdrBuffer* buffer, const CREATE_CLIENT_Payload* input) +bool uxr_serialize_CREATE_CLIENT_Payload( + ucdrBuffer* buffer, + const CREATE_CLIENT_Payload* input) { bool ret = true; ret &= uxr_serialize_CLIENT_Representation(buffer, &input->client_representation); return ret; } -bool uxr_deserialize_CREATE_CLIENT_Payload(ucdrBuffer* buffer, CREATE_CLIENT_Payload* output) +bool uxr_deserialize_CREATE_CLIENT_Payload( + ucdrBuffer* buffer, + CREATE_CLIENT_Payload* output) { bool ret = true; ret &= uxr_deserialize_CLIENT_Representation(buffer, &output->client_representation); return ret; } -bool uxr_serialize_CREATE_Payload(ucdrBuffer* buffer, const CREATE_Payload* input) +bool uxr_serialize_CREATE_Payload( + ucdrBuffer* buffer, + const CREATE_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -1878,7 +2180,9 @@ bool uxr_serialize_CREATE_Payload(ucdrBuffer* buffer, const CREATE_Payload* inpu return ret; } -bool uxr_deserialize_CREATE_Payload(ucdrBuffer* buffer, CREATE_Payload* output) +bool uxr_deserialize_CREATE_Payload( + ucdrBuffer* buffer, + CREATE_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -1886,7 +2190,9 @@ bool uxr_deserialize_CREATE_Payload(ucdrBuffer* buffer, CREATE_Payload* output) return ret; } -bool uxr_serialize_GET_INFO_Payload(ucdrBuffer* buffer, const GET_INFO_Payload* input) +bool uxr_serialize_GET_INFO_Payload( + ucdrBuffer* buffer, + const GET_INFO_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -1894,7 +2200,9 @@ bool uxr_serialize_GET_INFO_Payload(ucdrBuffer* buffer, const GET_INFO_Payload* return ret; } -bool uxr_deserialize_GET_INFO_Payload(ucdrBuffer* buffer, GET_INFO_Payload* output) +bool uxr_deserialize_GET_INFO_Payload( + ucdrBuffer* buffer, + GET_INFO_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -1902,21 +2210,27 @@ bool uxr_deserialize_GET_INFO_Payload(ucdrBuffer* buffer, GET_INFO_Payload* outp return ret; } -bool uxr_serialize_DELETE_Payload(ucdrBuffer* buffer, const DELETE_Payload* input) +bool uxr_serialize_DELETE_Payload( + ucdrBuffer* buffer, + const DELETE_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); return ret; } -bool uxr_deserialize_DELETE_Payload(ucdrBuffer* buffer, DELETE_Payload* output) +bool uxr_deserialize_DELETE_Payload( + ucdrBuffer* buffer, + DELETE_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); return ret; } -bool uxr_serialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, const STATUS_AGENT_Payload* input) +bool uxr_serialize_STATUS_AGENT_Payload( + ucdrBuffer* buffer, + const STATUS_AGENT_Payload* input) { bool ret = true; ret &= uxr_serialize_ResultStatus(buffer, &input->result); @@ -1924,7 +2238,9 @@ bool uxr_serialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, const STATUS_AGENT_P return ret; } -bool uxr_deserialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, STATUS_AGENT_Payload* output) +bool uxr_deserialize_STATUS_AGENT_Payload( + ucdrBuffer* buffer, + STATUS_AGENT_Payload* output) { bool ret = true; ret &= uxr_deserialize_ResultStatus(buffer, &output->result); @@ -1932,21 +2248,27 @@ bool uxr_deserialize_STATUS_AGENT_Payload(ucdrBuffer* buffer, STATUS_AGENT_Paylo return ret; } -bool uxr_serialize_STATUS_Payload(ucdrBuffer* buffer, const STATUS_Payload* input) +bool uxr_serialize_STATUS_Payload( + ucdrBuffer* buffer, + const STATUS_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectReply(buffer, &input->base); return ret; } -bool uxr_deserialize_STATUS_Payload(ucdrBuffer* buffer, STATUS_Payload* output) +bool uxr_deserialize_STATUS_Payload( + ucdrBuffer* buffer, + STATUS_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectReply(buffer, &output->base); return ret; } -bool uxr_serialize_INFO_Payload(ucdrBuffer* buffer, const INFO_Payload* input) +bool uxr_serialize_INFO_Payload( + ucdrBuffer* buffer, + const INFO_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectReply(buffer, &input->base); @@ -1954,7 +2276,9 @@ bool uxr_serialize_INFO_Payload(ucdrBuffer* buffer, const INFO_Payload* input) return ret; } -bool uxr_deserialize_INFO_Payload(ucdrBuffer* buffer, INFO_Payload* output) +bool uxr_deserialize_INFO_Payload( + ucdrBuffer* buffer, + INFO_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectReply(buffer, &output->base); @@ -1962,7 +2286,9 @@ bool uxr_deserialize_INFO_Payload(ucdrBuffer* buffer, INFO_Payload* output) return ret; } -bool uxr_serialize_READ_DATA_Payload(ucdrBuffer* buffer, const READ_DATA_Payload* input) +bool uxr_serialize_READ_DATA_Payload( + ucdrBuffer* buffer, + const READ_DATA_Payload* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -1970,7 +2296,9 @@ bool uxr_serialize_READ_DATA_Payload(ucdrBuffer* buffer, const READ_DATA_Payload return ret; } -bool uxr_deserialize_READ_DATA_Payload(ucdrBuffer* buffer, READ_DATA_Payload* output) +bool uxr_deserialize_READ_DATA_Payload( + ucdrBuffer* buffer, + READ_DATA_Payload* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -1978,21 +2306,27 @@ bool uxr_deserialize_READ_DATA_Payload(ucdrBuffer* buffer, READ_DATA_Payload* ou return ret; } -bool uxr_serialize_WRITE_DATA_Payload_Data(ucdrBuffer* buffer, const WRITE_DATA_Payload_Data* input) +bool uxr_serialize_WRITE_DATA_Payload_Data( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_Data* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); return ret; } -bool uxr_deserialize_WRITE_DATA_Payload_Data(ucdrBuffer* buffer, WRITE_DATA_Payload_Data* output) +bool uxr_deserialize_WRITE_DATA_Payload_Data( + ucdrBuffer* buffer, + WRITE_DATA_Payload_Data* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); return ret; } -bool uxr_serialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, const WRITE_DATA_Payload_Sample* input) +bool uxr_serialize_WRITE_DATA_Payload_Sample( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_Sample* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2000,7 +2334,9 @@ bool uxr_serialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, const WRITE_DAT return ret; } -bool uxr_deserialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, WRITE_DATA_Payload_Sample* output) +bool uxr_deserialize_WRITE_DATA_Payload_Sample( + ucdrBuffer* buffer, + WRITE_DATA_Payload_Sample* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2008,7 +2344,9 @@ bool uxr_deserialize_WRITE_DATA_Payload_Sample(ucdrBuffer* buffer, WRITE_DATA_Pa return ret; } -bool uxr_serialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, const WRITE_DATA_Payload_DataSeq* input) +bool uxr_serialize_WRITE_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_DataSeq* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2016,7 +2354,9 @@ bool uxr_serialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, const WRITE_DA return ret; } -bool uxr_deserialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, WRITE_DATA_Payload_DataSeq* output) +bool uxr_deserialize_WRITE_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + WRITE_DATA_Payload_DataSeq* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2024,7 +2364,9 @@ bool uxr_deserialize_WRITE_DATA_Payload_DataSeq(ucdrBuffer* buffer, WRITE_DATA_P return ret; } -bool uxr_serialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const WRITE_DATA_Payload_SampleSeq* input) +bool uxr_serialize_WRITE_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_SampleSeq* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2032,7 +2374,9 @@ bool uxr_serialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const WRITE_ return ret; } -bool uxr_deserialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, WRITE_DATA_Payload_SampleSeq* output) +bool uxr_deserialize_WRITE_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + WRITE_DATA_Payload_SampleSeq* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2040,7 +2384,9 @@ bool uxr_deserialize_WRITE_DATA_Payload_SampleSeq(ucdrBuffer* buffer, WRITE_DATA return ret; } -bool uxr_serialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const WRITE_DATA_Payload_PackedSamples* input) +bool uxr_serialize_WRITE_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + const WRITE_DATA_Payload_PackedSamples* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2048,7 +2394,9 @@ bool uxr_serialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const WR return ret; } -bool uxr_deserialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, WRITE_DATA_Payload_PackedSamples* output) +bool uxr_deserialize_WRITE_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + WRITE_DATA_Payload_PackedSamples* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2056,21 +2404,27 @@ bool uxr_deserialize_WRITE_DATA_Payload_PackedSamples(ucdrBuffer* buffer, WRITE_ return ret; } -bool uxr_serialize_DATA_Payload_Data(ucdrBuffer* buffer, const DATA_Payload_Data* input) +bool uxr_serialize_DATA_Payload_Data( + ucdrBuffer* buffer, + const DATA_Payload_Data* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); return ret; } -bool uxr_deserialize_DATA_Payload_Data(ucdrBuffer* buffer, DATA_Payload_Data* output) +bool uxr_deserialize_DATA_Payload_Data( + ucdrBuffer* buffer, + DATA_Payload_Data* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); return ret; } -bool uxr_serialize_DATA_Payload_Sample(ucdrBuffer* buffer, const DATA_Payload_Sample* input) +bool uxr_serialize_DATA_Payload_Sample( + ucdrBuffer* buffer, + const DATA_Payload_Sample* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2078,7 +2432,9 @@ bool uxr_serialize_DATA_Payload_Sample(ucdrBuffer* buffer, const DATA_Payload_Sa return ret; } -bool uxr_deserialize_DATA_Payload_Sample(ucdrBuffer* buffer, DATA_Payload_Sample* output) +bool uxr_deserialize_DATA_Payload_Sample( + ucdrBuffer* buffer, + DATA_Payload_Sample* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2086,7 +2442,9 @@ bool uxr_deserialize_DATA_Payload_Sample(ucdrBuffer* buffer, DATA_Payload_Sample return ret; } -bool uxr_serialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, const DATA_Payload_DataSeq* input) +bool uxr_serialize_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + const DATA_Payload_DataSeq* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2094,7 +2452,9 @@ bool uxr_serialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, const DATA_Payload_D return ret; } -bool uxr_deserialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, DATA_Payload_DataSeq* output) +bool uxr_deserialize_DATA_Payload_DataSeq( + ucdrBuffer* buffer, + DATA_Payload_DataSeq* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2102,7 +2462,9 @@ bool uxr_deserialize_DATA_Payload_DataSeq(ucdrBuffer* buffer, DATA_Payload_DataS return ret; } -bool uxr_serialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const DATA_Payload_SampleSeq* input) +bool uxr_serialize_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + const DATA_Payload_SampleSeq* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2110,7 +2472,9 @@ bool uxr_serialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, const DATA_Payload return ret; } -bool uxr_deserialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, DATA_Payload_SampleSeq* output) +bool uxr_deserialize_DATA_Payload_SampleSeq( + ucdrBuffer* buffer, + DATA_Payload_SampleSeq* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2118,7 +2482,9 @@ bool uxr_deserialize_DATA_Payload_SampleSeq(ucdrBuffer* buffer, DATA_Payload_Sam return ret; } -bool uxr_serialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const DATA_Payload_PackedSamples* input) +bool uxr_serialize_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + const DATA_Payload_PackedSamples* input) { bool ret = true; ret &= uxr_serialize_BaseObjectRequest(buffer, &input->base); @@ -2126,7 +2492,9 @@ bool uxr_serialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, const DATA_Pay return ret; } -bool uxr_deserialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, DATA_Payload_PackedSamples* output) +bool uxr_deserialize_DATA_Payload_PackedSamples( + ucdrBuffer* buffer, + DATA_Payload_PackedSamples* output) { bool ret = true; ret &= uxr_deserialize_BaseObjectRequest(buffer, &output->base); @@ -2134,7 +2502,9 @@ bool uxr_deserialize_DATA_Payload_PackedSamples(ucdrBuffer* buffer, DATA_Payload return ret; } -bool uxr_serialize_ACKNACK_Payload(ucdrBuffer* buffer, const ACKNACK_Payload* input) +bool uxr_serialize_ACKNACK_Payload( + ucdrBuffer* buffer, + const ACKNACK_Payload* input) { bool ret = true; ret &= ucdr_serialize_uint16_t(buffer, input->first_unacked_seq_num); @@ -2143,7 +2513,9 @@ bool uxr_serialize_ACKNACK_Payload(ucdrBuffer* buffer, const ACKNACK_Payload* in return ret; } -bool uxr_deserialize_ACKNACK_Payload(ucdrBuffer* buffer, ACKNACK_Payload* output) +bool uxr_deserialize_ACKNACK_Payload( + ucdrBuffer* buffer, + ACKNACK_Payload* output) { bool ret = true; ret &= ucdr_deserialize_uint16_t(buffer, &output->first_unacked_seq_num); @@ -2152,7 +2524,9 @@ bool uxr_deserialize_ACKNACK_Payload(ucdrBuffer* buffer, ACKNACK_Payload* output return ret; } -bool uxr_serialize_HEARTBEAT_Payload(ucdrBuffer* buffer, const HEARTBEAT_Payload* input) +bool uxr_serialize_HEARTBEAT_Payload( + ucdrBuffer* buffer, + const HEARTBEAT_Payload* input) { bool ret = true; ret &= ucdr_serialize_uint16_t(buffer, input->first_unacked_seq_nr); @@ -2161,7 +2535,9 @@ bool uxr_serialize_HEARTBEAT_Payload(ucdrBuffer* buffer, const HEARTBEAT_Payload return ret; } -bool uxr_deserialize_HEARTBEAT_Payload(ucdrBuffer* buffer, HEARTBEAT_Payload* output) +bool uxr_deserialize_HEARTBEAT_Payload( + ucdrBuffer* buffer, + HEARTBEAT_Payload* output) { bool ret = true; ret &= ucdr_deserialize_uint16_t(buffer, &output->first_unacked_seq_nr); @@ -2170,21 +2546,27 @@ bool uxr_deserialize_HEARTBEAT_Payload(ucdrBuffer* buffer, HEARTBEAT_Payload* ou return ret; } -bool uxr_serialize_TIMESTAMP_Payload(ucdrBuffer* buffer, const TIMESTAMP_Payload* input) +bool uxr_serialize_TIMESTAMP_Payload( + ucdrBuffer* buffer, + const TIMESTAMP_Payload* input) { bool ret = true; ret &= uxr_serialize_Time_t(buffer, &input->transmit_timestamp); return ret; } -bool uxr_deserialize_TIMESTAMP_Payload(ucdrBuffer* buffer, TIMESTAMP_Payload* output) +bool uxr_deserialize_TIMESTAMP_Payload( + ucdrBuffer* buffer, + TIMESTAMP_Payload* output) { bool ret = true; ret &= uxr_deserialize_Time_t(buffer, &output->transmit_timestamp); return ret; } -bool uxr_serialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, const TIMESTAMP_REPLY_Payload* input) +bool uxr_serialize_TIMESTAMP_REPLY_Payload( + ucdrBuffer* buffer, + const TIMESTAMP_REPLY_Payload* input) { bool ret = true; ret &= uxr_serialize_Time_t(buffer, &input->transmit_timestamp); @@ -2193,7 +2575,9 @@ bool uxr_serialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, const TIMESTAMP_R return ret; } -bool uxr_deserialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, TIMESTAMP_REPLY_Payload* output) +bool uxr_deserialize_TIMESTAMP_REPLY_Payload( + ucdrBuffer* buffer, + TIMESTAMP_REPLY_Payload* output) { bool ret = true; ret &= uxr_deserialize_Time_t(buffer, &output->transmit_timestamp); @@ -2202,37 +2586,47 @@ bool uxr_deserialize_TIMESTAMP_REPLY_Payload(ucdrBuffer* buffer, TIMESTAMP_REPLY return ret; } -bool uxr_serialize_GuidPrefix_t(ucdrBuffer* buffer, const GuidPrefix_t* input) +bool uxr_serialize_GuidPrefix_t( + ucdrBuffer* buffer, + const GuidPrefix_t* input) { bool ret = true; ret &= ucdr_serialize_array_uint8_t(buffer, input->data, sizeof(GuidPrefix_t)); return ret; } -bool uxr_deserialize_GuidPrefix_t(ucdrBuffer* buffer, GuidPrefix_t* output) +bool uxr_deserialize_GuidPrefix_t( + ucdrBuffer* buffer, + GuidPrefix_t* output) { bool ret = true; ret &= ucdr_deserialize_array_uint8_t(buffer, output->data, sizeof(GuidPrefix_t)); return ret; } -bool uxr_serialize_EntityId_t(ucdrBuffer* buffer, const EntityId_t* input) +bool uxr_serialize_EntityId_t( + ucdrBuffer* buffer, + const EntityId_t* input) { bool ret = true; - ret &= ucdr_serialize_array_uint8_t(buffer, input->entityKey, sizeof(((EntityId_t *)0)->entityKey)); + ret &= ucdr_serialize_array_uint8_t(buffer, input->entityKey, sizeof(((EntityId_t*)0)->entityKey)); ret &= ucdr_serialize_uint8_t(buffer, input->entityKind); return ret; } -bool uxr_deserialize_EntityId_t(ucdrBuffer* buffer, EntityId_t* output) +bool uxr_deserialize_EntityId_t( + ucdrBuffer* buffer, + EntityId_t* output) { bool ret = true; - ret &= ucdr_deserialize_array_uint8_t(buffer, output->entityKey, sizeof(((EntityId_t *)0)->entityKey)); + ret &= ucdr_deserialize_array_uint8_t(buffer, output->entityKey, sizeof(((EntityId_t*)0)->entityKey)); ret &= ucdr_deserialize_uint8_t(buffer, &output->entityKind); return ret; } -bool uxr_serialize_GUID_t(ucdrBuffer* buffer, const GUID_t* input) +bool uxr_serialize_GUID_t( + ucdrBuffer* buffer, + const GUID_t* input) { bool ret = true; ret &= uxr_serialize_GuidPrefix_t(buffer, &input->guidPrefix); @@ -2240,7 +2634,9 @@ bool uxr_serialize_GUID_t(ucdrBuffer* buffer, const GUID_t* input) return ret; } -bool uxr_deserialize_GUID_t(ucdrBuffer* buffer, GUID_t* output) +bool uxr_deserialize_GUID_t( + ucdrBuffer* buffer, + GUID_t* output) { bool ret = true; ret &= uxr_deserialize_GuidPrefix_t(buffer, &output->guidPrefix); @@ -2248,7 +2644,9 @@ bool uxr_deserialize_GUID_t(ucdrBuffer* buffer, GUID_t* output) return ret; } -bool uxr_serialize_SequenceNumber_t(ucdrBuffer* buffer, const SequenceNumber_t* input) +bool uxr_serialize_SequenceNumber_t( + ucdrBuffer* buffer, + const SequenceNumber_t* input) { bool ret = true; ret &= ucdr_serialize_int32_t(buffer, input->high); @@ -2256,7 +2654,9 @@ bool uxr_serialize_SequenceNumber_t(ucdrBuffer* buffer, const SequenceNumber_t* return ret; } -bool uxr_deserialize_SequenceNumber_t(ucdrBuffer* buffer, SequenceNumber_t* output) +bool uxr_deserialize_SequenceNumber_t( + ucdrBuffer* buffer, + SequenceNumber_t* output) { bool ret = true; ret &= ucdr_deserialize_int32_t(buffer, &output->high); @@ -2264,7 +2664,9 @@ bool uxr_deserialize_SequenceNumber_t(ucdrBuffer* buffer, SequenceNumber_t* outp return ret; } -bool uxr_serialize_SampleIdentity(ucdrBuffer* buffer, const SampleIdentity* input) +bool uxr_serialize_SampleIdentity( + ucdrBuffer* buffer, + const SampleIdentity* input) { bool ret = true; ret &= uxr_serialize_GUID_t(buffer, &input->writer_guid); @@ -2272,7 +2674,9 @@ bool uxr_serialize_SampleIdentity(ucdrBuffer* buffer, const SampleIdentity* inpu return ret; } -bool uxr_deserialize_SampleIdentity(ucdrBuffer* buffer, SampleIdentity* output) +bool uxr_deserialize_SampleIdentity( + ucdrBuffer* buffer, + SampleIdentity* output) { bool ret = true; ret &= uxr_deserialize_GUID_t(buffer, &output->writer_guid); @@ -2281,7 +2685,9 @@ bool uxr_deserialize_SampleIdentity(ucdrBuffer* buffer, SampleIdentity* output) } #ifdef PERFORMANCE_TESTING -bool uxr_serialize_PERFORMANCE_Payload(ucdrBuffer* buffer, const PERFORMANCE_Payload* input) +bool uxr_serialize_PERFORMANCE_Payload( + ucdrBuffer* buffer, + const PERFORMANCE_Payload* input) { bool ret = true; ret &= ucdr_serialize_uint32_t(buffer, input->epoch_time_lsb); @@ -2290,7 +2696,9 @@ bool uxr_serialize_PERFORMANCE_Payload(ucdrBuffer* buffer, const PERFORMANCE_Pay return ret; } -bool uxr_deserialize_PERFORMANCE_Payload(ucdrBuffer* buffer, PERFORMANCE_Payload* output) +bool uxr_deserialize_PERFORMANCE_Payload( + ucdrBuffer* buffer, + PERFORMANCE_Payload* output) { bool ret = true; ret &= ucdr_deserialize_uint32_t(buffer, &output->epoch_time_lsb); @@ -2298,4 +2706,5 @@ bool uxr_deserialize_PERFORMANCE_Payload(ucdrBuffer* buffer, PERFORMANCE_Payload ret &= ucdr_deserialize_array_uint8_t(buffer, output->buf, output->len); return ret; } -#endif + +#endif /* ifdef PERFORMANCE_TESTING */ diff --git a/src/c/core/session/common_create_entities.c b/src/c/core/session/common_create_entities.c index 75d1fbeb9..07b525746 100644 --- a/src/c/core/session/common_create_entities.c +++ b/src/c/core/session/common_create_entities.c @@ -8,7 +8,10 @@ //================================================================== // PUBLIC //================================================================== -uint16_t uxr_buffer_delete_entity(uxrSession* session, uxrStreamId stream_id, uxrObjectId object_id) +uint16_t uxr_buffer_delete_entity( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id) { uint16_t request_id = UXR_INVALID_REQUEST_ID; @@ -19,7 +22,7 @@ uint16_t uxr_buffer_delete_entity(uxrSession* session, uxrStreamId stream_id, ux payload_length = (uint16_t)(payload_length + 4); // delete payload (request id + object_id), no padding. ucdrBuffer ub; - if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_DELETE, 0)) + if (uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_DELETE, 0)) { request_id = uxr_init_base_object_request(&session->info, object_id, &payload.base); (void) uxr_serialize_DELETE_Payload(&ub, &payload); @@ -28,9 +31,13 @@ uint16_t uxr_buffer_delete_entity(uxrSession* session, uxrStreamId stream_id, ux return request_id; } -uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uint16_t xml_ref_size, uint8_t mode, - CREATE_Payload* payload) +uint16_t uxr_common_create_entity( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uint16_t xml_ref_size, + uint8_t mode, + CREATE_Payload* payload) { uint16_t request_id = UXR_INVALID_REQUEST_ID; @@ -42,11 +49,13 @@ uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, payload_length = (uint16_t)(payload_length + 2); // padding payload_length = (uint16_t)(payload_length + 4); // xml length payload_length = (uint16_t)(payload_length + xml_ref_size); // xml data (note: compiler executes strlen one time this function) - payload_length = (uint16_t)(payload_length + ((object_id.type == DDS_XRCE_OBJK_PARTICIPANT && payload_length % 2 != 0) ? 1 : 0)); // necessary padding + payload_length = + (uint16_t)(payload_length + + ((object_id.type == DDS_XRCE_OBJK_PARTICIPANT && payload_length % 2 != 0) ? 1 : 0)); // necessary padding payload_length = (uint16_t)(payload_length + 2); //object id ref ucdrBuffer ub; - if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_CREATE, mode)) + if (uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_CREATE, mode)) { request_id = uxr_init_base_object_request(&session->info, object_id, &payload->base); (void) uxr_serialize_CREATE_Payload(&ub, payload); @@ -54,4 +63,3 @@ uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, return request_id; } - diff --git a/src/c/core/session/common_create_entities_internal.h b/src/c/core/session/common_create_entities_internal.h index 266c1b4cd..cea5e66d1 100644 --- a/src/c/core/session/common_create_entities_internal.h +++ b/src/c/core/session/common_create_entities_internal.h @@ -18,18 +18,22 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include struct CREATE_Payload; -uint16_t uxr_common_create_entity(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uint16_t xml_ref_size, uint8_t mode, - struct CREATE_Payload* payload); +uint16_t uxr_common_create_entity( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uint16_t xml_ref_size, + uint8_t mode, + struct CREATE_Payload* payload); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif //_SRC_C_CORE_SESSION_COMMON_CREATE_ENTITIES_INTERNAL_H_ diff --git a/src/c/core/session/create_entities_ref.c b/src/c/core/session/create_entities_ref.c index b4fd44e8b..f64cfeaf9 100644 --- a/src/c/core/session/create_entities_ref.c +++ b/src/c/core/session/create_entities_ref.c @@ -5,15 +5,24 @@ #include -static uint16_t create_entity_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, const char* ref, uint8_t mode, - CREATE_Payload* payload); +static uint16_t create_entity_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + const char* ref, + uint8_t mode, + CREATE_Payload* payload); //================================================================== // PUBLIC //================================================================== -uint16_t uxr_buffer_create_participant_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, int16_t domain_id, const char* ref, uint8_t mode) +uint16_t uxr_buffer_create_participant_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + int16_t domain_id, + const char* ref, + uint8_t mode) { //assert with the object_id type @@ -24,9 +33,13 @@ uint16_t uxr_buffer_create_participant_ref(uxrSession* session, uxrStreamId stre return create_entity_ref(session, stream_id, object_id, ref, mode, &payload); } -uint16_t uxr_buffer_create_topic_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId participant_id, - const char* ref, uint8_t mode) +uint16_t uxr_buffer_create_topic_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* ref, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_TOPIC; @@ -35,9 +48,13 @@ uint16_t uxr_buffer_create_topic_ref(uxrSession* session, uxrStreamId stream_id, return create_entity_ref(session, stream_id, object_id, ref, mode, &payload); } -uint16_t uxr_buffer_create_datawriter_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId publisher_id, - const char* ref, uint8_t mode) +uint16_t uxr_buffer_create_datawriter_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId publisher_id, + const char* ref, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_DATAWRITER; @@ -46,9 +63,13 @@ uint16_t uxr_buffer_create_datawriter_ref(uxrSession* session, uxrStreamId strea return create_entity_ref(session, stream_id, object_id, ref, mode, &payload); } -uint16_t uxr_buffer_create_datareader_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId subscriber_id, - const char* ref, uint8_t mode) +uint16_t uxr_buffer_create_datareader_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId subscriber_id, + const char* ref, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_DATAREADER; @@ -58,12 +79,12 @@ uint16_t uxr_buffer_create_datareader_ref(uxrSession* session, uxrStreamId strea } uint16_t uxr_buffer_create_requester_ref( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId object_id, - uxrObjectId participant_id, - const char* ref, - uint8_t mode) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* ref, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_REQUESTER; @@ -73,12 +94,12 @@ uint16_t uxr_buffer_create_requester_ref( } uint16_t uxr_buffer_create_replier_ref( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId object_id, - uxrObjectId participant_id, - const char* ref, - uint8_t mode) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* ref, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_REPLIER; @@ -91,9 +112,13 @@ uint16_t uxr_buffer_create_replier_ref( // PRIVATE //================================================================== -inline uint16_t create_entity_ref(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, const char* ref, uint8_t mode, - CREATE_Payload* payload) +inline uint16_t create_entity_ref( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + const char* ref, + uint8_t mode, + CREATE_Payload* payload) { // Use participant access to access to the ref base of any object variant. //Future elegant change? payload->object_representation._.participant.base.representation.format = DDS_XRCE_REPRESENTATION_BY_REFERENCE; diff --git a/src/c/core/session/create_entities_xml.c b/src/c/core/session/create_entities_xml.c index 0d3256f61..b7c1726fc 100644 --- a/src/c/core/session/create_entities_xml.c +++ b/src/c/core/session/create_entities_xml.c @@ -5,15 +5,24 @@ #include -static uint16_t create_entity_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, const char* xml, uint8_t mode, - CREATE_Payload* payload); +static uint16_t create_entity_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + const char* xml, + uint8_t mode, + CREATE_Payload* payload); //================================================================== // PUBLIC //================================================================== -uint16_t uxr_buffer_create_participant_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uint16_t domain, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_participant_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uint16_t domain, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -24,8 +33,13 @@ uint16_t uxr_buffer_create_participant_xml(uxrSession* session, uxrStreamId stre return create_entity_xml(session, stream_id, object_id, xml, mode, &payload); } -uint16_t uxr_buffer_create_topic_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId participant_id, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_topic_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -36,8 +50,13 @@ uint16_t uxr_buffer_create_topic_xml(uxrSession* session, uxrStreamId stream_id, return create_entity_xml(session, stream_id, object_id, xml, mode, &payload); } -uint16_t uxr_buffer_create_publisher_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId participant_id, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_publisher_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -48,8 +67,13 @@ uint16_t uxr_buffer_create_publisher_xml(uxrSession* session, uxrStreamId stream return create_entity_xml(session, stream_id, object_id, xml, mode, &payload); } -uint16_t uxr_buffer_create_subscriber_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId participant_id, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_subscriber_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -60,8 +84,13 @@ uint16_t uxr_buffer_create_subscriber_xml(uxrSession* session, uxrStreamId strea return create_entity_xml(session, stream_id, object_id, xml, mode, &payload); } -uint16_t uxr_buffer_create_datawriter_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId publisher_id, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_datawriter_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId publisher_id, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -72,8 +101,13 @@ uint16_t uxr_buffer_create_datawriter_xml(uxrSession* session, uxrStreamId strea return create_entity_xml(session, stream_id, object_id, xml, mode, &payload); } -uint16_t uxr_buffer_create_datareader_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, uxrObjectId subscriber_id, const char* xml, uint8_t mode) +uint16_t uxr_buffer_create_datareader_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId subscriber_id, + const char* xml, + uint8_t mode) { //assert with the object_id type @@ -85,12 +119,12 @@ uint16_t uxr_buffer_create_datareader_xml(uxrSession* session, uxrStreamId strea } uint16_t uxr_buffer_create_requester_xml( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId object_id, - uxrObjectId participant_id, - const char* xml, - uint8_t mode) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* xml, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_REQUESTER; @@ -100,12 +134,12 @@ uint16_t uxr_buffer_create_requester_xml( } uint16_t uxr_buffer_create_replier_xml( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId object_id, - uxrObjectId participant_id, - const char* xml, - uint8_t mode) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + uxrObjectId participant_id, + const char* xml, + uint8_t mode) { CREATE_Payload payload; payload.object_representation.kind = DDS_XRCE_OBJK_REPLIER; @@ -118,9 +152,13 @@ uint16_t uxr_buffer_create_replier_xml( // PRIVATE //================================================================== -inline uint16_t create_entity_xml(uxrSession* session, uxrStreamId stream_id, - uxrObjectId object_id, const char* xml, uint8_t mode, - CREATE_Payload* payload) +inline uint16_t create_entity_xml( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId object_id, + const char* xml, + uint8_t mode, + CREATE_Payload* payload) { // Use participant access to access to the xml base of any object variant. //Future elegant change? payload->object_representation._.participant.base.representation.format = DDS_XRCE_REPRESENTATION_AS_XML_STRING; diff --git a/src/c/core/session/object_id.c b/src/c/core/session/object_id.c index f50664ce3..4b41ae111 100644 --- a/src/c/core/session/object_id.c +++ b/src/c/core/session/object_id.c @@ -3,7 +3,9 @@ //================================================================== // PUBLIC //================================================================== -uxrObjectId uxr_object_id(uint16_t id, uint8_t type) +uxrObjectId uxr_object_id( + uint16_t id, + uint8_t type) { uxrObjectId object_id; object_id.id = id; @@ -11,7 +13,8 @@ uxrObjectId uxr_object_id(uint16_t id, uint8_t type) return object_id; } -uxrObjectId uxr_object_id_from_raw(const uint8_t* raw) +uxrObjectId uxr_object_id_from_raw( + const uint8_t* raw) { uxrObjectId object_id; object_id.id = (uint16_t)((((uint16_t)raw[0]) << 4) + (raw[1] >> 4)); @@ -19,7 +22,9 @@ uxrObjectId uxr_object_id_from_raw(const uint8_t* raw) return object_id; } -void uxr_object_id_to_raw(uxrObjectId object_id, uint8_t* raw) +void uxr_object_id_to_raw( + uxrObjectId object_id, + uint8_t* raw) { raw[0] = (uint8_t) (object_id.id >> 4); raw[1] = (uint8_t)((((uint8_t) (object_id.id)) << 4) + (object_id.type & 0x0F)); diff --git a/src/c/core/session/read_access.c b/src/c/core/session/read_access.c index 3e9a72db0..b00422422 100644 --- a/src/c/core/session/read_access.c +++ b/src/c/core/session/read_access.c @@ -72,7 +72,7 @@ uint16_t uxr_buffer_request_data( payload.read_specification.optional_content_filter_expression = false; //not supported yet payload.read_specification.optional_delivery_control = (control != NULL); - if(control != NULL) + if (control != NULL) { payload.read_specification.delivery_control.max_bytes_per_seconds = control->max_bytes_per_second; payload.read_specification.delivery_control.max_elapsed_time = control->max_elapsed_time; @@ -87,7 +87,7 @@ uint16_t uxr_buffer_request_data( payload_length += (control != NULL) ? 8 : 0; // delivery control ucdrBuffer ub; - if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_READ_DATA, 0)) + if (uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &ub, SUBMESSAGE_ID_READ_DATA, 0)) { request_id = uxr_init_base_object_request(&session->info, datareader_id, &payload.base); (void) uxr_serialize_READ_DATA_Payload(&ub, &payload); @@ -101,8 +101,12 @@ uint16_t uxr_buffer_cancel_data( uxrStreamId stream_id, uxrObjectId datareader_id) { - uxrDeliveryControl delivery_control = {0}; - uxrStreamId in_stream = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; + uxrStreamId in_stream = { + 0 + }; return uxr_buffer_request_data(session, stream_id, datareader_id, in_stream, &delivery_control); } @@ -118,7 +122,7 @@ void read_submessage_format( uxrObjectId object_id, uint16_t request_id) { - switch(format) + switch (format) { case FORMAT_DATA: read_format_data(session, data, length, stream_id, object_id, request_id); @@ -158,7 +162,7 @@ inline void read_format_data( ucdr_set_on_full_buffer_callback(&temp_buffer, ub->on_full_buffer, ub->args); if (ub->args) { - uxrInputReliableStream * stream = (uxrInputReliableStream*) ub->args; + uxrInputReliableStream* stream = (uxrInputReliableStream*) ub->args; stream->cleanup_flag = false; } @@ -168,7 +172,9 @@ inline void read_format_data( { if (NULL != session->on_topic) { - session->on_topic(session, object_id, request_id, stream_id, &temp_buffer, length, session->on_topic_args); + session->on_topic(session, object_id, request_id, stream_id, &temp_buffer, length, + session->on_topic_args); + session->on_data_flag = true; } break; } @@ -182,7 +188,8 @@ inline void read_format_data( if (uxr_deserialize_SampleIdentity(&temp_buffer, &sample_id)) { uint16_t request_length = (uint16_t)(length - (temp_buffer.offset - offset)); - ucdr_init_buffer(&temp_buffer, temp_buffer.iterator, (size_t)(temp_buffer.final - temp_buffer.iterator)); + ucdr_init_buffer(&temp_buffer, temp_buffer.iterator, + (size_t)(temp_buffer.final - temp_buffer.iterator)); ucdr_set_on_full_buffer_callback(&temp_buffer, ub->on_full_buffer, ub->args); session->on_request( @@ -193,6 +200,8 @@ inline void read_format_data( &temp_buffer, (size_t)request_length, session->on_request_args); + + session->on_data_flag = true; } } break; @@ -207,7 +216,8 @@ inline void read_format_data( if (uxr_deserialize_BaseObjectRequest(&temp_buffer, &request)) { uint16_t reply_length = (uint16_t)(length - (temp_buffer.offset - offset)); - ucdr_init_buffer(&temp_buffer, temp_buffer.iterator, (size_t)(temp_buffer.final - temp_buffer.iterator)); + ucdr_init_buffer(&temp_buffer, temp_buffer.iterator, + (size_t)(temp_buffer.final - temp_buffer.iterator)); ucdr_set_on_full_buffer_callback(&temp_buffer, ub->on_full_buffer, ub->args); session->on_reply( @@ -218,6 +228,8 @@ inline void read_format_data( &temp_buffer, (size_t)reply_length, session->on_reply_args); + + session->on_data_flag = true; } } ub->iterator += length; @@ -229,7 +241,7 @@ inline void read_format_data( if (ub->args) { - uxrInputReliableStream * stream = (uxrInputReliableStream*) ub->args; + uxrInputReliableStream* stream = (uxrInputReliableStream*) ub->args; stream->cleanup_flag = true; } ucdr_advance_buffer(ub, length); diff --git a/src/c/core/session/session.c b/src/c/core/session/session.c index 21cc2f999..a4365c52e 100644 --- a/src/c/core/session/session.c +++ b/src/c/core/session/session.c @@ -24,44 +24,105 @@ #define TIMESTAMP_PAYLOAD_SIZE 8 #define TIMESTAMP_MAX_MSG_SIZE (MAX_HEADER_SIZE + SUBHEADER_SIZE + TIMESTAMP_PAYLOAD_SIZE) -static bool listen_message(uxrSession* session, int poll_ms); -static bool listen_message_reliably(uxrSession* session, int poll_ms); - -static bool wait_session_status(uxrSession* session, uint8_t* buffer, size_t length, size_t attempts); - -static bool send_message(const uxrSession* session, uint8_t* buffer, size_t length); -static bool recv_message(const uxrSession* session, uint8_t** buffer, size_t* length, int poll_ms); - -static void write_submessage_heartbeat(const uxrSession* session, uxrStreamId stream); -static void write_submessage_acknack(const uxrSession* session, uxrStreamId stream); - -static void read_message(uxrSession* session, ucdrBuffer* message); -static void read_stream(uxrSession* session, ucdrBuffer* message, uxrStreamId id, uxrSeqNum seq_num); -static void read_submessage_list(uxrSession* session, ucdrBuffer* submessages, uxrStreamId stream_id); -static void read_submessage(uxrSession* session, ucdrBuffer* submessage, - uint8_t submessage_id, uxrStreamId stream_id, uint16_t length, uint8_t flags); - -static void read_submessage_status(uxrSession* session, ucdrBuffer* submessage); -static void read_submessage_data(uxrSession* session, ucdrBuffer* submessage, uint16_t length, uxrStreamId stream_id, uint8_t format); -static void read_submessage_heartbeat(uxrSession* session, ucdrBuffer* submessage); -static void read_submessage_acknack(uxrSession* session, ucdrBuffer* submessage); -static void read_submessage_timestamp_reply(uxrSession* session, ucdrBuffer* submessage); +static bool listen_message( + uxrSession* session, + int poll_ms); +static bool listen_message_reliably( + uxrSession* session, + int poll_ms); + +static bool wait_session_status( + uxrSession* session, + uint8_t* buffer, + size_t length, + size_t attempts); + +static bool send_message( + const uxrSession* session, + uint8_t* buffer, + size_t length); +static bool recv_message( + const uxrSession* session, + uint8_t** buffer, + size_t* length, + int poll_ms); + +static void write_submessage_heartbeat( + const uxrSession* session, + uxrStreamId stream); +static void write_submessage_acknack( + const uxrSession* session, + uxrStreamId stream); + +static void read_message( + uxrSession* session, + ucdrBuffer* message); +static void read_stream( + uxrSession* session, + ucdrBuffer* message, + uxrStreamId id, + uxrSeqNum seq_num); +static void read_submessage_list( + uxrSession* session, + ucdrBuffer* submessages, + uxrStreamId stream_id); +static void read_submessage( + uxrSession* session, + ucdrBuffer* submessage, + uint8_t submessage_id, + uxrStreamId stream_id, + uint16_t length, + uint8_t flags); + +static void read_submessage_status( + uxrSession* session, + ucdrBuffer* submessage); +static void read_submessage_data( + uxrSession* session, + ucdrBuffer* submessage, + uint16_t length, + uxrStreamId stream_id, + uint8_t format); +static void read_submessage_heartbeat( + uxrSession* session, + ucdrBuffer* submessage); +static void read_submessage_acknack( + uxrSession* session, + ucdrBuffer* submessage); +static void read_submessage_timestamp_reply( + uxrSession* session, + ucdrBuffer* submessage); #ifdef PERFORMANCE_TESTING -static void read_submessage_performance(uxrSession* session, ucdrBuffer* submessage, uint16_t length); -#endif - -static void process_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status); -static void process_timestamp_reply(uxrSession* session, TIMESTAMP_REPLY_Payload* timestamp); - -static FragmentationInfo on_get_fragmentation_info(uint8_t* submessage_header); - -static bool run_session_until_sync(uxrSession* session, int timeout); +static void read_submessage_performance( + uxrSession* session, + ucdrBuffer* submessage, + uint16_t length); +#endif /* ifdef PERFORMANCE_TESTING */ + +static void process_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status); +static void process_timestamp_reply( + uxrSession* session, + TIMESTAMP_REPLY_Payload* timestamp); + +static FragmentationInfo on_get_fragmentation_info( + uint8_t* submessage_header); + +static bool run_session_until_sync( + uxrSession* session, + int timeout); //================================================================== // PUBLIC //================================================================== -void uxr_init_session(uxrSession* session, uxrCommunication* comm, uint32_t key) +void uxr_init_session( + uxrSession* session, + uxrCommunication* comm, + uint32_t key) { session->comm = comm; @@ -83,116 +144,169 @@ void uxr_init_session(uxrSession* session, uxrCommunication* comm, uint32_t key) uxr_init_stream_storage(&session->streams); } -void uxr_set_status_callback(uxrSession* session, uxrOnStatusFunc on_status_func, void* args) +void uxr_set_status_callback( + uxrSession* session, + uxrOnStatusFunc on_status_func, + void* args) { session->on_status = on_status_func; session->on_status_args = args; } -void uxr_set_topic_callback(uxrSession* session, uxrOnTopicFunc on_topic_func, void* args) +void uxr_set_topic_callback( + uxrSession* session, + uxrOnTopicFunc on_topic_func, + void* args) { session->on_topic = on_topic_func; session->on_topic_args = args; } -void uxr_set_time_callback(uxrSession* session, uxrOnTimeFunc on_time_func, void* args) +void uxr_set_time_callback( + uxrSession* session, + uxrOnTimeFunc on_time_func, + void* args) { session->on_time = on_time_func; session->on_time_args = args; } -void uxr_set_request_callback(uxrSession* session, uxrOnRequestFunc on_request_func, void* args) +void uxr_set_request_callback( + uxrSession* session, + uxrOnRequestFunc on_request_func, + void* args) { session->on_request = on_request_func; session->on_request_args = args; } -void uxr_set_reply_callback(uxrSession* session, uxrOnReplyFunc on_reply_func, void* args) +void uxr_set_reply_callback( + uxrSession* session, + uxrOnReplyFunc on_reply_func, + void* args) { session->on_reply = on_reply_func; session->on_reply_args = args; } #ifdef PERFORMANCE_TESTING -void uxr_set_performance_callback(uxrSession* session, uxrOnPerformanceFunc on_echo_func, void* args) +void uxr_set_performance_callback( + uxrSession* session, + uxrOnPerformanceFunc on_echo_func, + void* args) { session->on_performance = on_echo_func; session->on_performance_args = args; } -#endif -bool uxr_create_session(uxrSession* session) +#endif /* ifdef PERFORMANCE_TESTING */ + +bool uxr_create_session_retries( + uxrSession* session, + size_t retries) { uxr_reset_stream_storage(&session->streams); uint8_t create_session_buffer[CREATE_SESSION_MAX_MSG_SIZE]; ucdrBuffer ub; - ucdr_init_buffer_origin_offset(&ub, create_session_buffer, CREATE_SESSION_MAX_MSG_SIZE, 0u, uxr_session_header_offset(&session->info)); + ucdr_init_buffer_origin_offset(&ub, create_session_buffer, CREATE_SESSION_MAX_MSG_SIZE, 0u, uxr_session_header_offset( + &session->info)); uxr_buffer_create_session(&session->info, &ub, (uint16_t)(session->comm->mtu - INTERNAL_RELIABLE_BUFFER_OFFSET)); uxr_stamp_create_session_header(&session->info, ub.init); - bool received = wait_session_status(session, create_session_buffer, ucdr_buffer_length(&ub), UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS); + bool received = wait_session_status(session, create_session_buffer, ucdr_buffer_length(&ub), (size_t) retries); bool created = received && UXR_STATUS_OK == session->info.last_requested_status; return created; } -bool uxr_delete_session(uxrSession* session) +bool uxr_create_session( + uxrSession* session) +{ + return uxr_create_session_retries(session, UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS); +} + +bool uxr_delete_session_retries( + uxrSession* session, + size_t retries) { uint8_t delete_session_buffer[DELETE_SESSION_MAX_MSG_SIZE]; ucdrBuffer ub; - ucdr_init_buffer_origin_offset(&ub, delete_session_buffer, DELETE_SESSION_MAX_MSG_SIZE, 0u, uxr_session_header_offset(&session->info)); + ucdr_init_buffer_origin_offset(&ub, delete_session_buffer, DELETE_SESSION_MAX_MSG_SIZE, 0u, uxr_session_header_offset( + &session->info)); uxr_buffer_delete_session(&session->info, &ub); uxr_stamp_session_header(&session->info, 0, 0, ub.init); - bool received = wait_session_status(session, delete_session_buffer, ucdr_buffer_length(&ub), UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS); + bool received = wait_session_status(session, delete_session_buffer, ucdr_buffer_length(&ub), retries); return received && UXR_STATUS_OK == session->info.last_requested_status; } -uxrStreamId uxr_create_output_best_effort_stream(uxrSession* session, uint8_t* buffer, size_t size) +bool uxr_delete_session( + uxrSession* session) +{ + return uxr_delete_session_retries(session, UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS); +} + +uxrStreamId uxr_create_output_best_effort_stream( + uxrSession* session, + uint8_t* buffer, + size_t size) { uint8_t header_offset = uxr_session_header_offset(&session->info); return uxr_add_output_best_effort_buffer(&session->streams, buffer, size, header_offset); } -uxrStreamId uxr_create_output_reliable_stream(uxrSession* session, uint8_t* buffer, size_t size, uint16_t history) +uxrStreamId uxr_create_output_reliable_stream( + uxrSession* session, + uint8_t* buffer, + size_t size, + uint16_t history) { uint8_t header_offset = uxr_session_header_offset(&session->info); return uxr_add_output_reliable_buffer(&session->streams, buffer, size, history, header_offset); } -uxrStreamId uxr_create_input_best_effort_stream(uxrSession* session) +uxrStreamId uxr_create_input_best_effort_stream( + uxrSession* session) { return uxr_add_input_best_effort_buffer(&session->streams); } -uxrStreamId uxr_create_input_reliable_stream(uxrSession* session, uint8_t* buffer, size_t size, uint16_t history) +uxrStreamId uxr_create_input_reliable_stream( + uxrSession* session, + uint8_t* buffer, + size_t size, + uint16_t history) { return uxr_add_input_reliable_buffer(&session->streams, buffer, size, history, on_get_fragmentation_info); } -bool uxr_run_session_time(uxrSession* session, int timeout_ms) +bool uxr_run_session_time( + uxrSession* session, + int timeout_ms) { uxr_flash_output_streams(session); bool timeout = false; - while(!timeout) + while (!timeout) { - timeout = !listen_message_reliably(session, timeout_ms); + timeout = !listen_message_reliably(session, timeout_ms); } return uxr_output_streams_confirmed(&session->streams); } -bool uxr_run_session_timeout(uxrSession* session, int timeout_ms) +bool uxr_run_session_timeout( + uxrSession* session, + int timeout_ms) { int64_t start_timestamp = uxr_millis(); int remaining_time = timeout_ms; uxr_flash_output_streams(session); - while(remaining_time > 0) + while (remaining_time > 0) { listen_message_reliably(session, remaining_time); remaining_time = timeout_ms - (int)(uxr_millis() - start_timestamp); @@ -200,19 +314,45 @@ bool uxr_run_session_timeout(uxrSession* session, int timeout_ms) return uxr_output_streams_confirmed(&session->streams); } -bool uxr_run_session_until_timeout(uxrSession* session, int timeout_ms) +bool uxr_run_session_until_data( + uxrSession* session, + int timeout_ms) +{ + int64_t start_timestamp = uxr_millis(); + int remaining_time = timeout_ms; + + uxr_flash_output_streams(session); + + session->on_data_flag = false; + while (remaining_time > 0) + { + listen_message_reliably(session, remaining_time); + if (session->on_data_flag) + { + break; + } + remaining_time = timeout_ms - (int)(uxr_millis() - start_timestamp); + } + return session->on_data_flag; +} + +bool uxr_run_session_until_timeout( + uxrSession* session, + int timeout_ms) { uxr_flash_output_streams(session); return listen_message_reliably(session, timeout_ms); } -bool uxr_run_session_until_confirm_delivery(uxrSession* session, int timeout_ms) +bool uxr_run_session_until_confirm_delivery( + uxrSession* session, + int timeout_ms) { uxr_flash_output_streams(session); bool timeout = false; - while(!uxr_output_streams_confirmed(&session->streams) && !timeout) + while (!uxr_output_streams_confirmed(&session->streams) && !timeout) { timeout = !listen_message_reliably(session, timeout_ms); } @@ -220,11 +360,16 @@ bool uxr_run_session_until_confirm_delivery(uxrSession* session, int timeout_ms) return uxr_output_streams_confirmed(&session->streams); } -bool uxr_run_session_until_all_status(uxrSession* session, int timeout_ms, const uint16_t* request_list, uint8_t* status_list, size_t list_size) +bool uxr_run_session_until_all_status( + uxrSession* session, + int timeout_ms, + const uint16_t* request_list, + uint8_t* status_list, + size_t list_size) { uxr_flash_output_streams(session); - for(unsigned i = 0; i < list_size; ++i) + for (unsigned i = 0; i < list_size; ++i) { status_list[i] = UXR_STATUS_NONE; } @@ -235,21 +380,21 @@ bool uxr_run_session_until_all_status(uxrSession* session, int timeout_ms, const bool timeout = false; bool status_confirmed = false; - while(!timeout && !status_confirmed) + while (!timeout && !status_confirmed) { timeout = !listen_message_reliably(session, timeout_ms); status_confirmed = true; - for(unsigned i = 0; i < list_size && status_confirmed; ++i) + for (unsigned i = 0; i < list_size && status_confirmed; ++i) { status_confirmed = status_list[i] != UXR_STATUS_NONE - || request_list[i] == UXR_INVALID_REQUEST_ID; //CHECK: better give an error? an assert? + || request_list[i] == UXR_INVALID_REQUEST_ID; //CHECK: better give an error? an assert? } } session->request_status_list_size = 0; bool status_ok = true; - for(unsigned i = 0; i < list_size && status_ok; ++i) + for (unsigned i = 0; i < list_size && status_ok; ++i) { status_ok = status_list[i] == UXR_STATUS_OK || status_list[i] == UXR_STATUS_OK_MATCHED; } @@ -257,11 +402,16 @@ bool uxr_run_session_until_all_status(uxrSession* session, int timeout_ms, const return status_ok; } -bool uxr_run_session_until_one_status(uxrSession* session, int timeout_ms, const uint16_t* request_list, uint8_t* status_list, size_t list_size) +bool uxr_run_session_until_one_status( + uxrSession* session, + int timeout_ms, + const uint16_t* request_list, + uint8_t* status_list, + size_t list_size) { uxr_flash_output_streams(session); - for(unsigned i = 0; i < list_size; ++i) + for (unsigned i = 0; i < list_size; ++i) { status_list[i] = UXR_STATUS_NONE; } @@ -272,13 +422,13 @@ bool uxr_run_session_until_one_status(uxrSession* session, int timeout_ms, const bool timeout = false; bool status_confirmed = false; - while(!timeout && !status_confirmed) + while (!timeout && !status_confirmed) { timeout = !listen_message_reliably(session, timeout_ms); - for(unsigned i = 0; i < list_size && !status_confirmed; ++i) + for (unsigned i = 0; i < list_size && !status_confirmed; ++i) { status_confirmed = status_list[i] != UXR_STATUS_NONE - || request_list[i] == UXR_INVALID_REQUEST_ID; //CHECK: better give an error? an assert? + || request_list[i] == UXR_INVALID_REQUEST_ID; //CHECK: better give an error? an assert? } } @@ -287,11 +437,14 @@ bool uxr_run_session_until_one_status(uxrSession* session, int timeout_ms, const return status_confirmed; } -bool uxr_sync_session(uxrSession* session, int time) +bool uxr_sync_session( + uxrSession* session, + int time) { uint8_t timestamp_buffer[TIMESTAMP_MAX_MSG_SIZE]; ucdrBuffer ub; - ucdr_init_buffer_origin_offset(&ub, timestamp_buffer, sizeof(timestamp_buffer), 0u, uxr_session_header_offset(&session->info)); + ucdr_init_buffer_origin_offset(&ub, timestamp_buffer, sizeof(timestamp_buffer), 0u, + uxr_session_header_offset(&session->info)); uxr_buffer_submessage_header(&ub, SUBMESSAGE_ID_TIMESTAMP, TIMESTAMP_PAYLOAD_SIZE, 0); TIMESTAMP_Payload timestamp; @@ -305,23 +458,26 @@ bool uxr_sync_session(uxrSession* session, int time) return run_session_until_sync(session, time); } -int64_t uxr_epoch_millis(uxrSession* session) +int64_t uxr_epoch_millis( + uxrSession* session) { return uxr_epoch_nanos(session) / 1000000; } -int64_t uxr_epoch_nanos(uxrSession* session) +int64_t uxr_epoch_nanos( + uxrSession* session) { return uxr_nanos() - session->time_offset; } #ifdef PERFORMANCE_TESTING -bool uxr_buffer_performance(uxrSession *session, - uxrStreamId stream_id, - uint64_t epoch_time, - uint8_t* buf, - uint16_t len, - bool echo) +bool uxr_buffer_performance( + uxrSession* session, + uxrStreamId stream_id, + uint64_t epoch_time, + uint8_t* buf, + uint16_t len, + bool echo) { bool rv = false; PERFORMANCE_Payload payload; @@ -331,41 +487,44 @@ bool uxr_buffer_performance(uxrSession *session, payload.len = len; ucdrBuffer mb; const uint16_t payload_length = (uint16_t)(sizeof(payload.epoch_time_lsb) + - sizeof(payload.epoch_time_msb) + - len); + sizeof(payload.epoch_time_msb) + + len); uint8_t flags = (echo) ? UXR_ECHO : 0; - if(uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &mb, SUBMESSAGE_ID_PERFORMANCE, flags)) + if (uxr_prepare_stream_to_write_submessage(session, stream_id, payload_length, &mb, SUBMESSAGE_ID_PERFORMANCE, + flags)) { (void) uxr_serialize_PERFORMANCE_Payload(&mb, &payload); rv = true; } return rv; } -#endif -void uxr_flash_output_streams(uxrSession* session) +#endif /* ifdef PERFORMANCE_TESTING */ + +void uxr_flash_output_streams( + uxrSession* session) { - for(uint8_t i = 0; i < session->streams.output_best_effort_size; ++i) + for (uint8_t i = 0; i < session->streams.output_best_effort_size; ++i) { uxrOutputBestEffortStream* stream = &session->streams.output_best_effort[i]; uxrStreamId id = uxr_stream_id(i, UXR_BEST_EFFORT_STREAM, UXR_OUTPUT_STREAM); uint8_t* buffer; size_t length; uxrSeqNum seq_num; - if(uxr_prepare_best_effort_buffer_to_send(stream, &buffer, &length, &seq_num)) + if (uxr_prepare_best_effort_buffer_to_send(stream, &buffer, &length, &seq_num)) { uxr_stamp_session_header(&session->info, id.raw, seq_num, buffer); send_message(session, buffer, length); } } - for(uint8_t i = 0; i < session->streams.output_reliable_size; ++i) + for (uint8_t i = 0; i < session->streams.output_reliable_size; ++i) { uxrOutputReliableStream* stream = &session->streams.output_reliable[i]; uxrStreamId id = uxr_stream_id(i, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); uint8_t* buffer; size_t length; uxrSeqNum seq_num; - while(uxr_prepare_next_reliable_buffer_to_send(stream, &buffer, &length, &seq_num)) + while (uxr_prepare_next_reliable_buffer_to_send(stream, &buffer, &length, &seq_num)) { uxr_stamp_session_header(&session->info, id.raw, seq_num, buffer); send_message(session, buffer, length); @@ -376,11 +535,13 @@ void uxr_flash_output_streams(uxrSession* session) //================================================================== // PRIVATE //================================================================== -bool listen_message(uxrSession* session, int poll_ms) +bool listen_message( + uxrSession* session, + int poll_ms) { uint8_t* data; size_t length; bool must_be_read = recv_message(session, &data, &length, poll_ms); - if(must_be_read) + if (must_be_read) { ucdrBuffer ub; ucdr_init_buffer(&ub, data, (uint32_t)length); @@ -390,7 +551,9 @@ bool listen_message(uxrSession* session, int poll_ms) return must_be_read; } -bool listen_message_reliably(uxrSession* session, int poll_ms) +bool listen_message_reliably( + uxrSession* session, + int poll_ms) { bool received = false; int32_t poll = (poll_ms >= 0) ? poll_ms : INT32_MAX; @@ -398,76 +561,90 @@ bool listen_message_reliably(uxrSession* session, int poll_ms) { int64_t next_heartbeat_timestamp = INT64_MAX; int64_t timestamp = uxr_millis(); - for(uint8_t i = 0; i < session->streams.output_reliable_size; ++i) + for (uint8_t i = 0; i < session->streams.output_reliable_size; ++i) { uxrOutputReliableStream* stream = &session->streams.output_reliable[i]; uxrStreamId id = uxr_stream_id(i, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); - if(uxr_update_output_stream_heartbeat_timestamp(stream, timestamp)) + if (uxr_update_output_stream_heartbeat_timestamp(stream, timestamp)) { write_submessage_heartbeat(session, id); } - if(stream->next_heartbeat_timestamp < next_heartbeat_timestamp) + if (stream->next_heartbeat_timestamp < next_heartbeat_timestamp) { next_heartbeat_timestamp = stream->next_heartbeat_timestamp; } } - int32_t poll_to_next_heartbeat = (next_heartbeat_timestamp != INT64_MAX) ? (int32_t)(next_heartbeat_timestamp - timestamp) : poll; - if(0 == poll_to_next_heartbeat) + int32_t poll_to_next_heartbeat = + (next_heartbeat_timestamp != INT64_MAX) ? (int32_t)(next_heartbeat_timestamp - timestamp) : poll; + if (0 == poll_to_next_heartbeat) { poll_to_next_heartbeat = 1; } int poll_chosen = (poll_to_next_heartbeat < poll) ? poll_to_next_heartbeat : poll; received = listen_message(session, poll_chosen); - if(!received) + if (!received) { poll -= poll_chosen; } } - while(!received && poll > 0); + while (!received && poll > 0); return received; } -bool wait_session_status(uxrSession* session, uint8_t* buffer, size_t length, size_t attempts) +bool wait_session_status( + uxrSession* session, + uint8_t* buffer, + size_t length, + size_t attempts) { session->info.last_requested_status = UXR_STATUS_NONE; - int poll_ms = UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL; - for(size_t i = 0; i < attempts && session->info.last_requested_status == UXR_STATUS_NONE; ++i) + for (size_t i = 0; i < attempts && session->info.last_requested_status == UXR_STATUS_NONE; ++i) { send_message(session, buffer, length); - poll_ms = listen_message(session, poll_ms) ? UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL : poll_ms * 2; + listen_message(session, UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL); } return session->info.last_requested_status != UXR_STATUS_NONE; } -inline bool send_message(const uxrSession* session, uint8_t* buffer, size_t length) +inline bool send_message( + const uxrSession* session, + uint8_t* buffer, + size_t length) { bool sent = session->comm->send_msg(session->comm->instance, buffer, length); UXR_DEBUG_PRINT_MESSAGE((sent) ? UXR_SEND : UXR_ERROR_SEND, buffer, length, session->info.key); return sent; } -inline bool recv_message(const uxrSession* session, uint8_t**buffer, size_t* length, int poll_ms) +inline bool recv_message( + const uxrSession* session, + uint8_t** buffer, + size_t* length, + int poll_ms) { bool received = session->comm->recv_msg(session->comm->instance, buffer, length, poll_ms); - if(received) + if (received) { UXR_DEBUG_PRINT_MESSAGE(UXR_RECV, *buffer, *length, session->info.key); } return received; } -void write_submessage_heartbeat(const uxrSession* session, uxrStreamId id) +void write_submessage_heartbeat( + const uxrSession* session, + uxrStreamId id) { uint8_t heartbeat_buffer[HEARTBEAT_MAX_MSG_SIZE]; ucdrBuffer ub; - ucdr_init_buffer_origin_offset(&ub, heartbeat_buffer, HEARTBEAT_MAX_MSG_SIZE, 0u, uxr_session_header_offset(&session->info)); + ucdr_init_buffer_origin_offset(&ub, heartbeat_buffer, HEARTBEAT_MAX_MSG_SIZE, 0u, + uxr_session_header_offset(&session->info)); const uxrOutputReliableStream* stream = &session->streams.output_reliable[id.index]; @@ -486,11 +663,14 @@ void write_submessage_heartbeat(const uxrSession* session, uxrStreamId id) send_message(session, heartbeat_buffer, ucdr_buffer_length(&ub)); } -void write_submessage_acknack(const uxrSession* session, uxrStreamId id) +void write_submessage_acknack( + const uxrSession* session, + uxrStreamId id) { uint8_t acknack_buffer[ACKNACK_MAX_MSG_SIZE]; ucdrBuffer ub; - ucdr_init_buffer_origin_offset(&ub, acknack_buffer, ACKNACK_MAX_MSG_SIZE, 0u, uxr_session_header_offset(&session->info)); + ucdr_init_buffer_origin_offset(&ub, acknack_buffer, ACKNACK_MAX_MSG_SIZE, 0u, + uxr_session_header_offset(&session->info)); const uxrInputReliableStream* stream = &session->streams.input_reliable[id.index]; @@ -510,19 +690,25 @@ void write_submessage_acknack(const uxrSession* session, uxrStreamId id) send_message(session, acknack_buffer, ucdr_buffer_length(&ub)); } -void read_message(uxrSession* session, ucdrBuffer* ub) +void read_message( + uxrSession* session, + ucdrBuffer* ub) { uint8_t stream_id_raw; uxrSeqNum seq_num; - if(uxr_read_session_header(&session->info, ub, &stream_id_raw, &seq_num)) + if (uxr_read_session_header(&session->info, ub, &stream_id_raw, &seq_num)) { uxrStreamId id = uxr_stream_id_from_raw(stream_id_raw, UXR_INPUT_STREAM); read_stream(session, ub, id, seq_num); } } -void read_stream(uxrSession* session, ucdrBuffer* ub, uxrStreamId stream_id, uxrSeqNum seq_num) +void read_stream( + uxrSession* session, + ucdrBuffer* ub, + uxrStreamId stream_id, + uxrSeqNum seq_num) { - switch(stream_id.type) + switch (stream_id.type) { case UXR_NONE_STREAM: { @@ -533,7 +719,7 @@ void read_stream(uxrSession* session, ucdrBuffer* ub, uxrStreamId stream_id, uxr case UXR_BEST_EFFORT_STREAM: { uxrInputBestEffortStream* stream = uxr_get_input_best_effort_stream(&session->streams, stream_id.index); - if(stream && uxr_receive_best_effort_message(stream, seq_num)) + if (stream && uxr_receive_best_effort_message(stream, seq_num)) { read_submessage_list(session, ub, stream_id); } @@ -543,15 +729,17 @@ void read_stream(uxrSession* session, ucdrBuffer* ub, uxrStreamId stream_id, uxr { uxrInputReliableStream* stream = uxr_get_input_reliable_stream(&session->streams, stream_id.index); bool input_buffer_used; - if(stream && uxr_receive_reliable_message(stream, seq_num, ub->iterator, ucdr_buffer_remaining(ub), &input_buffer_used)) + if (stream && + uxr_receive_reliable_message(stream, seq_num, ub->iterator, ucdr_buffer_remaining( + ub), &input_buffer_used)) { - if(!input_buffer_used) + if (!input_buffer_used) { read_submessage_list(session, ub, stream_id); } ucdrBuffer next_mb; - while(uxr_next_input_reliable_buffer_available(stream, &next_mb, SUBHEADER_SIZE)) + while (uxr_next_input_reliable_buffer_available(stream, &next_mb, SUBHEADER_SIZE)) { read_submessage_list(session, &next_mb, stream_id); } @@ -564,28 +752,37 @@ void read_stream(uxrSession* session, ucdrBuffer* ub, uxrStreamId stream_id, uxr } } -void read_submessage_list(uxrSession* session, ucdrBuffer* submessages, uxrStreamId stream_id) +void read_submessage_list( + uxrSession* session, + ucdrBuffer* submessages, + uxrStreamId stream_id) { uint8_t id; uint16_t length; uint8_t flags; - while(uxr_read_submessage_header(submessages, &id, &length, &flags)) + while (uxr_read_submessage_header(submessages, &id, &length, &flags)) { read_submessage(session, submessages, id, stream_id, length, flags); } } -void read_submessage(uxrSession* session, ucdrBuffer* submessage, uint8_t submessage_id, uxrStreamId stream_id, uint16_t length, uint8_t flags) +void read_submessage( + uxrSession* session, + ucdrBuffer* submessage, + uint8_t submessage_id, + uxrStreamId stream_id, + uint16_t length, + uint8_t flags) { - switch(submessage_id) + switch (submessage_id) { case SUBMESSAGE_ID_STATUS_AGENT: - if(stream_id.type == UXR_NONE_STREAM) + if (stream_id.type == UXR_NONE_STREAM) { uxr_read_create_session_status(&session->info, submessage); } break; case SUBMESSAGE_ID_STATUS: - if(stream_id.type == UXR_NONE_STREAM) + if (stream_id.type == UXR_NONE_STREAM) { uxr_read_delete_session_status(&session->info, submessage); } @@ -615,14 +812,16 @@ void read_submessage(uxrSession* session, ucdrBuffer* submessage, uint8_t submes case SUBMESSAGE_ID_PERFORMANCE: read_submessage_performance(session, submessage, length); break; -#endif +#endif /* ifdef PERFORMANCE_TESTING */ default: break; } } -void read_submessage_status(uxrSession* session, ucdrBuffer* submessage) +void read_submessage_status( + uxrSession* session, + ucdrBuffer* submessage) { STATUS_Payload payload; uxr_deserialize_STATUS_Payload(submessage, &payload); @@ -634,11 +833,21 @@ void read_submessage_status(uxrSession* session, ucdrBuffer* submessage) process_status(session, object_id, request_id, status); } - -extern void read_submessage_format(uxrSession* session, ucdrBuffer* data, uint16_t length, uint8_t format, - uxrStreamId stream_id, uxrObjectId object_id, uint16_t request_id); - -void read_submessage_data(uxrSession* session, ucdrBuffer* submessage, uint16_t length, uxrStreamId stream_id, uint8_t format) +extern void read_submessage_format( + uxrSession* session, + ucdrBuffer* data, + uint16_t length, + uint8_t format, + uxrStreamId stream_id, + uxrObjectId object_id, + uint16_t request_id); + +void read_submessage_data( + uxrSession* session, + ucdrBuffer* submessage, + uint16_t length, + uxrStreamId stream_id, + uint8_t format) { BaseObjectRequest base; uxr_deserialize_BaseObjectRequest(submessage, &base); @@ -652,28 +861,32 @@ void read_submessage_data(uxrSession* session, ucdrBuffer* submessage, uint16_t read_submessage_format(session, submessage, length, format, stream_id, object_id, request_id); } -void read_submessage_heartbeat(uxrSession* session, ucdrBuffer* submessage) +void read_submessage_heartbeat( + uxrSession* session, + ucdrBuffer* submessage) { HEARTBEAT_Payload heartbeat; uxr_deserialize_HEARTBEAT_Payload(submessage, &heartbeat); uxrStreamId id = uxr_stream_id_from_raw(heartbeat.stream_id, UXR_INPUT_STREAM); uxrInputReliableStream* stream = uxr_get_input_reliable_stream(&session->streams, id.index); - if(stream) + if (stream) { uxr_process_heartbeat(stream, heartbeat.first_unacked_seq_nr, heartbeat.last_unacked_seq_nr); write_submessage_acknack(session, id); } } -void read_submessage_acknack(uxrSession* session, ucdrBuffer* submessage) +void read_submessage_acknack( + uxrSession* session, + ucdrBuffer* submessage) { ACKNACK_Payload acknack; uxr_deserialize_ACKNACK_Payload(submessage, &acknack); uxrStreamId id = uxr_stream_id_from_raw(acknack.stream_id, UXR_INPUT_STREAM); uxrOutputReliableStream* stream = uxr_get_output_reliable_stream(&session->streams, id.index); - if(stream) + if (stream) { uint16_t nack_bitmap = (uint16_t)(((uint16_t)acknack.nack_bitmap[0] << 8) + acknack.nack_bitmap[1]); uxr_process_acknack(stream, nack_bitmap, acknack.first_unacked_seq_num); @@ -687,7 +900,9 @@ void read_submessage_acknack(uxrSession* session, ucdrBuffer* submessage) } } -void read_submessage_timestamp_reply(uxrSession* session, ucdrBuffer* submessage) +void read_submessage_timestamp_reply( + uxrSession* session, + ucdrBuffer* submessage) { TIMESTAMP_REPLY_Payload timestamp_reply; uxr_deserialize_TIMESTAMP_REPLY_Payload(submessage, ×tamp_reply); @@ -696,24 +911,32 @@ void read_submessage_timestamp_reply(uxrSession* session, ucdrBuffer* submessage } #ifdef PERFORMANCE_TESTING -void read_submessage_performance(uxrSession* session, ucdrBuffer* submessage, uint16_t length) +void read_submessage_performance( + uxrSession* session, + ucdrBuffer* submessage, + uint16_t length) { ucdrBuffer mb_performance; ucdr_init_buffer(&mb_performance, submessage->iterator, length); session->on_performance(session, &mb_performance, session->on_performance_args); } -#endif -void process_status(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uint8_t status) +#endif /* ifdef PERFORMANCE_TESTING */ + +void process_status( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status) { - if(session->on_status != NULL) + if (session->on_status != NULL) { session->on_status(session, object_id, request_id, status, session->on_status_args); } - for(unsigned i = 0; i < session->request_status_list_size; ++i) + for (unsigned i = 0; i < session->request_status_list_size; ++i) { - if(request_id == session->request_list[i]) + if (request_id == session->request_list[i]) { session->status_list[i] = status; break; @@ -721,37 +944,46 @@ void process_status(uxrSession* session, uxrObjectId object_id, uint16_t request } } -void process_timestamp_reply(uxrSession* session, TIMESTAMP_REPLY_Payload* timestamp) +void process_timestamp_reply( + uxrSession* session, + TIMESTAMP_REPLY_Payload* timestamp) { - if(session->on_time != NULL) + if (session->on_time != NULL) { session->on_time(session, - uxr_nanos(), - uxr_convert_to_nanos(timestamp->receive_timestamp.seconds, timestamp->receive_timestamp.nanoseconds), - uxr_convert_to_nanos(timestamp->transmit_timestamp.seconds, timestamp->transmit_timestamp.nanoseconds), - uxr_convert_to_nanos(timestamp->originate_timestamp.seconds, timestamp->originate_timestamp.nanoseconds), - session->on_time_args); + uxr_nanos(), + uxr_convert_to_nanos(timestamp->receive_timestamp.seconds, timestamp->receive_timestamp.nanoseconds), + uxr_convert_to_nanos(timestamp->transmit_timestamp.seconds, timestamp->transmit_timestamp.nanoseconds), + uxr_convert_to_nanos(timestamp->originate_timestamp.seconds, + timestamp->originate_timestamp.nanoseconds), + session->on_time_args); } else { int64_t t3 = uxr_nanos(); int64_t t0 = uxr_convert_to_nanos(timestamp->originate_timestamp.seconds, - timestamp->originate_timestamp.nanoseconds); + timestamp->originate_timestamp.nanoseconds); int64_t t1 = uxr_convert_to_nanos(timestamp->receive_timestamp.seconds, - timestamp->receive_timestamp.nanoseconds); + timestamp->receive_timestamp.nanoseconds); int64_t t2 = uxr_convert_to_nanos(timestamp->transmit_timestamp.seconds, - timestamp->transmit_timestamp.nanoseconds); + timestamp->transmit_timestamp.nanoseconds); session->time_offset = ((t0 + t3) - (t1 + t2)) / 2; } session->synchronized = true; } -bool uxr_prepare_stream_to_write_submessage(uxrSession* session, uxrStreamId stream_id, size_t payload_size, ucdrBuffer* ub, uint8_t submessage_id, uint8_t mode) +bool uxr_prepare_stream_to_write_submessage( + uxrSession* session, + uxrStreamId stream_id, + size_t payload_size, + ucdrBuffer* ub, + uint8_t submessage_id, + uint8_t mode) { bool available = false; size_t submessage_size = SUBHEADER_SIZE + payload_size + uxr_submessage_padding(payload_size); - switch(stream_id.type) + switch (stream_id.type) { case UXR_BEST_EFFORT_STREAM: { @@ -769,7 +1001,7 @@ bool uxr_prepare_stream_to_write_submessage(uxrSession* session, uxrStreamId str break; } - if(available) + if (available) { (void) uxr_buffer_submessage_header(ub, submessage_id, (uint16_t)payload_size, mode); } @@ -777,7 +1009,8 @@ bool uxr_prepare_stream_to_write_submessage(uxrSession* session, uxrStreamId str return available; } -FragmentationInfo on_get_fragmentation_info(uint8_t* submessage_header) +FragmentationInfo on_get_fragmentation_info( + uint8_t* submessage_header) { ucdrBuffer ub; ucdr_init_buffer(&ub, submessage_header, SUBHEADER_SIZE); @@ -786,7 +1019,7 @@ FragmentationInfo on_get_fragmentation_info(uint8_t* submessage_header) uxr_read_submessage_header(&ub, &id, &length, &flags); FragmentationInfo fragmentation_info; - if(SUBMESSAGE_ID_FRAGMENT == id) + if (SUBMESSAGE_ID_FRAGMENT == id) { fragmentation_info = FLAG_LAST_FRAGMENT & flags ? LAST_FRAGMENT : INTERMEDIATE_FRAGMENT; } @@ -797,11 +1030,13 @@ FragmentationInfo on_get_fragmentation_info(uint8_t* submessage_header) return fragmentation_info; } -bool run_session_until_sync(uxrSession* session, int timeout) +bool run_session_until_sync( + uxrSession* session, + int timeout) { session->synchronized = false; bool timeout_exceeded = false; - while(!timeout_exceeded && !session->synchronized) + while (!timeout_exceeded && !session->synchronized) { timeout_exceeded = !listen_message_reliably(session, timeout); } diff --git a/src/c/core/session/session_info.c b/src/c/core/session/session_info.c index a962feff1..9c9b81095 100644 --- a/src/c/core/session/session_info.c +++ b/src/c/core/session/session_info.c @@ -12,15 +12,22 @@ #define RESERVED_REQUESTS_ID 9 -static uint16_t generate_request_id(uxrSessionInfo* info); +static uint16_t generate_request_id( + uxrSessionInfo* info); -static void process_delete_session_status(uxrSessionInfo* info, uint8_t status, uint16_t request_id); +static void process_delete_session_status( + uxrSessionInfo* info, + uint8_t status, + uint16_t request_id); //================================================================== // PUBLIC //================================================================== -void uxr_init_session_info(uxrSessionInfo* info, uint8_t id, uint32_t key) +void uxr_init_session_info( + uxrSessionInfo* info, + uint8_t id, + uint32_t key) { info->id = id; info->key[0] = (uint8_t)(key >> 24); @@ -31,7 +38,10 @@ void uxr_init_session_info(uxrSessionInfo* info, uint8_t id, uint32_t key) info->last_requested_status = UXR_STATUS_NONE; } -void uxr_buffer_create_session(uxrSessionInfo* info, ucdrBuffer* ub, uint16_t mtu) +void uxr_buffer_create_session( + uxrSessionInfo* info, + ucdrBuffer* ub, + uint16_t mtu) { CREATE_CLIENT_Payload payload; payload.client_representation.xrce_cookie = DDS_XRCE_XRCE_COOKIE; @@ -51,10 +61,16 @@ void uxr_buffer_create_session(uxrSessionInfo* info, ucdrBuffer* ub, uint16_t mt (void) uxr_serialize_CREATE_CLIENT_Payload(ub, &payload); } -void uxr_buffer_delete_session(uxrSessionInfo* info, ucdrBuffer* ub) +void uxr_buffer_delete_session( + uxrSessionInfo* info, + ucdrBuffer* ub) { DELETE_Payload payload; - payload.base.request_id = COMPOUND_LITERAL(RequestId){{0x00, UXR_REQUEST_LOGOUT}}; + payload.base.request_id = COMPOUND_LITERAL(RequestId){ + { + 0x00, UXR_REQUEST_LOGOUT + } + }; payload.base.object_id = DDS_XRCE_OBJECTID_CLIENT; info->last_request_id = UXR_REQUEST_LOGOUT; @@ -63,19 +79,23 @@ void uxr_buffer_delete_session(uxrSessionInfo* info, ucdrBuffer* ub) (void) uxr_serialize_DELETE_Payload(ub, &payload); } -void uxr_read_create_session_status(uxrSessionInfo* info, ucdrBuffer* ub) +void uxr_read_create_session_status( + uxrSessionInfo* info, + ucdrBuffer* ub) { STATUS_AGENT_Payload payload; (void) uxr_deserialize_STATUS_AGENT_Payload(ub, &payload); info->last_requested_status = payload.result.status; } -void uxr_read_delete_session_status(uxrSessionInfo* info, ucdrBuffer* ub) +void uxr_read_delete_session_status( + uxrSessionInfo* info, + ucdrBuffer* ub) { STATUS_Payload payload; (void) uxr_deserialize_STATUS_Payload(ub, &payload); - if(UXR_REQUEST_LOGOUT == info->last_request_id) + if (UXR_REQUEST_LOGOUT == info->last_request_id) { uxrObjectId object_id; uint16_t request_id; uxr_parse_base_object_request(&payload.base.related_request, &object_id, &request_id); @@ -83,7 +103,9 @@ void uxr_read_delete_session_status(uxrSessionInfo* info, ucdrBuffer* ub) } } -void uxr_stamp_create_session_header(const uxrSessionInfo* info, uint8_t* buffer) +void uxr_stamp_create_session_header( + const uxrSessionInfo* info, + uint8_t* buffer) { ucdrBuffer ub; ucdr_init_buffer(&ub, buffer, MAX_HEADER_SIZE); @@ -91,7 +113,11 @@ void uxr_stamp_create_session_header(const uxrSessionInfo* info, uint8_t* buffer uxr_serialize_message_header(&ub, info->id & SESSION_ID_WITHOUT_CLIENT_KEY, 0, 0, info->key); } -void uxr_stamp_session_header(const uxrSessionInfo* info, uint8_t stream_id_raw, uxrSeqNum seq_num, uint8_t* buffer) +void uxr_stamp_session_header( + const uxrSessionInfo* info, + uint8_t stream_id_raw, + uxrSeqNum seq_num, + uint8_t* buffer) { ucdrBuffer ub; ucdr_init_buffer(&ub, buffer, MAX_HEADER_SIZE); @@ -99,16 +125,20 @@ void uxr_stamp_session_header(const uxrSessionInfo* info, uint8_t stream_id_raw, uxr_serialize_message_header(&ub, info->id, stream_id_raw, seq_num, info->key); } -bool uxr_read_session_header(const uxrSessionInfo* info, ucdrBuffer* ub, uint8_t* stream_id_raw, uxrSeqNum* seq_num) +bool uxr_read_session_header( + const uxrSessionInfo* info, + ucdrBuffer* ub, + uint8_t* stream_id_raw, + uxrSeqNum* seq_num) { bool must_be_read = ucdr_buffer_remaining(ub) > MAX_HEADER_SIZE; - if(must_be_read) + if (must_be_read) { uint8_t session_id; uint8_t key[CLIENT_KEY_SIZE]; uxr_deserialize_message_header(ub, &session_id, stream_id_raw, seq_num, key); must_be_read = session_id == info->id; - if(must_be_read) + if (must_be_read) { if (SESSION_ID_WITHOUT_CLIENT_KEY > info->id) { @@ -120,12 +150,16 @@ bool uxr_read_session_header(const uxrSessionInfo* info, ucdrBuffer* ub, uint8_t return must_be_read; } -uint8_t uxr_session_header_offset(const uxrSessionInfo* info) +uint8_t uxr_session_header_offset( + const uxrSessionInfo* info) { return (SESSION_ID_WITHOUT_CLIENT_KEY > info->id) ? MAX_HEADER_SIZE : MIN_HEADER_SIZE; } -uint16_t uxr_init_base_object_request(uxrSessionInfo* info, uxrObjectId object_id, BaseObjectRequest* base) +uint16_t uxr_init_base_object_request( + uxrSessionInfo* info, + uxrObjectId object_id, + BaseObjectRequest* base) { uint16_t request_id = generate_request_id(info); @@ -136,17 +170,21 @@ uint16_t uxr_init_base_object_request(uxrSessionInfo* info, uxrObjectId object_i return request_id; } -void uxr_parse_base_object_request(const BaseObjectRequest* base, uxrObjectId* object_id, uint16_t* request_id) +void uxr_parse_base_object_request( + const BaseObjectRequest* base, + uxrObjectId* object_id, + uint16_t* request_id) { *object_id = uxr_object_id_from_raw(base->object_id.data); *request_id = (uint16_t)((((uint16_t) base->request_id.data[0]) << 8) - + base->request_id.data[1]); + + base->request_id.data[1]); } //================================================================== // PRIVATE //================================================================== -inline uint16_t generate_request_id(uxrSessionInfo* session) +inline uint16_t generate_request_id( + uxrSessionInfo* session) { bool out_of_bounds = (UINT16_MAX == session->last_request_id || RESERVED_REQUESTS_ID >= session->last_request_id); session->last_request_id = (uint16_t)((out_of_bounds ? RESERVED_REQUESTS_ID : session->last_request_id) + 1); @@ -154,11 +192,13 @@ inline uint16_t generate_request_id(uxrSessionInfo* session) return session->last_request_id; } -inline void process_delete_session_status(uxrSessionInfo* info, uint8_t status, uint16_t request_id) +inline void process_delete_session_status( + uxrSessionInfo* info, + uint8_t status, + uint16_t request_id) { - if(UXR_REQUEST_LOGOUT == request_id) + if (UXR_REQUEST_LOGOUT == request_id) { info->last_requested_status = status; } } - diff --git a/src/c/core/session/session_info_internal.h b/src/c/core/session/session_info_internal.h index 9bfdde880..1e1b01393 100644 --- a/src/c/core/session/session_info_internal.h +++ b/src/c/core/session/session_info_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include "../serialization/xrce_header_internal.h" @@ -32,25 +32,54 @@ extern "C" struct ucdrBuffer; struct BaseObjectRequest; -void uxr_init_session_info(uxrSessionInfo* info, uint8_t id, uint32_t key); +void uxr_init_session_info( + uxrSessionInfo* info, + uint8_t id, + uint32_t key); -void uxr_buffer_create_session(uxrSessionInfo* info, struct ucdrBuffer* ub, uint16_t mtu); -void uxr_buffer_delete_session(uxrSessionInfo* info, struct ucdrBuffer* ub); -void uxr_read_create_session_status(uxrSessionInfo* info, struct ucdrBuffer* ub); -void uxr_read_delete_session_status(uxrSessionInfo* info, struct ucdrBuffer* ub); +void uxr_buffer_create_session( + uxrSessionInfo* info, + struct ucdrBuffer* ub, + uint16_t mtu); +void uxr_buffer_delete_session( + uxrSessionInfo* info, + struct ucdrBuffer* ub); +void uxr_read_create_session_status( + uxrSessionInfo* info, + struct ucdrBuffer* ub); +void uxr_read_delete_session_status( + uxrSessionInfo* info, + struct ucdrBuffer* ub); -void uxr_stamp_create_session_header(const uxrSessionInfo* info, uint8_t* buffer); -void uxr_stamp_session_header(const uxrSessionInfo* info, uint8_t stream_id_raw, uxrSeqNum seq_num, uint8_t* buffer); -bool uxr_read_session_header(const uxrSessionInfo* info, struct ucdrBuffer* ub, uint8_t* stream_id_raw, uxrSeqNum* seq_num); +void uxr_stamp_create_session_header( + const uxrSessionInfo* info, + uint8_t* buffer); +void uxr_stamp_session_header( + const uxrSessionInfo* info, + uint8_t stream_id_raw, + uxrSeqNum seq_num, + uint8_t* buffer); +bool uxr_read_session_header( + const uxrSessionInfo* info, + struct ucdrBuffer* ub, + uint8_t* stream_id_raw, + uxrSeqNum* seq_num); -uint8_t uxr_session_header_offset(const uxrSessionInfo* info); +uint8_t uxr_session_header_offset( + const uxrSessionInfo* info); -uint16_t uxr_init_base_object_request(uxrSessionInfo* info, uxrObjectId object_id, struct BaseObjectRequest* base); -void uxr_parse_base_object_request(const struct BaseObjectRequest* base, uxrObjectId* object_id, uint16_t* request_id); +uint16_t uxr_init_base_object_request( + uxrSessionInfo* info, + uxrObjectId object_id, + struct BaseObjectRequest* base); +void uxr_parse_base_object_request( + const struct BaseObjectRequest* base, + uxrObjectId* object_id, + uint16_t* request_id); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_SESSION_INFO_INTERNAL_H_ diff --git a/src/c/core/session/session_internal.h b/src/c/core/session/session_internal.h index b88c04936..7b87fae56 100644 --- a/src/c/core/session/session_internal.h +++ b/src/c/core/session/session_internal.h @@ -18,22 +18,23 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include struct ucdrBuffer; -bool uxr_prepare_stream_to_write_submessage(uxrSession* session, - uxrStreamId stream_id, - size_t payload_size, - struct ucdrBuffer* ub, - uint8_t submessage_id, - uint8_t mode); +bool uxr_prepare_stream_to_write_submessage( + uxrSession* session, + uxrStreamId stream_id, + size_t payload_size, + struct ucdrBuffer* ub, + uint8_t submessage_id, + uint8_t mode); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_SESSION_INTERNAL_H_ diff --git a/src/c/core/session/stream/common_reliable_stream_internal.h b/src/c/core/session/stream/common_reliable_stream_internal.h index a10a460a4..bc0c96ae8 100644 --- a/src/c/core/session/stream/common_reliable_stream_internal.h +++ b/src/c/core/session/stream/common_reliable_stream_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -30,30 +30,30 @@ extern "C" typedef uint32_t length_t; #define INTERNAL_RELIABLE_BUFFER_OFFSET sizeof(length_t) -static inline uint8_t * uxr_get_reliable_buffer( - uxrReliableStream const * stream, +static inline uint8_t* uxr_get_reliable_buffer( + uxrReliableStream const* stream, uint16_t seq_num) { return stream->buffer - + ((seq_num % stream->history) * (stream->size / stream->history)) - + INTERNAL_RELIABLE_BUFFER_OFFSET; + + ((seq_num % stream->history) * (stream->size / stream->history)) + + INTERNAL_RELIABLE_BUFFER_OFFSET; } static inline size_t uxr_get_reliable_buffer_capacity( - uxrReliableStream const * stream) + uxrReliableStream const* stream) { return stream->size / stream->history - INTERNAL_RELIABLE_BUFFER_OFFSET; } static inline uint16_t uxr_get_reliable_buffer_history_position( - uxrReliableStream const * stream, - uint8_t const * current_position) + uxrReliableStream const* stream, + uint8_t const* current_position) { return (uint16_t)((size_t)(current_position - stream->buffer) / (stream->size / stream->history)); } static inline size_t uxr_get_reliable_buffer_size( - uxrReliableStream const * stream, + uxrReliableStream const* stream, uint16_t seq_num) { length_t length; @@ -65,7 +65,7 @@ static inline size_t uxr_get_reliable_buffer_size( } static inline void uxr_set_reliable_buffer_size( - uxrReliableStream const * stream, + uxrReliableStream const* stream, uint16_t seq_num, size_t length) { @@ -73,11 +73,11 @@ static inline void uxr_set_reliable_buffer_size( memcpy( uxr_get_reliable_buffer(stream, (seq_num % stream->history)) - INTERNAL_RELIABLE_BUFFER_OFFSET, &temp_length, - INTERNAL_RELIABLE_BUFFER_OFFSET); + INTERNAL_RELIABLE_BUFFER_OFFSET); } #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // SRC__C__CORE__SESSION__STREAM__COMMON_RELIABLE_STREAM_INTERNAL_H_ diff --git a/src/c/core/session/stream/input_best_effort_stream.c b/src/c/core/session/stream/input_best_effort_stream.c index 3d98087af..51bc57909 100644 --- a/src/c/core/session/stream/input_best_effort_stream.c +++ b/src/c/core/session/stream/input_best_effort_stream.c @@ -4,20 +4,24 @@ //================================================================== // PUBLIC //================================================================== -void uxr_init_input_best_effort_stream(uxrInputBestEffortStream* stream) +void uxr_init_input_best_effort_stream( + uxrInputBestEffortStream* stream) { stream->last_handled = SEQ_NUM_MAX; } -void uxr_reset_input_best_effort_stream(uxrInputBestEffortStream* stream) +void uxr_reset_input_best_effort_stream( + uxrInputBestEffortStream* stream) { stream->last_handled = SEQ_NUM_MAX; } -bool uxr_receive_best_effort_message(uxrInputBestEffortStream* stream, uxrSeqNum seq_num) +bool uxr_receive_best_effort_message( + uxrInputBestEffortStream* stream, + uxrSeqNum seq_num) { bool available_to_read = (0 > uxr_seq_num_cmp(stream->last_handled, seq_num)); - if(available_to_read) + if (available_to_read) { stream->last_handled = seq_num; } diff --git a/src/c/core/session/stream/input_best_effort_stream_internal.h b/src/c/core/session/stream/input_best_effort_stream_internal.h index b154cc9a3..2100d4eb9 100644 --- a/src/c/core/session/stream/input_best_effort_stream_internal.h +++ b/src/c/core/session/stream/input_best_effort_stream_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -26,12 +26,16 @@ extern "C" #include #include -void uxr_init_input_best_effort_stream(uxrInputBestEffortStream* stream); -void uxr_reset_input_best_effort_stream(uxrInputBestEffortStream* stream); -bool uxr_receive_best_effort_message(uxrInputBestEffortStream* stream, uxrSeqNum seq_num); +void uxr_init_input_best_effort_stream( + uxrInputBestEffortStream* stream); +void uxr_reset_input_best_effort_stream( + uxrInputBestEffortStream* stream); +bool uxr_receive_best_effort_message( + uxrInputBestEffortStream* stream, + uxrSeqNum seq_num); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_INPUT_STREAM_BEST_EFFORT_STREAM_INTERNAL_H_ diff --git a/src/c/core/session/stream/input_reliable_stream.c b/src/c/core/session/stream/input_reliable_stream.c index d90976f3c..e0d93bd4c 100644 --- a/src/c/core/session/stream/input_reliable_stream.c +++ b/src/c/core/session/stream/input_reliable_stream.c @@ -7,14 +7,24 @@ #include -static bool check_last_fragment(uxrInputReliableStream* stream, uxrSeqNum* last); -static uxrSeqNum uxr_get_first_unacked(const uxrInputReliableStream* stream); -static bool on_full_input_buffer(ucdrBuffer* ub, void* args); +static bool check_last_fragment( + uxrInputReliableStream* stream, + uxrSeqNum* last); +static uxrSeqNum uxr_get_first_unacked( + const uxrInputReliableStream* stream); +static bool on_full_input_buffer( + ucdrBuffer* ub, + void* args); //================================================================== // PUBLIC //================================================================== -void uxr_init_input_reliable_stream(uxrInputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info) +void uxr_init_input_reliable_stream( + uxrInputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + OnGetFragmentationInfo on_get_fragmentation_info) { // assert for history (must be 2^) stream->base.buffer = buffer; @@ -26,9 +36,10 @@ void uxr_init_input_reliable_stream(uxrInputReliableStream* stream, uint8_t* buf uxr_reset_input_reliable_stream(stream); } -void uxr_reset_input_reliable_stream(uxrInputReliableStream* stream) +void uxr_reset_input_reliable_stream( + uxrInputReliableStream* stream) { - for(uint16_t i = 0; i < stream->base.history; ++i) + for (uint16_t i = 0; i < stream->base.history; ++i) { uxr_set_reliable_buffer_size(&stream->base, i, 0); } @@ -37,19 +48,24 @@ void uxr_reset_input_reliable_stream(uxrInputReliableStream* stream) stream->last_announced = SEQ_NUM_MAX; } -bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_num, uint8_t* buffer, size_t length, bool* message_stored) +bool uxr_receive_reliable_message( + uxrInputReliableStream* stream, + uint16_t seq_num, + uint8_t* buffer, + size_t length, + bool* message_stored) { bool ready_to_read = false; /* Check if the seq_num is valid for the stream state */ uxrSeqNum last_history = uxr_seq_num_add(stream->last_handled, stream->base.history); - if(0 > uxr_seq_num_cmp(stream->last_handled, seq_num) && 0 <= uxr_seq_num_cmp(last_history, seq_num)) + if (0 > uxr_seq_num_cmp(stream->last_handled, seq_num) && 0 <= uxr_seq_num_cmp(last_history, seq_num)) { /* Process the message */ FragmentationInfo fragmentation_info = stream->on_get_fragmentation_info(buffer); uxrSeqNum next = uxr_seq_num_add(stream->last_handled, 1); - if((NO_FRAGMENTED == fragmentation_info) && (seq_num == next)) + if ((NO_FRAGMENTED == fragmentation_info) && (seq_num == next)) { stream->last_handled = next; ready_to_read = true; @@ -58,17 +74,17 @@ bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_n else { /* Check if the message received is not already received */ - uint8_t * internal_buffer = uxr_get_reliable_buffer(&stream->base, seq_num); - if(0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) + uint8_t* internal_buffer = uxr_get_reliable_buffer(&stream->base, seq_num); + if (0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) { memcpy(internal_buffer, buffer, length); uxr_set_reliable_buffer_size(&stream->base, seq_num, length); *message_stored = true; - if(NO_FRAGMENTED != fragmentation_info) + if (NO_FRAGMENTED != fragmentation_info) { uxrSeqNum last; - if(check_last_fragment(stream, &last)) + if (check_last_fragment(stream, &last)) { ready_to_read = true; } @@ -77,7 +93,7 @@ bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_n } } - if(0 > uxr_seq_num_cmp(stream->last_announced, seq_num)) + if (0 > uxr_seq_num_cmp(stream->last_announced, seq_num)) { stream->last_announced = seq_num; } @@ -85,16 +101,19 @@ bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_n return ready_to_read; } -bool uxr_next_input_reliable_buffer_available(uxrInputReliableStream* stream, ucdrBuffer* ub, size_t fragment_offset) +bool uxr_next_input_reliable_buffer_available( + uxrInputReliableStream* stream, + ucdrBuffer* ub, + size_t fragment_offset) { uxrSeqNum next = uxr_seq_num_add(stream->last_handled, 1); uint8_t* internal_buffer = uxr_get_reliable_buffer(&stream->base, next); size_t length = uxr_get_reliable_buffer_size(&stream->base, next); bool available_to_read = (0 != length); - if(available_to_read) + if (available_to_read) { FragmentationInfo fragmentation_info = stream->on_get_fragmentation_info(internal_buffer); - if(NO_FRAGMENTED == fragmentation_info) + if (NO_FRAGMENTED == fragmentation_info) { ucdr_init_buffer(ub, internal_buffer, (uint32_t)length); uxr_set_reliable_buffer_size(&stream->base, next, 0); @@ -104,7 +123,7 @@ bool uxr_next_input_reliable_buffer_available(uxrInputReliableStream* stream, uc { uxrSeqNum last; available_to_read = check_last_fragment(stream, &last); - if(available_to_read) + if (available_to_read) { uxr_set_reliable_buffer_size(&stream->base, next, 0); ucdr_init_buffer(ub, internal_buffer + fragment_offset, (uint32_t)(length - fragment_offset)); @@ -117,32 +136,38 @@ bool uxr_next_input_reliable_buffer_available(uxrInputReliableStream* stream, uc return available_to_read; } -void uxr_process_heartbeat(uxrInputReliableStream* stream, uxrSeqNum first_seq_num, uxrSeqNum last_seq_num) +void uxr_process_heartbeat( + uxrInputReliableStream* stream, + uxrSeqNum first_seq_num, + uxrSeqNum last_seq_num) { (void)first_seq_num; //TODO: Checks the first_seq_num to avoid hacks. - if(0 > uxr_seq_num_cmp(stream->last_announced, last_seq_num)) + if (0 > uxr_seq_num_cmp(stream->last_announced, last_seq_num)) { stream->last_announced = last_seq_num; } } -bool uxr_is_input_up_to_date(const uxrInputReliableStream* stream) +bool uxr_is_input_up_to_date( + const uxrInputReliableStream* stream) { return stream->last_announced == stream->last_handled; } -uint16_t uxr_compute_acknack(const uxrInputReliableStream* stream, uxrSeqNum* from) +uint16_t uxr_compute_acknack( + const uxrInputReliableStream* stream, + uxrSeqNum* from) { *from = uxr_get_first_unacked(stream); uint16_t buffers_to_ack = uxr_seq_num_sub(stream->last_announced, uxr_seq_num_sub(*from, 1)); uint16_t nack_bitmap = 0; - for(size_t i = 0; i < buffers_to_ack; ++i) + for (size_t i = 0; i < buffers_to_ack; ++i) { uxrSeqNum seq_num = uxr_seq_num_add(*from, (uxrSeqNum)i); - if(0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) + if (0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) { nack_bitmap = (uint16_t)(nack_bitmap | (1 << i)); } @@ -154,7 +179,9 @@ uint16_t uxr_compute_acknack(const uxrInputReliableStream* stream, uxrSeqNum* fr //================================================================== // PRIVATE //================================================================== -bool check_last_fragment(uxrInputReliableStream* stream, uxrSeqNum* last_fragment) +bool check_last_fragment( + uxrInputReliableStream* stream, + uxrSeqNum* last_fragment) { uxrSeqNum next = stream->last_handled; bool more_messages; @@ -164,30 +191,31 @@ bool check_last_fragment(uxrInputReliableStream* stream, uxrSeqNum* last_fragmen next = uxr_seq_num_add(next, 1); uint8_t* next_buffer = uxr_get_reliable_buffer(&stream->base, next); more_messages = (0 != uxr_get_reliable_buffer_size(&stream->base, next)); - if(more_messages) + if (more_messages) { FragmentationInfo next_fragmentation_info = stream->on_get_fragmentation_info(next_buffer); more_messages = INTERMEDIATE_FRAGMENT == next_fragmentation_info; - if(LAST_FRAGMENT == next_fragmentation_info) + if (LAST_FRAGMENT == next_fragmentation_info) { found = true; break; } } } - while(more_messages); + while (more_messages); *last_fragment = next; return found; } -uxrSeqNum uxr_get_first_unacked(const uxrInputReliableStream* stream) +uxrSeqNum uxr_get_first_unacked( + const uxrInputReliableStream* stream) { uxrSeqNum first_unknown = stream->last_handled; - for(size_t i = 0; i < stream->base.history; ++i) + for (size_t i = 0; i < stream->base.history; ++i) { uxrSeqNum seq_num = uxr_seq_num_add(stream->last_handled, (uint16_t)(i + 1)); - if(0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) + if (0 == uxr_get_reliable_buffer_size(&stream->base, seq_num)) { first_unknown = seq_num; break; @@ -197,12 +225,14 @@ uxrSeqNum uxr_get_first_unacked(const uxrInputReliableStream* stream) return first_unknown; } -bool on_full_input_buffer(ucdrBuffer* ub, void* args) +bool on_full_input_buffer( + ucdrBuffer* ub, + void* args) { uxrInputReliableStream* stream = (uxrInputReliableStream*) args; uint16_t history_position = (uint16_t)(1 + uxr_get_reliable_buffer_history_position(&stream->base, ub->init)); - uint8_t * buffer = uxr_get_reliable_buffer(&stream->base, history_position); + uint8_t* buffer = uxr_get_reliable_buffer(&stream->base, history_position); size_t buffer_size = uxr_get_reliable_buffer_size(&stream->base, history_position); if (stream->cleanup_flag) @@ -210,6 +240,12 @@ bool on_full_input_buffer(ucdrBuffer* ub, void* args) uxr_set_reliable_buffer_size(&stream->base, history_position, 0); } + // IMPORTANT: This situation only happens when stream->base.history is not power of two. + if (buffer_size < SUBHEADER_SIZE) + { + return true; + } + ucdr_init_buffer_origin( ub, buffer + SUBHEADER_SIZE, @@ -219,4 +255,3 @@ bool on_full_input_buffer(ucdrBuffer* ub, void* args) return false; } - diff --git a/src/c/core/session/stream/input_reliable_stream_internal.h b/src/c/core/session/stream/input_reliable_stream_internal.h index 5c88d8b4c..8481e2f4f 100644 --- a/src/c/core/session/stream/input_reliable_stream_internal.h +++ b/src/c/core/session/stream/input_reliable_stream_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -30,18 +30,38 @@ extern "C" struct ucdrBuffer; -void uxr_init_input_reliable_stream(uxrInputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info); -void uxr_reset_input_reliable_stream(uxrInputReliableStream* stream); -bool uxr_receive_reliable_message(uxrInputReliableStream* stream, uint16_t seq_num, uint8_t* buffer, size_t length, bool* message_stored); -bool uxr_next_input_reliable_buffer_available(uxrInputReliableStream* stream, struct ucdrBuffer* ub, size_t fragment_offset); +void uxr_init_input_reliable_stream( + uxrInputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + OnGetFragmentationInfo on_get_fragmentation_info); +void uxr_reset_input_reliable_stream( + uxrInputReliableStream* stream); +bool uxr_receive_reliable_message( + uxrInputReliableStream* stream, + uint16_t seq_num, + uint8_t* buffer, + size_t length, + bool* message_stored); +bool uxr_next_input_reliable_buffer_available( + uxrInputReliableStream* stream, + struct ucdrBuffer* ub, + size_t fragment_offset); -uint16_t uxr_compute_acknack(const uxrInputReliableStream* stream, uxrSeqNum* from); -void uxr_process_heartbeat(uxrInputReliableStream* stream, uxrSeqNum first_seq_num, uxrSeqNum last_seq_num); +uint16_t uxr_compute_acknack( + const uxrInputReliableStream* stream, + uxrSeqNum* from); +void uxr_process_heartbeat( + uxrInputReliableStream* stream, + uxrSeqNum first_seq_num, + uxrSeqNum last_seq_num); -bool uxr_is_input_up_to_date(const uxrInputReliableStream* stream); +bool uxr_is_input_up_to_date( + const uxrInputReliableStream* stream); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_INPUT_STREAM_RELIABLE_STREAM_INTERNAL_H_ diff --git a/src/c/core/session/stream/output_best_effort_stream.c b/src/c/core/session/stream/output_best_effort_stream.c index f28d0cb48..3357732a9 100644 --- a/src/c/core/session/stream/output_best_effort_stream.c +++ b/src/c/core/session/stream/output_best_effort_stream.c @@ -8,7 +8,11 @@ //================================================================== // PUBLIC //================================================================== -void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8_t* buffer, size_t size, uint8_t offset) +void uxr_init_output_best_effort_stream( + uxrOutputBestEffortStream* stream, + uint8_t* buffer, + size_t size, + uint8_t offset) { stream->buffer = buffer; stream->offset = offset; @@ -17,31 +21,40 @@ void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8 uxr_reset_output_best_effort_stream(stream); } -void uxr_reset_output_best_effort_stream(uxrOutputBestEffortStream* stream) +void uxr_reset_output_best_effort_stream( + uxrOutputBestEffortStream* stream) { stream->writer = stream->offset; stream->last_send = SEQ_NUM_MAX; } -bool uxr_prepare_best_effort_buffer_to_write(uxrOutputBestEffortStream* stream, size_t size, ucdrBuffer* ub) +bool uxr_prepare_best_effort_buffer_to_write( + uxrOutputBestEffortStream* stream, + size_t size, + ucdrBuffer* ub) { size_t current_padding = uxr_submessage_padding(stream->writer); size_t future_length = stream->writer + current_padding + size; bool available_to_write = future_length <= stream->size; - if(available_to_write) + if (available_to_write) { - ucdr_init_buffer_origin_offset(ub, stream->buffer, (uint32_t)future_length, 0u, (uint32_t)(stream->writer + current_padding)); + ucdr_init_buffer_origin_offset(ub, stream->buffer, (uint32_t)future_length, 0u, + (uint32_t)(stream->writer + current_padding)); stream->writer += size; } return available_to_write; } -bool uxr_prepare_best_effort_buffer_to_send(uxrOutputBestEffortStream* stream, uint8_t** buffer, size_t* length, uint16_t* seq_num) +bool uxr_prepare_best_effort_buffer_to_send( + uxrOutputBestEffortStream* stream, + uint8_t** buffer, + size_t* length, + uint16_t* seq_num) { bool data_to_send = stream->writer > stream->offset; - if(data_to_send) + if (data_to_send) { stream->last_send = uxr_seq_num_add(stream->last_send, 1); @@ -54,4 +67,3 @@ bool uxr_prepare_best_effort_buffer_to_send(uxrOutputBestEffortStream* stream, u return data_to_send; } - diff --git a/src/c/core/session/stream/output_best_effort_stream_internal.h b/src/c/core/session/stream/output_best_effort_stream_internal.h index 0300b4efd..7eae541c3 100644 --- a/src/c/core/session/stream/output_best_effort_stream_internal.h +++ b/src/c/core/session/stream/output_best_effort_stream_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -26,13 +26,25 @@ extern "C" #include #include -void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8_t* buffer, size_t size, uint8_t offset); -void uxr_reset_output_best_effort_stream(uxrOutputBestEffortStream* stream); -bool uxr_prepare_best_effort_buffer_to_write(uxrOutputBestEffortStream* stream, size_t size, struct ucdrBuffer* ub); -bool uxr_prepare_best_effort_buffer_to_send(uxrOutputBestEffortStream* stream, uint8_t** buffer, size_t* length, uint16_t* seq_num); +void uxr_init_output_best_effort_stream( + uxrOutputBestEffortStream* stream, + uint8_t* buffer, + size_t size, + uint8_t offset); +void uxr_reset_output_best_effort_stream( + uxrOutputBestEffortStream* stream); +bool uxr_prepare_best_effort_buffer_to_write( + uxrOutputBestEffortStream* stream, + size_t size, + struct ucdrBuffer* ub); +bool uxr_prepare_best_effort_buffer_to_send( + uxrOutputBestEffortStream* stream, + uint8_t** buffer, + size_t* length, + uint16_t* seq_num); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_STREAM_OUTPUT_BEST_EFFORT_STREAM_INTERNAL_H_ diff --git a/src/c/core/session/stream/output_reliable_stream.c b/src/c/core/session/stream/output_reliable_stream.c index 6894bce99..fe8d2c8fa 100644 --- a/src/c/core/session/stream/output_reliable_stream.c +++ b/src/c/core/session/stream/output_reliable_stream.c @@ -12,12 +12,15 @@ #define MIN_HEARTBEAT_TIME_INTERVAL ((int64_t) UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL) // ms #define MAX_HEARTBEAT_TRIES (sizeof(int64_t) * 8 - 1) -static bool on_full_output_buffer(ucdrBuffer* ub, void* args); - //================================================================== // PUBLIC //================================================================== -void uxr_init_output_reliable_stream(uxrOutputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset) +void uxr_init_output_reliable_stream( + uxrOutputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + uint8_t header_offset) { // assert for history (must be 2^) @@ -29,9 +32,10 @@ void uxr_init_output_reliable_stream(uxrOutputReliableStream* stream, uint8_t* b uxr_reset_output_reliable_stream(stream); } -void uxr_reset_output_reliable_stream(uxrOutputReliableStream* stream) +void uxr_reset_output_reliable_stream( + uxrOutputReliableStream* stream) { - for(uint16_t i = 0; i < stream->base.history; ++i) + for (uint16_t i = 0; i < stream->base.history; ++i) { uxr_set_reliable_buffer_size(&stream->base, i, stream->offset); } @@ -45,21 +49,24 @@ void uxr_reset_output_reliable_stream(uxrOutputReliableStream* stream) stream->send_lost = false; } -bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_t length, ucdrBuffer* ub) +bool uxr_prepare_reliable_buffer_to_write( + uxrOutputReliableStream* stream, + size_t length, + ucdrBuffer* ub) { bool available_to_write = false; uxrSeqNum seq_num = stream->last_written; size_t buffer_capacity = uxr_get_reliable_buffer_capacity(&stream->base); - uint8_t * buffer = uxr_get_reliable_buffer(&stream->base, seq_num); + uint8_t* buffer = uxr_get_reliable_buffer(&stream->base, seq_num); size_t buffer_size = uxr_get_reliable_buffer_size(&stream->base, seq_num); /* Check if the message fit in the current buffer */ - if(buffer_size + length <= buffer_capacity) + if (buffer_size + length <= buffer_capacity) { /* Check if there is space in the stream history to write */ uxrSeqNum last_available = uxr_seq_num_add(stream->last_acknown, stream->base.history); available_to_write = (0 >= uxr_seq_num_cmp(seq_num, last_available)); - if(available_to_write) + if (available_to_write) { size_t final_buffer_size = buffer_size + length; uxr_set_reliable_buffer_size(&stream->base, seq_num, final_buffer_size); @@ -67,13 +74,13 @@ bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_ } } /* Check if the message fit in a new empty buffer */ - else if(stream->offset + length <= buffer_capacity) + else if (stream->offset + length <= buffer_capacity) { /* Check if there is space in the stream history to write */ seq_num = uxr_seq_num_add(stream->last_written, 1); uxrSeqNum last_available = uxr_seq_num_add(stream->last_acknown, stream->base.history); available_to_write = (0 >= uxr_seq_num_cmp(seq_num, last_available)); - if(available_to_write) + if (available_to_write) { buffer = uxr_get_reliable_buffer(&stream->base, seq_num); size_t final_buffer_size = stream->offset + length; @@ -85,38 +92,38 @@ bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_ /* Check if the message fit in a fragmented message */ else { - size_t remaining_blocks = uxr_seq_num_sub(stream->last_acknown, seq_num) % stream->base.history; - /* Check if the current buffer free space is too small */ - if(buffer_size + (size_t)SUBHEADER_SIZE >= buffer_capacity) + if (buffer_size + (size_t)SUBHEADER_SIZE >= buffer_capacity) { seq_num = uxr_seq_num_add(seq_num, 1); buffer = uxr_get_reliable_buffer(&stream->base, seq_num); buffer_size = uxr_get_reliable_buffer_size(&stream->base, seq_num); - remaining_blocks = (0 < remaining_blocks) ? remaining_blocks - 1 : 0; } + size_t remaining_blocks = get_available_free_slots(stream); + uint16_t available_block_size = (uint16_t)(buffer_capacity - (uint16_t)(stream->offset + SUBHEADER_SIZE)); uint16_t first_fragment_size = (uint16_t)(buffer_capacity - (uint16_t)(buffer_size + SUBHEADER_SIZE)); uint16_t remaining_size = (uint16_t)(length - first_fragment_size); uint16_t last_fragment_size; - uint16_t necessary_blocks; + uint16_t necessary_complete_blocks; if (0 == (remaining_size % available_block_size)) { last_fragment_size = available_block_size; - necessary_blocks = (uint16_t)((0 < first_fragment_size) + (remaining_size / available_block_size)); + necessary_complete_blocks = (uint16_t)((remaining_size / available_block_size)); } else { last_fragment_size = remaining_size % available_block_size; - necessary_blocks = (uint16_t)((0 < first_fragment_size) + (remaining_size / available_block_size) + 1); + necessary_complete_blocks = (uint16_t)((remaining_size / available_block_size) + 1); } - available_to_write = necessary_blocks <= remaining_blocks; - if(available_to_write) + available_to_write = necessary_complete_blocks <= remaining_blocks; + if (available_to_write) { ucdrBuffer temp_ub; - for(uint16_t i = 0; i < necessary_blocks - 1; i++) + uint16_t fragment_size = first_fragment_size; + for (uint16_t i = 0; i < necessary_complete_blocks; i++) { ucdr_init_buffer_origin_offset( &temp_ub, @@ -124,9 +131,10 @@ bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_ buffer_capacity, 0u, uxr_get_reliable_buffer_size(&stream->base, seq_num)); - uxr_buffer_submessage_header(&temp_ub, SUBMESSAGE_ID_FRAGMENT, available_block_size, 0); + uxr_buffer_submessage_header(&temp_ub, SUBMESSAGE_ID_FRAGMENT, fragment_size, 0); uxr_set_reliable_buffer_size(&stream->base, seq_num, buffer_capacity); seq_num = uxr_seq_num_add(seq_num, 1); + fragment_size = available_block_size; } ucdr_init_buffer_origin_offset( @@ -136,7 +144,8 @@ bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_ 0u, uxr_get_reliable_buffer_size(&stream->base, seq_num)); uxr_buffer_submessage_header(&temp_ub, SUBMESSAGE_ID_FRAGMENT, last_fragment_size, FLAG_LAST_FRAGMENT); - uxr_set_reliable_buffer_size(&stream->base, seq_num, stream->offset + (size_t)(SUBHEADER_SIZE) + last_fragment_size); + uxr_set_reliable_buffer_size(&stream->base, seq_num, + stream->offset + (size_t)(SUBHEADER_SIZE) + last_fragment_size); ucdr_init_buffer( ub, @@ -150,19 +159,23 @@ bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_ return available_to_write; } -bool uxr_prepare_next_reliable_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t* length, uxrSeqNum* seq_num) +bool uxr_prepare_next_reliable_buffer_to_send( + uxrOutputReliableStream* stream, + uint8_t** buffer, + size_t* length, + uxrSeqNum* seq_num) { *seq_num = uxr_seq_num_add(stream->last_sent, 1); *buffer = uxr_get_reliable_buffer(&stream->base, *seq_num); *length = uxr_get_reliable_buffer_size(&stream->base, *seq_num); bool data_to_send = 0 >= uxr_seq_num_cmp(*seq_num, stream->last_written) - && *length > stream->offset - && uxr_seq_num_sub(stream->last_sent, stream->last_acknown) != stream->base.history; - if(data_to_send) + && *length > stream->offset + && uxr_seq_num_sub(stream->last_sent, stream->last_acknown) != stream->base.history; + if (data_to_send) { stream->last_sent = *seq_num; - if(stream->last_sent == stream->last_written) + if (stream->last_sent == stream->last_written) { stream->last_written = uxr_seq_num_add(stream->last_written, 1); } @@ -171,17 +184,19 @@ bool uxr_prepare_next_reliable_buffer_to_send(uxrOutputReliableStream* stream, u return data_to_send; } -bool uxr_update_output_stream_heartbeat_timestamp(uxrOutputReliableStream* stream, int64_t current_timestamp) +bool uxr_update_output_stream_heartbeat_timestamp( + uxrOutputReliableStream* stream, + int64_t current_timestamp) { bool must_confirm = false; - if(0 > uxr_seq_num_cmp(stream->last_acknown, stream->last_sent)) + if (0 > uxr_seq_num_cmp(stream->last_acknown, stream->last_sent)) { - if(0 == stream->next_heartbeat_tries) + if (0 == stream->next_heartbeat_tries) { stream->next_heartbeat_timestamp = current_timestamp + MIN_HEARTBEAT_TIME_INTERVAL; stream->next_heartbeat_tries = 1; } - else if(current_timestamp >= stream->next_heartbeat_timestamp) + else if (current_timestamp >= stream->next_heartbeat_timestamp) { int64_t increment = MIN_HEARTBEAT_TIME_INTERVAL << (stream->next_heartbeat_tries % MAX_HEARTBEAT_TRIES); int64_t difference = current_timestamp - stream->next_heartbeat_timestamp; @@ -198,22 +213,27 @@ bool uxr_update_output_stream_heartbeat_timestamp(uxrOutputReliableStream* strea return must_confirm; } -uxrSeqNum uxr_begin_output_nack_buffer_it(const uxrOutputReliableStream* stream) +uxrSeqNum uxr_begin_output_nack_buffer_it( + const uxrOutputReliableStream* stream) { return stream->last_acknown; } -bool uxr_next_reliable_nack_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t *length, uxrSeqNum* seq_num_it) +bool uxr_next_reliable_nack_buffer_to_send( + uxrOutputReliableStream* stream, + uint8_t** buffer, + size_t* length, + uxrSeqNum* seq_num_it) { bool it_updated = false; - if(stream->send_lost) + if (stream->send_lost) { bool check_next_buffer = true; - while(check_next_buffer && !it_updated) + while (check_next_buffer && !it_updated) { *seq_num_it = uxr_seq_num_add(*seq_num_it, 1); check_next_buffer = 0 >= uxr_seq_num_cmp(*seq_num_it, stream->last_sent); - if(check_next_buffer) + if (check_next_buffer) { *buffer = uxr_get_reliable_buffer(&stream->base, *seq_num_it); *length = uxr_get_reliable_buffer_size(&stream->base, *seq_num_it); @@ -221,7 +241,7 @@ bool uxr_next_reliable_nack_buffer_to_send(uxrOutputReliableStream* stream, uint } } - if(!it_updated) + if (!it_updated) { stream->send_lost = false; } @@ -230,11 +250,14 @@ bool uxr_next_reliable_nack_buffer_to_send(uxrOutputReliableStream* stream, uint return it_updated; } -void uxr_process_acknack(uxrOutputReliableStream* stream, uint16_t bitmap, uxrSeqNum first_unacked_seq_num) +void uxr_process_acknack( + uxrOutputReliableStream* stream, + uint16_t bitmap, + uxrSeqNum first_unacked_seq_num) { uxrSeqNum last_acked_seq_num = uxr_seq_num_sub(first_unacked_seq_num, 1); size_t buffers_to_clean = uxr_seq_num_sub(last_acked_seq_num, stream->last_acknown); - for(size_t i = 0; i < buffers_to_clean; i++) + for (size_t i = 0; i < buffers_to_clean; i++) { stream->last_acknown = uxr_seq_num_add(stream->last_acknown, 1); uxr_set_reliable_buffer_size(&stream->base, stream->last_acknown, stream->offset); @@ -246,7 +269,8 @@ void uxr_process_acknack(uxrOutputReliableStream* stream, uint16_t bitmap, uxrSe stream->next_heartbeat_tries = 0; } -bool uxr_is_output_up_to_date(const uxrOutputReliableStream* stream) +bool uxr_is_output_up_to_date( + const uxrOutputReliableStream* stream) { return 0 == uxr_seq_num_cmp(stream->last_acknown, stream->last_sent); } @@ -254,7 +278,9 @@ bool uxr_is_output_up_to_date(const uxrOutputReliableStream* stream) //================================================================== // PRIVATE //================================================================== -bool on_full_output_buffer(ucdrBuffer* ub, void* args) +bool on_full_output_buffer( + ucdrBuffer* ub, + void* args) { uxrOutputReliableStream* stream = (uxrOutputReliableStream*) args; @@ -272,3 +298,16 @@ bool on_full_output_buffer(ucdrBuffer* ub, void* args) return false; } +uint16_t get_available_free_slots( + uxrOutputReliableStream* stream) +{ + uint16_t free_slots = 0; + for (uint16_t i = 0; i < stream->base.history; i++) + { + if (uxr_get_reliable_buffer_size(&stream->base, i) == stream->offset) + { + free_slots++; + } + } + return free_slots; +} diff --git a/src/c/core/session/stream/output_reliable_stream_internal.h b/src/c/core/session/stream/output_reliable_stream_internal.h index 31eace835..744b02f3d 100644 --- a/src/c/core/session/stream/output_reliable_stream_internal.h +++ b/src/c/core/session/stream/output_reliable_stream_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -28,20 +28,50 @@ extern "C" #define HEARTBEAT_PAYLOAD_SIZE 5 -void uxr_init_output_reliable_stream(uxrOutputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset); -void uxr_reset_output_reliable_stream(uxrOutputReliableStream* stream); -bool uxr_prepare_reliable_buffer_to_write(uxrOutputReliableStream* stream, size_t size, struct ucdrBuffer* ub); -bool uxr_prepare_next_reliable_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t* length, uxrSeqNum* seq_num); +void uxr_init_output_reliable_stream( + uxrOutputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + uint8_t header_offset); +void uxr_reset_output_reliable_stream( + uxrOutputReliableStream* stream); +bool uxr_prepare_reliable_buffer_to_write( + uxrOutputReliableStream* stream, + size_t size, + struct ucdrBuffer* ub); +bool uxr_prepare_next_reliable_buffer_to_send( + uxrOutputReliableStream* stream, + uint8_t** buffer, + size_t* length, + uxrSeqNum* seq_num); -bool uxr_update_output_stream_heartbeat_timestamp(uxrOutputReliableStream* stream, int64_t current_timestamp); -uxrSeqNum uxr_begin_output_nack_buffer_it(const uxrOutputReliableStream* stream); -bool uxr_next_reliable_nack_buffer_to_send(uxrOutputReliableStream* stream, uint8_t** buffer, size_t *length, uxrSeqNum* seq_num_it); -void uxr_process_acknack(uxrOutputReliableStream* stream, uint16_t bitmap, uxrSeqNum first_unacked_seq_num); +bool uxr_update_output_stream_heartbeat_timestamp( + uxrOutputReliableStream* stream, + int64_t current_timestamp); +uxrSeqNum uxr_begin_output_nack_buffer_it( + const uxrOutputReliableStream* stream); +bool uxr_next_reliable_nack_buffer_to_send( + uxrOutputReliableStream* stream, + uint8_t** buffer, + size_t* length, + uxrSeqNum* seq_num_it); +void uxr_process_acknack( + uxrOutputReliableStream* stream, + uint16_t bitmap, + uxrSeqNum first_unacked_seq_num); -bool uxr_is_output_up_to_date(const uxrOutputReliableStream* stream); +bool uxr_is_output_up_to_date( + const uxrOutputReliableStream* stream); +bool on_full_output_buffer( + struct ucdrBuffer* ub, + void* args); + +uint16_t get_available_free_slots( + uxrOutputReliableStream* stream); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_STREAM_OUTPUT_RELIABLE_STREAM_INTERNAL_H_ diff --git a/src/c/core/session/stream/seq_num.c b/src/c/core/session/stream/seq_num.c index 834e6f2f3..39ac8f537 100644 --- a/src/c/core/session/stream/seq_num.c +++ b/src/c/core/session/stream/seq_num.c @@ -7,26 +7,32 @@ //================================================================== // PUBLIC //================================================================== -uxrSeqNum uxr_seq_num_add(uxrSeqNum seq_num, uint16_t increment) +uxrSeqNum uxr_seq_num_add( + uxrSeqNum seq_num, + uint16_t increment) { return (uxrSeqNum)((seq_num + increment) % SEQ_NUM_SIZE); } -uxrSeqNum uxr_seq_num_sub(uxrSeqNum seq_num, uint16_t decrement) +uxrSeqNum uxr_seq_num_sub( + uxrSeqNum seq_num, + uint16_t decrement) { return (uxrSeqNum)((decrement > seq_num) ? seq_num + (SEQ_NUM_SIZE - decrement) : seq_num - decrement); } -int uxr_seq_num_cmp(uxrSeqNum seq_num_1, uxrSeqNum seq_num_2) +int uxr_seq_num_cmp( + uxrSeqNum seq_num_1, + uxrSeqNum seq_num_2) { int result; - if(seq_num_1 == seq_num_2) + if (seq_num_1 == seq_num_2) { result = 0; } - else if((seq_num_1 < seq_num_2 && (seq_num_2 - seq_num_1) < SEQ_NUM_MIDSIZE) || + else if ((seq_num_1 < seq_num_2 && (seq_num_2 - seq_num_1) < SEQ_NUM_MIDSIZE) || (seq_num_1 > seq_num_2 && (seq_num_1 - seq_num_2) > SEQ_NUM_MIDSIZE)) { result = -1; diff --git a/src/c/core/session/stream/seq_num_internal.h b/src/c/core/session/stream/seq_num_internal.h index 83cc479e2..6c263925d 100644 --- a/src/c/core/session/stream/seq_num_internal.h +++ b/src/c/core/session/stream/seq_num_internal.h @@ -18,19 +18,25 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #define SEQ_NUM_MAX UINT16_MAX -uxrSeqNum uxr_seq_num_add(uxrSeqNum seq_num, uint16_t increment); -uxrSeqNum uxr_seq_num_sub(uxrSeqNum seq_num, uint16_t decrement); -int uxr_seq_num_cmp(uxrSeqNum seq_num_1, uxrSeqNum seq_num_2); +uxrSeqNum uxr_seq_num_add( + uxrSeqNum seq_num, + uint16_t increment); +uxrSeqNum uxr_seq_num_sub( + uxrSeqNum seq_num, + uint16_t decrement); +int uxr_seq_num_cmp( + uxrSeqNum seq_num_1, + uxrSeqNum seq_num_2); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_STREAM_SEQ_NUM_INTERNAL_H_ diff --git a/src/c/core/session/stream/stream_id.c b/src/c/core/session/stream/stream_id.c index 27a15867b..7c4d24668 100644 --- a/src/c/core/session/stream/stream_id.c +++ b/src/c/core/session/stream/stream_id.c @@ -8,14 +8,17 @@ //================================================================== // PUBLIC //================================================================== -uxrStreamId uxr_stream_id(uint8_t index, uxrStreamType type, uxrStreamDirection direction) +uxrStreamId uxr_stream_id( + uint8_t index, + uxrStreamType type, + uxrStreamDirection direction) { uxrStreamId stream_id; stream_id.direction = (uint8_t)direction; stream_id.index = index; stream_id.type = (uint8_t)type; - switch(type) + switch (type) { case UXR_NONE_STREAM: stream_id.raw = 0; @@ -31,18 +34,20 @@ uxrStreamId uxr_stream_id(uint8_t index, uxrStreamType type, uxrStreamDirection return stream_id; } -uxrStreamId uxr_stream_id_from_raw(uint8_t stream_id_raw, uxrStreamDirection direction) +uxrStreamId uxr_stream_id_from_raw( + uint8_t stream_id_raw, + uxrStreamDirection direction) { uxrStreamId stream_id; stream_id.raw = stream_id_raw; stream_id.direction = (uint8_t)direction; - if(BEST_EFFORT_STREAM_THRESHOLD > stream_id_raw) + if (BEST_EFFORT_STREAM_THRESHOLD > stream_id_raw) { stream_id.index = stream_id_raw; stream_id.type = UXR_NONE_STREAM; } - else if(RELIABLE_STREAM_THRESHOLD > stream_id_raw) + else if (RELIABLE_STREAM_THRESHOLD > stream_id_raw) { stream_id.index = (uint8_t)(stream_id_raw - BEST_EFFORT_STREAM_THRESHOLD); stream_id.type = UXR_BEST_EFFORT_STREAM; diff --git a/src/c/core/session/stream/stream_storage.c b/src/c/core/session/stream/stream_storage.c index 8cae56906..9e1e5251a 100644 --- a/src/c/core/session/stream/stream_storage.c +++ b/src/c/core/session/stream/stream_storage.c @@ -7,7 +7,8 @@ //================================================================== // PUBLIC //================================================================== -void uxr_init_stream_storage(uxrStreamStorage* storage) +void uxr_init_stream_storage( + uxrStreamStorage* storage) { storage->output_best_effort_size = 0; storage->output_reliable_size = 0; @@ -15,30 +16,35 @@ void uxr_init_stream_storage(uxrStreamStorage* storage) storage->input_reliable_size = 0; } -void uxr_reset_stream_storage(uxrStreamStorage* storage) +void uxr_reset_stream_storage( + uxrStreamStorage* storage) { - for(unsigned i = 0; i < storage->output_best_effort_size; ++i) + for (unsigned i = 0; i < storage->output_best_effort_size; ++i) { uxr_reset_output_best_effort_stream(&storage->output_best_effort[i]); } - for(unsigned i = 0; i < storage->input_best_effort_size; ++i) + for (unsigned i = 0; i < storage->input_best_effort_size; ++i) { uxr_reset_input_best_effort_stream(&storage->input_best_effort[i]); } - for(unsigned i = 0; i < storage->output_reliable_size; ++i) + for (unsigned i = 0; i < storage->output_reliable_size; ++i) { uxr_reset_output_reliable_stream(&storage->output_reliable[i]); } - for(unsigned i = 0; i < storage->input_reliable_size; ++i) + for (unsigned i = 0; i < storage->input_reliable_size; ++i) { uxr_reset_input_reliable_stream(&storage->input_reliable[i]); } } -uxrStreamId uxr_add_output_best_effort_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint8_t header_offset) +uxrStreamId uxr_add_output_best_effort_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint8_t header_offset) { uint8_t index = storage->output_best_effort_size++; //TODO: assert for index @@ -47,7 +53,12 @@ uxrStreamId uxr_add_output_best_effort_buffer(uxrStreamStorage* storage, uint8_t return uxr_stream_id(index, UXR_BEST_EFFORT_STREAM, UXR_OUTPUT_STREAM); } -uxrStreamId uxr_add_output_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset) +uxrStreamId uxr_add_output_reliable_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint16_t history, + uint8_t header_offset) { uint8_t index = storage->output_reliable_size++; //TODO: assert for index @@ -56,7 +67,8 @@ uxrStreamId uxr_add_output_reliable_buffer(uxrStreamStorage* storage, uint8_t* b return uxr_stream_id(index, UXR_RELIABLE_STREAM, UXR_OUTPUT_STREAM); } -uxrStreamId uxr_add_input_best_effort_buffer(uxrStreamStorage* storage) +uxrStreamId uxr_add_input_best_effort_buffer( + uxrStreamStorage* storage) { uint8_t index = storage->input_best_effort_size++; //TODO: assert for index @@ -65,7 +77,12 @@ uxrStreamId uxr_add_input_best_effort_buffer(uxrStreamStorage* storage) return uxr_stream_id(index, UXR_BEST_EFFORT_STREAM, UXR_INPUT_STREAM); } -uxrStreamId uxr_add_input_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info) +uxrStreamId uxr_add_input_reliable_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint16_t history, + OnGetFragmentationInfo on_get_fragmentation_info) { uint8_t index = storage->input_reliable_size++; //TODO: assert for index @@ -74,46 +91,55 @@ uxrStreamId uxr_add_input_reliable_buffer(uxrStreamStorage* storage, uint8_t* bu return uxr_stream_id(index, UXR_RELIABLE_STREAM, UXR_INPUT_STREAM); } -uxrOutputBestEffortStream* uxr_get_output_best_effort_stream(uxrStreamStorage* storage, uint8_t index) +uxrOutputBestEffortStream* uxr_get_output_best_effort_stream( + uxrStreamStorage* storage, + uint8_t index) { - if(index < storage->output_best_effort_size) + if (index < storage->output_best_effort_size) { return &storage->output_best_effort[index]; } return NULL; } -uxrOutputReliableStream* uxr_get_output_reliable_stream(uxrStreamStorage* storage, uint8_t index) +uxrOutputReliableStream* uxr_get_output_reliable_stream( + uxrStreamStorage* storage, + uint8_t index) { - if(index < storage->output_reliable_size) + if (index < storage->output_reliable_size) { return &storage->output_reliable[index]; } return NULL; } -uxrInputBestEffortStream* uxr_get_input_best_effort_stream(uxrStreamStorage* storage, uint8_t index) +uxrInputBestEffortStream* uxr_get_input_best_effort_stream( + uxrStreamStorage* storage, + uint8_t index) { - if(index < storage->input_best_effort_size) + if (index < storage->input_best_effort_size) { return &storage->input_best_effort[index]; } return NULL; } -uxrInputReliableStream* uxr_get_input_reliable_stream(uxrStreamStorage* storage, uint8_t index) +uxrInputReliableStream* uxr_get_input_reliable_stream( + uxrStreamStorage* storage, + uint8_t index) { - if(index < storage->input_reliable_size) + if (index < storage->input_reliable_size) { return &storage->input_reliable[index]; } return NULL; } -bool uxr_output_streams_confirmed(const uxrStreamStorage* storage) +bool uxr_output_streams_confirmed( + const uxrStreamStorage* storage) { bool up_to_date = true; - for(unsigned i = 0; i < storage->output_reliable_size && up_to_date; ++i) + for (unsigned i = 0; i < storage->output_reliable_size && up_to_date; ++i) { up_to_date = uxr_is_output_up_to_date(&storage->output_reliable[i]); } diff --git a/src/c/core/session/stream/stream_storage_internal.h b/src/c/core/session/stream/stream_storage_internal.h index d2b65b6b6..647b12667 100644 --- a/src/c/core/session/stream/stream_storage_internal.h +++ b/src/c/core/session/stream/stream_storage_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -28,28 +28,49 @@ extern "C" #include #include -void uxr_init_stream_storage(uxrStreamStorage* storage); -void uxr_reset_stream_storage(uxrStreamStorage* storage); +void uxr_init_stream_storage( + uxrStreamStorage* storage); +void uxr_reset_stream_storage( + uxrStreamStorage* storage); -uxrStreamId uxr_add_output_best_effort_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint8_t header_offset); -uxrStreamId uxr_add_output_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset); -uxrStreamId uxr_add_input_best_effort_buffer(uxrStreamStorage* storage); -uxrStreamId uxr_add_input_reliable_buffer(uxrStreamStorage* storage, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info); +uxrStreamId uxr_add_output_best_effort_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint8_t header_offset); +uxrStreamId uxr_add_output_reliable_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint16_t history, + uint8_t header_offset); +uxrStreamId uxr_add_input_best_effort_buffer( + uxrStreamStorage* storage); +uxrStreamId uxr_add_input_reliable_buffer( + uxrStreamStorage* storage, + uint8_t* buffer, + size_t size, + uint16_t history, + OnGetFragmentationInfo on_get_fragmentation_info); -uxrOutputBestEffortStream* uxr_get_output_best_effort_stream_id(uxrStreamStorage* storage, uint8_t index); -uxrOutputReliableStream* uxr_get_output_reliable_stream_id(uxrStreamStorage* storage, uint8_t index); -uxrInputBestEffortStream* uxr_get_input_best_effort_stream_id(uxrStreamStorage* storage, uint8_t index); -uxrInputReliableStream* uxr_get_input_reliable_stream_id(uxrStreamStorage* storage, uint8_t index); +uxrOutputBestEffortStream* uxr_get_output_best_effort_stream( + uxrStreamStorage* storage, + uint8_t index); +uxrOutputReliableStream* uxr_get_output_reliable_stream( + uxrStreamStorage* storage, + uint8_t index); +uxrInputBestEffortStream* uxr_get_input_best_effort_stream( + uxrStreamStorage* storage, + uint8_t index); +uxrInputReliableStream* uxr_get_input_reliable_stream( + uxrStreamStorage* storage, + uint8_t index); -uxrOutputBestEffortStream* uxr_get_output_best_effort_stream(uxrStreamStorage* storage, uint8_t index); -uxrOutputReliableStream* uxr_get_output_reliable_stream(uxrStreamStorage* storage, uint8_t index); -uxrInputBestEffortStream* uxr_get_input_best_effort_stream(uxrStreamStorage* storage, uint8_t index); -uxrInputReliableStream* uxr_get_input_reliable_stream(uxrStreamStorage* storage, uint8_t index); - -bool uxr_output_streams_confirmed(const uxrStreamStorage* storage); +bool uxr_output_streams_confirmed( + const uxrStreamStorage* storage); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_STREAM_STREAM_STORAGE_INTERNAL_H_ diff --git a/src/c/core/session/submessage.c b/src/c/core/session/submessage.c index 95269fff3..3319887a6 100644 --- a/src/c/core/session/submessage.c +++ b/src/c/core/session/submessage.c @@ -4,7 +4,11 @@ //================================================================== // PUBLIC //================================================================== -bool uxr_buffer_submessage_header(ucdrBuffer* ub, uint8_t submessage_id, uint16_t length, uint8_t flags) +bool uxr_buffer_submessage_header( + ucdrBuffer* ub, + uint8_t submessage_id, + uint16_t length, + uint8_t flags) { ucdr_align_to(ub, 4); ub->endianness = UCDR_MACHINE_ENDIANNESS; @@ -14,11 +18,15 @@ bool uxr_buffer_submessage_header(ucdrBuffer* ub, uint8_t submessage_id, uint16_ return ucdr_buffer_remaining(ub) >= length; } -bool uxr_read_submessage_header(ucdrBuffer* ub, uint8_t* submessage_id, uint16_t* length, uint8_t* flags) +bool uxr_read_submessage_header( + ucdrBuffer* ub, + uint8_t* submessage_id, + uint16_t* length, + uint8_t* flags) { ucdr_align_to(ub, 4); bool ready_to_read = ucdr_buffer_remaining(ub) >= SUBHEADER_SIZE; - if(ready_to_read) + if (ready_to_read) { uxr_deserialize_submessage_header(ub, submessage_id, flags, length); @@ -30,7 +38,8 @@ bool uxr_read_submessage_header(ucdrBuffer* ub, uint8_t* submessage_id, uint16_t return ready_to_read; } -size_t uxr_submessage_padding(size_t length) +size_t uxr_submessage_padding( + size_t length) { return (length % SUBHEADER_SIZE != 0) ? SUBHEADER_SIZE - (length % SUBHEADER_SIZE) : 0; } diff --git a/src/c/core/session/submessage_internal.h b/src/c/core/session/submessage_internal.h index c4e2f8a9b..b451c2847 100644 --- a/src/c/core/session/submessage_internal.h +++ b/src/c/core/session/submessage_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -50,7 +50,7 @@ typedef enum SubmessageId #ifdef PERFORMANCE_TESTING , SUBMESSAGE_ID_PERFORMANCE = 14 -#endif +#endif // ifdef PERFORMANCE_TESTING } SubmessageId; @@ -66,12 +66,21 @@ typedef enum SubmessageFlags } SubmessageFlags; -bool uxr_buffer_submessage_header(struct ucdrBuffer* ub, uint8_t submessage_id, uint16_t length, uint8_t flags); -bool uxr_read_submessage_header(struct ucdrBuffer* ub, uint8_t* submessage_id, uint16_t* length, uint8_t* flags); -size_t uxr_submessage_padding(size_t length); +bool uxr_buffer_submessage_header( + struct ucdrBuffer* ub, + uint8_t submessage_id, + uint16_t length, + uint8_t flags); +bool uxr_read_submessage_header( + struct ucdrBuffer* ub, + uint8_t* submessage_id, + uint16_t* length, + uint8_t* flags); +size_t uxr_submessage_padding( + size_t length); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // _SRC_C_CORE_SESSION_SUBMESSAGE_INTERNAL_H_ diff --git a/src/c/core/session/write_access.c b/src/c/core/session/write_access.c index 7a60d155d..9c7e5c4c9 100644 --- a/src/c/core/session/write_access.c +++ b/src/c/core/session/write_access.c @@ -4,6 +4,10 @@ #include "session_internal.h" #include "session_info_internal.h" #include "submessage_internal.h" +#include "./stream/output_reliable_stream_internal.h" +#include "./stream/common_reliable_stream_internal.h" +#include "./stream/stream_storage_internal.h" +#include "./stream/seq_num_internal.h" #define WRITE_DATA_PAYLOAD_SIZE 4 #define SAMPLE_IDENTITY_SIZE 24 @@ -12,17 +16,18 @@ // PUBLIC //================================================================== uint16_t uxr_buffer_request( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId requester_id, - uint8_t* buffer, - size_t len) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId requester_id, + uint8_t* buffer, + size_t len) { uint16_t rv = UXR_INVALID_REQUEST_ID; ucdrBuffer ub; size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + len; - ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); + ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, + FORMAT_DATA); if (!ub.error) { WRITE_DATA_Payload_Data payload; @@ -35,18 +40,19 @@ uint16_t uxr_buffer_request( } uint16_t uxr_buffer_reply( - uxrSession* session, - uxrStreamId stream_id, - uxrObjectId replier_id, - SampleIdentity* sample_id, - uint8_t* buffer, - size_t len) + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId replier_id, + SampleIdentity* sample_id, + uint8_t* buffer, + size_t len) { uint16_t rv = UXR_INVALID_REQUEST_ID; ucdrBuffer ub; size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + SAMPLE_IDENTITY_SIZE + len; - ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); + ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, + FORMAT_DATA); if (!ub.error) { WRITE_DATA_Payload_Data payload; @@ -59,15 +65,46 @@ uint16_t uxr_buffer_reply( return rv; } -bool uxr_prepare_output_stream(uxrSession* session, uxrStreamId stream_id, uxrObjectId datawriter_id, - ucdrBuffer* ub, uint32_t topic_size) +uint16_t uxr_buffer_topic( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId datawriter_id, + uint8_t* buffer, + size_t len) { - size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + topic_size; - ub->error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, ub, SUBMESSAGE_ID_WRITE_DATA, FORMAT_DATA); - if(!ub->error) + uint16_t rv = UXR_INVALID_REQUEST_ID; + ucdrBuffer ub; + size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + len; + + ub.error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, &ub, SUBMESSAGE_ID_WRITE_DATA, + FORMAT_DATA); + if (!ub.error) { WRITE_DATA_Payload_Data payload; - uxr_init_base_object_request(&session->info, datawriter_id, &payload.base); + rv = uxr_init_base_object_request(&session->info, datawriter_id, &payload.base); + uxr_serialize_WRITE_DATA_Payload_Data(&ub, &payload); + ucdr_serialize_array_uint8_t(&ub, buffer, len); + } + + return rv; +} + +uint16_t uxr_prepare_output_stream( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId entity_id, + ucdrBuffer* ub, + uint32_t data_size) +{ + uint16_t rv = UXR_INVALID_REQUEST_ID; + + size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + data_size; + ub->error = !uxr_prepare_stream_to_write_submessage(session, stream_id, payload_size, ub, SUBMESSAGE_ID_WRITE_DATA, + FORMAT_DATA); + if (!ub->error) + { + WRITE_DATA_Payload_Data payload; + rv = uxr_init_base_object_request(&session->info, entity_id, &payload.base); (void) uxr_serialize_WRITE_DATA_Payload_Data(ub, &payload); OnFullBuffer on_full_buffer = ub->on_full_buffer; @@ -76,6 +113,137 @@ bool uxr_prepare_output_stream(uxrSession* session, uxrStreamId stream_id, uxrOb ucdr_set_on_full_buffer_callback(ub, on_full_buffer, args); } - return !ub->error; + return rv; +} + +// Continuous fragment mode + +bool on_full_output_buffer_fragmented( + ucdrBuffer* ub, + void* args) +{ + uxrSession* session = (uxrSession*) args; + uxrContinuousArgs* local_args = &session->continuous_args; + + uxrOutputReliableStream* stream = uxr_get_output_reliable_stream(&session->streams, local_args->stream_id.index); + + size_t remaining_blocks = get_available_free_slots(stream); + + if (0 == remaining_blocks) + { + if (!local_args->flush_callback(session) || + 0 == (remaining_blocks = get_available_free_slots(stream))) + { + return true; + } + } + + size_t buffer_capacity = uxr_get_reliable_buffer_capacity(&stream->base); + uint16_t available_block_size = (uint16_t)(buffer_capacity - (uint16_t)(stream->offset + SUBHEADER_SIZE)); + local_args->data_size = local_args->data_size - (size_t) available_block_size; + + ucdrBuffer temp_ub; + ucdr_init_buffer_origin_offset( + &temp_ub, + uxr_get_reliable_buffer(&stream->base, stream->last_written), + buffer_capacity, + 0u, + uxr_get_reliable_buffer_size(&stream->base, stream->last_written)); + uxr_buffer_submessage_header(&temp_ub, SUBMESSAGE_ID_FRAGMENT, available_block_size, + (local_args->data_size < buffer_capacity) ? FLAG_LAST_FRAGMENT : 0); + uxr_set_reliable_buffer_size(&stream->base, stream->last_written, buffer_capacity); + stream->last_written = uxr_seq_num_add(stream->last_written, 1); + + // Preparing the buffer for the user + ucdr_init_buffer( + ub, + temp_ub.iterator, + (size_t)(temp_ub.final - temp_ub.iterator)); + ucdr_set_on_full_buffer_callback(ub, on_full_output_buffer_fragmented, args); + + return false; } +uint16_t uxr_prepare_output_stream_fragmented( + uxrSession* session, + uxrStreamId stream_id, + uxrObjectId entity_id, + ucdrBuffer* ub, + size_t data_size, + uxrOnBuffersFull flush_callback) +{ + uint16_t rv = UXR_INVALID_REQUEST_ID; + + size_t user_required_space = data_size + SUBHEADER_SIZE + WRITE_DATA_PAYLOAD_SIZE; + + uxrOutputReliableStream* stream = uxr_get_output_reliable_stream(&session->streams, stream_id.index); + + if (stream == NULL) + { + return rv; + } + + size_t remaining_blocks = get_available_free_slots(stream); + + if (0 == remaining_blocks) + { + if (!flush_callback(session) || + 0 == (remaining_blocks = get_available_free_slots(stream))) + { + return rv; + } + } + + uxrSeqNum seq_num = stream->last_written; + uint8_t* buffer = uxr_get_reliable_buffer(&stream->base, seq_num); + size_t buffer_size = uxr_get_reliable_buffer_size(&stream->base, seq_num); + size_t buffer_capacity = uxr_get_reliable_buffer_capacity(&stream->base); + + // Always start in a fresh buffer to avoid handling first fragment size + if (buffer_size > (size_t)stream->offset) + { + seq_num = uxr_seq_num_add(seq_num, 1); + buffer = uxr_get_reliable_buffer(&stream->base, seq_num); + buffer_size = uxr_get_reliable_buffer_size(&stream->base, seq_num); + } + + uint16_t available_block_size = (uint16_t)(buffer_capacity - (uint16_t)(stream->offset + SUBHEADER_SIZE)); + + ucdrBuffer temp_ub; + ucdr_init_buffer_origin_offset( + &temp_ub, + uxr_get_reliable_buffer(&stream->base, seq_num), + buffer_capacity, + 0u, + uxr_get_reliable_buffer_size(&stream->base, seq_num)); + uxr_buffer_submessage_header(&temp_ub, SUBMESSAGE_ID_FRAGMENT, available_block_size, + (user_required_space < buffer_capacity) ? FLAG_LAST_FRAGMENT : 0); + uxr_set_reliable_buffer_size(&stream->base, seq_num, buffer_capacity); + seq_num = uxr_seq_num_add(seq_num, 1); + + // Preparing the buffer for the user + ucdr_init_buffer( + ub, + buffer + buffer_size + SUBHEADER_SIZE, + (uint32_t)(buffer_capacity - buffer_size - SUBHEADER_SIZE)); + + stream->last_written = seq_num; + + // Fill the SUBMESSAGE_ID_WRITE_DATA + size_t payload_size = WRITE_DATA_PAYLOAD_SIZE + data_size; + + (void) uxr_buffer_submessage_header(ub, SUBMESSAGE_ID_WRITE_DATA, (uint16_t)payload_size, FORMAT_DATA); + + WRITE_DATA_Payload_Data payload; + rv = uxr_init_base_object_request(&session->info, entity_id, &payload.base); + (void) uxr_serialize_WRITE_DATA_Payload_Data(ub, &payload); + + ucdr_init_buffer(ub, ub->iterator, (size_t)(ub->final - ub->iterator)); + + session->continuous_args.stream_id = stream_id; + session->continuous_args.data_size = user_required_space; + session->continuous_args.flush_callback = flush_callback; + ucdr_set_on_full_buffer_callback(ub, on_full_output_buffer_fragmented, session); + + return rv; +} diff --git a/src/c/profile/discovery/discovery.c b/src/c/profile/discovery/discovery.c index 873469383..63f05834d 100644 --- a/src/c/profile/discovery/discovery.c +++ b/src/c/profile/discovery/discovery.c @@ -25,10 +25,17 @@ typedef struct CallbackData } CallbackData; -static void write_get_info_message(ucdrBuffer* ub); -static bool listen_info_message(uxrUDPTransportDatagram* transport, int period, CallbackData* callback); -static bool read_info_headers(ucdrBuffer* ub); -static bool read_info_message(ucdrBuffer* ub, CallbackData* callback); +static void write_get_info_message( + ucdrBuffer* ub); +static bool listen_info_message( + uxrUDPTransportDatagram* transport, + int period, + CallbackData* callback); +static bool read_info_headers( + ucdrBuffer* ub); +static bool read_info_message( + ucdrBuffer* ub, + CallbackData* callback); //================================================================== // PUBLIC @@ -64,12 +71,12 @@ void uxr_discovery_agents( size_t message_length = ucdr_buffer_length(&ub); uxrUDPTransportDatagram transport; - if(uxr_init_udp_transport_datagram(&transport)) + if (uxr_init_udp_transport_datagram(&transport)) { bool is_agent_found = false; - for(uint32_t a = 0; a < attempts && !is_agent_found; ++a) + for (uint32_t a = 0; a < attempts && !is_agent_found; ++a) { - for(size_t i = 0; i < agent_list_size; ++i) + for (size_t i = 0; i < agent_list_size; ++i) { (void) uxr_udp_send_datagram_to(&transport, output_buffer, message_length, &agent_list[i]); UXR_DEBUG_PRINT_MESSAGE(UXR_SEND, output_buffer, message_length, 0); @@ -77,12 +84,13 @@ void uxr_discovery_agents( int64_t timestamp = uxr_millis(); int poll = period; - while(0 < poll && !is_agent_found) + while (0 < poll && !is_agent_found) { is_agent_found = listen_info_message(&transport, poll, &callback); poll -= (int)(uxr_millis() - timestamp); } } + uxr_close_udp_transport_datagram(&transport); } } @@ -90,10 +98,14 @@ void uxr_discovery_agents( // INTERNAL //================================================================== -void write_get_info_message(ucdrBuffer* ub) +void write_get_info_message( + ucdrBuffer* ub) { GET_INFO_Payload payload; - payload.base.request_id = (RequestId){{0x00, GET_INFO_REQUEST_ID}}; + payload.base.request_id = (RequestId){{ + 0x00, GET_INFO_REQUEST_ID + } + }; payload.base.object_id = DDS_XRCE_OBJECTID_AGENT; payload.info_mask = INFO_CONFIGURATION | INFO_ACTIVITY; @@ -111,13 +123,13 @@ bool listen_info_message( bool is_succeed = false; bool received = uxr_udp_recv_datagram(transport, &input_buffer, &length, poll); - if(received) + if (received) { UXR_DEBUG_PRINT_MESSAGE(UXR_RECV, input_buffer, length, 0); ucdrBuffer ub; ucdr_init_buffer(&ub, input_buffer, (uint32_t)length); - if(read_info_headers(&ub)) + if (read_info_headers(&ub)) { is_succeed = read_info_message(&ub, callback); } @@ -126,7 +138,8 @@ bool listen_info_message( return is_succeed; } -bool read_info_headers(ucdrBuffer* ub) +bool read_info_headers( + ucdrBuffer* ub) { uint8_t session_id; uint8_t stream_id_raw; uxrSeqNum seq_num; uint8_t key[CLIENT_KEY_SIZE]; uxr_deserialize_message_header(ub, &session_id, &stream_id_raw, &seq_num, key); @@ -135,6 +148,45 @@ bool read_info_headers(ucdrBuffer* ub) return uxr_read_submessage_header(ub, &id, &length, &flags); } +bool uxr_deserialize_discovery_INFO_Payload( + ucdrBuffer* buffer, + INFO_Payload* output) +{ + bool ret = true; + ret &= uxr_deserialize_BaseObjectReply(buffer, &output->base); + ret &= ucdr_deserialize_bool(buffer, &output->object_info.optional_config); + if (output->object_info.optional_config == true) + { + ret &= uxr_deserialize_ObjectVariant(buffer, &output->object_info.config); + } + + ret &= ucdr_deserialize_bool(buffer, &output->object_info.optional_activity); + if (output->object_info.optional_activity == true) + { + ret &= ucdr_deserialize_uint8_t(buffer, &output->object_info.activity.kind); + ret &= output->object_info.activity.kind == DDS_XRCE_OBJK_AGENT; + if (ret) + { + ret &= ucdr_deserialize_int16_t(buffer, &output->object_info.activity._.agent.availability); + ret &= ucdr_deserialize_uint32_t(buffer, &output->object_info.activity._.agent.address_seq.size); + + // This function takes care of deserializing at least the possible address_seq items + // if the sent sequence is too long for the allocated UXR_TRANSPORT_LOCATOR_SEQUENCE_MAX + output->object_info.activity._.agent.address_seq.size = + (output->object_info.activity._.agent.address_seq.size > UXR_TRANSPORT_LOCATOR_SEQUENCE_MAX) ? + UXR_TRANSPORT_LOCATOR_SEQUENCE_MAX : + output->object_info.activity._.agent.address_seq.size; + + for (uint32_t i = 0; i < output->object_info.activity._.agent.address_seq.size && ret; i++) + { + ret &= uxr_deserialize_TransportLocator(buffer, + &output->object_info.activity._.agent.address_seq.data[i]); + } + } + } + return ret; +} + bool read_info_message( ucdrBuffer* ub, CallbackData* callback) @@ -142,14 +194,14 @@ bool read_info_message( bool is_succeed = false; INFO_Payload payload; - if(uxr_deserialize_INFO_Payload(ub, &payload)) + if (uxr_deserialize_discovery_INFO_Payload(ub, &payload)) { XrceVersion* version = &payload.object_info.config._.agent.xrce_version; - TransportLocatorSeq * locators = &payload.object_info.activity._.agent.address_seq; + TransportLocatorSeq* locators = &payload.object_info.activity._.agent.address_seq; for (size_t i = 0; i < (size_t)locators->size; ++i) { TransportLocator* transport = &locators->data[i]; - if(0 == memcmp(version->data, DDS_XRCE_XRCE_VERSION.data, sizeof(DDS_XRCE_XRCE_VERSION.data))) + if (0 == memcmp(version->data, DDS_XRCE_XRCE_VERSION.data, sizeof(DDS_XRCE_XRCE_VERSION.data))) { is_succeed = callback->on_agent(transport, callback->args); } diff --git a/src/c/profile/discovery/transport/udp_transport_datagram_freertos_plus_tcp.c b/src/c/profile/discovery/transport/udp_transport_datagram_freertos_plus_tcp.c new file mode 100644 index 000000000..989539581 --- /dev/null +++ b/src/c/profile/discovery/transport/udp_transport_datagram_freertos_plus_tcp.c @@ -0,0 +1,118 @@ +// Copyright 2018 eSOL Co.,Ltd. +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "udp_transport_datagram_internal.h" +#include "FreeRTOS.h" +#include "FreeRTOS_Sockets.h" + +#include +#include +#include + +bool uxr_init_udp_transport_datagram( + uxrUDPTransportDatagram* transport) +{ + bool rv = false; + + transport->fd = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP); + + if (FREERTOS_INVALID_SOCKET != transport->fd) + { + transport->poll_fd = FreeRTOS_CreateSocketSet(); + + if (NULL != transport->poll_fd) + { + /* FreeRTOS_FD_SET() is a void function. */ + FreeRTOS_FD_SET(transport->fd, transport->poll_fd, eSELECT_READ); + rv = true; + } + } + + return rv; +} + +bool uxr_close_udp_transport_datagram( + uxrUDPTransportDatagram* transport) +{ + /* FreeRTOS_closesocket() always returns 0. */ + (void) FreeRTOS_closesocket(transport->fd); + + return true; +} + +bool uxr_udp_send_datagram_to( + uxrUDPTransportDatagram* transport, + const uint8_t* buf, + size_t len, + const TransportLocator* locator) +{ + bool rv = true; + + struct freertos_sockaddr remote_addr; + memcpy(&remote_addr.sin_addr, &locator->_.medium_locator.address, sizeof(locator->_.medium_locator.address)); + if (0 != remote_addr.sin_addr) + { + remote_addr.sin_family = FREERTOS_AF_INET; + remote_addr.sin_port = FreeRTOS_htons(locator->_.medium_locator.locator_port); + + int32_t bytes_sent = FreeRTOS_sendto(transport->fd, (void*)buf, len, 0, + (struct freertos_sockaddr*)&remote_addr, sizeof(remote_addr)); + + /* FreeRTOS_sendto() returns 0 if an error or timeout occurred. */ + if (0 >= bytes_sent) + { + rv = false; + } + } + + return rv; +} + +bool uxr_udp_recv_datagram( + uxrUDPTransportDatagram* transport, + uint8_t** buf, + size_t* len, + int timeout) +{ + bool rv = false; + + BaseType_t poll_rv = FreeRTOS_select(transport->poll_fd, pdMS_TO_TICKS(timeout)); + if (0 < poll_rv) + { + int32_t bytes_received = FreeRTOS_recvfrom(transport->fd, (void*)transport->buffer, sizeof(transport->buffer), + 0, NULL, NULL); + if (0 < bytes_received) + { + *len = (size_t)bytes_received; + *buf = transport->buffer; + rv = true; + } + } + else if (0 == poll_rv) + { + errno = ETIME; + } + + return rv; +} + +void uxr_bytes_to_ip( + const uint8_t* bytes, + char* ip) +{ + uint32_t addr; + addr = (uint32_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); + FreeRTOS_inet_ntoa(addr, ip); +} diff --git a/src/c/profile/discovery/transport/udp_transport_datagram_internal.h b/src/c/profile/discovery/transport/udp_transport_datagram_internal.h index 257ec1b5e..a7bb3ba75 100644 --- a/src/c/profile/discovery/transport/udp_transport_datagram_internal.h +++ b/src/c/profile/discovery/transport/udp_transport_datagram_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include @@ -34,7 +34,12 @@ extern "C" #include #elif defined(UCLIENT_PLATFORM_WINDOWS) #include -#endif +#elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) +#include "FreeRTOS.h" +#include "list.h" +#include "FreeRTOS_IP.h" +#include "FreeRTOS_Sockets.h" +#endif // if defined(UCLIENT_PLATFORM_POSIX) // TODO (julibert): move this to CMake flag. @@ -45,9 +50,14 @@ typedef struct uxrUDPTransportDatagram uint8_t buffer[UXR_UDP_TRANSPORT_MTU_DATAGRAM]; #if defined(UCLIENT_PLATFORM_POSIX) struct pollfd poll_fd; +#elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) + int fd; #elif defined(UCLIENT_PLATFORM_WINDOWS) WSAPOLLFD poll_fd; -#endif +#elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) + SocketSet_t poll_fd; + Socket_t fd; +#endif // if defined(UCLIENT_PLATFORM_POSIX) } uxrUDPTransportDatagram; @@ -66,12 +76,15 @@ bool uxr_udp_recv_datagram( size_t* len, int timeout); +bool uxr_close_udp_transport_datagram( + struct uxrUDPTransportDatagram* transport); + void uxr_bytes_to_ip( const uint8_t* bytes, char* ip); #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // SRC_C_CLIENT_UDP_TRANSPORT_DATAGRAM_INTERNAL_H_ diff --git a/src/c/profile/discovery/transport/udp_transport_datagram_posix.c b/src/c/profile/discovery/transport/udp_transport_datagram_posix.c index 00e9d8395..1b5313621 100644 --- a/src/c/profile/discovery/transport/udp_transport_datagram_posix.c +++ b/src/c/profile/discovery/transport/udp_transport_datagram_posix.c @@ -38,7 +38,7 @@ bool uxr_udp_send_datagram_to( remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); ssize_t bytes_sent = sendto(transport->poll_fd.fd, (const void*)buf, len, 0, - (struct sockaddr*)&remote_addr, sizeof(remote_addr)); + (struct sockaddr*)&remote_addr, sizeof(remote_addr)); if (0 > bytes_sent) { rv = false; @@ -88,4 +88,3 @@ void uxr_bytes_to_ip( char* internal_ip = inet_ntoa(addr); strcpy(ip, internal_ip); } - diff --git a/src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c b/src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c new file mode 100644 index 000000000..7ad3f5211 --- /dev/null +++ b/src/c/profile/discovery/transport/udp_transport_datagram_posix_nopoll.c @@ -0,0 +1,91 @@ +#include "udp_transport_datagram_internal.h" + +#include +#include +#include +#include +#include +#include + +bool uxr_init_udp_transport_datagram( + uxrUDPTransportDatagram* transport) +{ + int fd = socket(PF_INET, SOCK_DGRAM, 0); + transport->fd = fd; + + return fd != -1; +} + +bool uxr_close_udp_transport_datagram( + uxrUDPTransportDatagram* transport) +{ + return (0 == close(transport->fd)); +} + +bool uxr_udp_send_datagram_to( + uxrUDPTransportDatagram* transport, + const uint8_t* buf, + size_t len, + const TransportLocator* locator) +{ + bool rv = true; + switch (locator->format) + { + case ADDRESS_FORMAT_MEDIUM: + { + struct sockaddr_in remote_addr; + memcpy(&remote_addr.sin_addr, locator->_.medium_locator.address, sizeof(remote_addr.sin_addr)); + remote_addr.sin_family = AF_INET; + remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); + + ssize_t bytes_sent = sendto(transport->fd, (const void*)buf, len, 0, + (struct sockaddr*)&remote_addr, sizeof(remote_addr)); + if (0 > bytes_sent) + { + rv = false; + } + break; + } + default: + rv = false; + break; + } + return rv; +} + +bool uxr_udp_recv_datagram( + uxrUDPTransportDatagram* transport, + uint8_t** buf, + size_t* len, + int timeout) +{ + bool rv = false; + + timeout = (timeout <= 0) ? 1 : timeout; + + struct timeval tv; + tv.tv_sec = timeout / 1000; + tv.tv_usec = (timeout % 1000) * 1000; + + setsockopt(transport->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + + ssize_t bytes_received = recv(transport->fd, (void*)transport->buffer, sizeof(transport->buffer), 0); + if (-1 != bytes_received) + { + *len = (size_t)bytes_received; + *buf = transport->buffer; + rv = true; + } + + return rv; +} + +void uxr_bytes_to_ip( + const uint8_t* bytes, + char* ip) +{ + struct in_addr addr; + addr.s_addr = (in_addr_t)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); + char* internal_ip = inet_ntoa(addr); + strcpy(ip, internal_ip); +} diff --git a/src/c/profile/discovery/transport/udp_transport_datagram_windows.c b/src/c/profile/discovery/transport/udp_transport_datagram_windows.c index 4b3c3878b..7e50fbb13 100644 --- a/src/c/profile/discovery/transport/udp_transport_datagram_windows.c +++ b/src/c/profile/discovery/transport/udp_transport_datagram_windows.c @@ -49,7 +49,7 @@ bool uxr_udp_send_datagram_to( remote_addr.sin_port = htons(locator->_.medium_locator.locator_port); int bytes_sent = sendto(transport->poll_fd.fd, (const char*)buf, (int)len, 0, - (struct sockaddr*)&remote_addr, sizeof(remote_addr)); + (struct sockaddr*)&remote_addr, sizeof(remote_addr)); rv = (SOCKET_ERROR != bytes_sent); break; } @@ -94,4 +94,3 @@ void uxr_bytes_to_ip( addr.s_addr = (unsigned long)(*bytes + (*(bytes + 1) << 8) + (*(bytes + 2) << 16) + (*(bytes + 3) << 24)); inet_ntop(AF_INET, &(addr.s_addr), ip, INET_ADDRSTRLEN); } - diff --git a/src/c/profile/transport/custom/custom_transport.c b/src/c/profile/transport/custom/custom_transport.c new file mode 100644 index 000000000..2d3cb6023 --- /dev/null +++ b/src/c/profile/transport/custom/custom_transport.c @@ -0,0 +1,166 @@ +#include +#include "../stream_framing/stream_framing_protocol.h" +#include + +/******************************************************************************* +* Static members. +*******************************************************************************/ +static uint8_t error_code; + +/******************************************************************************* +* Private function definitions. +*******************************************************************************/ +static bool send_custom_msg( + void* instance, + const uint8_t* buf, + size_t len) +{ + bool rv = false; + uxrCustomTransport* transport = (uxrCustomTransport*)instance; + + uint8_t errcode; + size_t bytes_written = 0; + if (transport->framing) + { + bytes_written = uxr_write_framed_msg(&transport->framing_io, + (uxr_write_cb) transport->write, + transport, + buf, + len, + 0x00, + &errcode); + } + else + { + bytes_written = transport->write(transport, buf, len, &errcode); + } + + if ((0 < bytes_written) && (bytes_written == len)) + { + rv = true; + } + else + { + error_code = errcode; + } + + return rv; +} + +static bool recv_custom_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout) +{ + bool rv = false; + uxrCustomTransport* transport = (uxrCustomTransport*)instance; + + size_t bytes_read = 0; + do + { + int64_t time_init = uxr_millis(); + uint8_t remote_addr = 0x00; + uint8_t errcode; + + if (transport->framing) + { + bytes_read = uxr_read_framed_msg(&transport->framing_io, + (uxr_read_cb) transport->read, + transport, + transport->buffer, + sizeof(transport->buffer), + &remote_addr, + timeout, + &errcode); + } + else + { + bytes_read = transport->read(transport, + transport->buffer, + sizeof(transport->buffer), + timeout, + &errcode); + } + + if ((0 < bytes_read) && (remote_addr == 0x00)) + { + *len = bytes_read; + *buf = transport->buffer; + rv = true; + } + else + { + error_code = errcode; + } + timeout -= (int)(uxr_millis() - time_init); + } + while ((0 == bytes_read) && (0 < timeout)); + + return rv; +} + +static uint8_t get_custom_error( + void) +{ + return error_code; +} + +/******************************************************************************* +* Public function definitions. +*******************************************************************************/ +void uxr_set_custom_transport_callbacks( + uxrCustomTransport* transport, + bool framing, + open_custom_func open, + close_custom_func close, + write_custom_func write, + read_custom_func read) +{ + transport->framing = framing; + transport->open = open; + transport->close = close; + transport->write = write; + transport->read = read; +} + +bool uxr_init_custom_transport( + uxrCustomTransport* transport, + void* args) +{ + bool rv = false; + if (transport->open == NULL || + transport->close == NULL || + transport->write == NULL || + transport->read == NULL) + { + return rv; + } + + transport->args = args; + + if (transport->open(transport)) + { + if (transport->framing) + { + /* Init FramingIO. */ + uxr_init_framing_io(&transport->framing_io, 0x00); + } + + /* Setup interface. */ + transport->comm.instance = (void*)transport; + transport->comm.send_msg = send_custom_msg; + transport->comm.recv_msg = recv_custom_msg; + transport->comm.comm_error = get_custom_error; + transport->comm.mtu = UXR_CONFIG_CUSTOM_TRANSPORT_MTU; + + rv = true; + } + return rv; +} + +bool uxr_close_custom_transport( + uxrCustomTransport* transport) +{ + return transport->close(transport); +} diff --git a/src/c/profile/transport/ip/ip_freertos_plus_tcp.c b/src/c/profile/transport/ip/ip_freertos_plus_tcp.c new file mode 100644 index 000000000..013d5b4e3 --- /dev/null +++ b/src/c/profile/transport/ip/ip_freertos_plus_tcp.c @@ -0,0 +1,70 @@ +// Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "FreeRTOS.h" +#include "FreeRTOS_Sockets.h" + +bool uxr_ip_to_locator( + char const* ip, + uint16_t port, + uxrIpProtocol ip_protocol, + TransportLocator* locator) +{ + bool result = false; + switch (ip_protocol) + { + case UXR_IPv4: + locator->format = ADDRESS_FORMAT_MEDIUM; + locator->_.medium_locator.locator_port = port; + uint32_t addr = FreeRTOS_inet_addr(ip); + memcpy(&locator->_.medium_locator.address, &addr, sizeof(locator->_.medium_locator.address)); + result = locator->_.medium_locator.address != 0; + break; + case UXR_IPv6: + break; + default: + break; + } + return result; +} + +bool uxr_locator_to_ip( + TransportLocator const* locator, + char* ip, + size_t size, + uint16_t* port, + uxrIpProtocol* ip_protocol) +{ + bool result = false; + (void)size; + switch (locator->format) + { + case ADDRESS_FORMAT_MEDIUM: + *port = locator->_.medium_locator.locator_port; + *ip_protocol = UXR_IPv4; + uint32_t addr; + memcpy(&addr, &locator->_.medium_locator.address, sizeof(locator->_.medium_locator.address)); + FreeRTOS_inet_ntoa(addr, ip); + result = true; + break; + case ADDRESS_FORMAT_LARGE: + break; + default: + break; + } + return result; +} \ No newline at end of file diff --git a/src/c/profile/transport/ip/ip_posix.c b/src/c/profile/transport/ip/ip_posix.c index 66a0b263c..0f2626912 100644 --- a/src/c/profile/transport/ip/ip_posix.c +++ b/src/c/profile/transport/ip/ip_posix.c @@ -19,13 +19,13 @@ #include #elif defined(UCLIENT_PLATFORM_POSIX_NOPOLL) #include -#endif +#endif /* if defined(UCLIENT_PLATFORM_POSIX) */ bool uxr_ip_to_locator( - char const * ip, + char const* ip, uint16_t port, uxrIpProtocol ip_protocol, - TransportLocator * locator) + TransportLocator* locator) { bool result = false; switch (ip_protocol) @@ -47,11 +47,11 @@ bool uxr_ip_to_locator( } bool uxr_locator_to_ip( - TransportLocator const * locator, - char * ip, + TransportLocator const* locator, + char* ip, size_t size, - uint16_t * port, - uxrIpProtocol * ip_protocol) + uint16_t* port, + uxrIpProtocol* ip_protocol) { bool result = false; switch (locator->format) diff --git a/src/c/profile/transport/ip/ip_windows.c b/src/c/profile/transport/ip/ip_windows.c index 9854519bb..19c47e0ef 100644 --- a/src/c/profile/transport/ip/ip_windows.c +++ b/src/c/profile/transport/ip/ip_windows.c @@ -17,10 +17,10 @@ #include bool uxr_ip_to_locator( - char const * ip, + char const* ip, uint16_t port, uxrIpProtocol ip_protocol, - TransportLocator * locator) + TransportLocator* locator) { bool result = false; switch (ip_protocol) @@ -42,11 +42,11 @@ bool uxr_ip_to_locator( } bool uxr_locator_to_ip( - TransportLocator const * locator, - char * ip, + TransportLocator const* locator, + char* ip, size_t size, - uint16_t * port, - uxrIpProtocol * ip_protocol) + uint16_t* port, + uxrIpProtocol* ip_protocol) { bool result = false; switch (locator->format) diff --git a/src/c/profile/transport/ip/tcp/tcp_transport.c b/src/c/profile/transport/ip/tcp/tcp_transport.c index d0c707431..7fb66eea8 100644 --- a/src/c/profile/transport/ip/tcp/tcp_transport.c +++ b/src/c/profile/transport/ip/tcp/tcp_transport.c @@ -4,22 +4,35 @@ #define UXR_MAX_WRITE_TCP_ATTEMPS 16 /******************************************************************************* - * Static members. - *******************************************************************************/ +* Static members. +*******************************************************************************/ static uint8_t error_code; /******************************************************************************* - * Private function declarations. - *******************************************************************************/ -static bool send_tcp_msg(void* instance, const uint8_t* buf, size_t len); -static bool recv_tcp_msg(void* instance, uint8_t** buf, size_t* len, int timeout); -static uint8_t get_tcp_error(void); -static size_t read_tcp_data(uxrTCPTransport* transport, int timeout); +* Private function declarations. +*******************************************************************************/ +static bool send_tcp_msg( + void* instance, + const uint8_t* buf, + size_t len); +static bool recv_tcp_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout); +static uint8_t get_tcp_error( + void); +static size_t read_tcp_data( + uxrTCPTransport* transport, + int timeout); /******************************************************************************* - * Private function definitions. - *******************************************************************************/ -bool send_tcp_msg(void* instance, const uint8_t* buf, size_t len) +* Private function definitions. +*******************************************************************************/ +bool send_tcp_msg( + void* instance, + const uint8_t* buf, + size_t len) { bool rv = false; uxrTCPTransport* transport = (uxrTCPTransport*)instance; @@ -35,7 +48,7 @@ bool send_tcp_msg(void* instance, const uint8_t* buf, size_t len) do { uint8_t errcode; - size_t send_rv = uxr_write_tcp_data_platform(transport->platform, msg_size_buf, 2, &errcode); + size_t send_rv = uxr_write_tcp_data_platform(&transport->platform, msg_size_buf, 2, &errcode); if (0 < send_rv) { bytes_sent = (size_t)(bytes_sent + send_rv); @@ -62,10 +75,10 @@ bool send_tcp_msg(void* instance, const uint8_t* buf, size_t len) do { uint8_t errcode; - size_t send_rv = uxr_write_tcp_data_platform(transport->platform, - buf + bytes_sent, - len - bytes_sent, - &errcode); + size_t send_rv = uxr_write_tcp_data_platform(&transport->platform, + buf + bytes_sent, + len - bytes_sent, + &errcode); if (0 < send_rv) { bytes_sent = (size_t)(bytes_sent + send_rv); @@ -90,13 +103,17 @@ bool send_tcp_msg(void* instance, const uint8_t* buf, size_t len) } else { - uxr_disconnect_tcp_platform(transport->platform); + uxr_disconnect_tcp_platform(&transport->platform); } return rv; } -bool recv_tcp_msg(void* instance, uint8_t** buf, size_t* len, int timeout) +bool recv_tcp_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout) { bool rv = false; uxrTCPTransport* transport = (uxrTCPTransport*)instance; @@ -119,18 +136,21 @@ bool recv_tcp_msg(void* instance, uint8_t** buf, size_t* len, int timeout) return rv; } -uint8_t get_tcp_error(void) +uint8_t get_tcp_error( + void) { return error_code; } -size_t read_tcp_data(uxrTCPTransport* transport, int timeout) +size_t read_tcp_data( + uxrTCPTransport* transport, + int timeout) { size_t rv = 0; bool exit_flag = false; /* State Machine. */ - while(!exit_flag) + while (!exit_flag) { switch (transport->input_buffer.state) { @@ -139,7 +159,8 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) transport->input_buffer.position = 0; uint8_t size_buf[2]; uint8_t errcode; - size_t bytes_received = uxr_read_tcp_data_platform(transport->platform, size_buf, 2, timeout, &errcode); + size_t bytes_received = + uxr_read_tcp_data_platform(&transport->platform, size_buf, 2, timeout, &errcode); if (0 < bytes_received) { transport->input_buffer.msg_size = 0; @@ -161,7 +182,7 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) { if (0 < errcode) { - uxr_disconnect_tcp_platform(transport->platform); + uxr_disconnect_tcp_platform(&transport->platform); } error_code = errcode; exit_flag = true; @@ -172,7 +193,8 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) { uint8_t size_msb; uint8_t errcode; - size_t bytes_received = uxr_read_tcp_data_platform(transport->platform, &size_msb, 1, timeout, &errcode); + size_t bytes_received = + uxr_read_tcp_data_platform(&transport->platform, &size_msb, 1, timeout, &errcode); if (0 < bytes_received) { transport->input_buffer.msg_size = (size_t)(size_msb << 8) | transport->input_buffer.msg_size; @@ -189,7 +211,7 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) { if (0 < errcode) { - uxr_disconnect_tcp_platform(transport->platform); + uxr_disconnect_tcp_platform(&transport->platform); } error_code = errcode; exit_flag = true; @@ -199,11 +221,11 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) case UXR_TCP_SIZE_READ: { uint8_t errcode; - size_t bytes_received = uxr_read_tcp_data_platform(transport->platform, - transport->input_buffer.buffer, - transport->input_buffer.msg_size, - timeout, - &errcode); + size_t bytes_received = uxr_read_tcp_data_platform(&transport->platform, + transport->input_buffer.buffer, + transport->input_buffer.msg_size, + timeout, + &errcode); if (0 < bytes_received) { if (bytes_received == transport->input_buffer.msg_size) @@ -221,7 +243,7 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) { if (0 < errcode) { - uxr_disconnect_tcp_platform(transport->platform); + uxr_disconnect_tcp_platform(&transport->platform); } error_code = errcode; exit_flag = true; @@ -231,13 +253,13 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) case UXR_TCP_MESSAGE_INCOMPLETE: { uint8_t errcode; - size_t bytes_received = uxr_read_tcp_data_platform(transport->platform, - transport->input_buffer.buffer + - transport->input_buffer.position, - (size_t)(transport->input_buffer.msg_size - - transport->input_buffer.position), - timeout, - &errcode); + size_t bytes_received = uxr_read_tcp_data_platform(&transport->platform, + transport->input_buffer.buffer + + transport->input_buffer.position, + (size_t)(transport->input_buffer.msg_size - + transport->input_buffer.position), + timeout, + &errcode); if (0 < bytes_received) { transport->input_buffer.position = (size_t)(transport->input_buffer.position + bytes_received); @@ -254,7 +276,7 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) { if (0 < errcode) { - uxr_disconnect_tcp_platform(transport->platform); + uxr_disconnect_tcp_platform(&transport->platform); } error_code = errcode; exit_flag = true; @@ -279,22 +301,18 @@ size_t read_tcp_data(uxrTCPTransport* transport, int timeout) } /******************************************************************************* - * Public function definitions. - *******************************************************************************/ +* Public function definitions. +*******************************************************************************/ bool uxr_init_tcp_transport( uxrTCPTransport* transport, - struct uxrTCPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port) { bool rv = false; - if(uxr_init_tcp_platform(platform, ip_protocol, ip, port)) + if (uxr_init_tcp_platform(&transport->platform, ip_protocol, ip, port)) { - /* Setup platform. */ - transport->platform = platform; - /* Interface setup. */ transport->comm.instance = (void*)transport; transport->comm.send_msg = send_tcp_msg; @@ -308,7 +326,8 @@ bool uxr_init_tcp_transport( return rv; } -bool uxr_close_tcp_transport(uxrTCPTransport* transport) +bool uxr_close_tcp_transport( + uxrTCPTransport* transport) { - return uxr_close_tcp_platform(transport->platform); + return uxr_close_tcp_platform(&transport->platform); } diff --git a/src/c/profile/transport/ip/tcp/tcp_transport_external.c.template b/src/c/profile/transport/ip/tcp/tcp_transport_external.c.template deleted file mode 100644 index bcf8720b6..000000000 --- a/src/c/profile/transport/ip/tcp/tcp_transport_external.c.template +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include "tcp_transport_internal.h" - -// Place here your includes - -bool uxr_init_tcp_platform( - struct uxrTCPPlatform* platform, - uxrIpProtocol ip_protocol, - const char* ip, - const char* port) -{ - // Place here your initialization platform code - // Return true if success -} - -bool uxr_close_tcp_platform( - struct uxrTCPPlatform* platform) -{ - // Place here your closing platform code - // Return true if success -} - -size_t uxr_write_tcp_data_platform( - struct uxrTCPPlatform* platform, - const uint8_t* buf, - size_t len, - uint8_t* errcode) -{ - // Place here your writing bytes platform code - // Return number of bytes written -} - -size_t uxr_read_tcp_data_platform( - struct uxrTCPPlatform* platform, - uint8_t* buf, - size_t len, - int timeout, - uint8_t* errcode) -{ - // Place here your reading bytes platform code - // Return number of bytes read (max bytes: len) -} - -void uxr_disconnect_tcp_platform( - struct uxrTCPPlatform* platform) -{ - // Place here your disconnection platform code -} diff --git a/src/c/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.c b/src/c/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.c new file mode 100644 index 000000000..598c85c0c --- /dev/null +++ b/src/c/profile/transport/ip/tcp/tcp_transport_freertos_plus_tcp.c @@ -0,0 +1,148 @@ +// Copyright 2018 eSOL Co.,Ltd. +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "tcp_transport_internal.h" + +#include +#include +#include + +bool uxr_init_tcp_platform( + struct uxrTCPPlatform* platform, + uxrIpProtocol ip_protocol, + const char* ip, + const char* port) +{ + bool rv = false; + uint16_t iport; + + (void) ip_protocol; + iport = (uint16_t)atoi(port); + + /* Socket initialization. */ + platform->fd = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP); + if (FREERTOS_INVALID_SOCKET != platform->fd) + { + /* Remote IP setup. */ + platform->remote_addr.sin_family = FREERTOS_AF_INET; + platform->remote_addr.sin_port = FreeRTOS_htons(iport); + platform->remote_addr.sin_addr = FreeRTOS_inet_addr(ip); + + /* Poll setup. */ + platform->poll_fd = FreeRTOS_CreateSocketSet(); + if (NULL != platform->poll_fd) + { + /* FreeRTOS_FD_SET() is a void function. */ + FreeRTOS_FD_SET(platform->fd, platform->poll_fd, eSELECT_READ); + rv = true; + } + + /* Server connection. */ + if (rv) + { + BaseType_t connected = FreeRTOS_connect(platform->fd, + &platform->remote_addr, + sizeof(platform->remote_addr)); + rv = (0 == connected); + } + else + { + rv = false; + } + } + + return rv; +} + +bool uxr_close_tcp_platform( + struct uxrTCPPlatform* platform) +{ + (void) FreeRTOS_shutdown(platform->fd, FREERTOS_SHUT_RDWR); + + /* FreeRTOS_closesocket() must be called even if FreeRTOS_shutdown() returns error. + * FreeRTOS_closesocket() always returns 0. */ + (void) FreeRTOS_closesocket(platform->fd); + + return true; +} + +size_t uxr_write_tcp_data_platform( + struct uxrTCPPlatform* platform, + const uint8_t* buf, + size_t len, + uint8_t* errcode) +{ + size_t rv = 0; + + BaseType_t bytes_sent = FreeRTOS_send(platform->fd, (void*)buf, len, 0); + + /* FreeRTOS_send() returns the number of bytes queued for sending. + * If an error or timeout occurred, FreeRTOS_send() returns a negative value. */ + if (0 <= bytes_sent) + { + rv = (size_t)bytes_sent; + *errcode = 0; + } + else + { + *errcode = 1; + } + + return rv; +} + +size_t uxr_read_tcp_data_platform( + struct uxrTCPPlatform* platform, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode) +{ + size_t rv = 0; + + BaseType_t poll_rv = FreeRTOS_select(platform->poll_fd, pdMS_TO_TICKS(timeout)); + if (0 < poll_rv) + { + BaseType_t bytes_received = FreeRTOS_recv(platform->fd, (void*)buf, len, 0); + if (0 <= bytes_received) + { + rv = (size_t)bytes_received; + *errcode = 0; + } + else + { + *errcode = 1; + } + } + else + { + *errcode = (0 == poll_rv) ? 0 : 1; + } + + return rv; +} + +void uxr_disconnect_tcp_platform( + struct uxrTCPPlatform* platform) +{ + (void) FreeRTOS_shutdown(platform->fd, FREERTOS_SHUT_RDWR); + + /* FreeRTOS_closesocket() must be called even if FreeRTOS_shutdown() returns error. + * FreeRTOS_closesocket() always returns 0. */ + (void) FreeRTOS_closesocket(platform->fd); + platform->fd = FREERTOS_INVALID_SOCKET; + platform->poll_fd = NULL; +} diff --git a/src/c/profile/transport/ip/tcp/tcp_transport_internal.h b/src/c/profile/transport/ip/tcp/tcp_transport_internal.h index 5902a48eb..de5d36d49 100644 --- a/src/c/profile/transport/ip/tcp/tcp_transport_internal.h +++ b/src/c/profile/transport/ip/tcp/tcp_transport_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -49,6 +49,6 @@ void uxr_disconnect_tcp_platform( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // SRC_C_PROFILE_TRANSPORT_TCP_TCP_TRANSPORT_INTERNAL_H_ diff --git a/src/c/profile/transport/ip/tcp/tcp_transport_posix.c b/src/c/profile/transport/ip/tcp/tcp_transport_posix.c index 696d85e25..c81467410 100644 --- a/src/c/profile/transport/ip/tcp/tcp_transport_posix.c +++ b/src/c/profile/transport/ip/tcp/tcp_transport_posix.c @@ -9,11 +9,13 @@ #include #ifdef UCLIENT_PLATFORM_LINUX -static void sigpipe_handler(int fd) +static void sigpipe_handler( + int fd) { (void)fd; } -#endif + +#endif /* ifdef UCLIENT_PLATFORM_LINUX */ bool uxr_init_tcp_platform( struct uxrTCPPlatform* platform, @@ -37,7 +39,7 @@ bool uxr_init_tcp_platform( { #ifdef UCLIENT_PLATFORM_LINUX signal(SIGPIPE, sigpipe_handler); -#endif +#endif /* ifdef UCLIENT_PLATFORM_LINUX */ struct addrinfo hints; struct addrinfo* result; struct addrinfo* ptr; diff --git a/src/c/profile/transport/ip/tcp/tcp_transport_windows.c b/src/c/profile/transport/ip/tcp/tcp_transport_windows.c index 3fd9a31ec..80200bd0c 100644 --- a/src/c/profile/transport/ip/tcp/tcp_transport_windows.c +++ b/src/c/profile/transport/ip/tcp/tcp_transport_windows.c @@ -65,16 +65,18 @@ bool uxr_init_tcp_platform( return rv; } -bool uxr_close_tcp_platform(struct uxrTCPPlatform* platform) +bool uxr_close_tcp_platform( + struct uxrTCPPlatform* platform) { bool rv = (INVALID_SOCKET == platform->poll_fd.fd) ? true : (0 == closesocket(platform->poll_fd.fd)); return (0 == WSACleanup()) && rv; } -size_t uxr_write_tcp_data_platform(struct uxrTCPPlatform* platform, - const uint8_t* buf, - size_t len, - uint8_t* errcode) +size_t uxr_write_tcp_data_platform( + struct uxrTCPPlatform* platform, + const uint8_t* buf, + size_t len, + uint8_t* errcode) { size_t rv = 0; int bytes_sent = send(platform->poll_fd.fd, (const char*)buf, (int)len, 0); @@ -90,11 +92,12 @@ size_t uxr_write_tcp_data_platform(struct uxrTCPPlatform* platform, return rv; } -size_t uxr_read_tcp_data_platform(struct uxrTCPPlatform* platform, - uint8_t* buf, - size_t len, - int timeout, - uint8_t* errcode) +size_t uxr_read_tcp_data_platform( + struct uxrTCPPlatform* platform, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode) { size_t rv = 0; int poll_rv = WSAPoll(&platform->poll_fd, 1, timeout); @@ -118,7 +121,8 @@ size_t uxr_read_tcp_data_platform(struct uxrTCPPlatform* platform, return rv; } -void uxr_disconnect_tcp_platform(struct uxrTCPPlatform* platform) +void uxr_disconnect_tcp_platform( + struct uxrTCPPlatform* platform) { closesocket(platform->poll_fd.fd); platform->poll_fd.fd = INVALID_SOCKET; diff --git a/src/c/profile/transport/ip/udp/udp_transport.c b/src/c/profile/transport/ip/udp/udp_transport.c index 4ce775850..8dfcb1e21 100644 --- a/src/c/profile/transport/ip/udp/udp_transport.c +++ b/src/c/profile/transport/ip/udp/udp_transport.c @@ -1,27 +1,38 @@ #include "udp_transport_internal.h" /******************************************************************************* - * Static members. - *******************************************************************************/ +* Static members. +*******************************************************************************/ static uint8_t error_code; /******************************************************************************* - * Private function declarations. - *******************************************************************************/ -static bool send_udp_msg(void* instance, const uint8_t* buf, size_t len); -static bool recv_udp_msg(void* instance, uint8_t** buf, size_t* len, int timeout); -static uint8_t get_udp_error(void); +* Private function declarations. +*******************************************************************************/ +static bool send_udp_msg( + void* instance, + const uint8_t* buf, + size_t len); +static bool recv_udp_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout); +static uint8_t get_udp_error( + void); /******************************************************************************* - * Private function definitions. - *******************************************************************************/ -static bool send_udp_msg(void* instance, const uint8_t* buf, size_t len) +* Private function definitions. +*******************************************************************************/ +static bool send_udp_msg( + void* instance, + const uint8_t* buf, + size_t len) { bool rv = false; uxrUDPTransport* transport = (uxrUDPTransport*)instance; uint8_t errcode; - size_t bytes_sent = uxr_write_udp_data_platform(transport->platform, buf, len, &errcode); + size_t bytes_sent = uxr_write_udp_data_platform(&transport->platform, buf, len, &errcode); if (0 < bytes_sent) { rv = (bytes_sent == len); @@ -33,17 +44,21 @@ static bool send_udp_msg(void* instance, const uint8_t* buf, size_t len) return rv; } -static bool recv_udp_msg(void* instance, uint8_t** buf, size_t* len, int timeout) +static bool recv_udp_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout) { bool rv = false; uxrUDPTransport* transport = (uxrUDPTransport*)instance; uint8_t errcode; - size_t bytes_received = uxr_read_udp_data_platform(transport->platform, - transport->buffer, - sizeof(transport->buffer), - timeout, - &errcode); + size_t bytes_received = uxr_read_udp_data_platform(&transport->platform, + transport->buffer, + sizeof(transport->buffer), + timeout, + &errcode); if (0 < bytes_received) { *buf = transport->buffer; @@ -57,28 +72,25 @@ static bool recv_udp_msg(void* instance, uint8_t** buf, size_t* len, int timeout return rv; } -static uint8_t get_udp_error(void) +static uint8_t get_udp_error( + void) { return error_code; } /******************************************************************************* - * Public function definitions. - *******************************************************************************/ +* Public function definitions. +*******************************************************************************/ bool uxr_init_udp_transport( uxrUDPTransport* transport, - struct uxrUDPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port) { bool rv = false; - if (uxr_init_udp_platform(platform, ip_protocol, ip, port)) + if (uxr_init_udp_platform(&transport->platform, ip_protocol, ip, port)) { - /* Setup platform. */ - transport->platform = platform; - /* Setup interface. */ transport->comm.instance = (void*)transport; transport->comm.send_msg = send_udp_msg; @@ -90,7 +102,8 @@ bool uxr_init_udp_transport( return rv; } -bool uxr_close_udp_transport(uxrUDPTransport* transport) +bool uxr_close_udp_transport( + uxrUDPTransport* transport) { - return uxr_close_udp_platform(transport->platform); + return uxr_close_udp_platform(&transport->platform); } diff --git a/src/c/profile/transport/ip/udp/udp_transport_external.c.template b/src/c/profile/transport/ip/udp/udp_transport_external.c.template deleted file mode 100644 index 8f7d985b5..000000000 --- a/src/c/profile/transport/ip/udp/udp_transport_external.c.template +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include "udp_transport_internal.h" - -// Place here your includes - -bool uxr_init_udp_platform( - uxrUDPPlatform* platform, - uxrIpProtocol ip_protocol, - const char* ip, - const char* port) -{ - // Place here your initialization platform code - // Return true if success -} - -bool uxr_close_udp_platform( - uxrUDPPlatform* platform) -{ - // Place here your closing platform code - // Return true if success -} - -size_t uxr_write_udp_data_platform( - uxrUDPPlatform* platform, - const uint8_t* buf, - size_t len, - uint8_t* errcode) -{ - // Place here your writing bytes platform code - // Return number of bytes written -} - -size_t uxr_read_udp_data_platform( - uxrUDPPlatform* platform, - uint8_t* buf, - size_t len, - int timeout, - uint8_t* errcode) -{ - // Place here your reading bytes platform code - // Return number of bytes read (max bytes: len) -} diff --git a/src/c/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.c b/src/c/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.c new file mode 100644 index 000000000..3facab1ea --- /dev/null +++ b/src/c/profile/transport/ip/udp/udp_transport_freertos_plus_tcp.c @@ -0,0 +1,121 @@ +// Copyright 2018 eSOL Co.,Ltd. +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include "udp_transport_internal.h" +#include "FreeRTOS_Sockets.h" + +#include +#include +#include + +bool uxr_init_udp_platform( + uxrUDPPlatform* platform, + uxrIpProtocol ip_protocol, + const char* ip, + const char* port) +{ + bool rv = false; + uint16_t iport; + + (void) ip_protocol; + iport = (uint16_t)atoi(port); + + /* Socket initialization */ + platform->fd = FreeRTOS_socket(FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP); + if (FREERTOS_INVALID_SOCKET != platform->fd) + { + /* Remote IP setup. */ + platform->remote_addr.sin_family = FREERTOS_AF_INET; + platform->remote_addr.sin_port = FreeRTOS_htons(iport); + platform->remote_addr.sin_addr = FreeRTOS_inet_addr(ip); + + /* Poll setup. */ + platform->poll_fd = FreeRTOS_CreateSocketSet(); + if (NULL != platform->poll_fd) + { + /* FreeRTOS_FD_SET() is a void function. */ + FreeRTOS_FD_SET(platform->fd, platform->poll_fd, eSELECT_READ); + rv = true; + } + } + + return rv; +} + +bool uxr_close_udp_platform( + uxrUDPPlatform* platform) +{ + /* FreeRTOS_closesocket() always returns 0. */ + (void) FreeRTOS_closesocket(platform->fd); + + return true; +} + +size_t uxr_write_udp_data_platform( + uxrUDPPlatform* platform, + const uint8_t* buf, + size_t len, + uint8_t* errcode) +{ + size_t rv = 0; + + int32_t bytes_sent = FreeRTOS_sendto(platform->fd, (const void*)buf, len, 0, + &platform->remote_addr, sizeof(platform->remote_addr)); + + /* FreeRTOS_sendto() returns 0 if an error or timeout occurred. */ + if (0 < bytes_sent) + { + rv = (size_t)bytes_sent; + *errcode = 0; + } + else + { + *errcode = 1; + } + + return rv; +} + +size_t uxr_read_udp_data_platform( + uxrUDPPlatform* platform, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode) +{ + size_t rv = 0; + + BaseType_t poll_rv = FreeRTOS_select(platform->poll_fd, pdMS_TO_TICKS(timeout)); + if (0 < poll_rv) + { + int32_t bytes_received = FreeRTOS_recvfrom(platform->fd, (void*)buf, len, 0, NULL, NULL); + if (0 <= bytes_received) + { + rv = (size_t)bytes_received; + *errcode = 0; + } + else + { + *errcode = 1; + } + } + else + { + *errcode = (0 == poll_rv) ? 0 : 1; + } + + return rv; +} diff --git a/src/c/profile/transport/ip/udp/udp_transport_internal.h b/src/c/profile/transport/ip/udp/udp_transport_internal.h index c8ff1aad3..b29aced39 100644 --- a/src/c/profile/transport/ip/udp/udp_transport_internal.h +++ b/src/c/profile/transport/ip/udp/udp_transport_internal.h @@ -18,7 +18,7 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include @@ -46,6 +46,6 @@ size_t uxr_read_udp_data_platform( #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // SRC_C_PROFILE_TRANSPORT_UDP_UDP_TRANSPORT_INTERNAL_H_ diff --git a/src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c b/src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c index 0f405cba9..a566db7da 100644 --- a/src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c +++ b/src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -47,7 +48,7 @@ bool uxr_init_udp_platform( if (0 == getaddrinfo(ip, port, &hints, &result)) { for (ptr = result; ptr != NULL; ptr = ptr->ai_next) - { + { if (0 == connect(platform->fd, ptr->ai_addr, ptr->ai_addrlen)) { rv = true; @@ -95,9 +96,11 @@ size_t uxr_read_udp_data_platform( { size_t rv = 0; + timeout = (timeout <= 0) ? 1 : timeout; + struct timeval tv; tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; + tv.tv_usec = (timeout % 1000) * 1000; setsockopt(platform->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); @@ -111,6 +114,6 @@ size_t uxr_read_udp_data_platform( { *errcode = 1; } - + return rv; } diff --git a/src/c/profile/transport/serial/serial_protocol.c b/src/c/profile/transport/serial/serial_protocol.c deleted file mode 100644 index c9bfe18c2..000000000 --- a/src/c/profile/transport/serial/serial_protocol.c +++ /dev/null @@ -1,442 +0,0 @@ -#include "serial_protocol_internal.h" -#include - -/******************************************************************************* - * Static members. - *******************************************************************************/ -// CRC-16 table for POLY 0x8005 (x^16 + x^15 + x^2 + 1). -static const uint16_t crc16_table[256] = { - 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, - 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, - 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, - 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, - 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, - 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, - 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, - 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, - 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, - 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, - 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, - 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, - 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, - 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, - 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, - 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, - 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, - 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, - 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, - 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, - 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, - 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, - 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, - 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, - 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, - 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, - 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, - 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, - 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, - 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, - 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, - 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 -}; - -/******************************************************************************* - * Public function definitions. - *******************************************************************************/ -void uxr_update_crc(uint16_t* crc, const uint8_t data) -{ - *crc = (*crc >> 8) ^ crc16_table[(*crc ^ data) & 0xFF]; -} - -bool uxr_get_next_octet(uxrSerialIO* serial_io, uint8_t* octet) -{ - bool rv = false; - *octet = 0; - if (serial_io->rb_head != serial_io->rb_tail) - { - if (UXR_FRAMING_ESC_FLAG != serial_io->rb[serial_io->rb_tail]) - { - *octet = serial_io->rb[serial_io->rb_tail]; - serial_io->rb_tail = (uint8_t)((size_t)(serial_io->rb_tail + 1) % sizeof(serial_io->rb)); - rv = (UXR_FRAMING_BEGIN_FLAG != *octet); - } - else - { - uint8_t temp_tail = (uint8_t)((size_t)(serial_io->rb_tail + 1) % sizeof(serial_io->rb)); - if (temp_tail != serial_io->rb_head) - { - *octet = serial_io->rb[temp_tail]; - serial_io->rb_tail = (uint8_t)((size_t)(serial_io->rb_tail + 2) % sizeof(serial_io->rb)); - if (UXR_FRAMING_BEGIN_FLAG != *octet) - { - *octet ^= UXR_FRAMING_XOR_FLAG; - rv = true; - } - } - } - } - return rv; -} - -bool uxr_add_next_octet(uxrSerialIO* serial_io, uint8_t octet) -{ - bool rv = false; - - if (UXR_FRAMING_BEGIN_FLAG == octet || UXR_FRAMING_ESC_FLAG == octet) - { - if ((uint8_t)(serial_io->wb_pos + 1) < sizeof(serial_io->wb)) - { - serial_io->wb[serial_io->wb_pos] = UXR_FRAMING_ESC_FLAG; - serial_io->wb[serial_io->wb_pos + 1] = octet ^ UXR_FRAMING_XOR_FLAG; - serial_io->wb_pos = (uint8_t)(serial_io->wb_pos + 2); - rv = true; - } - } - else - { - if (serial_io->wb_pos < sizeof(serial_io->wb)) - { - serial_io->wb[serial_io->wb_pos] = octet; - serial_io->wb_pos = (uint8_t)(serial_io->wb_pos + 1); - rv = true; - } - } - - return rv; -} - -void uxr_init_serial_io(uxrSerialIO* serial_io, uint8_t local_addr) -{ - serial_io->local_addr = local_addr; - serial_io->state = UXR_SERIAL_UNINITIALIZED; - serial_io->rb_head = 0; - serial_io->rb_tail = 0; -} - -size_t uxr_write_serial_msg(uxrSerialIO* serial_io, - uxr_write_cb write_cb, - void* cb_arg, - const uint8_t* buf, - size_t len, - uint8_t remote_addr, - uint8_t* errcode) -{ - /* Buffer being flag. */ - serial_io->wb[0] = UXR_FRAMING_BEGIN_FLAG; - serial_io->wb_pos = 1; - - /* Buffer header. */ - uxr_add_next_octet(serial_io, serial_io->local_addr); - uxr_add_next_octet(serial_io, remote_addr); - uxr_add_next_octet(serial_io, (uint8_t)(len & 0xFF)); - uxr_add_next_octet(serial_io, (uint8_t)(len >> 8)); - - /* Write payload. */ - uint8_t octet = 0; - uint16_t written_len = 0; - uint16_t crc = 0; - bool cond = true; - while (written_len < len && cond) - { - octet = *(buf + written_len); - if (uxr_add_next_octet(serial_io, octet)) - { - uxr_update_crc(&crc, octet); - ++written_len; - } - else - { - size_t bytes_written = write_cb(cb_arg, serial_io->wb, serial_io->wb_pos, errcode); - if (0 < bytes_written) - { - cond = true; - serial_io->wb_pos = (uint8_t)(serial_io->wb_pos - bytes_written); - } - else - { - cond = false; - } - } - } - - /* Write CRC. */ - uint8_t tmp_crc[2]; - tmp_crc[0] = (uint8_t)(crc & 0xFF); - tmp_crc[1] = (uint8_t)(crc >> 8); - written_len = 0; - while (written_len < sizeof(tmp_crc) && cond) - { - octet = *(tmp_crc + written_len); - if (uxr_add_next_octet(serial_io, octet)) - { - uxr_update_crc(&crc, octet); - ++written_len; - } - else - { - size_t bytes_written = write_cb(cb_arg, serial_io->wb, serial_io->wb_pos, errcode); - if (0 < bytes_written) - { - cond = true; - serial_io->wb_pos = (uint8_t)(serial_io->wb_pos - bytes_written); - } - else - { - cond = false; - } - } - } - - /* Flus write buffer. */ - if (cond && (0 < serial_io->wb_pos)) - { - size_t bytes_written = write_cb(cb_arg, serial_io->wb, serial_io->wb_pos, errcode); - if (0 < bytes_written) - { - cond = true; - serial_io->wb_pos = (uint8_t)(serial_io->wb_pos - bytes_written); - } - else - { - cond = false; - } - } - - return cond ? (uint16_t)(len) : 0; -} - -size_t uxr_read_serial_msg(uxrSerialIO* serial_io, - uxr_read_cb read_cb, - void* cb_arg, - uint8_t* buf, - size_t len, - uint8_t* remote_addr, - int timeout, - uint8_t* errcode) -{ - size_t rv = 0; - - /* Compute read-buffer available size. */ - uint8_t av_len[2] = {0, 0}; - if (serial_io->rb_head == serial_io->rb_tail) - { - serial_io->rb_head = 0; - serial_io->rb_tail = 0; - av_len[0] = sizeof(serial_io->rb) - 1; - } - else if (serial_io->rb_head > serial_io->rb_tail) - { - if (0 < serial_io->rb_tail) - { - av_len[0] = (uint8_t)(sizeof(serial_io->rb) - serial_io->rb_head); - av_len[1] = (uint8_t)(serial_io->rb_tail - 1); - } - else - { - av_len[0] = (uint8_t)(sizeof(serial_io->rb) - serial_io->rb_head - 1); - } - } - else - { - av_len[0] = (uint8_t)(serial_io->rb_tail - serial_io->rb_head - 1); - } - - /* Read from serial. */ - size_t bytes_read[2] = {0}; - if (0 < av_len[0]) - { - bytes_read[0] = read_cb(cb_arg, &serial_io->rb[serial_io->rb_head], av_len[0], timeout, errcode); - serial_io->rb_head = (uint8_t)((size_t)(serial_io->rb_head + bytes_read[0]) % sizeof(serial_io->rb)); - if (0 < bytes_read[0]) - { - if ((bytes_read[0] == av_len[0]) && (0 < av_len[1])) - { - bytes_read[1] = read_cb(cb_arg, &serial_io->rb[serial_io->rb_head], av_len[1], 0, errcode); - serial_io->rb_head = (uint8_t)((size_t)(serial_io->rb_head + bytes_read[1]) % sizeof(serial_io->rb)); - } - } - } - - if (0 < (bytes_read[0] + bytes_read[1]) || (serial_io->rb_tail != serial_io->rb_head)) - { - /* State Machine. */ - bool exit_cond = false; - while (!exit_cond) - { - uint8_t octet = 0; - switch (serial_io->state) - { - case UXR_SERIAL_UNINITIALIZED: - { - octet = 0; - while ((UXR_FRAMING_BEGIN_FLAG != octet) && (serial_io->rb_head != serial_io->rb_tail)) - { - octet = serial_io->rb[serial_io->rb_tail]; - serial_io->rb_tail = (uint8_t)((size_t)(serial_io->rb_tail + 1) % sizeof(serial_io->rb)); - } - - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - break; - } - case UXR_SERIAL_READING_SRC_ADDR: - { - if (uxr_get_next_octet(serial_io, &serial_io->src_addr)) - { - serial_io->state = UXR_SERIAL_READING_DST_ADDR; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG != serial_io->src_addr) - { - exit_cond = true; - } - } - break; - } - case UXR_SERIAL_READING_DST_ADDR: - if (uxr_get_next_octet(serial_io, &octet)) - { - serial_io->state = (octet == serial_io->local_addr) ? UXR_SERIAL_READING_LEN_LSB : - UXR_SERIAL_UNINITIALIZED; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - case UXR_SERIAL_READING_LEN_LSB: - if (uxr_get_next_octet(serial_io, &octet)) - { - serial_io->msg_len = octet; - serial_io->state = UXR_SERIAL_READING_LEN_MSB; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - case UXR_SERIAL_READING_LEN_MSB: - if (uxr_get_next_octet(serial_io, &octet)) - { - serial_io->msg_len = (uint16_t)(serial_io->msg_len + (octet << 8)); - serial_io->msg_pos = 0; - serial_io->cmp_crc = 0; - if (len < serial_io->msg_len) - { - serial_io->state = UXR_SERIAL_UNINITIALIZED; - exit_cond = true; - } - else - { - serial_io->state = UXR_SERIAL_READING_PAYLOAD; - } - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - case UXR_SERIAL_READING_PAYLOAD: - { - while ((serial_io->msg_pos < serial_io->msg_len) && uxr_get_next_octet(serial_io, &octet)) - { - buf[(size_t)serial_io->msg_pos] = octet; - serial_io->msg_pos = (uint16_t)(serial_io->msg_pos + 1); - uxr_update_crc(&serial_io->cmp_crc, octet); - } - - if (serial_io->msg_pos == serial_io->msg_len) - { - serial_io->state = UXR_SERIAL_READING_CRC_LSB; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - } - case UXR_SERIAL_READING_CRC_LSB: - if (uxr_get_next_octet(serial_io, &octet)) - { - serial_io->msg_crc = octet; - serial_io->state = UXR_SERIAL_READING_CRC_MSB; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - case UXR_SERIAL_READING_CRC_MSB: - if (uxr_get_next_octet(serial_io, &octet)) - { - serial_io->msg_crc = (uint16_t)(serial_io->msg_crc + (octet << 8)); - serial_io->state = UXR_SERIAL_UNINITIALIZED; - if (serial_io->cmp_crc == serial_io->msg_crc) - { - *remote_addr = serial_io->src_addr; - rv = serial_io->msg_len; - } - exit_cond = true; - } - else - { - if (UXR_FRAMING_BEGIN_FLAG == octet) - { - serial_io->state = UXR_SERIAL_READING_SRC_ADDR; - } - else - { - exit_cond = true; - } - } - break; - default: - break; - } - } - } - - return rv; -} diff --git a/src/c/profile/transport/serial/serial_protocol_internal.h b/src/c/profile/transport/serial/serial_protocol_internal.h deleted file mode 100644 index bbf621bdc..000000000 --- a/src/c/profile/transport/serial/serial_protocol_internal.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ -#define _SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ -#ifdef __cplusplus -extern "C" -{ -#endif - -#include -#include -#include - -#define UXR_FRAMING_BEGIN_FLAG 0x7E -#define UXR_FRAMING_ESC_FLAG 0x7D -#define UXR_FRAMING_XOR_FLAG 0x20 - -void uxr_init_serial_io(uxrSerialIO* serial_io, uint8_t local_addr); - -void uxr_update_crc(uint16_t* crc, const uint8_t data); -bool uxr_get_next_octet(uxrSerialIO* serial_io, uint8_t* octet); -bool uxr_add_next_octet(uxrSerialIO* serial_io, uint8_t octet); - -struct uxrSerialPlatform; -typedef size_t (*uxr_write_cb)(struct uxrSerialPlatform*, uint8_t*, size_t, uint8_t*); -typedef size_t (*uxr_read_cb)(struct uxrSerialPlatform*, uint8_t*, size_t, int, uint8_t*); - -size_t uxr_write_serial_msg(uxrSerialIO* serial_io, - uxr_write_cb write_cb, - void* cb_arg, - const uint8_t* buf, - size_t len, - uint8_t remote_addr, - uint8_t* errcode); - -size_t uxr_read_serial_msg(uxrSerialIO* serial_io, - uxr_read_cb read_cb, - void* cb_arg, - uint8_t* buf, - size_t len, - uint8_t* remote_addr, - int timeout, - uint8_t* errcode); - -#ifdef __cplusplus -} -#endif - -#endif //_SRC_C_PROFILE_TRANSPORT_SERIAL_SERIAL_PROTOCOL_INTERNAL_H_ diff --git a/src/c/profile/transport/serial/serial_transport.c b/src/c/profile/transport/serial/serial_transport.c index 4ab0c9ed7..747ed272f 100644 --- a/src/c/profile/transport/serial/serial_transport.c +++ b/src/c/profile/transport/serial/serial_transport.c @@ -1,35 +1,46 @@ #include -#include "serial_protocol_internal.h" +#include "../stream_framing/stream_framing_protocol.h" #include /******************************************************************************* - * Static members. - *******************************************************************************/ +* Static members. +*******************************************************************************/ static uint8_t error_code; /******************************************************************************* - * Private function declarations. - *******************************************************************************/ -static bool send_serial_msg(void* instance, const uint8_t* buf, size_t len); -static bool recv_serial_msg(void* instance, uint8_t** buf, size_t* len, int timeout); -static uint8_t get_serial_error(void); +* Private function declarations. +*******************************************************************************/ +static bool send_serial_msg( + void* instance, + const uint8_t* buf, + size_t len); +static bool recv_serial_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout); +static uint8_t get_serial_error( + void); /******************************************************************************* - * Private function definitions. - *******************************************************************************/ -static bool send_serial_msg(void* instance, const uint8_t* buf, size_t len) +* Private function definitions. +*******************************************************************************/ +static bool send_serial_msg( + void* instance, + const uint8_t* buf, + size_t len) { bool rv = false; uxrSerialTransport* transport = (uxrSerialTransport*)instance; uint8_t errcode; - size_t bytes_written = uxr_write_serial_msg(&transport->serial_io, - uxr_write_serial_data_platform, - transport->platform, - buf, - len, - transport->remote_addr, - &errcode); + size_t bytes_written = uxr_write_framed_msg(&transport->framing_io, + uxr_write_serial_data_platform, + &transport->platform, + buf, + len, + transport->remote_addr, + &errcode); if ((0 < bytes_written) && (bytes_written == len)) { rv = true; @@ -42,7 +53,11 @@ static bool send_serial_msg(void* instance, const uint8_t* buf, size_t len) return rv; } -static bool recv_serial_msg(void* instance, uint8_t** buf, size_t* len, int timeout) +static bool recv_serial_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout) { bool rv = false; uxrSerialTransport* transport = (uxrSerialTransport*)instance; @@ -53,14 +68,14 @@ static bool recv_serial_msg(void* instance, uint8_t** buf, size_t* len, int time int64_t time_init = uxr_millis(); uint8_t remote_addr; uint8_t errcode; - bytes_read = uxr_read_serial_msg(&transport->serial_io, - uxr_read_serial_data_platform, - transport->platform, - transport->buffer, - sizeof(transport->buffer), - &remote_addr, - timeout, - &errcode); + bytes_read = uxr_read_framed_msg(&transport->framing_io, + uxr_read_serial_data_platform, + &transport->platform, + transport->buffer, + sizeof(transport->buffer), + &remote_addr, + timeout, + &errcode); if ((0 < bytes_read) && (remote_addr == transport->remote_addr)) { *len = bytes_read; @@ -78,31 +93,29 @@ static bool recv_serial_msg(void* instance, uint8_t** buf, size_t* len, int time return rv; } -static uint8_t get_serial_error(void) +static uint8_t get_serial_error( + void) { return error_code; } /******************************************************************************* - * Public function definitions. - *******************************************************************************/ -bool uxr_init_serial_transport(uxrSerialTransport* transport, - struct uxrSerialPlatform* platfrom, - const int fd, - uint8_t remote_addr, - uint8_t local_addr) +* Public function definitions. +*******************************************************************************/ +bool uxr_init_serial_transport( + uxrSerialTransport* transport, + const int fd, + uint8_t remote_addr, + uint8_t local_addr) { bool rv = false; - if (uxr_init_serial_platform(platfrom, fd, remote_addr, local_addr)) + if (uxr_init_serial_platform(&transport->platform, fd, remote_addr, local_addr)) { - /* Setup platform. */ - transport->platform = platfrom; - /* Setup address. */ transport->remote_addr = remote_addr; - /* Init SerialIO. */ - uxr_init_serial_io(&transport->serial_io, local_addr); + /* Init FramingIO. */ + uxr_init_framing_io(&transport->framing_io, local_addr); /* Setup interface. */ transport->comm.instance = (void*)transport; @@ -116,7 +129,8 @@ bool uxr_init_serial_transport(uxrSerialTransport* transport, return rv; } -bool uxr_close_serial_transport(uxrSerialTransport* transport) +bool uxr_close_serial_transport( + uxrSerialTransport* transport) { - return uxr_close_serial_platform(transport->platform); + return uxr_close_serial_platform(&transport->platform); } diff --git a/src/c/profile/transport/serial/serial_transport_external.c.template b/src/c/profile/transport/serial/serial_transport_external.c.template deleted file mode 100644 index 295c4dd24..000000000 --- a/src/c/profile/transport/serial/serial_transport_external.c.template +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -// Place here your includes - -bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, int fd, uint8_t remote_addr, uint8_t local_addr) -{ - // Place here your initialization platform code - // Return true if success -} - -bool uxr_close_serial_platform(struct uxrSerialPlatform* platform) -{ - // Place here your closing platform code - // Return true if success -} - -size_t uxr_write_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, uint8_t* errcode) -{ - // Place here your writing bytes platform code - // Return number of bytes written -} - -size_t uxr_read_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, int timeout, uint8_t* errcode) -{ - // Place here your reading bytes platform code - // Return number of bytes read (max bytes: len) -} diff --git a/src/c/profile/transport/serial/serial_transport_posix.c b/src/c/profile/transport/serial/serial_transport_posix.c index 3c311c05e..6e7e885cc 100644 --- a/src/c/profile/transport/serial/serial_transport_posix.c +++ b/src/c/profile/transport/serial/serial_transport_posix.c @@ -4,11 +4,17 @@ #include #include -bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, int fd, uint8_t remote_addr, uint8_t local_addr) +bool uxr_init_serial_platform( + void* args, + int fd, + uint8_t remote_addr, + uint8_t local_addr) { (void) remote_addr; (void) local_addr; + struct uxrSerialPlatform* platform = (struct uxrSerialPlatform*) args; + /* Poll setup. */ platform->poll_fd.fd = fd; platform->poll_fd.events = POLLIN; @@ -16,14 +22,21 @@ bool uxr_init_serial_platform(struct uxrSerialPlatform* platform, int fd, uint8_ return true; } -bool uxr_close_serial_platform(struct uxrSerialPlatform* platform) +bool uxr_close_serial_platform( + void* args) { + struct uxrSerialPlatform* platform = (struct uxrSerialPlatform*) args; return (-1 == platform->poll_fd.fd) ? true : (0 == close(platform->poll_fd.fd)); } -size_t uxr_write_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, uint8_t* errcode) +size_t uxr_write_serial_data_platform( + void* args, + const uint8_t* buf, + size_t len, + uint8_t* errcode) { size_t rv = 0; + struct uxrSerialPlatform* platform = (struct uxrSerialPlatform*) args; ssize_t bytes_written = write(platform->poll_fd.fd, (void*)buf, (size_t)len); if (-1 != bytes_written) @@ -38,9 +51,15 @@ size_t uxr_write_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, return rv; } -size_t uxr_read_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, size_t len, int timeout, uint8_t* errcode) +size_t uxr_read_serial_data_platform( + void* args, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* errcode) { size_t rv = 0; + struct uxrSerialPlatform* platform = (struct uxrSerialPlatform*) args; int poll_rv = poll(&platform->poll_fd, 1, timeout); if (0 < poll_rv) @@ -62,4 +81,3 @@ size_t uxr_read_serial_data_platform(uxrSerialPlatform* platform, uint8_t* buf, } return rv; } - diff --git a/src/c/profile/transport/serial/serial_transport_windows.c b/src/c/profile/transport/serial/serial_transport_windows.c deleted file mode 100644 index d16843e6f..000000000 --- a/src/c/profile/transport/serial/serial_transport_windows.c +++ /dev/null @@ -1,2 +0,0 @@ -#include -#include diff --git a/src/c/profile/transport/stream_framing/stream_framing_protocol.c b/src/c/profile/transport/stream_framing/stream_framing_protocol.c new file mode 100644 index 000000000..0ad58a3d8 --- /dev/null +++ b/src/c/profile/transport/stream_framing/stream_framing_protocol.c @@ -0,0 +1,483 @@ +#include +#include "stream_framing_protocol.h" +#include + +/******************************************************************************* +* Static members. +*******************************************************************************/ +// CRC-16 table for POLY 0x8005 (x^16 + x^15 + x^2 + 1). +static const uint16_t crc16_table[256] = { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 +}; + +/******************************************************************************* +* Public function definitions. +*******************************************************************************/ +void uxr_update_crc( + uint16_t* crc, + const uint8_t data) +{ + *crc = (*crc >> 8) ^ crc16_table[(*crc ^ data) & 0xFF]; +} + +bool uxr_get_next_octet( + uxrFramingIO* framing_io, + uint8_t* octet) +{ + bool rv = false; + *octet = 0; + if (framing_io->rb_head != framing_io->rb_tail) + { + if (UXR_FRAMING_ESC_FLAG != framing_io->rb[framing_io->rb_tail]) + { + *octet = framing_io->rb[framing_io->rb_tail]; + framing_io->rb_tail = (uint8_t)((size_t)(framing_io->rb_tail + 1) % sizeof(framing_io->rb)); + rv = (UXR_FRAMING_BEGIN_FLAG != *octet); + } + else + { + uint8_t temp_tail = (uint8_t)((size_t)(framing_io->rb_tail + 1) % sizeof(framing_io->rb)); + if (temp_tail != framing_io->rb_head) + { + *octet = framing_io->rb[temp_tail]; + framing_io->rb_tail = (uint8_t)((size_t)(framing_io->rb_tail + 2) % sizeof(framing_io->rb)); + if (UXR_FRAMING_BEGIN_FLAG != *octet) + { + *octet ^= UXR_FRAMING_XOR_FLAG; + rv = true; + } + } + } + } + return rv; +} + +bool uxr_add_next_octet( + uxrFramingIO* framing_io, + uint8_t octet) +{ + bool rv = false; + + if (UXR_FRAMING_BEGIN_FLAG == octet || UXR_FRAMING_ESC_FLAG == octet) + { + if ((uint8_t)(framing_io->wb_pos + 1) < sizeof(framing_io->wb)) + { + framing_io->wb[framing_io->wb_pos] = UXR_FRAMING_ESC_FLAG; + framing_io->wb[framing_io->wb_pos + 1] = octet ^ UXR_FRAMING_XOR_FLAG; + framing_io->wb_pos = (uint8_t)(framing_io->wb_pos + 2); + rv = true; + } + } + else + { + if (framing_io->wb_pos < sizeof(framing_io->wb)) + { + framing_io->wb[framing_io->wb_pos] = octet; + framing_io->wb_pos = (uint8_t)(framing_io->wb_pos + 1); + rv = true; + } + } + + return rv; +} + +void uxr_init_framing_io( + uxrFramingIO* framing_io, + uint8_t local_addr) +{ + framing_io->local_addr = local_addr; + framing_io->state = UXR_FRAMING_UNINITIALIZED; + framing_io->rb_head = 0; + framing_io->rb_tail = 0; +} + +bool uxr_framing_write_transport( + uxrFramingIO* framing_io, + uxr_write_cb write_cb, + void* cb_arg, + uint8_t* errcode) +{ + size_t bytes_written = 0; + size_t last_written = 0; + + do + { + last_written = write_cb(cb_arg, &framing_io->wb[bytes_written], framing_io->wb_pos - bytes_written, errcode); + bytes_written += last_written; + } while (bytes_written < framing_io->wb_pos && 0 < last_written); + + if (bytes_written == framing_io->wb_pos) + { + framing_io->wb_pos = 0; + return true; + } + return false; +} + +size_t uxr_write_framed_msg( + uxrFramingIO* framing_io, + uxr_write_cb write_cb, + void* cb_arg, + const uint8_t* buf, + size_t len, + uint8_t remote_addr, + uint8_t* errcode) +{ + /* Buffer being flag. */ + framing_io->wb[0] = UXR_FRAMING_BEGIN_FLAG; + framing_io->wb_pos = 1; + + /* Buffer header. */ + uxr_add_next_octet(framing_io, framing_io->local_addr); + uxr_add_next_octet(framing_io, remote_addr); + uxr_add_next_octet(framing_io, (uint8_t)(len & 0xFF)); + uxr_add_next_octet(framing_io, (uint8_t)(len >> 8)); + + /* Write payload. */ + uint8_t octet = 0; + uint16_t written_len = 0; + uint16_t crc = 0; + bool cond = true; + while (written_len < len && cond) + { + octet = *(buf + written_len); + if (uxr_add_next_octet(framing_io, octet)) + { + uxr_update_crc(&crc, octet); + ++written_len; + } + else + { + cond = uxr_framing_write_transport(framing_io, write_cb, cb_arg, errcode); + } + } + + /* Write CRC. */ + uint8_t tmp_crc[2]; + tmp_crc[0] = (uint8_t)(crc & 0xFF); + tmp_crc[1] = (uint8_t)(crc >> 8); + written_len = 0; + while (written_len < sizeof(tmp_crc) && cond) + { + octet = *(tmp_crc + written_len); + if (uxr_add_next_octet(framing_io, octet)) + { + uxr_update_crc(&crc, octet); + ++written_len; + } + else + { + cond = uxr_framing_write_transport(framing_io, write_cb, cb_arg, errcode); + } + } + + /* Flush write buffer. */ + if (cond && (0 < framing_io->wb_pos)) + { + cond = uxr_framing_write_transport(framing_io, write_cb, cb_arg, errcode); + } + + return cond ? (uint16_t)(len) : 0; +} + +size_t uxr_framing_read_transport( + uxrFramingIO* framing_io, + uxr_read_cb read_cb, + void* cb_arg, + int* timeout, + uint8_t* errcode) +{ + int64_t time_init = uxr_millis(); + + /* Compute read-buffer available size. */ + uint8_t av_len[2] = { + 0, 0 + }; + if (framing_io->rb_head == framing_io->rb_tail) + { + framing_io->rb_head = 0; + framing_io->rb_tail = 0; + av_len[0] = sizeof(framing_io->rb) - 1; + } + else if (framing_io->rb_head > framing_io->rb_tail) + { + if (0 < framing_io->rb_tail) + { + av_len[0] = (uint8_t)(sizeof(framing_io->rb) - framing_io->rb_head); + av_len[1] = (uint8_t)(framing_io->rb_tail - 1); + } + else + { + av_len[0] = (uint8_t)(sizeof(framing_io->rb) - framing_io->rb_head - 1); + } + } + else + { + av_len[0] = (uint8_t)(framing_io->rb_tail - framing_io->rb_head - 1); + } + + /* Read */ + size_t bytes_read[2] = { + 0 + }; + if (0 < av_len[0]) + { + bytes_read[0] = read_cb(cb_arg, &framing_io->rb[framing_io->rb_head], av_len[0], *timeout, errcode); + framing_io->rb_head = (uint8_t)((size_t)(framing_io->rb_head + bytes_read[0]) % sizeof(framing_io->rb)); + if (0 < bytes_read[0]) + { + if ((bytes_read[0] == av_len[0]) && (0 < av_len[1])) + { + bytes_read[1] = read_cb(cb_arg, &framing_io->rb[framing_io->rb_head], av_len[1], 0, errcode); + framing_io->rb_head = (uint8_t)((size_t)(framing_io->rb_head + bytes_read[1]) % sizeof(framing_io->rb)); + } + } + } + + *timeout -= (int)(uxr_millis() - time_init); + *timeout = (0 > *timeout) ? 0 : *timeout; + return bytes_read[0] + bytes_read[1]; +} + +size_t uxr_read_framed_msg( + uxrFramingIO* framing_io, + uxr_read_cb read_cb, + void* cb_arg, + uint8_t* buf, + size_t len, + uint8_t* remote_addr, + int timeout, + uint8_t* errcode) +{ + size_t rv = 0; + + size_t readed_bytes = uxr_framing_read_transport(framing_io, read_cb, cb_arg, &timeout, errcode); + + if (0 < readed_bytes || (framing_io->rb_tail != framing_io->rb_head)) + { + /* State Machine. */ + bool exit_cond = false; + while (!exit_cond) + { + uint8_t octet = 0; + switch (framing_io->state) + { + case UXR_FRAMING_UNINITIALIZED: + { + octet = 0; + while ((UXR_FRAMING_BEGIN_FLAG != octet) && (framing_io->rb_head != framing_io->rb_tail)) + { + octet = framing_io->rb[framing_io->rb_tail]; + framing_io->rb_tail = (uint8_t)((size_t)(framing_io->rb_tail + 1) % sizeof(framing_io->rb)); + } + + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + break; + } + case UXR_FRAMING_READING_SRC_ADDR: + { + if (uxr_get_next_octet(framing_io, &framing_io->src_addr)) + { + framing_io->state = UXR_FRAMING_READING_DST_ADDR; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG != framing_io->src_addr) + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_DST_ADDR: + { + if (uxr_get_next_octet(framing_io, &octet)) + { + framing_io->state = (octet == framing_io->local_addr) ? UXR_FRAMING_READING_LEN_LSB : + UXR_FRAMING_UNINITIALIZED; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_LEN_LSB: + { + if (uxr_get_next_octet(framing_io, &octet)) + { + framing_io->msg_len = octet; + framing_io->state = UXR_FRAMING_READING_LEN_MSB; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_LEN_MSB: + { + if (uxr_get_next_octet(framing_io, &octet)) + { + framing_io->msg_len = (uint16_t)(framing_io->msg_len + (octet << 8)); + framing_io->msg_pos = 0; + framing_io->cmp_crc = 0; + if (len < framing_io->msg_len) + { + framing_io->state = UXR_FRAMING_UNINITIALIZED; + exit_cond = true; + } + else + { + framing_io->state = UXR_FRAMING_READING_PAYLOAD; + } + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_PAYLOAD: + { + while ((framing_io->msg_pos < framing_io->msg_len) && uxr_get_next_octet(framing_io, &octet)) + { + buf[(size_t)framing_io->msg_pos] = octet; + framing_io->msg_pos = (uint16_t)(framing_io->msg_pos + 1); + uxr_update_crc(&framing_io->cmp_crc, octet); + } + + if (framing_io->msg_pos == framing_io->msg_len) + { + framing_io->state = UXR_FRAMING_READING_CRC_LSB; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, &timeout, errcode)) + { + + } + else + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_CRC_LSB: + { + if (uxr_get_next_octet(framing_io, &octet)) + { + framing_io->msg_crc = octet; + framing_io->state = UXR_FRAMING_READING_CRC_MSB; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + } + break; + } + case UXR_FRAMING_READING_CRC_MSB: + { + if (uxr_get_next_octet(framing_io, &octet)) + { + framing_io->msg_crc = (uint16_t)(framing_io->msg_crc + (octet << 8)); + framing_io->state = UXR_FRAMING_UNINITIALIZED; + if (framing_io->cmp_crc == framing_io->msg_crc) + { + *remote_addr = framing_io->src_addr; + rv = framing_io->msg_len; + } + exit_cond = true; + } + else + { + if (UXR_FRAMING_BEGIN_FLAG == octet) + { + framing_io->state = UXR_FRAMING_READING_SRC_ADDR; + } + else + { + exit_cond = true; + } + } + break; + } + default: + break; + } + } + } + + return rv; +} diff --git a/src/c/profile/transport/stream_framing/stream_framing_protocol.h b/src/c/profile/transport/stream_framing/stream_framing_protocol.h new file mode 100644 index 000000000..eb8bd0ec3 --- /dev/null +++ b/src/c/profile/transport/stream_framing/stream_framing_protocol.h @@ -0,0 +1,79 @@ +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _SRC_C_PROFILE_TRANSPORT_FRAMING_PROTOCOL_INTERNAL_H_ +#define _SRC_C_PROFILE_TRANSPORT_FRAMING_PROTOCOL_INTERNAL_H_ +#ifdef __cplusplus +extern "C" +{ +#endif // ifdef __cplusplus + +#include +#include +#include + +#define UXR_FRAMING_BEGIN_FLAG 0x7E +#define UXR_FRAMING_ESC_FLAG 0x7D +#define UXR_FRAMING_XOR_FLAG 0x20 + +void uxr_init_framing_io( + uxrFramingIO* framing_io, + uint8_t local_addr); + +void uxr_update_crc( + uint16_t* crc, + const uint8_t data); +bool uxr_get_next_octet( + uxrFramingIO* framing_io, + uint8_t* octet); +bool uxr_add_next_octet( + uxrFramingIO* framing_io, + uint8_t octet); + +typedef size_t (* uxr_write_cb)( + void*, + const uint8_t*, + size_t, + uint8_t*); +typedef size_t (* uxr_read_cb)( + void*, + uint8_t*, + size_t, + int, + uint8_t*); + +size_t uxr_write_framed_msg( + uxrFramingIO* framing_io, + uxr_write_cb write_cb, + void* cb_arg, + const uint8_t* buf, + size_t len, + uint8_t remote_addr, + uint8_t* errcode); + +size_t uxr_read_framed_msg( + uxrFramingIO* framing_io, + uxr_read_cb read_cb, + void* cb_arg, + uint8_t* buf, + size_t len, + uint8_t* remote_addr, + int timeout, + uint8_t* errcode); + +#ifdef __cplusplus +} +#endif // ifdef __cplusplus + +#endif //_SRC_C_PROFILE_TRANSPORT_FRAMING_PROTOCOL_INTERNAL_H_ diff --git a/src/c/util/ping.c b/src/c/util/ping.c new file mode 100644 index 000000000..6f19682d9 --- /dev/null +++ b/src/c/util/ping.c @@ -0,0 +1,153 @@ +#include +#include + +#include +#include + +#include "../core/serialization/xrce_header_internal.h" +#include "../core/session/submessage_internal.h" + +bool serialize_get_info_message( + ucdrBuffer* ub); + +bool uxr_acknack_pong( + ucdrBuffer* buffer); + +bool listen_info_message( + const uxrCommunication* comm, + const int timeout); + +//================================================================== +// PUBLIC +//================================================================== +bool uxr_ping_agent_attempts( + const uxrCommunication* comm, + const int timeout, + const uint8_t attempts) +{ + bool agent_pong = false; + uint8_t output_buffer[UXR_PING_BUF]; + ucdrBuffer ub; + ucdr_init_buffer(&ub, output_buffer, sizeof(output_buffer)); + + if (serialize_get_info_message(&ub)) + { + size_t message_length = ucdr_buffer_length(&ub); + + for (size_t i = 0; !agent_pong && i < attempts; ++i) + { + comm->send_msg( + comm->instance, + output_buffer, + message_length); + + int64_t timestamp = uxr_millis(); + int poll = timeout; + + while (0 < poll && !agent_pong) + { + agent_pong = listen_info_message(comm, timeout); + poll -= (int)(uxr_millis() - timestamp); + timestamp = uxr_millis(); + } + } + } + + return agent_pong; +} + +inline bool uxr_ping_agent( + const uxrCommunication* comm, + const int timeout) +{ + return uxr_ping_agent_attempts(comm, timeout, 1); +} + +//================================================================== +// PRIVATE +//================================================================== +bool serialize_get_info_message( + ucdrBuffer* ub) +{ + bool res = true; + GET_INFO_Payload gi_payload; + + gi_payload.base.request_id = (RequestId){{ + 0x00, GET_INFO_REQUEST_ID + } + }; + gi_payload.base.object_id = DDS_XRCE_OBJECTID_AGENT; + gi_payload.info_mask = INFO_ACTIVITY; + + uxr_serialize_message_header(ub, SESSION_ID_WITHOUT_CLIENT_KEY, 0, 0, 0); + res &= uxr_buffer_submessage_header(ub, SUBMESSAGE_ID_GET_INFO, GET_INFO_MSG_SIZE, 0); + res &= uxr_serialize_GET_INFO_Payload(ub, &gi_payload); + + return res; +} + +bool uxr_acknack_pong( + ucdrBuffer* buffer) +{ + bool success = true; + INFO_Payload info_payload; + + success &= uxr_deserialize_BaseObjectReply(buffer, &info_payload.base); + success &= ucdr_deserialize_bool(buffer, &info_payload.object_info.optional_config); + + if (info_payload.object_info.optional_config) + { + success &= uxr_deserialize_ObjectVariant(buffer, &info_payload.object_info.config); + } + + success &= ucdr_deserialize_bool(buffer, &info_payload.object_info.optional_activity); + if (info_payload.object_info.optional_activity) + { + success &= ucdr_deserialize_uint8_t(buffer, &info_payload.object_info.activity.kind); + if (success && DDS_XRCE_OBJK_AGENT == info_payload.object_info.activity.kind) + { + success &= ucdr_deserialize_int16_t(buffer, + &info_payload.object_info.activity._.agent.availability); + success &= (bool)info_payload.object_info.activity._.agent.availability; + } + } + else + { + success = false; + } + + return success; +} + +bool listen_info_message( + const uxrCommunication* comm, + const int timeout) +{ + uint8_t* input_buffer = NULL; + size_t len; + + bool success = comm->recv_msg( + comm->instance, + &input_buffer, + &len, + timeout); + + if (success) + { + ucdrBuffer ub; + ucdr_init_buffer(&ub, input_buffer, len); + + size_t advance_len = 1 /* uint8_t session_id */ + + 1 /* uint8_t stream_id */ + + 2 /* uint16_t sequence_number */ + + CLIENT_KEY_SIZE + + 1 /* uint8_t submessage_header_id */ + + 1 /* uint8_t submessage_flags */ + + 2; /* uint16_t submessage_length */ + ucdr_advance_buffer(&ub, advance_len); + + return uxr_acknack_pong(&ub); + } + + return false; +} diff --git a/src/c/util/time.c b/src/c/util/time.c index 0d071baf3..024d32ab2 100644 --- a/src/c/util/time.c +++ b/src/c/util/time.c @@ -1,22 +1,30 @@ #include +#include #include #ifdef WIN32 #include -#endif +#elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) +#include "FreeRTOS.h" +#include "task.h" +#endif /* ifdef WIN32 */ //================================================================== // PUBLIC //================================================================== -int64_t uxr_millis(void) +int64_t uxr_millis( + void) { return uxr_nanos() / 1000000; } -int64_t uxr_nanos(void) +int64_t uxr_nanos( + void) { #ifdef WIN32 - SYSTEMTIME epoch_tm = {1970, 1, 4, 1, 0, 0, 0, 0}; + SYSTEMTIME epoch_tm = { + 1970, 1, 4, 1, 0, 0, 0, 0 + }; FILETIME epoch_ft; SystemTimeToFileTime(&epoch_tm, &epoch_ft); uint64_t epoch_time = (((uint64_t) epoch_ft.dwHighDateTime) << 32) + epoch_ft.dwLowDateTime; @@ -28,9 +36,28 @@ int64_t uxr_nanos(void) uint64_t current_time = (((uint64_t) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; return (current_time - epoch_time) * 100; +#elif defined(PLATFORM_NAME_FREERTOS_PLUS_TCP) + TimeOut_t tick_count; + + /* Get the current tick count. */ + vTaskSetTimeOutState(&tick_count); + + /* Pack the current tick count in int64_t. */ + int64_t total_tick = (int64_t) tick_count.xOverflowCount; +#if ( configUSE_16_BIT_TICKS == 1 ) /* Use 16-bit tick type. */ + total_tick <<= 16; +#else //( configUSE_16_BIT_TICKS == 1 ) /* Use 32-bit tick type. */ + total_tick <<= 32; +#endif // ( configUSE_16_BIT_TICKS == 1 ) + total_tick |= (int64_t) tick_count.xTimeOnEntering; + return (( total_tick / (int64_t) portTICK_PERIOD_MS ) * 1000000 ); +#elif defined(UCLIENT_PLATFORM_ZEPHYR) + struct timespec ts; + z_impl_clock_gettime(CLOCK_REALTIME, &ts); + return (((int64_t)ts.tv_sec) * 1000000000) + ts.tv_nsec; #else struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); return (((int64_t)ts.tv_sec) * 1000000000) + ts.tv_nsec; -#endif +#endif /* ifdef WIN32 */ } diff --git a/src/c/util/time_internal.h b/src/c/util/time_internal.h index eccecbd48..bd3403d9d 100644 --- a/src/c/util/time_internal.h +++ b/src/c/util/time_internal.h @@ -18,18 +18,20 @@ #ifdef __cplusplus extern "C" { -#endif +#endif // ifdef __cplusplus #include #include -static inline int64_t uxr_convert_to_nanos(int32_t sec, uint32_t nsec) +static inline int64_t uxr_convert_to_nanos( + int32_t sec, + uint32_t nsec) { return ((int64_t)sec * 1000000000) + nsec; } #ifdef __cplusplus } -#endif +#endif // ifdef __cplusplus #endif // SRC_C_UTIL_TIME_H_ diff --git a/test/memory/consumption/MemoryConsumption.c b/test/memory/consumption/MemoryConsumption.c index e49e9dbbf..50d1b9c01 100644 --- a/test/memory/consumption/MemoryConsumption.c +++ b/test/memory/consumption/MemoryConsumption.c @@ -22,15 +22,23 @@ #include #define STREAM_HISTORY 2 -#define BUFFER_SIZE UXR_CONFIG_SERIAL_TRANSPORT_MTU * STREAM_HISTORY - -void on_topic(uxrSession* session, uxrObjectId object_id, uint16_t request_id, uxrStreamId stream_id, struct ucdrBuffer* ub, void* args) +#define BUFFER_SIZE UXR_CONFIG_SERIAL_TRANSPORT_MTU* STREAM_HISTORY + +void on_topic( + uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) { (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) ub; + (void) length; (void) args; } @@ -46,9 +54,10 @@ int main() int* memory_flag = malloc(sizeof(int)); // Transport. - uxrSerialTransport transport = {0}; - uxrSerialPlatform platform = {0}; - (void) uxr_init_serial_transport(&transport, &platform, fd, 0, 1); + uxrSerialTransport transport = { + 0 + }; + (void) uxr_init_serial_transport(&transport, fd, 0, 1); // Session. uxrSession session; @@ -56,43 +65,61 @@ int main() uxr_set_topic_callback(&session, on_topic, NULL); // Streams - uint8_t output_reliable_stream_buffer[BUFFER_SIZE] = {0}; - uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); - - uint8_t input_reliable_stream_buffer[BUFFER_SIZE] = {0}; - uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, STREAM_HISTORY); + uint8_t output_reliable_stream_buffer[BUFFER_SIZE] = { + 0 + }; + uxrStreamId reliable_out = uxr_create_output_reliable_stream(&session, output_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); + + uint8_t input_reliable_stream_buffer[BUFFER_SIZE] = { + 0 + }; + uxrStreamId reliable_in = uxr_create_input_reliable_stream(&session, input_reliable_stream_buffer, BUFFER_SIZE, + STREAM_HISTORY); // Create entities. uxrObjectId participant_id = uxr_object_id(0x01, UXR_PARTICIPANT_ID); const char* participant_ref = "default_xrce_participant_profile"; - uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, participant_ref, UXR_REPLACE); + uint16_t participant_req = uxr_buffer_create_participant_ref(&session, reliable_out, participant_id, 0, + participant_ref, UXR_REPLACE); uxrObjectId topic_id = uxr_object_id(0x01, UXR_TOPIC_ID); const char* topic_xml = "HelloWorldTopicHelloWorld"; - uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, UXR_REPLACE); + uint16_t topic_req = uxr_buffer_create_topic_xml(&session, reliable_out, topic_id, participant_id, topic_xml, + UXR_REPLACE); uxrObjectId publisher_id = uxr_object_id(0x01, UXR_PUBLISHER_ID); const char* publisher_xml = ""; - uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, publisher_xml, UXR_REPLACE); + uint16_t publisher_req = uxr_buffer_create_publisher_xml(&session, reliable_out, publisher_id, participant_id, + publisher_xml, UXR_REPLACE); uxrObjectId datawriter_id = uxr_object_id(0x01, UXR_DATAWRITER_ID); - const char* datawriter_xml = "NO_KEYHelloWorldTopicHelloWorldKEEP_LAST5TRANSIENT_LOCAL"; - uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, datawriter_xml, UXR_REPLACE); + const char* datawriter_xml = + "NO_KEYHelloWorldTopicHelloWorldKEEP_LAST5TRANSIENT_LOCAL"; + uint16_t datawriter_req = uxr_buffer_create_datawriter_xml(&session, reliable_out, datawriter_id, publisher_id, + datawriter_xml, UXR_REPLACE); uxrObjectId subscriber_id = uxr_object_id(0x01, UXR_SUBSCRIBER_ID); const char* subscriber_xml = ""; - uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, subscriber_xml, UXR_REPLACE); + uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(&session, reliable_out, subscriber_id, participant_id, + subscriber_xml, UXR_REPLACE); uxrObjectId datareader_id = uxr_object_id(0x01, UXR_DATAREADER_ID); - const char* datareader_xml = "NO_KEYHelloWorldTopicHelloWorldKEEP_LAST5TRANSIENT_LOCAL"; - uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, datareader_xml, UXR_REPLACE); + const char* datareader_xml = + "NO_KEYHelloWorldTopicHelloWorldKEEP_LAST5TRANSIENT_LOCAL"; + uint16_t datareader_req = uxr_buffer_create_datareader_xml(&session, reliable_out, datareader_id, subscriber_id, + datareader_xml, UXR_REPLACE); uint8_t status[6]; - uint16_t request[6] = {participant_req, topic_req, publisher_req, datawriter_req, subscriber_req, datareader_req}; + uint16_t request[6] = { + participant_req, topic_req, publisher_req, datawriter_req, subscriber_req, datareader_req + }; (void) uxr_run_session_until_all_status(&session, 0, request, status, 6); // Request topics - uxrDeliveryControl delivery_control = {0}; + uxrDeliveryControl delivery_control = { + 0 + }; delivery_control.max_samples = UXR_MAX_SAMPLES_UNLIMITED; (void) uxr_buffer_request_data(&session, reliable_out, datareader_id, reliable_in, &delivery_control); diff --git a/test/memory/consumption/performance_profile.config b/test/memory/consumption/performance_profile.config index 0298e734e..26849d5d7 100644 --- a/test/memory/consumption/performance_profile.config +++ b/test/memory/consumption/performance_profile.config @@ -1,18 +1,12 @@ -PROFILE_UDP_TRANSPORT=FALSE -PROFILE_TCP_TRANSPORT=FALSE -PROFILE_SERIAL_TRANSPORT=TRUE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=128 +UCLIENT_PROFILE_UDP=FALSE +UCLIENT_PROFILE_TCP=FALSE +UCLIENT_PROFILE_SERIAL=TRUE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=FALSE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 + +UCLIENT_SERIAL_TRANSPORT_MTU=128 diff --git a/test/memory/memory_map/complete_profile.config b/test/memory/memory_map/complete_profile.config index d7c6b77ba..4db723b11 100644 --- a/test/memory/memory_map/complete_profile.config +++ b/test/memory/memory_map/complete_profile.config @@ -1,19 +1,10 @@ -PROFILE_DISCOVERY=TRUE -PROFILE_UDP_TRANSPORT=TRUE -PROFILE_TCP_TRANSPORT=TRUE -PROFILE_SERIAL_TRANSPORT=TRUE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 +UCLIENT_PROFILE_DISCOVERY=TRUE +UCLIENT_PROFILE_UDP=TRUE +UCLIENT_PROFILE_TCP=TRUE +UCLIENT_PROFILE_SERIAL=TRUE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=TRUE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_map/core_profile.config b/test/memory/memory_map/core_profile.config index cf74dc722..8710e1180 100644 --- a/test/memory/memory_map/core_profile.config +++ b/test/memory/memory_map/core_profile.config @@ -1,19 +1,10 @@ -PROFILE_UDP_TRANSPORT=FALSE -PROFILE_TCP_TRANSPORT=FALSE -PROFILE_SERIAL_TRANSPORT=FALSE -PROFILE_DISCOVERY=FALSE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 +UCLIENT_PROFILE_UDP=FALSE +UCLIENT_PROFILE_TCP=FALSE +UCLIENT_PROFILE_SERIAL=FALSE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=FALSE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_map/custom_profile.config b/test/memory/memory_map/custom_profile.config new file mode 100644 index 000000000..223880e8a --- /dev/null +++ b/test/memory/memory_map/custom_profile.config @@ -0,0 +1,10 @@ +UCLIENT_PROFILE_UDP=FALSE +UCLIENT_PROFILE_TCP=FALSE +UCLIENT_PROFILE_SERIAL=FALSE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=TRUE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_map/memory_map_analysis.py b/test/memory/memory_map/memory_map_analysis.py index fdf445049..e9e75a78b 100644 --- a/test/memory/memory_map/memory_map_analysis.py +++ b/test/memory/memory_map/memory_map_analysis.py @@ -2,7 +2,7 @@ import re import csv -patter = re.compile('(?P[\w]+)\s(?P[\d]+)\s(?P[\d]+)\s(?P[\d]+)\s') +pattern = re.compile('(?P[\w]+)\s(?P[\d]+)\s(?P[\d]+)\s(?P[\d]+)\s') # Take data from file. complete_profile_data = [] @@ -11,17 +11,17 @@ with open(sys.argv[1], 'r') as memory_map_file: # Complete profile data line = memory_map_file.readline() - m = patter.match(line) + m = pattern.match(line) complete_profile_data = [int(m.group('text')), int(m.group('data')), int(m.group('bss'))] # Core profile data line = memory_map_file.readline() - m = patter.match(line) + m = pattern.match(line) core_profile_data = [int(m.group('text')), int(m.group('data')), int(m.group('bss'))] line = memory_map_file.readline() while line: - m = patter.match(line) + m = pattern.match(line) profiles_data[0].append(m.group('name')) profiles_data[1].append(int(m.group('text')) - core_profile_data[0]) profiles_data[2].append(int(m.group('data')) - core_profile_data[1]) diff --git a/test/memory/memory_map/serial_profile.config b/test/memory/memory_map/serial_profile.config index cabfd3b70..86741aeab 100644 --- a/test/memory/memory_map/serial_profile.config +++ b/test/memory/memory_map/serial_profile.config @@ -1,19 +1,10 @@ -PROFILE_UDP_TRANSPORT=FALSE -PROFILE_TCP_TRANSPORT=FALSE -PROFILE_SERIAL_TRANSPORT=TRUE -PROFILE_DISCOVERY=FALSE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 +UCLIENT_PROFILE_UDP=FALSE +UCLIENT_PROFILE_TCP=FALSE +UCLIENT_PROFILE_SERIAL=TRUE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=FALSE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_map/tcp_profile.config b/test/memory/memory_map/tcp_profile.config index 2a6a2b324..0af45765f 100644 --- a/test/memory/memory_map/tcp_profile.config +++ b/test/memory/memory_map/tcp_profile.config @@ -1,19 +1,10 @@ -PROFILE_UDP_TRANSPORT=FALSE -PROFILE_TCP_TRANSPORT=TRUE -PROFILE_SERIAL_TRANSPORT=FALSE -PROFILE_DISCOVERY=FALSE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 +UCLIENT_PROFILE_UDP=FALSE +UCLIENT_PROFILE_TCP=TRUE +UCLIENT_PROFILE_SERIAL=FALSE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=FALSE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_map/udp_profile.config b/test/memory/memory_map/udp_profile.config index 6b06441ba..58002c31e 100644 --- a/test/memory/memory_map/udp_profile.config +++ b/test/memory/memory_map/udp_profile.config @@ -1,19 +1,10 @@ -PROFILE_UDP_TRANSPORT=TRUE -PROFILE_TCP_TRANSPORT=FALSE -PROFILE_SERIAL_TRANSPORT=FALSE -PROFILE_DISCOVERY=FALSE - -CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_OUTPUT_RELIABLE_STREAMS=1 -CONFIG_MAX_INPUT_BEST_EFFORT_STREAMS=1 -CONFIG_MAX_INPUT_RELIABLE_STREAMS=1 - -CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS=10 -CONFIG_MIN_SESSION_CONNECTION_INTERVAL=1 -CONFIG_MIN_HEARTBEAT_TIME_INTERVAL=1 - -CONFIG_SERIALIZATION_ENDIANNESS=0 - -CONFIG_UDP_TRANSPORT_MTU=512 -CONFIG_TCP_TRANSPORT_MTU=512 -CONFIG_SERIAL_TRANSPORT_MTU=512 +UCLIENT_PROFILE_UDP=TRUE +UCLIENT_PROFILE_TCP=FALSE +UCLIENT_PROFILE_SERIAL=FALSE +UCLIENT_PROFILE_DISCOVERY=FALSE +UCLIENT_PROFILE_CUSTOM_TRANSPORT=FALSE + +UCLIENT_MAX_OUTPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_OUTPUT_RELIABLE_STREAMS=1 +UCLIENT_MAX_INPUT_BEST_EFFORT_STREAMS=1 +UCLIENT_MAX_INPUT_RELIABLE_STREAMS=1 diff --git a/test/memory/memory_test.sh b/test/memory/memory_test.sh index c57c80023..d231019b7 100755 --- a/test/memory/memory_test.sh +++ b/test/memory/memory_test.sh @@ -6,11 +6,8 @@ if [ -d build ]; then fi mkdir build && cd build; -# Configure global cmake. -cmake ..; - # Compile profiles. -PROFILES="complete_profile core_profile tcp_profile udp_profile serial_profile" +PROFILES="complete_profile core_profile tcp_profile udp_profile serial_profile custom_profile" for P in $PROFILES do cmake -DUCLIENT_CONFIG="${PWD}"/../test/memory/memory_map/$P.config ..; diff --git a/test/transport/custom_comm/CMakeLists.txt b/test/transport/custom_comm/CMakeLists.txt new file mode 100644 index 000000000..1efc3ebff --- /dev/null +++ b/test/transport/custom_comm/CMakeLists.txt @@ -0,0 +1,70 @@ +############################################################################### +# +# Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################### + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +# New project because of the CXX GTest dependency. +if(CMAKE_VERSION VERSION_LESS 3.0) + project(custom_transport_test C CXX) +else() + cmake_policy(SET CMP0048 NEW) + project(custom_transport_test LANGUAGES C CXX) +endif() + +if(NOT UCLIENT_PROFILE_CUSTOM_TRANSPORT) + message(WARNING "Can not compile test: The UCLIENT_PROFILE_CUSTOM_TRANSPORT must be enabled.") +else() + + set(SRCS CustomComm.cpp) + + add_executable(${PROJECT_NAME} ${SRCS}) + + set_common_compile_options(${PROJECT_NAME}) + + if(MSVC OR MSVC_IDE) + target_compile_options(${PROJECT_NAME} PRIVATE /wd4996) + endif() + + add_gtest(${PROJECT_NAME} + SOURCES + ${SRCS} + DEPENDENCIES + microxrcedds_client + ) + + target_link_libraries(${PROJECT_NAME} + PRIVATE + microxrcedds_client + ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ) + + target_include_directories(${PROJECT_NAME} + PUBLIC + ${PROJECT_SOURCE_DIR} + PRIVATE + ${GTEST_INCLUDE_DIRS} + ) + + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD + 11 + CXX_STANDARD_REQUIRED + YES + ) +endif() diff --git a/test/transport/custom_comm/CustomComm.cpp b/test/transport/custom_comm/CustomComm.cpp new file mode 100644 index 000000000..a49b26944 --- /dev/null +++ b/test/transport/custom_comm/CustomComm.cpp @@ -0,0 +1,194 @@ +#include "CustomComm.hpp" + +#include + +CustomComm::CustomComm() + : buffer(2000) +{ + max_payload = 20; + uxr_set_custom_transport_callbacks(&master_, true, open, close, write, read); + uxr_init_custom_transport(&master_, this); + + uxr_set_custom_transport_callbacks(&slave_, true, open, close, write, read); + uxr_init_custom_transport(&slave_, this); +} + +CustomComm::~CustomComm() +{ + uxr_close_custom_transport(&master_); + uxr_close_custom_transport(&slave_); +} + +bool CustomComm::open( + uxrCustomTransport* /*transport*/) +{ + return true; +} + +bool CustomComm::close( + uxrCustomTransport* /*transport*/) +{ + return true; +} + +size_t CustomComm::write( + uxrCustomTransport* transport, + const uint8_t* buf, + size_t len, + uint8_t* /*error*/) +{ + CustomComm* custom_comm = static_cast(transport->args); + + size_t written = 0; + while (written < len && written < custom_comm->max_payload) + { + if (0 == custom_comm->buffer.write(buf[written])) + { + written++; + } + else + { + break; + } + } + return written; +} + +size_t CustomComm::read( + uxrCustomTransport* transport, + uint8_t* buf, + size_t len, + int /*timeout*/, + uint8_t* /*error*/) +{ + CustomComm* custom_comm = static_cast(transport->args); + + size_t readed = 0; + while (readed < len && readed < custom_comm->max_payload) + { + if (0 == custom_comm->buffer.read(&buf[readed])) + { + readed++; + } + else + { + break; + } + } + + return readed; +} + +TEST_F(CustomComm, SingleWriteReadTest) +{ + uint8_t output_msg[3] = {11, 11, 89}; + uint8_t* input_msg; + size_t input_msg_len; + + /* Send message. */ + ASSERT_TRUE(master_.comm.send_msg(&master_, output_msg, sizeof(output_msg))); + + /* Receive message. */ + ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); + ASSERT_EQ(memcmp(output_msg, input_msg, sizeof(output_msg)), 0); + ASSERT_FALSE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); +} + +TEST_F(CustomComm, MultiWriteReadTest) +{ + uint16_t msgs_size = 1; + uint8_t output_msg[3] = {11, 11, 89}; + uint8_t* input_msg; + size_t input_msg_len; + + /* Send messages. */ + for (int i = 0; i < msgs_size; ++i) + { + ASSERT_TRUE(master_.comm.send_msg(&master_, output_msg, sizeof(output_msg))); + } + + /* Receive messages. */ + for (int i = 0; i < msgs_size; ++i) + { + ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); + ASSERT_EQ(memcmp(output_msg, input_msg, sizeof(output_msg)), 0); + } + ASSERT_FALSE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); +} + +TEST_F(CustomComm, SingleOctetTest) +{ + uint8_t output_msg = 0; + uint8_t* input_msg; + size_t input_msg_len; + + /* Send messages. */ + ASSERT_TRUE(master_.comm.send_msg(&master_, &output_msg, 1)); + + /* Receive message. */ + ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); + ASSERT_EQ(input_msg_len, size_t(1)); + ASSERT_EQ(*input_msg, 0); +} + +TEST_F(CustomComm, NoPayloadTest) +{ + uint8_t output_msg = 0; + + /* Send messages. */ + ASSERT_FALSE(master_.comm.send_msg(&master_, &output_msg, 0)); +} + + +TEST_F(CustomComm, WorstStuffingTest) +{ + uint8_t output_msg[UXR_CONFIG_SERIAL_TRANSPORT_MTU]; + uint8_t* input_msg; + size_t input_msg_len; + + memset(output_msg, UXR_FRAMING_BEGIN_FLAG, sizeof(output_msg)); + ASSERT_TRUE(master_.comm.send_msg(&master_, output_msg, sizeof(output_msg))); + + ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 100)); + ASSERT_EQ(memcmp(output_msg, input_msg, sizeof(output_msg)), 0); +} + +TEST_F(CustomComm, FatigueTest) +{ + uint16_t msgs_size = uint16_t(~0); + uint16_t sent_counter = 0; + uint16_t recv_counter = 0; + uint8_t receiver_ratio = 8; + uint8_t output_msg[UXR_CONFIG_SERIAL_TRANSPORT_MTU]; + uint8_t* input_msg; + size_t input_msg_len; + + for (size_t i = 0; i < sizeof(output_msg); ++i) + { + output_msg[i] = uint8_t(i % (std::numeric_limits::max() + 1)); + } + + for (uint16_t i = 0; i < msgs_size; ++i) + { + size_t output_len = (i % sizeof(output_msg)); + if (master_.comm.send_msg(&master_, output_msg, output_len)) + { + ++sent_counter; + } + + if (i % receiver_ratio == 0) + { + if (slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)) + { + ++recv_counter; + } + } + } + + while (slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)) + { + ++recv_counter; + } + + ASSERT_EQ(recv_counter, sent_counter); +} diff --git a/test/transport/custom_comm/CustomComm.hpp b/test/transport/custom_comm/CustomComm.hpp new file mode 100644 index 000000000..8b50d9139 --- /dev/null +++ b/test/transport/custom_comm/CustomComm.hpp @@ -0,0 +1,121 @@ +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _TEST_TRANSPORT_SERIALCOMM_HPP_ +#define _TEST_TRANSPORT_SERIALCOMM_HPP_ + +#include +#include + +class CircularBuffer +{ +public: + + CircularBuffer( + size_t len) + : maxlen(len) + , head(0) + , tail(0) + { + buffer = static_cast(malloc(maxlen)); + } + + ~CircularBuffer() + { + free(buffer); + } + + int write( + uint8_t data) + { + size_t next; + + next = head + 1; + if (next >= maxlen) + { + next = 0; + } + + if (next == tail) + { + return -1; + } + + buffer[head] = data; + head = next; + return 0; + } + + int read( + uint8_t* data) + { + size_t next; + + if (head == tail) + { + return -1; + } + + next = tail + 1; + if (next >= maxlen) + { + next = 0; + } + + *data = buffer[tail]; + tail = next; + return 0; + } + +private: + + uint8_t* buffer; + size_t maxlen; + size_t head; + size_t tail; +}; + +class CustomComm : public testing::Test +{ +public: + + CustomComm(); + ~CustomComm(); + +protected: + + uxrCustomTransport master_; + uxrCustomTransport slave_; + + static bool open( + uxrCustomTransport* args); + static bool close( + uxrCustomTransport* transport); + static size_t write( + uxrCustomTransport* transport, + const uint8_t* buf, + size_t len, + uint8_t* error); + static size_t read( + uxrCustomTransport* transport, + uint8_t* buf, + size_t len, + int timeout, + uint8_t* error); + + CircularBuffer buffer; + size_t max_payload; +}; + +#endif //_TEST_TRANSPORT_SERIALCOMM_HPP_ diff --git a/test/transport/serial_comm/CMakeLists.txt b/test/transport/serial_comm/CMakeLists.txt index 2f04b8afc..5d6046721 100644 --- a/test/transport/serial_comm/CMakeLists.txt +++ b/test/transport/serial_comm/CMakeLists.txt @@ -26,8 +26,8 @@ else() project(serial_comm_transport_test LANGUAGES C CXX) endif() -if(NOT PROFILE_SERIAL_TRANSPORT) - message(WARNING "Can not compile test: The PROFILE_SERIAL_TRANSPORT must be enabled.") +if(NOT UCLIENT_PROFILE_SERIAL) + message(WARNING "Can not compile test: The UCLIENT_PROFILE_SERIAL must be enabled.") else() set(SRCS SerialComm.cpp) diff --git a/test/transport/serial_comm/SerialComm.cpp b/test/transport/serial_comm/SerialComm.cpp index 2429e42ee..1452f7dc8 100644 --- a/test/transport/serial_comm/SerialComm.cpp +++ b/test/transport/serial_comm/SerialComm.cpp @@ -4,7 +4,8 @@ #include #include -SerialComm::SerialComm() : fd_(-1) +SerialComm::SerialComm() + : fd_(-1) { } @@ -29,8 +30,8 @@ int SerialComm::init() { fcntl(fd_, F_SETFL, O_NONBLOCK); fcntl(fd_, F_SETPIPE_SZ, 4096); - if (!uxr_init_serial_transport(&master_, &master_platform_, fd_, 1, 0) || - !uxr_init_serial_transport(&slave_, &slave_platform_, fd_, 0, 1)) + if (!uxr_init_serial_transport(&master_, fd_, 1, 0) || + !uxr_init_serial_transport(&slave_, fd_, 0, 1)) { rv = -1; } @@ -95,7 +96,7 @@ TEST_F(SerialComm, SingleOctetTest) /* Receive message. */ ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); - ASSERT_EQ(input_msg_len, 1); + ASSERT_EQ(input_msg_len, size_t(1)); ASSERT_EQ(*input_msg, 0); } @@ -174,17 +175,17 @@ TEST_F(SerialComm, SplitMessageTest) uint8_t flag = UXR_FRAMING_BEGIN_FLAG; /* Send BEGIN flag. */ - ASSERT_EQ(write(slave_.platform->poll_fd.fd, static_cast(&flag), 1), 1); + ASSERT_EQ(write(slave_.platform.poll_fd.fd, static_cast(&flag), 1), 1); /* Send PAYLOAD. */ for (size_t i = 0; i < sizeof(output_msg); ++i) { ASSERT_FALSE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); - ASSERT_EQ(write(slave_.platform->poll_fd.fd, static_cast(&output_msg[i]), 1), 1); + ASSERT_EQ(write(slave_.platform.poll_fd.fd, static_cast(&output_msg[i]), 1), 1); } ASSERT_TRUE(slave_.comm.recv_msg(&slave_, &input_msg, &input_msg_len, 10)); - ASSERT_EQ(input_msg_len, 1); + ASSERT_EQ(input_msg_len, size_t(1)); ASSERT_EQ(*input_msg, 0); } diff --git a/test/transport/serial_comm/SerialComm.hpp b/test/transport/serial_comm/SerialComm.hpp index c492e1f68..f22ea1f5c 100644 --- a/test/transport/serial_comm/SerialComm.hpp +++ b/test/transport/serial_comm/SerialComm.hpp @@ -21,16 +21,16 @@ class SerialComm : public testing::Test { public: + SerialComm(); ~SerialComm(); int init(); protected: + int fd_; uxrSerialTransport master_; - uxrSerialPlatform master_platform_; uxrSerialTransport slave_; - uxrSerialPlatform slave_platform_; }; #endif //_TEST_TRANSPORT_SERIALCOMM_HPP_ diff --git a/test/unitary/CMakeLists.txt b/test/unitary/CMakeLists.txt index 2aed348ae..03de4e1e0 100644 --- a/test/unitary/CMakeLists.txt +++ b/test/unitary/CMakeLists.txt @@ -55,4 +55,5 @@ unitary_test(Submessage session/Submessage.cpp) unitary_test(SessionInfo session/SessionInfo.cpp) unitary_test(Session session/Session.cpp) unitary_test(WriteReadAccess session/WriteReadAccess.cpp) +unitary_test(Utils session/Utils.cpp) diff --git a/test/unitary/session/Session.cpp b/test/unitary/session/Session.cpp index 0706a8a8b..936da8460 100644 --- a/test/unitary/session/Session.cpp +++ b/test/unitary/session/Session.cpp @@ -42,6 +42,7 @@ extern "C" class SessionTest : public testing::Test { public: + static SessionTest* current; SessionTest() { @@ -93,6 +94,7 @@ class SessionTest : public testing::Test } public: + uxrCommunication comm; uxrSession session; uint8_t output_best_effort_buffer[MTU]; @@ -101,28 +103,31 @@ class SessionTest : public testing::Test static int listening_counter; - static bool send_msg(void* instance, const uint8_t* buf, size_t len) + static bool send_msg( + void* instance, + const uint8_t* buf, + size_t len) { (void) buf; EXPECT_EQ(SessionTest::current, instance); - if(std::string("FlashStreams") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + if (std::string("FlashStreams") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(size_t(OFFSET + SUBHEADER_SIZE + 8), len); } - else if(std::string("SendMessageOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("SendMessageOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(size_t(MTU), len); } - else if(std::string("SendMessageError") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("SendMessageError") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(size_t(MTU), len); return false; } - else if(std::string("SendHeartbeat") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("SendHeartbeat") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(size_t(HEARTBEAT_MAX_MSG_SIZE - (MAX_HEADER_SIZE - OFFSET)), len); } - else if(std::string("SendAcknack") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("SendAcknack") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(size_t(ACKNACK_MAX_MSG_SIZE - (MAX_HEADER_SIZE - OFFSET)), len); } @@ -130,17 +135,21 @@ class SessionTest : public testing::Test return true; } - static bool recv_msg(void* instance, uint8_t** buf, size_t* len, int timeout) + static bool recv_msg( + void* instance, + uint8_t** buf, + size_t* len, + int timeout) { EXPECT_EQ(SessionTest::current, instance); (void) timeout; static std::array input_buffer; - if(std::string("CreateOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + if (std::string("CreateOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { std::vector message = {0x81, 0x00, 0x00, 0x00, 0x04, 0x01, 0x19, 0x00, 0x00, 0x01, 0xFF, 0xFE, 0x00, 0x00, 0x58, 0x52, - 0x43, 0x45, 0x01, 0x00, 0x01, 0x0F , 0x0, 0x00, + 0x43, 0x45, 0x01, 0x00, 0x01, 0x0F, 0x0, 0x00, 0x77, 0x6B, 0x48, 0x5C, 0x43, 0x14, 0x1C, 0x34, 0x00}; *len = message.size(); @@ -148,11 +157,11 @@ class SessionTest : public testing::Test std::copy_n(message.begin(), *len, input_buffer.begin()); return true; } - else if(std::string("CreateNoOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("CreateNoOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { return false; } - else if(std::string("DeleteOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("DeleteOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { std::vector message = {0x81, 0x00, 0x00, 0x00, 0x05, 0x01, 0x06, 0x00, 0x00, 0x02, 0xFF, 0xFE, 0x00, 0x00}; @@ -161,57 +170,63 @@ class SessionTest : public testing::Test std::copy_n(message.begin(), *len, input_buffer.begin()); return true; } - else if(std::string("DeleteNoOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("DeleteNoOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { return false; } - else if(std::string("Listen") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("Listen") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { *len = 0u; *buf = NULL; return true; } - else if(std::string("ListenTimeout") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("ListenTimeout") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { return false; } - else if(std::string("ListenReliably") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("ListenReliably") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { *len = 0u; *buf = NULL; return true; } - else if(std::string("ListenReliablyTimeout") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("ListenReliablyTimeout") == + ::testing::UnitTest::GetInstance()->current_test_info()->name()) { return false; } - else if(std::string("WaitSessionStatusBad") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("WaitSessionStatusBad") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { SessionTest::listening_counter++; return false; } - else if(std::string("RecvMessageOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("RecvMessageOk") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { *len = 8; return true; } - else if(std::string("RecvMessageError") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + else if (std::string("RecvMessageError") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { return false; } return false; } - static uint8_t comm_error(void) + static uint8_t comm_error( + void) { return 0u; } - static void on_status_func (struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, - uint8_t status, void* args) + static void on_status_func ( + struct uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint8_t status, + void* args) { (void) session; (void) object_id; (void) request_id; (void) status; (void) args; - if(std::string("ProcessStatus") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) + if (std::string("ProcessStatus") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) { EXPECT_EQ(&SessionTest::current->session, session); EXPECT_EQ(2, object_id.id); @@ -222,8 +237,14 @@ class SessionTest : public testing::Test } } - static void on_topic_func (struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, - uxrStreamId stream_id, struct ucdrBuffer* ub, uint16_t length, void* args) + static void on_topic_func ( + struct uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) { (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) length; (void) args; if (std::string("ReadUint64") == ::testing::UnitTest::GetInstance()->current_test_info()->name()) @@ -234,12 +255,18 @@ class SessionTest : public testing::Test } } - static void on_time_func (struct uxrSession* session, int64_t current_timestamp, int64_t transmit_timestamp, - int64_t received_timestamp, int64_t originate_timestamp, void* args) + static void on_time_func ( + struct uxrSession* session, + int64_t current_timestamp, + int64_t transmit_timestamp, + int64_t received_timestamp, + int64_t originate_timestamp, + void* args) { (void) session; (void) current_timestamp; (void) transmit_timestamp; (void) received_timestamp; (void) originate_timestamp; (void) args; } + }; SessionTest* SessionTest::current = nullptr; diff --git a/test/unitary/session/Submessage.cpp b/test/unitary/session/Submessage.cpp index 1df403e05..6ff6375f3 100644 --- a/test/unitary/session/Submessage.cpp +++ b/test/unitary/session/Submessage.cpp @@ -12,13 +12,18 @@ extern "C" class SubmessageTest : public testing::Test { public: + SubmessageTest() { ucdr_init_buffer(&ub_write, buffer, BUFFER_SIZE); ucdr_init_buffer(&ub_read, buffer, BUFFER_SIZE); } - void write_and_read(uint8_t id, uint16_t length, uint8_t flags, bool fit_payload) + void write_and_read( + uint8_t id, + uint16_t length, + uint8_t flags, + bool fit_payload) { ASSERT_EQ(fit_payload, uxr_buffer_submessage_header(&ub_write, id, length, flags)); uint8_t read_id; uint16_t read_length; uint8_t read_flags; @@ -35,6 +40,7 @@ class SubmessageTest : public testing::Test } protected: + uint8_t buffer[BUFFER_SIZE]; ucdrBuffer ub_write; ucdrBuffer ub_read; diff --git a/test/unitary/session/Utils.cpp b/test/unitary/session/Utils.cpp new file mode 100644 index 000000000..4400a0fba --- /dev/null +++ b/test/unitary/session/Utils.cpp @@ -0,0 +1,13 @@ +#include + +extern "C" +{ +#include +} + +TEST(UtilsTest, ConvertToNanos) +{ + int64_t nanos = uxr_convert_to_nanos(16, 42); + EXPECT_EQ(16000000042, nanos); +} + diff --git a/test/unitary/session/WriteReadAccess.cpp b/test/unitary/session/WriteReadAccess.cpp index 8f543c668..4bef746e3 100644 --- a/test/unitary/session/WriteReadAccess.cpp +++ b/test/unitary/session/WriteReadAccess.cpp @@ -28,11 +28,13 @@ extern "C" #define HISTORY 4 #define TOPIC_FITTED_SIZE (MTU - (MIN_HEADER_SIZE + SUBHEADER_SIZE + WRITE_DATA_PAYLOAD_SIZE)) #define REQUEST_FITTED_SIZE TOPIC_FITTED_SIZE -#define REPLY_FITTED_SIZE (MTU - (MIN_HEADER_SIZE + SUBHEADER_SIZE + WRITE_DATA_PAYLOAD_SIZE) - sizeof(SampleIdentity)) +#define REPLY_FITTED_SIZE (MTU - (MIN_HEADER_SIZE + SUBHEADER_SIZE + WRITE_DATA_PAYLOAD_SIZE) - \ + sizeof(SampleIdentity)) class WriteReadAccessTest : public testing::Test { public: + WriteReadAccessTest() : session_{} , data_writer_id_{uxr_object_id(0, UXR_DATAWRITER_ID)} @@ -51,8 +53,14 @@ class WriteReadAccessTest : public testing::Test uxr_set_request_callback(&session_, on_request_func, &request_); } - static void on_topic_func (struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, - uxrStreamId stream_id, struct ucdrBuffer* ub, uint16_t length, void* args) + static void on_topic_func ( + struct uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uxrStreamId stream_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) { (void) session; (void) object_id; (void) request_id; (void) stream_id; (void) length; (void) args; uint64_t topic_sent = *reinterpret_cast(args); @@ -61,8 +69,14 @@ class WriteReadAccessTest : public testing::Test EXPECT_EQ(topic_sent, topic_received); } - static void on_reply_func (struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, - uint16_t reply_id, struct ucdrBuffer* ub, uint16_t length, void* args) + static void on_reply_func ( + struct uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + uint16_t reply_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) { (void) session; (void) object_id; (void) request_id; (void) reply_id; (void) length; (void) args; uint64_t reply_sent = *reinterpret_cast(args); @@ -71,8 +85,14 @@ class WriteReadAccessTest : public testing::Test EXPECT_EQ(reply_sent, reply_received); } - static void on_request_func (struct uxrSession* session, uxrObjectId object_id, uint16_t request_id, - SampleIdentity* sample_id, struct ucdrBuffer* ub, uint16_t length, void* args) + static void on_request_func ( + struct uxrSession* session, + uxrObjectId object_id, + uint16_t request_id, + SampleIdentity* sample_id, + struct ucdrBuffer* ub, + uint16_t length, + void* args) { (void) session; (void) object_id; (void) request_id; (void) sample_id; (void) length; (void) args; uint32_t* data_ptr = reinterpret_cast(args); @@ -84,6 +104,7 @@ class WriteReadAccessTest : public testing::Test } protected: + uxrSession session_; uxrObjectId data_writer_id_; uxrObjectId data_reader_id_; @@ -94,6 +115,7 @@ class WriteReadAccessTest : public testing::Test uint64_t reply_; private: + uint8_t output_best_effort_buffer_[MTU]; }; @@ -184,6 +206,34 @@ TEST_F(WriteReadAccessTest, BufferReply) ASSERT_TRUE(uxr_buffer_reply(&session_, stream_id, replier_id_, &sample_id, buffer, data_length)); } +TEST_F(WriteReadAccessTest, BufferTopic) +{ + uint8_t buffer[MTU]; + uxrStreamId stream_id; + uint16_t data_length; + + // stream_id: no valid + // data_length: fitted + // expected: false + stream_id = uxr_stream_id(1, UXR_BEST_EFFORT_STREAM, UXR_OUTPUT_STREAM); + data_length = uint16_t(TOPIC_FITTED_SIZE); + ASSERT_FALSE(uxr_buffer_topic(&session_, stream_id, data_writer_id_, buffer, data_length)); + + // stream_id: valid + // data_length: no fitted + // expected: false + stream_id = uxr_stream_id(0, UXR_BEST_EFFORT_STREAM, UXR_OUTPUT_STREAM); + data_length = uint16_t(1 + TOPIC_FITTED_SIZE); + ASSERT_FALSE(uxr_buffer_topic(&session_, stream_id, data_writer_id_, buffer, data_length)); + + // stream_id: valid + // data_length: fitted + // expected: true + stream_id = uxr_stream_id(0, UXR_BEST_EFFORT_STREAM, UXR_OUTPUT_STREAM); + data_length = uint16_t(TOPIC_FITTED_SIZE); + ASSERT_TRUE(uxr_buffer_topic(&session_, stream_id, data_writer_id_, buffer, data_length)); +} + TEST_F(WriteReadAccessTest, ReadFormatData) { uint8_t buffer[MTU] = {0}; diff --git a/test/unitary/session/streams/CommonReliableStream.cpp b/test/unitary/session/streams/CommonReliableStream.cpp index c2ca24276..7f8463c33 100644 --- a/test/unitary/session/streams/CommonReliableStream.cpp +++ b/test/unitary/session/streams/CommonReliableStream.cpp @@ -17,7 +17,7 @@ TEST(CommonReliableStreamTest, GetBufferSize) TEST(CommonReliableStreamTest, GetBuffer) { uint16_t history_pos = 3; - uint8_t * buffer = uxr_get_reliable_buffer(&stream, history_pos); + uint8_t* buffer = uxr_get_reliable_buffer(&stream, history_pos); size_t slot_size = BUFFER_SIZE / HISTORY; EXPECT_EQ(history_pos * slot_size + INTERNAL_RELIABLE_BUFFER_OFFSET, size_t(buffer - stream_buffer)); diff --git a/test/unitary/session/streams/InputBestEffortStream.cpp b/test/unitary/session/streams/InputBestEffortStream.cpp index 4e1f10cb3..2a09018bf 100644 --- a/test/unitary/session/streams/InputBestEffortStream.cpp +++ b/test/unitary/session/streams/InputBestEffortStream.cpp @@ -10,6 +10,7 @@ extern "C" class InputBestEffortStreamTest : public testing::Test { public: + InputBestEffortStreamTest() { uxr_init_input_best_effort_stream(&stream); @@ -21,6 +22,7 @@ class InputBestEffortStreamTest : public testing::Test } protected: + uxrInputBestEffortStream stream; }; diff --git a/test/unitary/session/streams/InputReliableStream.cpp b/test/unitary/session/streams/InputReliableStream.cpp index e99772e41..8c35e59f4 100644 --- a/test/unitary/session/streams/InputReliableStream.cpp +++ b/test/unitary/session/streams/InputReliableStream.cpp @@ -12,18 +12,22 @@ extern "C" #define MAX_MESSAGE_SIZE (BUFFER_SIZE / HISTORY - INTERNAL_RELIABLE_BUFFER_OFFSET) #define FRAGMENT_OFFSET size_t(4) -bool operator == (const uxrInputReliableStream& stream1, const uxrInputReliableStream& stream2) +bool operator == ( + const uxrInputReliableStream& stream1, + const uxrInputReliableStream& stream2) { return stream1.base.buffer == stream2.base.buffer - && stream1.base.size == stream2.base.size - && stream1.base.history == stream2.base.history - && stream1.last_handled == stream2.last_handled - && stream1.last_announced == stream2.last_announced - && stream1.on_get_fragmentation_info == stream2.on_get_fragmentation_info - && stream1.cleanup_flag == stream2.cleanup_flag; + && stream1.base.size == stream2.base.size + && stream1.base.history == stream2.base.history + && stream1.last_handled == stream2.last_handled + && stream1.last_announced == stream2.last_announced + && stream1.on_get_fragmentation_info == stream2.on_get_fragmentation_info + && stream1.cleanup_flag == stream2.cleanup_flag; } -bool operator != (const uxrInputReliableStream& stream1, const uxrInputReliableStream& stream2) +bool operator != ( + const uxrInputReliableStream& stream1, + const uxrInputReliableStream& stream2) { return !(stream1 == stream2); } @@ -31,6 +35,7 @@ bool operator != (const uxrInputReliableStream& stream1, const uxrInputReliableS class InputReliableStreamTest : public testing::Test { public: + InputReliableStreamTest() { uxr_init_input_reliable_stream(&stream, buffer, BUFFER_SIZE, HISTORY, on_get_fragmentation_info); @@ -41,13 +46,15 @@ class InputReliableStreamTest : public testing::Test EXPECT_EQ(SEQ_NUM_MAX, stream.last_announced); EXPECT_EQ(false, stream.cleanup_flag); - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { EXPECT_EQ(size_t(0), uxr_get_reliable_buffer_size(&stream.base, i)); } } - void copy(uxrInputReliableStream* dest, uxrInputReliableStream* source) + void copy( + uxrInputReliableStream* dest, + uxrInputReliableStream* source) { dest->base.buffer = source->base.buffer; dest->base.size = source->base.size; @@ -66,15 +73,18 @@ class InputReliableStreamTest : public testing::Test } protected: + uxrInputReliableStream stream; uint8_t buffer[BUFFER_SIZE]; uint8_t message[MAX_MESSAGE_SIZE]; - static FragmentationInfo on_get_fragmentation_info(uint8_t* buffer) + static FragmentationInfo on_get_fragmentation_info( + uint8_t* buffer) { (void) buffer; return NO_FRAGMENTED; } + }; TEST_F(InputReliableStreamTest, UpToDate) @@ -215,7 +225,7 @@ TEST_F(InputReliableStreamTest, Reset) uxr_reset_input_reliable_stream(&stream); EXPECT_EQ(backup, stream); - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { EXPECT_EQ(size_t(0), uxr_get_reliable_buffer_size(&stream.base, i)); } @@ -235,7 +245,8 @@ TEST_F(InputReliableStreamTest, FragmentationJumpToNextBuffer) stream.cleanup_flag = true; uint8_t array[BUFFER_SIZE]; - (void) ucdr_serialize_array_uint8_t(&ub, array, uint32_t((capacity + capacity - 1) - 2 * (sizeof(length_t) + SUBHEADER_SIZE))); + (void) ucdr_serialize_array_uint8_t(&ub, array, + uint32_t((capacity + capacity - 1) - 2 * (sizeof(length_t) + SUBHEADER_SIZE))); ASSERT_FALSE(ub.error); EXPECT_EQ(slot_1 + SUBHEADER_SIZE, ub.init); EXPECT_EQ(slot_1 + capacity - 1, ub.final); @@ -247,7 +258,7 @@ TEST_F(InputReliableStreamTest, FragmentationJumpToNextBufferLastPosition) size_t capacity = uxr_get_reliable_buffer_capacity(&stream.base); uint8_t* slot_history_1 = uxr_get_reliable_buffer(&stream.base, HISTORY - 1); uint8_t* slot_0 = uxr_get_reliable_buffer(&stream.base, 0); - uxr_set_reliable_buffer_size(&stream.base, HISTORY -1, capacity); + uxr_set_reliable_buffer_size(&stream.base, HISTORY - 1, capacity); uxr_set_reliable_buffer_size(&stream.base, 0, capacity - 1); ucdrBuffer ub; @@ -256,7 +267,8 @@ TEST_F(InputReliableStreamTest, FragmentationJumpToNextBufferLastPosition) stream.cleanup_flag = true; uint8_t array[BUFFER_SIZE]; - (void) ucdr_serialize_array_uint8_t(&ub, array, uint32_t((capacity + capacity - 1) - 2 * (sizeof(length_t) + SUBHEADER_SIZE))); + (void) ucdr_serialize_array_uint8_t(&ub, array, + uint32_t((capacity + capacity - 1) - 2 * (sizeof(length_t) + SUBHEADER_SIZE))); ASSERT_FALSE(ub.error); EXPECT_EQ(slot_0 + SUBHEADER_SIZE, ub.init); EXPECT_EQ(slot_0 + capacity - 1, ub.final); diff --git a/test/unitary/session/streams/OutputBestEffortStream.cpp b/test/unitary/session/streams/OutputBestEffortStream.cpp index 6982846ef..f09c9664b 100644 --- a/test/unitary/session/streams/OutputBestEffortStream.cpp +++ b/test/unitary/session/streams/OutputBestEffortStream.cpp @@ -15,6 +15,7 @@ extern "C" class OutputBestEffortStreamTest : public testing::Test { public: + OutputBestEffortStreamTest() { uxr_init_output_best_effort_stream(&stream, buffer, BUFFER_SIZE, OFFSET); @@ -30,6 +31,7 @@ class OutputBestEffortStreamTest : public testing::Test } protected: + uxrOutputBestEffortStream stream; uint8_t buffer[BUFFER_SIZE]; }; diff --git a/test/unitary/session/streams/OutputReliableStream.cpp b/test/unitary/session/streams/OutputReliableStream.cpp index 8abcbbfac..3fc0f21e6 100644 --- a/test/unitary/session/streams/OutputReliableStream.cpp +++ b/test/unitary/session/streams/OutputReliableStream.cpp @@ -7,6 +7,7 @@ extern "C" #include #include #include +#include } #define BUFFER_SIZE size_t(128) @@ -18,21 +19,25 @@ extern "C" #define FRAGMENT_OFFSET size_t(4) #define MAX_FRAGMENT_SIZE (MAX_MESSAGE_SIZE - OFFSET - FRAGMENT_OFFSET) -bool operator == (const uxrOutputReliableStream& stream1, const uxrOutputReliableStream& stream2) +bool operator == ( + const uxrOutputReliableStream& stream1, + const uxrOutputReliableStream& stream2) { return stream1.base.buffer == stream2.base.buffer - && stream1.base.size == stream2.base.size - && stream1.base.history == stream2.base.history - && stream1.offset == stream2.offset - && stream1.last_written == stream2.last_written - && stream1.last_sent == stream2.last_sent - && stream1.last_acknown == stream2.last_acknown - && stream1.next_heartbeat_timestamp == stream2.next_heartbeat_timestamp - && stream1.next_heartbeat_tries == stream2.next_heartbeat_tries - && stream1.send_lost == stream2.send_lost; + && stream1.base.size == stream2.base.size + && stream1.base.history == stream2.base.history + && stream1.offset == stream2.offset + && stream1.last_written == stream2.last_written + && stream1.last_sent == stream2.last_sent + && stream1.last_acknown == stream2.last_acknown + && stream1.next_heartbeat_timestamp == stream2.next_heartbeat_timestamp + && stream1.next_heartbeat_tries == stream2.next_heartbeat_tries + && stream1.send_lost == stream2.send_lost; } -bool operator != (const uxrOutputReliableStream& stream1, const uxrOutputReliableStream& stream2) +bool operator != ( + const uxrOutputReliableStream& stream1, + const uxrOutputReliableStream& stream2) { return !(stream1 == stream2); } @@ -40,6 +45,7 @@ bool operator != (const uxrOutputReliableStream& stream1, const uxrOutputReliabl class OutputReliableStreamTest : public testing::Test { public: + OutputReliableStreamTest() { uxr_init_output_reliable_stream(&stream, buffer, BUFFER_SIZE, HISTORY, OFFSET); @@ -54,13 +60,15 @@ class OutputReliableStreamTest : public testing::Test EXPECT_EQ(0, stream.next_heartbeat_tries); EXPECT_EQ(false, stream.send_lost); - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { EXPECT_EQ(OFFSET, uxr_get_reliable_buffer_size(&stream.base, i)); } } - void copy(uxrOutputReliableStream* dest, uxrOutputReliableStream* source) + void copy( + uxrOutputReliableStream* dest, + uxrOutputReliableStream* source) { dest->base.buffer = source->base.buffer; dest->base.size = source->base.size; @@ -81,6 +89,7 @@ class OutputReliableStreamTest : public testing::Test } protected: + uxrOutputReliableStream stream; uint8_t buffer[BUFFER_SIZE]; }; @@ -198,6 +207,60 @@ TEST_F(OutputReliableStreamTest, WriteFragmentMessage) EXPECT_EQ(slot_2 + OFFSET + FRAGMENT_OFFSET + SUBMESSAGE_SIZE, ub.final); } +TEST_F(OutputReliableStreamTest, WriteTwoFragmentMessage) +{ + ucdrBuffer ub; + bool available_to_write = uxr_prepare_reliable_buffer_to_write(&stream, MAX_FRAGMENT_SIZE * 2, &ub); + ASSERT_TRUE(available_to_write); + available_to_write = uxr_prepare_reliable_buffer_to_write(&stream, MAX_FRAGMENT_SIZE * 2, &ub); + ASSERT_TRUE(available_to_write); +} + + +TEST_F(OutputReliableStreamTest, WriteMultipleFragmentsAndCheckSubHeaders) +{ + ucdrBuffer ub; + uint8_t client_key[4] = {0xAA, 0xAA, 0xAA, 0xAA}; + + // Init all message headers + for (uint16_t i = 0; i < HISTORY; i++) + { + uint8_t* slot = uxr_get_reliable_buffer(&stream.base, i); + ucdr_init_buffer(&ub, slot, MAX_MESSAGE_SIZE); + uxr_serialize_message_header(&ub, 0, 0, 0, client_key); + } + + // Writing two fragmented message, 3 slots should be used + size_t first_message_size = 24; // 1.5 * MAX_FRAGMENT_SIZE; + bool available_to_write = uxr_prepare_reliable_buffer_to_write(&stream, first_message_size, &ub); + ASSERT_TRUE(available_to_write); + available_to_write = uxr_prepare_reliable_buffer_to_write(&stream, first_message_size, &ub); + ASSERT_TRUE(available_to_write); + + // Deserialize both messages + size_t buffer_capacity = uxr_get_reliable_buffer_capacity(&stream.base); + for (uint16_t i = 0; i < stream.last_written; i++) + { + uint8_t* slot = uxr_get_reliable_buffer(&stream.base, i); + ucdr_init_buffer_origin_offset(&ub, slot, buffer_capacity, 0u, 0u); + + uint8_t session_id, stream_id; + uint16_t seq_no; + uint8_t output_client_key[4]; + uxr_deserialize_message_header(&ub, &session_id, &stream_id, &seq_no, output_client_key); + + while (ub.iterator < ub.final) + { + uint8_t id, flags; + uint16_t length; + uxr_deserialize_submessage_header(&ub, &id, &flags, &length); + uint8_t* fragment = reinterpret_cast(malloc(length * sizeof(uint8_t))); + ASSERT_TRUE(ucdr_deserialize_array_uint8_t(&ub, fragment, length)); + free(fragment); + } + } +} + TEST_F(OutputReliableStreamTest, WriteMaxSubmessageSize) { ucdrBuffer ub; @@ -210,7 +273,7 @@ TEST_F(OutputReliableStreamTest, WriteMaxSubmessageSize) TEST_F(OutputReliableStreamTest, WriteMessagesUntilFullBuffer) { ucdrBuffer ub; - for(size_t i = 0; i < HISTORY; ++i) + for (size_t i = 0; i < HISTORY; ++i) { bool available_to_write = uxr_prepare_reliable_buffer_to_write(&stream, MAX_SUBMESSAGE_SIZE, &ub); ASSERT_TRUE(available_to_write); @@ -222,7 +285,7 @@ TEST_F(OutputReliableStreamTest, WriteMessagesUntilFullBuffer) ASSERT_FALSE(available_to_write); EXPECT_EQ(backup, stream); - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { EXPECT_EQ(MAX_MESSAGE_SIZE, uxr_get_reliable_buffer_size(&stream.base, i)); } @@ -255,12 +318,12 @@ TEST_F(OutputReliableStreamTest, PrepareToSendNoMessage) TEST_F(OutputReliableStreamTest, PrepareToSendAllMessages) { ucdrBuffer ub; - for(size_t i = 0; i < HISTORY; ++i) + for (size_t i = 0; i < HISTORY; ++i) { (void) uxr_prepare_reliable_buffer_to_write(&stream, MAX_SUBMESSAGE_SIZE, &ub); } - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { uint8_t* slot_i = uxr_get_reliable_buffer(&stream.base, i); uint8_t* message; size_t length; uxrSeqNum seq_num; @@ -278,7 +341,7 @@ TEST_F(OutputReliableStreamTest, PrepareToSendAllMessages) ASSERT_FALSE(data_to_send); EXPECT_EQ(backup, stream); - for(uint16_t i = 0; i < HISTORY; ++i) + for (uint16_t i = 0; i < HISTORY; ++i) { EXPECT_EQ(MAX_MESSAGE_SIZE, uxr_get_reliable_buffer_size(&stream.base, i)); } @@ -372,7 +435,7 @@ TEST_F(OutputReliableStreamTest, AcknackProcessLost) uint8_t* message; size_t length; uxrSeqNum seq_num; (void) uxr_prepare_next_reliable_buffer_to_send(&stream, &message, &length, &seq_num); (void) uxr_update_output_stream_heartbeat_timestamp(&stream, 0); - size_t message_length = uxr_get_reliable_buffer_size(&stream.base,0); + size_t message_length = uxr_get_reliable_buffer_size(&stream.base, 0); uxr_process_acknack(&stream, 1, uxrSeqNum(0)); EXPECT_TRUE(stream.send_lost); @@ -424,3 +487,18 @@ TEST_F(OutputReliableStreamTest, FragmentedSerialization) EXPECT_EQ(slot_1 + uxr_get_reliable_buffer_size(&stream.base, 1), ub.iterator); EXPECT_EQ(slot_1 + uxr_get_reliable_buffer_size(&stream.base, 1), ub.final); } + +TEST_F(OutputReliableStreamTest, GetAvailableSeqNum) +{ + EXPECT_EQ(get_available_free_slots(&stream), HISTORY); + + ucdrBuffer ub; + for (size_t i = 0; i < HISTORY; i++) + { + ASSERT_TRUE(uxr_prepare_reliable_buffer_to_write(&stream, MAX_SUBMESSAGE_SIZE, &ub)); + EXPECT_EQ(get_available_free_slots(&stream), HISTORY - (i + 1)); + } + + ASSERT_FALSE(uxr_prepare_reliable_buffer_to_write(&stream, MAX_SUBMESSAGE_SIZE, &ub)); + EXPECT_EQ(get_available_free_slots(&stream), 0); +} diff --git a/test/unitary/session/streams/StreamStorage.cpp b/test/unitary/session/streams/StreamStorage.cpp index de6026e08..85ec9edad 100644 --- a/test/unitary/session/streams/StreamStorage.cpp +++ b/test/unitary/session/streams/StreamStorage.cpp @@ -15,6 +15,7 @@ extern "C" class StreamStorageTest : public testing::Test { public: + StreamStorageTest() { uxr_init_stream_storage(&storage); @@ -30,18 +31,21 @@ class StreamStorageTest : public testing::Test } protected: + uxrStreamStorage storage; uint8_t ob_buffer[BUFFER_SIZE / HISTORY]; uint8_t or_buffer[BUFFER_SIZE]; uint8_t ir_buffer[BUFFER_SIZE]; - static FragmentationInfo on_get_fragmentation_info(uint8_t* buffer) + static FragmentationInfo on_get_fragmentation_info( + uint8_t* buffer) { (void) buffer; return NO_FRAGMENTED; } public: + static int output_best_effort_reset_times; static int input_best_effort_reset_times; static int output_reliable_reset_times; @@ -111,7 +115,8 @@ TEST_F(StreamStorageTest, OutputBestEffortInitialization) TEST_F(StreamStorageTest, InputReliableInitialization) { input_reliable_initialized = false; - uxrStreamId id = uxr_add_input_reliable_buffer(&storage, ir_buffer, BUFFER_SIZE, HISTORY, on_get_fragmentation_info); + uxrStreamId id = + uxr_add_input_reliable_buffer(&storage, ir_buffer, BUFFER_SIZE, HISTORY, on_get_fragmentation_info); EXPECT_TRUE(input_reliable_initialized); EXPECT_EQ(0, id.index); EXPECT_EQ(128, id.raw); @@ -167,55 +172,75 @@ TEST_F(StreamStorageTest, OutputStreamNoConfirmed) // ****************************************************************************Y // MOCKS // ****************************************************************************Y -void uxr_reset_output_best_effort_stream(uxrOutputBestEffortStream* stream) +void uxr_reset_output_best_effort_stream( + uxrOutputBestEffortStream* stream) { (void) stream; StreamStorageTest::output_best_effort_reset_times++; } -void uxr_reset_input_best_effort_stream(uxrInputBestEffortStream* stream) +void uxr_reset_input_best_effort_stream( + uxrInputBestEffortStream* stream) { (void) stream; StreamStorageTest::input_best_effort_reset_times++; } -void uxr_reset_output_reliable_stream(uxrOutputReliableStream* stream) +void uxr_reset_output_reliable_stream( + uxrOutputReliableStream* stream) { (void) stream; StreamStorageTest::output_reliable_reset_times++; } -void uxr_reset_input_reliable_stream(uxrInputReliableStream* stream) +void uxr_reset_input_reliable_stream( + uxrInputReliableStream* stream) { (void) stream; StreamStorageTest::input_reliable_reset_times++; } -void uxr_init_input_best_effort_stream(uxrInputBestEffortStream* stream) +void uxr_init_input_best_effort_stream( + uxrInputBestEffortStream* stream) { (void) stream; StreamStorageTest::input_best_effort_initialized = true; } -void uxr_init_output_best_effort_stream(uxrOutputBestEffortStream* stream, uint8_t* buffer, size_t size, uint8_t offset) +void uxr_init_output_best_effort_stream( + uxrOutputBestEffortStream* stream, + uint8_t* buffer, + size_t size, + uint8_t offset) { (void) stream; (void) buffer; (void) size; (void) offset; StreamStorageTest::output_best_effort_initialized = true; } -void uxr_init_input_reliable_stream(uxrInputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, OnGetFragmentationInfo on_get_fragmentation_info) +void uxr_init_input_reliable_stream( + uxrInputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + OnGetFragmentationInfo on_get_fragmentation_info) { (void) stream; (void) buffer; (void) size; (void) history; (void) on_get_fragmentation_info; StreamStorageTest::input_reliable_initialized = true; } -void uxr_init_output_reliable_stream(uxrOutputReliableStream* stream, uint8_t* buffer, size_t size, uint16_t history, uint8_t header_offset) +void uxr_init_output_reliable_stream( + uxrOutputReliableStream* stream, + uint8_t* buffer, + size_t size, + uint16_t history, + uint8_t header_offset) { (void) stream; (void) buffer; (void) size; (void) history; (void) header_offset; StreamStorageTest::output_reliable_initialized = true; } -bool uxr_is_output_up_to_date(const uxrOutputReliableStream* stream) +bool uxr_is_output_up_to_date( + const uxrOutputReliableStream* stream) { (void) stream; return StreamStorageTest::output_reliable_up_to_date;