diff --git a/rosidl_typesupport_fastrtps_c/CMakeLists.txt b/rosidl_typesupport_fastrtps_c/CMakeLists.txt new file mode 100644 index 000000000..bed191d6f --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/CMakeLists.txt @@ -0,0 +1,86 @@ +cmake_minimum_required(VERSION 3.5) + +project(rosidl_typesupport_fastrtps_c) + +set(FASTRTPS_STATIC_DISABLE $ENV{FASTRTPS_STATIC_DISABLE} + CACHE BOOL "If fastrtps Static should be disabled.") + +# Default to C99 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 99) +endif() + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) + +find_package(fastrtps_cmake_module REQUIRED) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) +if(FASTRTPS_STATIC_DISABLE) + ament_package() + message(STATUS "fastrtps static rmw implementation explicitly disabled - skipping '${PROJECT_NAME}'") + return() +endif() + +find_package(ament_cmake_python REQUIRED) +find_package(rosidl_typesupport_fastrtps_cpp REQUIRED) + +ament_export_dependencies(rmw) +ament_export_dependencies(rosidl_cmake) +ament_export_dependencies(rosidl_generator_c) +ament_export_dependencies(rosidl_generator_dds_idl) +ament_export_dependencies(rosidl_typesupport_fastrtps_cpp) +ament_export_include_directories(include) + +ament_python_install_package(${PROJECT_NAME}) + +add_library(${PROJECT_NAME} SHARED src/identifier.cpp) +if(WIN32) + target_compile_definitions(${PROJECT_NAME} + PRIVATE "ROSIDL_TYPESUPPORT_FASTRTPS_C_BUILDING_DLL") +endif() +target_include_directories(${PROJECT_NAME} PUBLIC include) +ament_target_dependencies(${PROJECT_NAME} "rosidl_typesupport_fastrtps_cpp") +ament_export_libraries(${PROJECT_NAME}) + +ament_index_register_resource("rosidl_typesupport_c") + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package( + CONFIG_EXTRAS "rosidl_typesupport_fastrtps_c-extras.cmake.in" +) + +install( + PROGRAMS bin/rosidl_typesupport_fastrtps_c + DESTINATION lib/rosidl_typesupport_fastrtps_c +) + +install( + DIRECTORY cmake resource + DESTINATION share/${PROJECT_NAME} +) + +install( + DIRECTORY include/ + DESTINATION include +) + +install( + TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) diff --git a/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c b/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c new file mode 100644 index 000000000..4b0498fc8 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys + +from rosidl_cmake import read_generator_arguments +from rosidl_parser import UnknownMessageType +from rosidl_typesupport_fastrtps_c import generate_typesupport_fastrtps_c + + +def is_valid_file(parser, file_name): + if not os.path.exists(file_name): + parser.error("File does not exist: '{0}'".format(file_name)) + file_name_abs = os.path.abspath(file_name) + if not os.path.isfile(file_name_abs): + parser.error("Path exists but is not a file: '{0}'".format(file_name_abs)) + return file_name + + +def main(argv=sys.argv[1:]): + parser = argparse.ArgumentParser( + description='Generate the C interfaces for fastrtps.', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument( + '--generator-arguments-file', + required=True, + help='The location of the file containing the generator arguments') + args = parser.parse_args(argv) + + generator_args = read_generator_arguments(args.generator_arguments_file) + + try: + rc = generate_typesupport_fastrtps_c(generator_args) + except UnknownMessageType as e: + print(str(e), file=sys.stderr) + return 1 + if rc: + return rc + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/rosidl_typesupport_fastrtps_c/cmake/rosidl_typesupport_fastrtps_c_generate_interfaces.cmake b/rosidl_typesupport_fastrtps_c/cmake/rosidl_typesupport_fastrtps_c_generate_interfaces.cmake new file mode 100644 index 000000000..5df3b57d8 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/cmake/rosidl_typesupport_fastrtps_c_generate_interfaces.cmake @@ -0,0 +1,278 @@ +# Copyright 2016 Open Source Robotics Foundation, Inc. +# +# 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. + +find_package(fastrtps_cmake_module QUIET) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) + +set(_dds_idl_files "") +set(_dds_idl_base_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_dds_idl") +foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + get_filename_component(_name "${_idl_file}" NAME_WE) + list(APPEND _dds_idl_files + "${_dds_idl_base_path}/${PROJECT_NAME}/${_parent_folder}/dds_fastrtps/${_name}_.idl") + endif() +endforeach() + +set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c/${PROJECT_NAME}") +set(_generated_msg_files "") +set(_generated_srv_files "") +foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + get_filename_component(_msg_name "${_idl_file}" NAME_WE) + string_camel_case_to_lower_case_underscore("${_msg_name}" _header_name) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + if(_parent_folder STREQUAL "msg") + set(_var2 "_generated_msg_files") + elseif(_parent_folder STREQUAL "srv") + set(_var2 "_generated_srv_files") + else() + message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") + endif() + list(APPEND ${_var2} "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_c.h") + list(APPEND ${_var2} "${_output_path}/${_parent_folder}/dds_fastrtps_c/${_header_name}__type_support_c.cpp") + elseif(_extension STREQUAL ".srv") + list(APPEND _generated_srv_files "${_output_path}/srv/${_header_name}__rosidl_typesupport_fastrtps_c.h") + list(APPEND _generated_srv_files "${_output_path}/srv/dds_fastrtps_c/${_header_name}__type_support_c.cpp") + else() + message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}") + endif() +endforeach() + +# If not on Windows, disable some warnings with fastrtps's generated code +if(NOT WIN32) + set(_fastrtps_compile_flags) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(_fastrtps_compile_flags + "-Wno-deprecated-register" + "-Wno-return-type-c-linkage" + "-Wno-unused-parameter" + ) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(_fastrtps_compile_flags + # no-strict-aliasing necessary only for Release builds + "-Wno-strict-aliasing" + "-Wno-unused-parameter" + ) + endif() + if(NOT _fastrtps_compile_flags STREQUAL "") + string(REPLACE ";" " " _fastrtps_compile_flags "${_fastrtps_compile_flags}") + endif() +endif() + +set(_dependency_files "") +set(_dependencies "") +foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) + foreach(_idl_file ${${_pkg_name}_INTERFACE_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + get_filename_component(_name "${_idl_file}" NAME_WE) + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_parent_folder}/dds_fastrtps/${_name}_.idl") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependency_files "${_abs_idl_file}") + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") + endif() + endforeach() +endforeach() + +set(target_dependencies + "${rosidl_typesupport_fastrtps_c_BIN}" + ${rosidl_typesupport_fastrtps_c_GENERATOR_FILES} + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__type_support_c.cpp.em" + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__type_support_c.cpp.em" + ${_dependency_files}) +foreach(dep ${target_dependencies}) + if(NOT EXISTS "${dep}") + message(FATAL_ERROR "Target dependency '${dep}' does not exist") + endif() +endforeach() + +set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c__arguments.json") +rosidl_write_generator_arguments( + "${generator_arguments_file}" + PACKAGE_NAME "${PROJECT_NAME}" + ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}" + ROS_INTERFACE_DEPENDENCIES "${_dependencies}" + OUTPUT_DIR "${_output_path}" + TEMPLATE_DIR "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}" + TARGET_DEPENDENCIES ${target_dependencies} + ADDITIONAL_FILES ${_dds_idl_files} +) + +add_custom_command( + OUTPUT ${_generated_msg_files} ${_generated_srv_files} + COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_fastrtps_c_BIN} + --generator-arguments-file "${generator_arguments_file}" + DEPENDS ${target_dependencies} ${_dds_idl_files} + COMMENT "Generating C type support for eProsima Fast-RTPS" + VERBATIM +) + +# generate header to switch between export and import for a specific package +set(_visibility_control_file +"${_output_path}/msg/rosidl_typesupport_fastrtps_c__visibility_control.h") +string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER) +configure_file( + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/rosidl_typesupport_fastrtps_c__visibility_control.h.in" + "${_visibility_control_file}" + @ONLY +) + +set(_target_suffix "__rosidl_typesupport_fastrtps_c") + +link_directories(${fastrtps_LIBRARY_DIRS}) +add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} SHARED + ${_generated_msg_files} ${_generated_srv_files}) +if(rosidl_generate_interfaces_LIBRARY_NAME) + set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES OUTPUT_NAME "${rosidl_generate_interfaces_LIBRARY_NAME}${_target_suffix}") +endif() +set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES CXX_STANDARD 14) +if(fastrtps_GLIBCXX_USE_CXX11_ABI_ZERO) + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE fastrtps_GLIBCXX_USE_CXX11_ABI_ZERO) +endif() +ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} + "fastrtps" + "rmw" + "rosidl_typesupport_fastrtps_cpp" + "rosidl_typesupport_fastrtps_c" + "rosidl_generator_c" + "rosidl_typesupport_interface") +if(WIN32) + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE "ROSIDL_TYPESUPPORT_FASTRTPS_C_BUILDING_DLL_${PROJECT_NAME}") + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE "NDDS_USER_DLL_EXPORT_${PROJECT_NAME}") +endif() + +if(NOT WIN32) + set(_target_compile_flags "-Wall -Wextra -Wpedantic") +else() + set(_target_compile_flags + "/W4" # Enable level 3 warnings + "/wd4100" # Ignore unreferenced formal parameter warnings + "/wd4127" # Ignore conditional expression is constant warnings + "/wd4275" # Ignore "an exported class derived from a non-exported class" warnings + "/wd4305" # Ignore "initializing: truncation from..." warnings + "/wd4458" # Ignore class hides member variable warnings + "/wd4701" # Ignore unused variable warnings + ) +endif() +string(REPLACE ";" " " _target_compile_flags "${_target_compile_flags}") +set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES COMPILE_FLAGS "${_target_compile_flags}") +target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PUBLIC + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp +) +ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} + "fastrtps" + "rosidl_typesupport_fastrtps_cpp" + "rosidl_typesupport_fastrtps_c" + "${PROJECT_NAME}__rosidl_typesupport_fastrtps_cpp") +foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) + set(_msg_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/msg/dds_fastrtps_c") + set(_srv_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/srv/dds_fastrtps_c") + normalize_path(_msg_include_dir "${_msg_include_dir}") + normalize_path(_srv_include_dir "${_srv_include_dir}") + target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PUBLIC + "${_msg_include_dir}" + "${_srv_include_dir}" + ) + ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${_pkg_name}) +endforeach() +target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${rosidl_generate_interfaces_TARGET}__rosidl_generator_c + ${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_fastrtps_cpp) + +add_dependencies( + ${rosidl_generate_interfaces_TARGET} + ${rosidl_generate_interfaces_TARGET}${_target_suffix} +) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${rosidl_generate_interfaces_TARGET}__rosidl_typesupport_fastrtps_cpp +) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${rosidl_generate_interfaces_TARGET}__cpp +) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${rosidl_generate_interfaces_TARGET}__dds_fastrtps_idl +) + +if(NOT rosidl_generate_interfaces_SKIP_INSTALL) + install( + DIRECTORY "${_output_path}/" + DESTINATION "include/${PROJECT_NAME}" + PATTERN "*.cpp" EXCLUDE + ) + + if(NOT _generated_msg_files STREQUAL "" OR NOT _generated_srv_files STREQUAL "") + ament_export_include_directories(include) + endif() + + install( + TARGETS ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + ) + + ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix}) +endif() + +if(BUILD_TESTING AND rosidl_generate_interfaces_ADD_LINTER_TESTS) + if(NOT _generated_msg_files STREQUAL "" OR NOT _generated_srv_files STREQUAL "") + find_package(ament_cmake_cppcheck REQUIRED) + ament_cppcheck( + TESTNAME "cppcheck_rosidl_typesupport_fastrtps_c" + ${_generated_msg_files} ${_generated_srv_files}) + + find_package(ament_cmake_cpplint REQUIRED) + get_filename_component(_cpplint_root "${_output_path}" DIRECTORY) + ament_cpplint( + TESTNAME "cpplint_rosidl_typesupport_fastrtps_c" + # the generated code might contain longer lines for templated types + MAX_LINE_LENGTH 999 + ROOT "${_cpplint_root}" + ${_generated_msg_files} ${_generated_srv_files}) + + find_package(ament_cmake_uncrustify REQUIRED) + ament_uncrustify( + TESTNAME "uncrustify_rosidl_typesupport_fastrtps_c" + # the generated code might contain longer lines for templated types + MAX_LINE_LENGTH 999 + ${_generated_msg_files} ${_generated_srv_files}) + endif() +endif() diff --git a/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/identifier.h b/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/identifier.h new file mode 100644 index 000000000..0ac3c9ae0 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/identifier.h @@ -0,0 +1,32 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_C__IDENTIFIER_H_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_C__IDENTIFIER_H_ + +#include "rosidl_typesupport_fastrtps_c/visibility_control.h" + +#if __cplusplus +extern "C" +{ +#endif + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC +extern const char * rosidl_typesupport_fastrtps_c__identifier; + +#if __cplusplus +} +#endif + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_C__IDENTIFIER_H_ diff --git a/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/visibility_control.h b/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/visibility_control.h new file mode 100644 index 000000000..d0e373466 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/include/rosidl_typesupport_fastrtps_c/visibility_control.h @@ -0,0 +1,56 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ + +#if __cplusplus +extern "C" +{ +#endif + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT __attribute__ ((dllexport)) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT __attribute__ ((dllimport)) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT __declspec(dllexport) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT __declspec(dllimport) + #endif + #ifdef ROSIDL_TYPESUPPORT_FASTRTPS_C_BUILDING_DLL + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT + #endif + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_LOCAL +#else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT + #if __GNUC__ >= 4 + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_LOCAL + #endif +#endif + +#if __cplusplus +} +#endif + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ diff --git a/rosidl_typesupport_fastrtps_c/package.xml b/rosidl_typesupport_fastrtps_c/package.xml new file mode 100644 index 000000000..3b669c263 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/package.xml @@ -0,0 +1,40 @@ + + + + rosidl_typesupport_fastrtps_c + 0.4.0 + Generate the C interfaces for eProsima FastRTPS. + Ricardo González + Apache License 2.0 + + ament_cmake + fastrtps_cmake_module + fastcdr + fastrtps + rosidl_cmake + rosidl_generator_c + rosidl_typesupport_fastrtps_cpp + + ament_cmake + fastrtps_cmake_module + fastcdr + fastrtps + rosidl_cmake + rosidl_generator_c + rosidl_generator_dds_idl + rosidl_typesupport_fastrtps_cpp + + rmw + + rosidl_parser + rosidl_typesupport_interface + + ament_lint_auto + ament_lint_common + + rosidl_typesupport_c_packages + + + ament_cmake + + diff --git a/rosidl_typesupport_fastrtps_c/resource/msg__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/msg__rosidl_typesupport_fastrtps_c.h.em new file mode 100644 index 000000000..67838c0d8 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/msg__rosidl_typesupport_fastrtps_c.h.em @@ -0,0 +1,57 @@ +// generated from +// rosidl_typesupport_fastrtps_c/resource/msg__rosidl_typesupport_fastrtps_c.h.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating +@# __rosidl_typesupport_fastrtps_c.h files +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .msg file +@# - subfolder (string) +@# The subfolder / subnamespace of the message +@# Either 'msg' or 'srv' +@# - get_header_filename_from_msg_name (function) +@####################################################################### +@ +@{ +header_guard_parts = [ + spec.base_type.pkg_name, subfolder, + get_header_filename_from_msg_name(spec.base_type.type) + '__rosidl_typesupport_fastrtps_c_h'] +header_guard_variable = '__'.join([x.upper() for x in header_guard_parts]) + '_' +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +#include + +#include "rosidl_generator_c/message_type_support_struct.h" +#include "rosidl_typesupport_interface/macros.h" + +#include "@(spec.base_type.pkg_name)/msg/rosidl_typesupport_fastrtps_c__visibility_control.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +size_t get_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + const void * untyped_ros_message, + size_t current_alignment); + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +size_t max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + bool & full_bounded, + size_t current_alignment); + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +const rosidl_message_type_support_t * + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.base_type.pkg_name), @(subfolder), @(spec.base_type.type))(); + +#ifdef __cplusplus +} +#endif + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em new file mode 100644 index 000000000..3fca5eaad --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em @@ -0,0 +1,491 @@ +// generated from rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em +// generated code does not contain a copyright notice + +@########################################################################## +@# EmPy template for generating __type_support_c.cpp files for fastrtps +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .msg file +@# - pkg (string) +@# name of the containing package; equivalent to spec.base_type.pkg_name +@# - msg (string) +@# name of the message; equivalent to spec.msg_name +@# - type (string) +@# full type of the message; equivalent to spec.base_type.type +@# - subfolder (string) +@# The subfolder / subnamespace of the message +@# Either 'msg' or 'srv' +@# - get_header_filename_from_msg_name (function) +@########################################################################## +@ +#include "@(spec.base_type.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.base_type.type))__rosidl_typesupport_fastrtps_c.h" + +#include +#include +#include + +// Provides the rosidl_typesupport_fastrtps_c__identifier symbol declaration. +#include "rosidl_typesupport_fastrtps_c/identifier.h" +// Provides the definition of the message_type_support_callbacks_t struct. +#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h" + +#include "@(pkg)/msg/rosidl_typesupport_fastrtps_c__visibility_control.h" +@{header_file_name = get_header_filename_from_msg_name(type)}@ +#include "@(pkg)/@(subfolder)/@(header_file_name)__struct.h" +#include "@(pkg)/@(subfolder)/@(header_file_name)__functions.h" + +#include "fastcdr/Cdr.h" + +#ifndef _WIN32 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-parameter" +# ifdef __clang__ +# pragma clang diagnostic ignored "-Wdeprecated-register" +# pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +# endif +#endif +#ifndef _WIN32 +# pragma GCC diagnostic pop +#endif + +// includes and forward declarations of message dependencies and their conversion functions + +@# // Include the message header for each non-primitive field. +#if defined(__cplusplus) +extern "C" +{ +#endif + +@{ +includes = {} +for field in spec.fields: + keys = set([]) + if field.type.is_primitive_type(): + if field.type.is_array: + keys.add('rosidl_generator_c/primitives_array.h') + keys.add('rosidl_generator_c/primitives_array_functions.h') + if field.type.type == 'string': + keys.add('rosidl_generator_c/string.h') + keys.add('rosidl_generator_c/string_functions.h') + else: + header_file_name = get_header_filename_from_msg_name(field.type.type) + keys.add('%s/msg/%s__functions.h' % (field.type.pkg_name, header_file_name)) + for key in keys: + if key not in includes: + includes[key] = set([]) + includes[key].add(field.name) +}@ +@[for key in sorted(includes.keys())]@ +#include "@(key)" // @(', '.join(includes[key])) +@[end for]@ + +// forward declare type support functions +@{ +forward_declares = {} +for field in spec.fields: + if not field.type.is_primitive_type(): + key = (field.type.pkg_name, field.type.type) + if key not in includes: + forward_declares[key] = set([]) + forward_declares[key].add(field.name) +}@ +@[for key in sorted(forward_declares.keys())]@ +@[ if key[0] != pkg]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ end if]@ +size_t get_serialized_size_@(key[0])__msg__@(key[1])( + const void * untyped_ros_message, + size_t current_alignment); + +@[ if key[0] != pkg]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ end if]@ +size_t max_serialized_size_@(key[0])__msg__@(key[1])( + bool & full_bounded, + size_t current_alignment); + +@[ if key[0] != pkg]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ end if]@ +const rosidl_message_type_support_t * + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(key[0]), msg, @(key[1]))(); +@[end for]@ + +@# // Make callback functions specific to this message type. + +using __ros_msg_type = @(pkg)__@(subfolder)__@(type); + +static bool __cdr_serialize( + const void * untyped_ros_message, + eprosima::fastcdr::Cdr & cdr) +{ + if (!untyped_ros_message) { + fprintf(stderr, "ros message handle is null\n"); + return false; + } +@[if not spec.fields]@ + // No fields is a no-op. + (void)cdr; + (void)untyped_ros_message; +@[else]@ + const __ros_msg_type * ros_message = static_cast(untyped_ros_message); +@[end if]@ +@[for field in spec.fields]@ + // Field name: @(field.name) + { +@[ if not field.type.is_primitive_type()]@ + const message_type_support_callbacks_t * @(field.type.pkg_name)__msg__@(field.type.type)__callbacks = + static_cast( + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(field.type.pkg_name), msg, @(field.type.type) + )()->data); +@[ end if]@ +@[ if field.type.is_array]@ +@[ if field.type.array_size and not field.type.is_upper_bound]@ + size_t size = @(field.type.array_size); + auto array_ptr = ros_message->@(field.name); +@[ else]@ + size_t size = ros_message->@(field.name).size; + auto array_ptr = ros_message->@(field.name).data; +@[ if field.type.is_upper_bound]@ + if (size > @(field.type.array_size)) { + fprintf(stderr, "array size exceeds upper bound\n"); + return false; + } +@[ end if]@ + cdr << static_cast(size); +@[ end if]@ +@[ if field.type.type == 'string']@ + for (size_t i = 0; i < size; ++i) { + const rosidl_generator_c__String * str = &array_ptr[i]; + if (str->capacity == 0 || str->capacity <= str->size) { + fprintf(stderr, "string capacity not greater than size\n"); + return false; + } + if (str->data[str->size] != '\0') { + fprintf(stderr, "string not null-terminated\n"); + return false; + } + cdr << str->data; + } +@[ elif field.type.is_primitive_type()]@ + cdr.serializeArray(array_ptr, size); +@[ else]@ + for (size_t i = 0; i < size; ++i) { + if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_serialize( + &array_ptr[i], cdr)) + { + return false; + } + } +@[ end if]@ +@[ elif field.type.type == 'string']@ + const rosidl_generator_c__String * str = &ros_message->@(field.name); + if (str->capacity == 0 || str->capacity <= str->size) { + fprintf(stderr, "string capacity not greater than size\n"); + return false; + } + if (str->data[str->size] != '\0') { + fprintf(stderr, "string not null-terminated\n"); + return false; + } + cdr << str->data; +@[ elif field.type.is_primitive_type()]@ + cdr << ros_message->@(field.name); +@[ else]@ + if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_serialize( + &ros_message->@(field.name), cdr)) + { + return false; + } +@[ end if]@ + } + +@[end for]@ + return true; +} + +static bool __cdr_deserialize( + eprosima::fastcdr::Cdr & cdr, + void * untyped_ros_message) +{ + if (!untyped_ros_message) { + fprintf(stderr, "ros message handle is null\n"); + return false; + } +@[if not spec.fields]@ + // No fields is a no-op. + (void)cdr; + (void)untyped_ros_message; +@[else]@ + __ros_msg_type * ros_message = static_cast<__ros_msg_type *>(untyped_ros_message); +@[end if]@ +@[for field in spec.fields]@ + // Field name: @(field.name) + { +@[ if not field.type.is_primitive_type()]@ + const message_type_support_callbacks_t * @(field.type.pkg_name)__msg__@(field.type.type)__callbacks = + static_cast( + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(field.type.pkg_name), msg, @(field.type.type) + )()->data); +@[ end if]@ +@[ if field.type.is_array]@ +@[ if field.type.array_size and not field.type.is_upper_bound]@ + size_t size = @(field.type.array_size); + auto array_ptr = ros_message->@(field.name); +@[ else]@ +@{ +if field.type.type == 'string': + array_init = 'rosidl_generator_c__String__Array__init' + array_fini = 'rosidl_generator_c__String__Array__fini' +elif field.type.is_primitive_type(): + array_init = 'rosidl_generator_c__{field.type.type}__Array__init'.format(**locals()) + array_fini = 'rosidl_generator_c__{field.type.type}__Array__fini'.format(**locals()) +else: + array_init = '{field.type.pkg_name}__msg__{field.type.type}__Array__init'.format(**locals()) + array_fini = '{field.type.pkg_name}__msg__{field.type.type}__Array__fini'.format(**locals()) +}@ + uint32_t cdrSize; + cdr >> cdrSize; + size_t size = static_cast(cdrSize); + if (ros_message->@(field.name).data) { + @(array_fini)(&ros_message->@(field.name)); + } + if (!@(array_init)(&ros_message->@(field.name), size)) { + return "failed to create array for field '@(field.name)'"; + } + auto array_ptr = ros_message->@(field.name).data; +@[ end if]@ +@[ if field.type.type == 'string']@ + for (size_t i = 0; i < size; ++i) { + std::string tmp; + cdr >> tmp; + auto & ros_i = array_ptr[i]; + if (!ros_i.data) { + rosidl_generator_c__String__init(&ros_i); + } + bool succeeded = rosidl_generator_c__String__assign( + &ros_i, + tmp.c_str()); + if (!succeeded) { + fprintf(stderr, "failed to assign string into field '@(field.name)'\n"); + return false; + } + } +@[ elif field.type.is_primitive_type()]@ + cdr.deserializeArray(array_ptr, size); +@[ else]@ + for (size_t i = 0; i < size; ++i) { + if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_deserialize( + cdr, &array_ptr[i])) + { + return false; + } + } +@[ end if]@ +@[ elif field.type.type == 'string']@ + std::string tmp; + cdr >> tmp; + if (!ros_message->@(field.name).data) { + rosidl_generator_c__String__init(&ros_message->@(field.name)); + } + bool succeeded = rosidl_generator_c__String__assign( + &ros_message->@(field.name), + tmp.c_str()); + if (!succeeded) { + fprintf(stderr, "failed to assign string into field '@(field.name)'\n"); + return false; + } +@[ elif field.type.is_primitive_type()]@ + cdr >> ros_message->@(field.name); +@[ else]@ + if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_deserialize( + cdr, &ros_message->@(field.name))) + { + return false; + } +@[ end if]@ + } + +@[end for]@ + return true; +} + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +size_t get_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + const void * untyped_ros_message, + size_t current_alignment) +{ +@[if not spec.fields]@ + (void)untyped_ros_message; + (void)current_alignment; +@[else]@ + const __ros_msg_type * ros_message = static_cast(untyped_ros_message); + (void)ros_message; + size_t initial_alignment = current_alignment; + + const size_t padding = 4; + (void)padding; +@[end if]@ + +@[for field in spec.fields]@ + // field.name @(field.name) +@[ if field.type.is_array]@ + { +@[ if field.type.array_size and not field.type.is_upper_bound]@ + size_t array_size = @(field.type.array_size); + auto array_ptr = ros_message->@(field.name); +@[ else]@ + size_t array_size = ros_message->@(field.name).size; + auto array_ptr = ros_message->@(field.name).data; + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); +@[ end if]@ +@[ if field.type.type == 'string']@ + for (size_t index = 0; index < array_size; ++index) { + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + array_ptr[index].size + 1; + } +@[ elif field.type.is_primitive_type()]@ + (void)array_ptr; + size_t item_size = sizeof(array_ptr[0]); + current_alignment += array_size * item_size + + eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); +@[ else] + for (size_t index = 0; index < array_size; ++index) { + current_alignment += get_serialized_size_@(field.type.pkg_name)__msg__@(field.type.type)( + &array_ptr[index], current_alignment); + } +@[ end if]@ + } +@[ else]@ +@[ if field.type.type == 'string']@ + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + ros_message->@(field.name).size + 1; +@[ elif field.type.is_primitive_type()]@ + { + size_t item_size = sizeof(ros_message->@(field.name)); + current_alignment += item_size + + eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); + } +@[ else] + current_alignment += get_serialized_size_@(field.type.pkg_name)__msg__@(field.type.type)( + &(ros_message->@(field.name)), current_alignment); +@[ end if]@ +@[ end if]@ +@[end for]@ + +@[if not spec.fields]@ + return 0; +@[else]@ + return current_alignment - initial_alignment; +@[end if]@ +} + +static uint32_t __get_serialized_size(const void * untyped_ros_message) +{ + return static_cast( + get_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + untyped_ros_message, 0)); +} + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +size_t max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + bool & full_bounded, + size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + const size_t padding = 4; + (void)padding; + (void)full_bounded; + +@[for field in spec.fields]@ + // field.name @(field.name) + { +@[ if field.type.is_array]@ +@[ if field.type.array_size]@ + size_t array_size = @(field.type.array_size); +@[ else]@ + size_t array_size = 0; +@[ end if]@ +@[ if not field.type.array_size or field.type.is_upper_bound]@ + full_bounded = false; + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); +@[ end if]@ +@[ else]@ + size_t array_size = 1; +@[ end if]@ + +@[ if field.type.type == 'string']@ + full_bounded = false; + for (size_t index = 0; index < array_size; ++index) { + current_alignment += padding + +@[ if field.type.string_upper_bound]@ + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + @(field.type.string_upper_bound) + 1; +@[ else]@ + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + 1; +@[ end if]@ + } +@[ elif field.type.is_primitive_type()]@ +@[ if field.type.type == 'bool' or field.type.type == 'byte' or field.type.type == 'char' or field.type.type == 'uint8' or field.type.type == 'int8' ] + current_alignment += array_size * sizeof(uint8_t); +@[ elif field.type.type == 'int16' or field.type.type == 'uint16'] + current_alignment += array_size * sizeof(uint16_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint16_t)); +@[ elif field.type.type == 'int32' or field.type.type == 'uint32' or field.type.type == 'float32'] + current_alignment += array_size * sizeof(uint32_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint32_t)); +@[ elif field.type.type == 'int64' or field.type.type == 'uint64' or field.type.type == 'float64'] + current_alignment += array_size * sizeof(uint64_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint64_t)); +@[ end if]@ +@[ else] + for (size_t index = 0; index < array_size; ++index) { + current_alignment += + max_serialized_size_@(field.type.pkg_name)__msg__@(field.type.type)( + full_bounded, current_alignment); + } +@[ end if]@ + } +@[end for]@ + + return current_alignment - initial_alignment; +} + +static size_t __max_serialized_size(bool & full_bounded) +{ + return max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + full_bounded, 0); +} + +@ +@# // Collect the callback functions and provide a function to get the type support struct. + +static message_type_support_callbacks_t __callbacks = { + "@(pkg)", + "@(msg)", + __cdr_serialize, + __cdr_deserialize, + __get_serialized_size, + __max_serialized_size +}; + +static rosidl_message_type_support_t __type_support = { + rosidl_typesupport_fastrtps_c__identifier, + &__callbacks, + get_message_typesupport_handle_function, +}; + +const rosidl_message_type_support_t * +ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(pkg), @(subfolder), @(msg))() { + return &__type_support; +} + +#if defined(__cplusplus) +} +#endif diff --git a/rosidl_typesupport_fastrtps_c/resource/rosidl_typesupport_fastrtps_c__visibility_control.h.in b/rosidl_typesupport_fastrtps_c/resource/rosidl_typesupport_fastrtps_c__visibility_control.h.in new file mode 100644 index 000000000..16b92154a --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/rosidl_typesupport_fastrtps_c__visibility_control.h.in @@ -0,0 +1,43 @@ +// generated from +// rosidl_typesupport_fastrtps_c/resource/rosidl_typesupport_fastrtps_c__visibility_control.h.in +// generated code does not contain a copyright notice + +#ifndef @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ +#define @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ + +#if __cplusplus +extern "C" +{ +#endif + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT_@PROJECT_NAME@ __attribute__ ((dllexport)) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@PROJECT_NAME@ __attribute__ ((dllimport)) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT_@PROJECT_NAME@ __declspec(dllexport) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@PROJECT_NAME@ __declspec(dllimport) + #endif + #ifdef ROSIDL_TYPESUPPORT_FASTRTPS_C_BUILDING_DLL_@PROJECT_NAME@ + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@PROJECT_NAME@ ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT_@PROJECT_NAME@ + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@PROJECT_NAME@ ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@PROJECT_NAME@ + #endif +#else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_EXPORT_@PROJECT_NAME@ __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@PROJECT_NAME@ + #if __GNUC__ >= 4 + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@PROJECT_NAME@ __attribute__ ((visibility("default"))) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@PROJECT_NAME@ + #endif +#endif + +#if __cplusplus +} +#endif + +#endif // @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_C__VISIBILITY_CONTROL_H_ diff --git a/rosidl_typesupport_fastrtps_c/resource/srv__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/srv__rosidl_typesupport_fastrtps_c.h.em new file mode 100644 index 000000000..8f1181ef0 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/srv__rosidl_typesupport_fastrtps_c.h.em @@ -0,0 +1,42 @@ +// generated from +// rosidl_typesupport_fastrtps_c/resource/srv__rosidl_typesupport_fastrtps_c.h.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating +@# __rosidl_typesupport_fastrtps_c.h files +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .srv file +@# - get_header_filename_from_srv_name (function) +@####################################################################### +@ +@{ +header_guard_parts = [ + spec.pkg_name, 'srv', + get_header_filename_from_msg_name(spec.srv_name) + '__rosidl_typesupport_fastrtps_c_h'] +header_guard_variable = '__'.join([x.upper() for x in header_guard_parts]) + '_' +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +#include "rosidl_generator_c/service_type_support_struct.h" +#include "rosidl_typesupport_interface/macros.h" + +#include "@(spec.pkg_name)/msg/rosidl_typesupport_fastrtps_c__visibility_control.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.pkg_name) +const rosidl_service_type_support_t * + ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), @(spec.srv_name))(); + +#ifdef __cplusplus +} +#endif + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em b/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em new file mode 100644 index 000000000..61dc12089 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em @@ -0,0 +1,55 @@ +// generated from rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating __type_support_c.cpp files +@# +@# Context: +@# - spec (rosidl_parser.ServiceSpecification) +@# Parsed specification of the .srv file +@# - get_header_filename_from_msg_name (function) +@####################################################################### +@ +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name))__rosidl_typesupport_fastrtps_c.h" + +// Provides the definition of the service_type_support_callbacks_t struct. +#include + +#include "rosidl_typesupport_cpp/service_type_support.hpp" +#include "rosidl_typesupport_fastrtps_c/identifier.h" + +#include "@(spec.pkg_name)/msg/rosidl_typesupport_fastrtps_c__visibility_control.h" +@{req_header_file_name = get_header_filename_from_msg_name(spec.srv_name + '__request')}@ +@{res_header_file_name = get_header_filename_from_msg_name(spec.srv_name + '__response')}@ +#include "@(spec.pkg_name)/srv/@(req_header_file_name).h" +#include "@(spec.pkg_name)/srv/@(res_header_file_name).h" + +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_c.h" +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_c.h" + +#if defined(__cplusplus) +extern "C" +{ +#endif + +static service_type_support_callbacks_t callbacks = { + "@(spec.pkg_name)", + "@(spec.srv_name)", + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), srv, @(spec.srv_name)_Request)(), + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), srv, @(spec.srv_name)_Response)(), +}; + +static rosidl_service_type_support_t handle = { + rosidl_typesupport_fastrtps_c__identifier, + &callbacks, + get_service_typesupport_handle_function, +}; + +const rosidl_service_type_support_t * +ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), @(spec.srv_name))() { + return &handle; +} + +#if defined(__cplusplus) +} +#endif diff --git a/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in new file mode 100644 index 000000000..29e484fe9 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in @@ -0,0 +1,34 @@ +# generated from +# rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in + +find_package(fastrtps_cmake_module QUIET) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) + +if(NOT FastRTPS_FOUND) + message(STATUS + "Could not find eProsima Fast-RTPS: skipping rosidl_typesupport_fastrtps_c" + ) +else() + find_package(ament_cmake_core QUIET REQUIRED) + ament_register_extension( + "rosidl_generate_interfaces" + "rosidl_typesupport_fastrtps_c" + "rosidl_typesupport_fastrtps_c_generate_interfaces.cmake") + + set(rosidl_typesupport_fastrtps_c_BIN + "${rosidl_typesupport_fastrtps_c_DIR}/../../../lib/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c") + normalize_path(rosidl_typesupport_fastrtps_c_BIN + "${rosidl_typesupport_fastrtps_c_BIN}") + + set(rosidl_typesupport_fastrtps_c_GENERATOR_FILES + "${rosidl_typesupport_fastrtps_c_DIR}/../../../@PYTHON_INSTALL_DIR@/rosidl_typesupport_fastrtps_c/__init__.py") + normalize_path(rosidl_typesupport_fastrtps_c_GENERATOR_FILES + "${rosidl_typesupport_fastrtps_c_GENERATOR_FILES}") + + set(rosidl_typesupport_fastrtps_c_TEMPLATE_DIR + "${rosidl_typesupport_fastrtps_c_DIR}/../resource") + normalize_path(rosidl_typesupport_fastrtps_c_TEMPLATE_DIR + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}") +endif() diff --git a/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py new file mode 100644 index 000000000..02d93b96a --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py @@ -0,0 +1,103 @@ +# Copyright 2016 Open Source Robotics Foundation, Inc. +# +# 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. + +import os + +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +from rosidl_cmake import expand_template +from rosidl_cmake import extract_message_types +from rosidl_cmake import get_newest_modification_time +from rosidl_parser import parse_message_file +from rosidl_parser import parse_service_file +from rosidl_parser import validate_field_types + + +def generate_typesupport_fastrtps_c(args): + template_dir = args['template_dir'] + mapping_msgs = { + os.path.join(template_dir, 'msg__rosidl_typesupport_fastrtps_c.h.em'): + '%s__rosidl_typesupport_fastrtps_c.h', + os.path.join(template_dir, 'msg__type_support_c.cpp.em'): + '%s__type_support_c.cpp', + } + + mapping_srvs = { + os.path.join(template_dir, 'srv__rosidl_typesupport_fastrtps_c.h.em'): + '%s__rosidl_typesupport_fastrtps_c.h', + os.path.join(template_dir, 'srv__type_support_c.cpp.em'): + '%s__type_support_c.cpp', + } + + for template_file in mapping_msgs.keys(): + assert os.path.exists(template_file), 'Could not find template: ' + template_file + + for template_file in mapping_srvs.keys(): + assert os.path.exists(template_file), 'Could not find template: ' + template_file + + pkg_name = args['package_name'] + known_msg_types = extract_message_types( + pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) + + functions = { + 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, + } + # generate_dds_fastrtps_cpp() and therefore the make target depend on the additional files + # therefore they must be listed here even if the generated type support files are independent + latest_target_timestamp = get_newest_modification_time( + args['target_dependencies'] + args.get('additional_files', [])) + + for idl_file in args['ros_interface_files']: + extension = os.path.splitext(idl_file)[1] + if extension == '.msg': + spec = parse_message_file(pkg_name, idl_file) + validate_field_types(spec, known_msg_types) + subfolder = os.path.basename(os.path.dirname(idl_file)) + for template_file, generated_filename in mapping_msgs.items(): + generated_file = os.path.join(args['output_dir'], subfolder) + if generated_filename.endswith('.cpp'): + generated_file = os.path.join(generated_file, 'dds_fastrtps_c') + generated_file = os.path.join( + generated_file, generated_filename % + convert_camel_case_to_lower_case_underscore(spec.base_type.type)) + + data = { + 'spec': spec, + 'pkg': spec.base_type.pkg_name, + 'msg': spec.msg_name, + 'type': spec.base_type.type, + 'subfolder': subfolder, + } + data.update(functions) + expand_template( + template_file, data, generated_file, + minimum_timestamp=latest_target_timestamp) + + elif extension == '.srv': + spec = parse_service_file(pkg_name, idl_file) + validate_field_types(spec, known_msg_types) + for template_file, generated_filename in mapping_srvs.items(): + generated_file = os.path.join(args['output_dir'], 'srv') + if generated_filename.endswith('.cpp'): + generated_file = os.path.join(generated_file, 'dds_fastrtps_c') + generated_file = os.path.join( + generated_file, generated_filename % + convert_camel_case_to_lower_case_underscore(spec.srv_name)) + + data = {'spec': spec} + data.update(functions) + expand_template( + template_file, data, generated_file, + minimum_timestamp=latest_target_timestamp) + + return 0 diff --git a/rosidl_typesupport_fastrtps_c/src/identifier.cpp b/rosidl_typesupport_fastrtps_c/src/identifier.cpp new file mode 100644 index 000000000..bf6466606 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/src/identifier.cpp @@ -0,0 +1,29 @@ +// Copyright 2016 Open Source Robotics Foundation, Inc. +// +// 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 + +#if defined(__cplusplus) +extern "C" +{ +#endif + +const char * + rosidl_typesupport_fastrtps_c__identifier = "rosidl_typesupport_fastrtps_c"; + +#if defined(__cplusplus) +} +#endif diff --git a/rosidl_typesupport_fastrtps_cpp/CMakeLists.txt b/rosidl_typesupport_fastrtps_cpp/CMakeLists.txt new file mode 100644 index 000000000..35b1221f3 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/CMakeLists.txt @@ -0,0 +1,82 @@ +cmake_minimum_required(VERSION 3.5) + +project(rosidl_typesupport_fastrtps_cpp) + +set(FASTRTPS_STATIC_DISABLE $ENV{FASTRTPS_STATIC_DISABLE} + CACHE BOOL "If fastrtps Static should be disabled.") + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) + +find_package(fastrtps_cmake_module QUIET) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) +if(FASTRTPS_STATIC_DISABLE) + ament_package() + message(STATUS "fastrtps static rmw implementation explicitly disabled - skipping '${PROJECT_NAME}'") + return() +endif() + +find_package(ament_cmake_python REQUIRED) + +ament_export_dependencies(fastrtps) +ament_export_dependencies(rmw) +ament_export_dependencies(rosidl_cmake) +ament_export_dependencies(rosidl_generator_c) +ament_export_dependencies(rosidl_generator_cpp) +ament_export_dependencies(rosidl_generator_dds_idl) +ament_export_dependencies(rosidl_typesupport_interface) + +ament_export_include_directories(include) + +ament_python_install_package(${PROJECT_NAME}) + +add_library(${PROJECT_NAME} SHARED src/identifier.cpp) +if(WIN32) + target_compile_definitions(${PROJECT_NAME} + PRIVATE "ROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL") +endif() +target_include_directories(${PROJECT_NAME} + PUBLIC + include +) +ament_export_libraries(${PROJECT_NAME}) + +ament_index_register_resource("rosidl_typesupport_cpp") + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package( + CONFIG_EXTRAS "rosidl_typesupport_fastrtps_cpp-extras.cmake.in" +) + +install( + PROGRAMS bin/rosidl_typesupport_fastrtps_cpp + DESTINATION lib/rosidl_typesupport_fastrtps_cpp +) +install( + DIRECTORY cmake resource + DESTINATION share/${PROJECT_NAME} +) +install( + DIRECTORY include/ + DESTINATION include +) +install( + TARGETS ${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) diff --git a/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp b/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp new file mode 100644 index 000000000..08f9e27b6 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import argparse +import sys + +from rosidl_cmake import extract_message_types +from rosidl_cmake import read_generator_arguments +from rosidl_parser import UnknownMessageType +from rosidl_typesupport_fastrtps_cpp import generate_cpp +from rosidl_typesupport_fastrtps_cpp import generate_dds_fastrtps_cpp +from rosidl_typesupport_fastrtps_cpp import parse_ros_interface_files + + +def main(argv=sys.argv[1:]): + parser = argparse.ArgumentParser( + description='Generate the C++ interfaces for fastrtps.', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument( + '--generator-arguments-file', + required=True, + help='The location of the file containing the generator arguments') + parser.add_argument( + '--dds-interface-base-path', + required=True, + help='The base location of the DDS interface files') + parser.add_argument( + '--idl-pp', + required=True, + help='The location of the IDL preprocessor') + args = parser.parse_args(argv) + + generator_args = read_generator_arguments(args.generator_arguments_file) + + message_specs, service_specs = parse_ros_interface_files( + generator_args['package_name'], generator_args['ros_interface_files']) + + known_msg_types = extract_message_types( + generator_args['package_name'], generator_args['ros_interface_files'], + generator_args.get('ros_interface_dependencies', [])) + + try: + rc = generate_cpp(generator_args, message_specs, service_specs, known_msg_types) + except UnknownMessageType as e: + print(str(e), file=sys.stderr) + return 1 + if rc: + return rc + return generate_dds_fastrtps_cpp( + generator_args['package_name'], + generator_args.get('additional_files', []), + args.dds_interface_base_path, + generator_args.get('ros_interface_dependencies', []), + generator_args['output_dir'], + args.idl_pp, + message_specs, + service_specs, + ) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/rosidl_typesupport_fastrtps_cpp/cmake/rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake b/rosidl_typesupport_fastrtps_cpp/cmake/rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake new file mode 100644 index 000000000..e14de45a0 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/cmake/rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake @@ -0,0 +1,286 @@ +# Copyright 2014-2015 Open Source Robotics Foundation, Inc. +# +# 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. + +find_package(fastrtps_cmake_module QUIET) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) + +set(_ros_idl_files "") +foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + # Skip .srv files + if(_extension STREQUAL ".msg") + list(APPEND _ros_idl_files "${_idl_file}") + endif() +endforeach() + +rosidl_generate_dds_interfaces( + ${rosidl_generate_interfaces_TARGET}__dds_fastrtps_idl + IDL_FILES ${_ros_idl_files} + DEPENDENCY_PACKAGE_NAMES ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} + OUTPUT_SUBFOLDERS "dds_fastrtps" +) + +set(_dds_idl_files "") +set(_dds_idl_base_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_dds_idl") +foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + get_filename_component(_name "${_idl_file}" NAME_WE) + list(APPEND _dds_idl_files + "${_dds_idl_base_path}/${PROJECT_NAME}/${_parent_folder}/dds_fastrtps/${_name}_.idl") + endif() +endforeach() + +set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp/${PROJECT_NAME}") +set(_generated_msg_files "") +set(_generated_srv_files "") +foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + get_filename_component(_msg_name "${_idl_file}" NAME_WE) + string_camel_case_to_lower_case_underscore("${_msg_name}" _header_name) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + if(_parent_folder STREQUAL "msg") + set(_var2 "_generated_msg_files") + elseif(_parent_folder STREQUAL "srv") + set(_var2 "_generated_srv_files") + else() + message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") + endif() + + list(APPEND ${_var2} "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_cpp.hpp") + list(APPEND ${_var2} "${_output_path}/${_parent_folder}/dds_fastrtps/${_header_name}__type_support.cpp") + elseif(_extension STREQUAL ".srv") + list(APPEND _generated_srv_files "${_output_path}/srv/${_header_name}__rosidl_typesupport_fastrtps_cpp.hpp") + list(APPEND _generated_srv_files "${_output_path}/srv/dds_fastrtps/${_header_name}__type_support.cpp") + else() + message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}") + endif() +endforeach() + +# If not on Windows, disable some warnings with fastrtps's generated code +if(NOT WIN32) + set(_fastrtps_compile_flags) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(_fastrtps_compile_flags + "-Wno-deprecated-register" + "-Wno-return-type-c-linkage" + "-Wno-unused-parameter" + ) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(_fastrtps_compile_flags + # no-strict-aliasing necessary only for Release builds + "-Wno-strict-aliasing" + "-Wno-unused-parameter" + ) + endif() + if(NOT _fastrtps_compile_flags STREQUAL "") + string(REPLACE ";" " " _fastrtps_compile_flags "${_fastrtps_compile_flags}") + endif() +endif() + +set(_dependency_files "") +set(_dependencies "") +foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) + foreach(_idl_file ${${_pkg_name}_INTERFACE_FILES}) + get_filename_component(_extension "${_idl_file}" EXT) + if(_extension STREQUAL ".msg") + get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + get_filename_component(_parent_folder "${_parent_folder}" NAME) + get_filename_component(_name "${_idl_file}" NAME_WE) + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_parent_folder}/dds_fastrtps/${_name}_.idl") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependency_files "${_abs_idl_file}") + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") + endif() + endforeach() +endforeach() + +set(target_dependencies + "${rosidl_typesupport_fastrtps_cpp_BIN}" + ${rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES} + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/msg__rosidl_typesupport_fastrtps_cpp.hpp.em" + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/msg__type_support.cpp.em" + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/srv__rosidl_typesupport_fastrtps_cpp.hpp.em" + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/srv__type_support.cpp.em" + ${_dependency_files}) +foreach(dep ${target_dependencies}) + if(NOT EXISTS "${dep}") + message(FATAL_ERROR "Target dependency '${dep}' does not exist") + endif() +endforeach() + +set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp__arguments.json") +rosidl_write_generator_arguments( + "${generator_arguments_file}" + PACKAGE_NAME "${PROJECT_NAME}" + ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}" + ROS_INTERFACE_DEPENDENCIES "${_dependencies}" + OUTPUT_DIR "${_output_path}" + TEMPLATE_DIR "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}" + TARGET_DEPENDENCIES ${target_dependencies} + ADDITIONAL_FILES ${_dds_idl_files} +) + +set(_idl_pp "") +add_custom_command( + OUTPUT ${_generated_msg_files} ${_generated_srv_files} + COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_fastrtps_cpp_BIN} + --generator-arguments-file "${generator_arguments_file}" + --dds-interface-base-path "${_dds_idl_base_path}" + --idl-pp "${_idl_pp}" + DEPENDS ${target_dependencies} ${_dds_idl_files} + COMMENT "Generating C++ type support for eProsima Fast-RTPS" + VERBATIM +) + +# generate header to switch between export and import for a specific package +set(_visibility_control_file +"${_output_path}/msg/rosidl_typesupport_fastrtps_cpp__visibility_control.h") +string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER) +configure_file( + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/rosidl_typesupport_fastrtps_cpp__visibility_control.h.in" + "${_visibility_control_file}" + @ONLY +) + +set(_target_suffix "__rosidl_typesupport_fastrtps_cpp") + +# link_directories(${fastrtps_LIBRARY_DIRS}) +add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} SHARED + ${_generated_msg_files} ${_generated_srv_files}) +if(rosidl_generate_interfaces_LIBRARY_NAME) + set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES OUTPUT_NAME "${rosidl_generate_interfaces_LIBRARY_NAME}${_target_suffix}") +endif() +set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES CXX_STANDARD 14) +if(fastrtps_GLIBCXX_USE_CXX11_ABI_ZERO) + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE fastrtps_GLIBCXX_USE_CXX11_ABI_ZERO) +endif() +if(WIN32) + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE "ROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL_${PROJECT_NAME}") + target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PRIVATE "EPROSIMA_USER_DLL_EXPORT") +endif() +if(NOT WIN32) + set(_target_compile_flags "-Wall -Wextra -Wpedantic") +else() + set(_target_compile_flags + "/W4" + "/wd4100" + "/wd4127" + "/wd4275" + "/wd4305" + "/wd4458" + "/wd4701" + ) +endif() +string(REPLACE ";" " " _target_compile_flags "${_target_compile_flags}") +set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PROPERTIES COMPILE_FLAGS "${_target_compile_flags}") +target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PUBLIC + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp + ${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp +) +ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} + "fastrtps" + "rmw" + "rosidl_typesupport_fastrtps_cpp" + "rosidl_typesupport_interface") +foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) + set(_msg_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/msg/dds_fastrtps") + set(_srv_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/srv/dds_fastrtps") + normalize_path(_msg_include_dir "${_msg_include_dir}") + normalize_path(_srv_include_dir "${_srv_include_dir}") + target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} + PUBLIC + "${_msg_include_dir}" + "${_srv_include_dir}" + ) + ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${_pkg_name}) +endforeach() +target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} fastrtps fastcdr) +add_dependencies( + ${rosidl_generate_interfaces_TARGET} + ${rosidl_generate_interfaces_TARGET}${_target_suffix} +) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ${rosidl_generate_interfaces_TARGET}__cpp +) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}__dds_fastrtps_idl + ${rosidl_generate_interfaces_TARGET}${_target_suffix} +) + +if(NOT rosidl_generate_interfaces_SKIP_INSTALL) + install( + DIRECTORY "${_output_path}/" + DESTINATION "include/${PROJECT_NAME}" + PATTERN "*.cpp" EXCLUDE + ) + + if( + NOT _generated_msg_files STREQUAL "" OR + NOT _generated_srv_files STREQUAL "" + ) + ament_export_include_directories(include) + endif() + + install( + TARGETS ${rosidl_generate_interfaces_TARGET}${_target_suffix} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + ) + + ament_export_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix}) +endif() + +if(BUILD_TESTING AND rosidl_generate_interfaces_ADD_LINTER_TESTS) + if(NOT _generated_msg_files STREQUAL "" OR NOT _generated_srv_files STREQUAL "") + find_package(ament_cmake_cppcheck REQUIRED) + ament_cppcheck( + TESTNAME "cppcheck_rosidl_typesupport_fastrtps_cpp" + ${_generated_msg_files} ${_generated_srv_files}) + + find_package(ament_cmake_cpplint REQUIRED) + get_filename_component(_cpplint_root "${_output_path}" DIRECTORY) + ament_cpplint( + TESTNAME "cpplint_rosidl_typesupport_fastrtps_cpp" + # the generated code might contain longer lines for templated types + MAX_LINE_LENGTH 999 + ROOT "${_cpplint_root}" + ${_generated_msg_files} ${_generated_srv_files}) + + find_package(ament_cmake_uncrustify REQUIRED) + ament_uncrustify( + TESTNAME "uncrustify_rosidl_typesupport_fastrtps_cpp" + # the generated code might contain longer lines for templated types + MAX_LINE_LENGTH 999 + ${_generated_msg_files} ${_generated_srv_files}) + endif() +endif() diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/identifier.hpp b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/identifier.hpp new file mode 100644 index 000000000..910689139 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/identifier.hpp @@ -0,0 +1,28 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__IDENTIFIER_HPP_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__IDENTIFIER_HPP_ + +#include + +namespace rosidl_typesupport_fastrtps_cpp +{ + +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT +extern const char * typesupport_identifier; + +} // namespace rosidl_typesupport_fastrtps_cpp + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__IDENTIFIER_HPP_ diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support.h b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support.h new file mode 100644 index 000000000..0a0f06b63 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support.h @@ -0,0 +1,44 @@ +// Copyright 2014-2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_H_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_H_ + +#include "rosidl_generator_c/message_type_support_struct.h" + +#include + +typedef struct message_type_support_callbacks_t +{ + const char * package_name_; + const char * message_name_; + + // Function for message serialization + bool (* cdr_serialize)( + const void * untyped_ros_message, + eprosima::fastcdr::Cdr & cdr); + + // Function for message deserialization + bool (* cdr_deserialize)( + eprosima::fastcdr::Cdr & cdr, + void * untyped_ros_message); + + // Function to get size of data + uint32_t (* get_serialized_size)(const void *); + + // Function for type support initialization + size_t (* max_serialized_size)(bool & full_bounded); +} message_type_support_callbacks_t; + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_H_ diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support_decl.hpp b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support_decl.hpp new file mode 100644 index 000000000..8d0f5de58 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/message_type_support_decl.hpp @@ -0,0 +1,33 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_DECL_HPP_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_DECL_HPP_ + +// Provides the definition of the rosidl_message_type_support_t struct. +#include +// Provides visibility macros like ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC. +#include + +namespace rosidl_typesupport_fastrtps_cpp +{ + +// This is implemented in the shared library provided by this package. +template +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC +const rosidl_message_type_support_t * get_message_type_support_handle(); + +} // namespace rosidl_typesupport_fastrtps_cpp + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__MESSAGE_TYPE_SUPPORT_DECL_HPP_ diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support.h b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support.h new file mode 100644 index 000000000..2fe7fa2d4 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support.h @@ -0,0 +1,33 @@ +// Copyright 2014-2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_H_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_H_ + +#include +#include +#include "rosidl_generator_c/service_type_support_struct.h" + +#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h" + +typedef struct service_type_support_callbacks_t +{ + const char * package_name_; + const char * service_name_; + + const rosidl_message_type_support_t * request_members_; + const rosidl_message_type_support_t * response_members_; +} service_type_support_callbacks_t; + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_H_ diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp new file mode 100644 index 000000000..c989fcb2f --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp @@ -0,0 +1,33 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_DECL_HPP_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_DECL_HPP_ + +// Provides the definition of the rosidl_service_type_support_t struct. +#include +// Provides visibility macros like ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC. +#include + +namespace rosidl_typesupport_fastrtps_cpp +{ + +// This is implemented in the shared library provided by this package. +template +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC +const rosidl_service_type_support_t * get_service_type_support_handle(); + +} // namespace rosidl_typesupport_fastrtps_cpp + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__SERVICE_TYPE_SUPPORT_DECL_HPP_ diff --git a/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/visibility_control.h b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/visibility_control.h new file mode 100644 index 000000000..1e94d2c91 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/include/rosidl_typesupport_fastrtps_cpp/visibility_control.h @@ -0,0 +1,56 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// 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 ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ +#define ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ + +#if __cplusplus +extern "C" +{ +#endif + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT __attribute__ ((dllexport)) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT __attribute__ ((dllimport)) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT __declspec(dllexport) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT __declspec(dllimport) + #endif + #ifdef ROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT + #endif + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_LOCAL +#else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT + #if __GNUC__ >= 4 + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_LOCAL + #endif +#endif + +#if __cplusplus +} +#endif + +#endif // ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ diff --git a/rosidl_typesupport_fastrtps_cpp/package.xml b/rosidl_typesupport_fastrtps_cpp/package.xml new file mode 100644 index 000000000..ac149590f --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/package.xml @@ -0,0 +1,40 @@ + + + + rosidl_typesupport_fastrtps_cpp + 0.4.0 + Generate the C++ interfaces for eProsima FastRTPS. + Ricardo González + Apache License 2.0 + + ament_cmake + fastrtps_cmake_module + fastcdr + fastrtps + rosidl_cmake + rosidl_generator_c + rosidl_generator_cpp + + ament_cmake + fastrtps_cmake_module + fastcdr + fastrtps + rosidl_cmake + rosidl_generator_c + rosidl_generator_cpp + rosidl_generator_dds_idl + + rmw + + rosidl_parser + rosidl_typesupport_interface + + ament_lint_auto + ament_lint_common + + rosidl_typesupport_cpp_packages + + + ament_cmake + + diff --git a/rosidl_typesupport_fastrtps_cpp/resource/msg__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/msg__rosidl_typesupport_fastrtps_cpp.hpp.em new file mode 100644 index 000000000..1858c00b5 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/msg__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -0,0 +1,99 @@ +// generated from +// rosidl_typesupport_fastrtps_cpp/resource/msg__rosidl_typesupport_fastrtps_cpp.hpp.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating +@# __rosidl_typesupport_fastrtps_cpp.hpp files +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .msg file +@# - subfolder (string) +@# The subfolder / subnamespace of the message +@# Either 'msg' or 'srv' +@# - get_header_filename_from_msg_name (function) +@####################################################################### +@ +@{ +header_guard_parts = [ + spec.base_type.pkg_name, subfolder, + get_header_filename_from_msg_name(spec.base_type.type) + '__rosidl_typesupport_fastrtps_cpp_hpp'] +header_guard_variable = '__'.join([x.upper() for x in header_guard_parts]) + '_' +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +#include "rosidl_generator_c/message_type_support_struct.h" +#include "rosidl_typesupport_interface/macros.h" + +#include "@(spec.base_type.pkg_name)/msg/rosidl_typesupport_fastrtps_cpp__visibility_control.h" + +#include "@(spec.base_type.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.base_type.type))__struct.hpp" +#ifndef _WIN32 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-parameter" +# ifdef __clang__ +# pragma clang diagnostic ignored "-Wdeprecated-register" +# pragma clang diagnostic ignored "-Wreturn-type-c-linkage" +# endif +#endif +#ifndef _WIN32 +# pragma GCC diagnostic pop +#endif + +#include "fastcdr/Cdr.h" + +namespace @(spec.base_type.pkg_name) +{ + +namespace @(subfolder) +{ + +namespace typesupport_fastrtps_cpp +{ + +bool +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +cdr_serialize( + const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + eprosima::fastcdr::Cdr & cdr); + +bool +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +cdr_deserialize( + eprosima::fastcdr::Cdr & cdr, + @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message); + +size_t +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +get_serialized_size( + const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + size_t current_alignment); + +size_t +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +max_serialized_size_@(spec.base_type.type)( + bool & full_bounded, + size_t current_alignment); + +} // namespace typesupport_fastrtps_cpp + +} // namespace @(subfolder) + +} // namespace @(spec.base_type.pkg_name) + +#ifdef __cplusplus +extern "C" +{ +#endif + +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +const rosidl_message_type_support_t * + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.base_type.pkg_name), @(subfolder), @(spec.base_type.type))(); + +#ifdef __cplusplus +} +#endif + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em new file mode 100644 index 000000000..975fa8083 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em @@ -0,0 +1,412 @@ +// generated from rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating __type_support.cpp files +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .msg file +@# - subfolder (string) +@# The subfolder / subnamespace of the message +@# Either 'msg' or 'srv' +@# - get_header_filename_from_msg_name (function) +@####################################################################### +@ +#include "@(spec.base_type.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.base_type.type))__rosidl_typesupport_fastrtps_cpp.hpp" + +#include +#include +#include + +#include "rosidl_typesupport_cpp/message_type_support.hpp" + +#include "rosidl_typesupport_fastrtps_cpp/identifier.hpp" +#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h" +#include "rosidl_typesupport_fastrtps_cpp/message_type_support_decl.hpp" + +#include "fastcdr/Cdr.h" + +// forward declaration of message dependencies and their conversion functions +@[for field in spec.fields]@ +@[ if not field.type.is_primitive_type()]@ +namespace @(field.type.pkg_name) +{ +namespace msg +{ +namespace typesupport_fastrtps_cpp +{ +bool cdr_serialize( + const @(field.type.pkg_name)::msg::@(field.type.type) &, + eprosima::fastcdr::Cdr &); +bool cdr_deserialize( + eprosima::fastcdr::Cdr &, + @(field.type.pkg_name)::msg::@(field.type.type) &); +size_t get_serialized_size( + const @(field.type.pkg_name)::msg::@(field.type.type) &, + size_t current_alignment); +size_t +max_serialized_size_@(field.type.type)( + bool & full_bounded, + size_t current_alignment); +} // namespace typesupport_fastrtps_cpp +} // namespace msg +} // namespace @(field.type.pkg_name) + +@[ end if]@ +@[end for]@ + +namespace @(spec.base_type.pkg_name) +{ + +namespace @(subfolder) +{ + +namespace typesupport_fastrtps_cpp +{ + +bool +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +cdr_serialize( + const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + eprosima::fastcdr::Cdr & cdr) +{ +@[if not spec.fields]@ + (void)ros_message; + (void)cdr; +@[end if]@ +@[for field in spec.fields]@ + // field.name @(field.name) +@[ if field.type.is_array]@ + { +@[ if field.type.array_size and not field.type.is_upper_bound]@ +@[ if field.type.is_primitive_type()]@ + cdr << ros_message.@(field.name); +@[ else]@ + for (size_t i = 0; i < @(field.type.array_size); i++) { + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(field.name)[i], + cdr); + } +@[ end if]@ +@[ else]@ +@[ if field.type.is_upper_bound or not field.type.is_primitive_type()]@ + size_t size = ros_message.@(field.name).size(); +@[ if field.type.is_upper_bound]@ + if (size > @(field.type.array_size)) { + throw std::runtime_error("array size exceeds upper bound"); + } +@[ end if]@ +@[ end if]@ +@[ if field.type.is_primitive_type() and not field.type.is_upper_bound]@ + cdr << ros_message.@(field.name); +@[ else]@ + cdr << static_cast(size); + for (size_t i = 0; i < size; i++) { +@[ if field.type.type == 'bool']@ + cdr << (ros_message.@(field.name)[i] ? true : false); +@[ elif field.type.is_primitive_type()]@ + cdr << ros_message.@(field.name)[i]; +@[ else]@ + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(field.name)[i], + cdr); +@[ end if]@ + } +@[ end if]@ +@[ end if]@ + } +@[ elif field.type.is_primitive_type()]@ + cdr << ros_message.@(field.name); +@[ else]@ + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(field.name), + cdr); +@[ end if]@ +@[end for]@ + return true; +} + +bool +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +cdr_deserialize( + eprosima::fastcdr::Cdr & cdr, + @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message) +{ +@[if not spec.fields]@ + (void)ros_message; + (void)cdr; +@[end if]@ +@[for field in spec.fields]@ + // field.name @(field.name) +@[ if field.type.is_array]@ + { +@[ if field.type.array_size and not field.type.is_upper_bound]@ +@[ if field.type.is_primitive_type()]@ + cdr >> ros_message.@(field.name); +@[ else]@ + for (size_t i = 0; i < @(field.type.array_size); i++) { + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( + cdr, + ros_message.@(field.name)[i]); + } +@[ end if]@ +@[ else]@ +@[ if field.type.is_primitive_type() and not field.type.is_upper_bound]@ + cdr >> ros_message.@(field.name); +@[ else]@ + uint32_t cdrSize; + cdr >> cdrSize; + size_t size = static_cast(cdrSize); + ros_message.@(field.name).resize(size); + for (size_t i = 0; i < size; i++) { +@[ if field.type.type == 'bool']@ + uint8_t tmp; + cdr >> tmp; + ros_message.@(field.name)[i] = tmp ? true : false; +@[ elif field.type.is_primitive_type()]@ + cdr >> ros_message.@(field.name)[i]; +@[ else]@ + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( + cdr, ros_message.@(field.name)[i]); +@[ end if]@ + } +@[ end if]@ +@[ end if]@ + } +@[ elif field.type.is_primitive_type()]@ + cdr >> ros_message.@(field.name); +@[ else]@ + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( + cdr, ros_message.@(field.name)); +@[ end if]@ + +@[end for]@ + return true; +} + +size_t +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +get_serialized_size( + const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + size_t current_alignment) +{ +@[if not spec.fields]@ + (void)ros_message; + (void)current_alignment; +@[else]@ + size_t initial_alignment = current_alignment; + + const size_t padding = 4; + (void)padding; + +@[end if]@ +@[for field in spec.fields]@ + // field.name @(field.name) +@[ if field.type.is_array]@ + { +@[ if field.type.array_size and not field.type.is_upper_bound]@ + size_t array_size = @(field.type.array_size); +@[ else]@ + size_t array_size = ros_message.@(field.name).size(); +@[ if field.type.is_upper_bound]@ + if (array_size > @(field.type.array_size)) { + throw std::runtime_error("array size exceeds upper bound"); + } +@[ end if]@ + + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); +@[ end if]@ +@[ if field.type.type == 'string']@ + for (size_t index = 0; index < array_size; ++index) { + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + ros_message.@(field.name)[index].size() + 1; + } +@[ elif field.type.is_primitive_type()]@ + size_t item_size = sizeof(ros_message.@(field.name)[0]); + current_alignment += array_size * item_size + + eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); +@[ else] + for (size_t index = 0; index < array_size; ++index) { + current_alignment += + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::get_serialized_size( + ros_message.@(field.name)[index], current_alignment); + } +@[ end if]@ + } +@[ else]@ +@[ if field.type.type == 'string']@ + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + ros_message.@(field.name).size() + 1; +@[ elif field.type.is_primitive_type()]@ + { + size_t item_size = sizeof(ros_message.@(field.name)); + current_alignment += item_size + + eprosima::fastcdr::Cdr::alignment(current_alignment, item_size); + } +@[ else] + current_alignment += + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::get_serialized_size( + ros_message.@(field.name), current_alignment); +@[ end if]@ +@[ end if]@ +@[end for]@ + +@[if not spec.fields]@ + return 0; +@[else]@ + return current_alignment - initial_alignment; +@[end if]@ +} + +size_t +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +max_serialized_size_@(spec.base_type.type)( + bool & full_bounded, + size_t current_alignment) +{ + size_t initial_alignment = current_alignment; + + const size_t padding = 4; + (void)padding; + (void)full_bounded; + +@[for field in spec.fields]@ + // field.name @(field.name) + { +@[ if field.type.is_array]@ +@[ if field.type.array_size]@ + size_t array_size = @(field.type.array_size); +@[ else]@ + size_t array_size = 0; +@[ end if]@ +@[ if not field.type.array_size or field.type.is_upper_bound]@ + full_bounded = false; + current_alignment += padding + + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); +@[ end if]@ +@[ else]@ + size_t array_size = 1; +@[ end if]@ + +@[ if field.type.type == 'string']@ + full_bounded = false; + for (size_t index = 0; index < array_size; ++index) { + current_alignment += padding + +@[ if field.type.string_upper_bound]@ + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + + @(field.type.string_upper_bound) + 1; +@[ else]@ + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + 1; +@[ end if]@ + } +@[ elif field.type.is_primitive_type()]@ +@[ if field.type.type == 'bool' or field.type.type == 'byte' or field.type.type == 'char' or field.type.type == 'uint8' or field.type.type == 'int8' ] + current_alignment += array_size * sizeof(uint8_t); +@[ elif field.type.type == 'int16' or field.type.type == 'uint16'] + current_alignment += array_size * sizeof(uint16_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint16_t)); +@[ elif field.type.type == 'int32' or field.type.type == 'uint32' or field.type.type == 'float32'] + current_alignment += array_size * sizeof(uint32_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint32_t)); +@[ elif field.type.type == 'int64' or field.type.type == 'uint64' or field.type.type == 'float64'] + current_alignment += array_size * sizeof(uint64_t) + + eprosima::fastcdr::Cdr::alignment(current_alignment, sizeof(uint64_t)); +@[ end if]@ +@[ else] + for (size_t index = 0; index < array_size; ++index) { + current_alignment += + @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::max_serialized_size_@(field.type.type)( + full_bounded, current_alignment); + } +@[ end if]@ + } +@[end for]@ + + return current_alignment - initial_alignment; +} + +static bool __cdr_serialize( + const void * untyped_ros_message, + eprosima::fastcdr::Cdr & cdr) +{ + auto typed_message = + static_cast( + untyped_ros_message); + return cdr_serialize(*typed_message, cdr); +} + +static bool __cdr_deserialize( + eprosima::fastcdr::Cdr & cdr, + void * untyped_ros_message) +{ + auto typed_message = + static_cast<@(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) *>( + untyped_ros_message); + return cdr_deserialize(cdr, *typed_message); +} + +static uint32_t __get_serialized_size( + const void * untyped_ros_message) +{ + auto typed_message = + static_cast( + untyped_ros_message); + return static_cast(get_serialized_size(*typed_message, 0)); +} + +static size_t __max_serialized_size(bool & full_bounded) +{ + return max_serialized_size_@(spec.base_type.type)(full_bounded, 0); +} + +static message_type_support_callbacks_t callbacks = { + "@(spec.base_type.pkg_name)", + "@(spec.base_type.type)", + __cdr_serialize, + __cdr_deserialize, + __get_serialized_size, + __max_serialized_size +}; + +static rosidl_message_type_support_t handle = { + rosidl_typesupport_fastrtps_cpp::typesupport_identifier, + &callbacks, + get_message_typesupport_handle_function, +}; + +} // namespace typesupport_fastrtps_cpp + +} // namespace @(subfolder) + +} // namespace @(spec.base_type.pkg_name) + +namespace rosidl_typesupport_fastrtps_cpp +{ + +template<> +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@(spec.base_type.pkg_name) +const rosidl_message_type_support_t * +get_message_type_support_handle<@(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type)>() +{ + return &@(spec.base_type.pkg_name)::@(subfolder)::typesupport_fastrtps_cpp::handle; +} + +} // namespace rosidl_typesupport_fastrtps_cpp + +#ifdef __cplusplus +extern "C" +{ +#endif + +const rosidl_message_type_support_t * +ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.base_type.pkg_name), @(subfolder), @(spec.base_type.type))() { + return &@(spec.base_type.pkg_name)::@(subfolder)::typesupport_fastrtps_cpp::handle; +} + +#ifdef __cplusplus +} +#endif diff --git a/rosidl_typesupport_fastrtps_cpp/resource/rosidl_typesupport_fastrtps_cpp__visibility_control.h.in b/rosidl_typesupport_fastrtps_cpp/resource/rosidl_typesupport_fastrtps_cpp__visibility_control.h.in new file mode 100644 index 000000000..edce4ea73 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/rosidl_typesupport_fastrtps_cpp__visibility_control.h.in @@ -0,0 +1,43 @@ +// generated from +// rosidl_typesupport_fastrtps_cpp/resource/rosidl_typesupport_fastrtps_cpp__visibility_control.h.in +// generated code does not contain a copyright notice + +#ifndef @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ +#define @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ + +#if __cplusplus +extern "C" +{ +#endif + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((dllexport)) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT_@PROJECT_NAME@ __attribute__ ((dllimport)) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@PROJECT_NAME@ __declspec(dllexport) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT_@PROJECT_NAME@ __declspec(dllimport) + #endif + #ifdef ROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL_@PROJECT_NAME@ + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@PROJECT_NAME@ + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT_@PROJECT_NAME@ + #endif +#else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((visibility("default"))) + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_IMPORT_@PROJECT_NAME@ + #if __GNUC__ >= 4 + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@PROJECT_NAME@ __attribute__ ((visibility("default"))) + #else + #define ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@PROJECT_NAME@ + #endif +#endif + +#if __cplusplus +} +#endif + +#endif // @PROJECT_NAME_UPPER@__MSG__ROSIDL_TYPESUPPORT_FASTRTPS_CPP__VISIBILITY_CONTROL_H_ diff --git a/rosidl_typesupport_fastrtps_cpp/resource/srv__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/srv__rosidl_typesupport_fastrtps_cpp.hpp.em new file mode 100644 index 000000000..0ce70978c --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -0,0 +1,44 @@ +// generated from +// rosidl_typesupport_fastrtps_cpp/resource/srv__rosidl_typesupport_fastrtps_cpp.hpp.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating +@# __rosidl_typesupport_fastrtps_cpp.hpp files +@# +@# Context: +@# - spec (rosidl_parser.MessageSpecification) +@# Parsed specification of the .srv file +@# - get_header_filename_from_srv_name (function) +@####################################################################### +@ +@{ +header_guard_parts = [ + spec.pkg_name, 'srv', + get_header_filename_from_msg_name(spec.srv_name) + '__rosidl_typesupport_fastrtps_cpp_hpp'] +header_guard_variable = '__'.join([x.upper() for x in header_guard_parts]) + '_' +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +#include + +#include "rosidl_typesupport_cpp/service_type_support.hpp" +#include "rosidl_typesupport_interface/macros.h" + +#include "@(spec.pkg_name)/msg/rosidl_typesupport_fastrtps_cpp__visibility_control.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.pkg_name) +const rosidl_service_type_support_t * + ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), @(spec.srv_name))(); + +#ifdef __cplusplus +} +#endif + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em new file mode 100644 index 000000000..bf720150d --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em @@ -0,0 +1,64 @@ +// generated from rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em +// generated code does not contain a copyright notice + +@####################################################################### +@# EmPy template for generating __type_support.cpp files +@# +@# Context: +@# - spec (rosidl_parser.ServiceSpecification) +@# Parsed specification of the .srv file +@# - get_header_filename_from_msg_name (function) +@####################################################################### +@ +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name))__rosidl_typesupport_fastrtps_cpp.hpp" + +#include "rmw/error_handling.h" +#include "rosidl_typesupport_fastrtps_cpp/identifier.hpp" +#include "rosidl_typesupport_fastrtps_cpp/service_type_support.h" +#include "rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp" + +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name))__struct.hpp" +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_cpp.hpp" +#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_cpp.hpp" + +namespace @(spec.pkg_name) +{ + +namespace srv +{ + +namespace typesupport_fastrtps_cpp +{ + +static service_type_support_callbacks_t callbacks = { + "@(spec.pkg_name)", + "@(spec.srv_name)", + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), srv, @(spec.srv_name)_Request)(), + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), srv, @(spec.srv_name)_Response)(), +}; + +static rosidl_service_type_support_t handle = { + rosidl_typesupport_fastrtps_cpp::typesupport_identifier, + &callbacks, + get_service_typesupport_handle_function, +}; + +} // namespace typesupport_fastrtps_cpp + +} // namespace srv + +} // namespace @(spec.pkg_name) + +#ifdef __cplusplus +extern "C" +{ +#endif + +const rosidl_service_type_support_t * +ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), @(spec.srv_name))() { + return &@(spec.pkg_name)::srv::typesupport_fastrtps_cpp::handle; +} + +#ifdef __cplusplus +} +#endif diff --git a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp-extras.cmake.in b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp-extras.cmake.in new file mode 100644 index 000000000..6fb87c476 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp-extras.cmake.in @@ -0,0 +1,35 @@ +# generated from +# rosidl_typesupport_fastrtps_cpp/ +# rosidl_typesupport_fastrtps_cpp-extras.cmake.in + +find_package(fastrtps_cmake_module QUIET) +find_package(fastcdr REQUIRED CONFIG) +find_package(fastrtps REQUIRED CONFIG) +find_package(FastRTPS REQUIRED MODULE) + +if(NOT FastRTPS_FOUND) + message(STATUS + "Could not find eProsima Fast-RTPS - skip rosidl_typesupport_fastrtps_cpp" + ) +else() + find_package(ament_cmake_core QUIET REQUIRED) + ament_register_extension( + "rosidl_generate_interfaces" + "rosidl_typesupport_fastrtps_cpp" + "rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake") + + set(rosidl_typesupport_fastrtps_cpp_BIN + "${rosidl_typesupport_fastrtps_cpp_DIR}/../../../lib/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp") + normalize_path(rosidl_typesupport_fastrtps_cpp_BIN + "${rosidl_typesupport_fastrtps_cpp_BIN}") + + set(rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES + "${rosidl_typesupport_fastrtps_cpp_DIR}/../../../@PYTHON_INSTALL_DIR@/rosidl_typesupport_fastrtps_cpp/__init__.py") + normalize_path(rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES + "${rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES}") + + set(rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR + "${rosidl_typesupport_fastrtps_cpp_DIR}/../resource") + normalize_path(rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}") +endif() diff --git a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py new file mode 100644 index 000000000..68f2d7311 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py @@ -0,0 +1,106 @@ +# Copyright 2014 Open Source Robotics Foundation, Inc. +# +# 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. + +import os + +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +from rosidl_cmake import expand_template +from rosidl_cmake import get_newest_modification_time +from rosidl_parser import parse_message_file +from rosidl_parser import parse_service_file +from rosidl_parser import validate_field_types + + +def parse_ros_interface_files(pkg_name, ros_interface_files): + message_specs = [] + service_specs = [] + for idl_file in ros_interface_files: + extension = os.path.splitext(idl_file)[1] + if extension == '.msg': + message_spec = parse_message_file(pkg_name, idl_file) + message_specs.append((idl_file, message_spec)) + elif extension == '.srv': + service_spec = parse_service_file(pkg_name, idl_file) + service_specs.append(service_spec) + return (message_specs, service_specs) + + +def generate_dds_fastrtps_cpp( + pkg_name, dds_interface_files, dds_interface_base_path, deps, + output_basepath, idl_pp, message_specs, service_specs): + return 0 + + +def generate_cpp(args, message_specs, service_specs, known_msg_types): + template_dir = args['template_dir'] + mapping_msgs = { + os.path.join(template_dir, 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em'): + '%s__rosidl_typesupport_fastrtps_cpp.hpp', + os.path.join(template_dir, 'msg__type_support.cpp.em'): + '%s__type_support.cpp', + } + mapping_srvs = { + os.path.join(template_dir, 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em'): + '%s__rosidl_typesupport_fastrtps_cpp.hpp', + os.path.join(template_dir, 'srv__type_support.cpp.em'): + '%s__type_support.cpp', + } + + for template_file in mapping_msgs.keys(): + assert os.path.exists(template_file), 'Could not find template: ' + template_file + for template_file in mapping_srvs.keys(): + assert os.path.exists(template_file), 'Could not find template: ' + template_file + + functions = { + 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, + } + # generate_dds_fastrtps_cpp() and therefore the make target depend on the additional files + # therefore they must be listed here even if the generated type support files are independent + latest_target_timestamp = get_newest_modification_time( + args['target_dependencies'] + args.get('additional_files', [])) + + for idl_file, spec in message_specs: + validate_field_types(spec, known_msg_types) + subfolder = os.path.basename(os.path.dirname(idl_file)) + for template_file, generated_filename in mapping_msgs.items(): + generated_file = os.path.join(args['output_dir'], subfolder) + if generated_filename.endswith('.cpp'): + generated_file = os.path.join(generated_file, 'dds_fastrtps') + generated_file = os.path.join( + generated_file, generated_filename % + convert_camel_case_to_lower_case_underscore(spec.base_type.type)) + + data = {'spec': spec, 'subfolder': subfolder} + data.update(functions) + expand_template( + template_file, data, generated_file, + minimum_timestamp=latest_target_timestamp) + + for spec in service_specs: + validate_field_types(spec, known_msg_types) + for template_file, generated_filename in mapping_srvs.items(): + generated_file = os.path.join(args['output_dir'], 'srv') + if generated_filename.endswith('.cpp'): + generated_file = os.path.join(generated_file, 'dds_fastrtps') + generated_file = os.path.join( + generated_file, generated_filename % + convert_camel_case_to_lower_case_underscore(spec.srv_name)) + + data = {'spec': spec} + data.update(functions) + expand_template( + template_file, data, generated_file, + minimum_timestamp=latest_target_timestamp) + + return 0 diff --git a/rosidl_typesupport_fastrtps_cpp/src/identifier.cpp b/rosidl_typesupport_fastrtps_cpp/src/identifier.cpp new file mode 100644 index 000000000..8c991d57b --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/src/identifier.cpp @@ -0,0 +1,23 @@ +// Copyright 2015 Open Source Robotics Foundation, Inc. +// +// 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 + +namespace rosidl_typesupport_fastrtps_cpp +{ + +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT +const char * typesupport_identifier = "rosidl_typesupport_fastrtps_cpp"; + +} // namespace rosidl_typesupport_fastrtps_cpp