From 4ff80230f8e3326b80a068ebb03766d2799980fb Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 21 Nov 2018 15:22:25 -0800 Subject: [PATCH 01/20] update includes and type mapping --- .../resource/msg__type_support_c.cpp.em | 25 +++++++++++++++---- .../resource/srv__type_support_c.cpp.em | 5 +--- ...sg__rosidl_typesupport_fastrtps_cpp.hpp.em | 15 ++++++++++- .../resource/srv__type_support.cpp.em | 11 +++++++- 4 files changed, 45 insertions(+), 11 deletions(-) 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 index c7846ca..bd9a503 100644 --- a/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em @@ -31,9 +31,21 @@ #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" +@{ +header_filename = get_header_filename_from_msg_name(type) +if header_filename.endswith('__request'): + header_filename = header_filename[:-9] +elif header_filename.endswith('__response'): + header_filename = header_filename[:-10] +if header_filename.endswith('__goal'): + header_filename = header_filename[:-6] +elif header_filename.endswith('__result'): + header_filename = header_filename[:-8] +elif header_filename.endswith('__feedback'): + header_filename = header_filename[:-10] +}@ +#include "@(pkg)/@(subfolder)/@(header_filename)__struct.h" +#include "@(pkg)/@(subfolder)/@(header_filename)__functions.h" #include "fastcdr/Cdr.h" @@ -241,8 +253,11 @@ if field.type.type == 'string': array_init = 'rosidl_generator_c__String__Sequence__init' array_fini = 'rosidl_generator_c__String__Sequence__fini' elif field.type.is_primitive_type(): - array_init = 'rosidl_generator_c__{field.type.type}__Sequence__init'.format(**locals()) - array_fini = 'rosidl_generator_c__{field.type.type}__Sequence__fini'.format(**locals()) + type_ = field.type.type + if type_ == 'char': + type_ = 'uint8' + array_init = 'rosidl_generator_c__{type_}__Sequence__init'.format(**locals()) + array_fini = 'rosidl_generator_c__{type_}__Sequence__fini'.format(**locals()) else: array_init = '{field.type.pkg_name}__msg__{field.type.type}__Sequence__init'.format(**locals()) array_fini = '{field.type.pkg_name}__msg__{field.type.type}__Sequence__fini'.format(**locals()) 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 index ae3c762..f8d05f6 100644 --- a/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em @@ -22,10 +22,7 @@ #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)/@(subfolder)/@(req_header_file_name).h" -#include "@(spec.pkg_name)/@(subfolder)/@(res_header_file_name).h" +#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name)).h" #include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_c.h" #include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_c.h" 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 index 1858c00..04d3936 100644 --- 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 @@ -29,7 +29,20 @@ header_guard_variable = '__'.join([x.upper() for x in header_guard_parts]) + '_' #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" +@{ +header_filename = get_header_filename_from_msg_name(spec.base_type.type) +if header_filename.endswith('__request'): + header_filename = header_filename[:-9] +elif header_filename.endswith('__response'): + header_filename = header_filename[:-10] +if header_filename.endswith('__goal'): + header_filename = header_filename[:-6] +elif header_filename.endswith('__result'): + header_filename = header_filename[:-8] +elif header_filename.endswith('__feedback'): + header_filename = header_filename[:-10] +}@ +#include "@(spec.base_type.pkg_name)/@(subfolder)/@(header_filename)__struct.hpp" #ifndef _WIN32 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-parameter" diff --git a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em index 0143cc7..12d94a0 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em @@ -20,7 +20,16 @@ #include "rosidl_typesupport_fastrtps_cpp/service_type_support.h" #include "rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp" -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name))__struct.hpp" +@{ +header_filename = get_header_filename_from_msg_name(spec.srv_name) +if header_filename.endswith('__goal'): + header_filename = header_filename[:-6] +elif header_filename.endswith('__result'): + header_filename = header_filename[:-8] +elif header_filename.endswith('__feedback'): + header_filename = header_filename[:-10] +}@ +#include "@(spec.pkg_name)/@(subfolder)/@(header_filename)__struct.hpp" #include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_cpp.hpp" #include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_cpp.hpp" From fee9878b0f8a03a095d6453659e51bf9908615a1 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 26 Nov 2018 17:06:01 -0800 Subject: [PATCH 02/20] remove service check for feedback suffix --- .../resource/srv__type_support.cpp.em | 2 -- 1 file changed, 2 deletions(-) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em index 12d94a0..84b9ac8 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em @@ -26,8 +26,6 @@ if header_filename.endswith('__goal'): header_filename = header_filename[:-6] elif header_filename.endswith('__result'): header_filename = header_filename[:-8] -elif header_filename.endswith('__feedback'): - header_filename = header_filename[:-10] }@ #include "@(spec.pkg_name)/@(subfolder)/@(header_filename)__struct.hpp" #include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_cpp.hpp" From b1499eaf7df7178fb5aab793271379b0495602e7 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 29 Nov 2018 12:30:06 -0800 Subject: [PATCH 03/20] update C typesupport generator to use IDL-based extension point --- .../bin/rosidl_typesupport_fastrtps_c | 5 +- ...pport_fastrtps_c_generate_interfaces.cmake | 56 +-- .../idl__rosidl_typesupport_fastrtps_c.h.em | 90 ++++ .../resource/idl__type_support_c.cpp.em | 107 ++++ .../msg__rosidl_typesupport_fastrtps_c.h.em | 64 +-- .../resource/msg__type_support_c.cpp.em | 456 +++++++++--------- .../srv__rosidl_typesupport_fastrtps_c.h.em | 49 +- .../resource/srv__type_support_c.cpp.em | 86 ++-- ...idl_typesupport_fastrtps_c-extras.cmake.in | 2 +- .../rosidl_typesupport_fastrtps_c/__init__.py | 93 +--- 10 files changed, 559 insertions(+), 449 deletions(-) create mode 100644 rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em create mode 100644 rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em diff --git a/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c b/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c index 4b0498f..c3e330c 100644 --- a/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c +++ b/rosidl_typesupport_fastrtps_c/bin/rosidl_typesupport_fastrtps_c @@ -4,7 +4,6 @@ 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 @@ -28,10 +27,8 @@ def main(argv=sys.argv[1:]): 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) + rc = generate_typesupport_fastrtps_c(args.generator_arguments_file) except UnknownMessageType as e: print(str(e), file=sys.stderr) return 1 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 index 4af57d8..d029321 100644 --- 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 @@ -1,4 +1,4 @@ -# Copyright 2016 Open Source Robotics Foundation, Inc. +# Copyright 2016-2018 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. @@ -19,56 +19,42 @@ find_package(FastRTPS REQUIRED MODULE) set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c/${PROJECT_NAME}") set(_generated_files "") -foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) - get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) +foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) + string(REGEX REPLACE ":([^:]*)$" "/\\1" _abs_idl_file "${_idl_tuple}") + get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY) get_filename_component(_parent_folder "${_parent_folder}" NAME) - 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") - set(_allowed_parent_folders "msg" "srv" "action") - if(NOT _parent_folder IN_LIST _allowed_parent_folders) - message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") - endif() - elseif(_extension STREQUAL ".srv") - set(_allowed_parent_folders "srv" "action") - if(NOT _parent_folder IN_LIST _allowed_parent_folders) - message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") - endif() - else() - message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}") - endif() - list(APPEND _generated_files "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_c.h") - list(APPEND _generated_files "${_output_path}/${_parent_folder}/dds_fastrtps_c/${_header_name}__type_support_c.cpp") + get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE) + string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name) + list(APPEND _generated_files + "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_c.h" + "${_output_path}/${_parent_folder}/${_header_name}__type_support_c.cpp") endforeach() 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") - set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") - normalize_path(_abs_idl_file "${_abs_idl_file}") - list(APPEND _dependency_files "${_abs_idl_file}") - list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") - endif() + foreach(_idl_file ${${_pkg_name}_IDL_FILES}) + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependency_files "${_abs_idl_file}") + list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") endforeach() endforeach() set(target_dependencies "${rosidl_typesupport_fastrtps_c_BIN}" ${rosidl_typesupport_fastrtps_c_GENERATOR_FILES} + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/idl__rosidl_typesupport_fastrtps_c.h.em" + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/idl__type_support_c.cpp.em" + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__rosidl_typesupport_fastrtps_c.h.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__type_support_c.cpp.em" + "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__rosidl_typesupport_fastrtps_c.h.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__type_support_c.cpp.em" - ${rosidl_generate_interfaces_IDL_FILES} + # ${rosidl_generate_interfaces_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") - get_property(is_generated SOURCE "${dep}" PROPERTY GENERATED) - if(NOT ${_is_generated}) - message(FATAL_ERROR "Target dependency '${dep}' does not exist") - endif() + message(FATAL_ERROR "Target dependency '${dep}' does not exist") endif() endforeach() @@ -76,7 +62,7 @@ set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fas rosidl_write_generator_arguments( "${generator_arguments_file}" PACKAGE_NAME "${PROJECT_NAME}" - ROS_INTERFACE_FILES "${rosidl_generate_interfaces_IDL_FILES}" + IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}" ROS_INTERFACE_DEPENDENCIES "${_dependencies}" OUTPUT_DIR "${_output_path}" TEMPLATE_DIR "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}" diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em new file mode 100644 index 0000000..2eb6bc0 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @@ -0,0 +1,90 @@ +// generated from rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em +// with input from @(package_name):@(interface_path) +// generated code does not contain a copyright notice +@ +@####################################################################### +@# EmPy template for generating __rosidl_typesupport_fastrtps_c.h files +@# +@# Context: +@# - package_name (string) +@# - interface_path (Path relative to the directory named after the package) +@# - content (IdlContent, list of elements, e.g. Messages or Services) +@# - type_supports (list of strings, the names of the type support packages) +@####################################################################### +@ +@{ +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ + '__ROSIDL_TYPESUPPORT_FASTRTPS_C_H_' +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +@{ +include_directives = set() +}@ +@####################################################################### +@# Handle message +@####################################################################### +@{ +from rosidl_parser.definition import Message +}@ +@[for message in content.get_elements_of_type(Message)]@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=message, + include_directives=include_directives) +}@ +@[end for]@ +@ +@####################################################################### +@# Handle service +@####################################################################### +@{ +from rosidl_parser.definition import Service +}@ +@[for service in content.get_elements_of_type(Service)]@ + +@{ +TEMPLATE( + 'srv__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, service=service, + include_directives=include_directives) +}@ +@[end for]@ +@ +@####################################################################### +@# Handle action +@####################################################################### +@{ +from rosidl_parser.definition import Action +}@ +@[for action in content.get_elements_of_type(Action)]@ + +@{ +TEMPLATE( + 'srv__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, service=action.goal_service, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'srv__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, service=action.result_service, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=action.feedback_message, + include_directives=include_directives) +}@ +@[end for]@ + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em new file mode 100644 index 0000000..3bf0ec7 --- /dev/null +++ b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em @@ -0,0 +1,107 @@ +// generated from rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em +// with input from @(package_name):@(interface_path) +// generated code does not contain a copyright notice +@ +@####################################################################### +@# EmPy template for generating __type_support.cpp files +@# +@# Context: +@# - package_name (string) +@# - interface_path (Path relative to the directory named after the package) +@# - content (IdlContent, list of elements, e.g. Messages or Services) +@# - type_supports (list of strings, the names of the type support packages) +@####################################################################### +@ +@{ +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) +}@ +#include "@(include_base)__rosidl_typesupport_fastrtps_c.h" + +@{ +include_directives = set() +}@ +@####################################################################### +@# Handle message +@####################################################################### +@{ +from rosidl_parser.definition import Message +}@ +@[for message in content.get_elements_of_type(Message)]@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, message=message, + include_directives=include_directives) +}@ +@[end for]@ +@ +@####################################################################### +@# Handle service +@####################################################################### +@{ +from rosidl_parser.definition import Service +}@ +@[for service in content.get_elements_of_type(Service)]@ + +@{ +TEMPLATE( + 'srv__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, service=service, + include_directives=include_directives) +}@ +@[end for]@ +@ +@####################################################################### +@# Handle action +@####################################################################### +@{ +from rosidl_parser.definition import Action +}@ +@[for action in content.get_elements_of_type(Action)]@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + message=action.goal_request, include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + message=action.result_response, include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + message=action.feedback, include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'srv__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + service=action.goal_service, include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'srv__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + service=action.result_service, include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, + message=action.feedback_message, include_directives=include_directives) +}@ +@[end for]@ 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 index 0237976..edcc835 100644 --- 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 @@ -1,57 +1,45 @@ -// 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 -@# Could be either 'msg', 'srv' or 'action' -@# - get_header_filename_from_msg_name (function) -@####################################################################### -@ +@# Included from rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @{ -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]) + '_' +header_files = [ + 'stddef.h', + 'rosidl_generator_c/message_type_support_struct.h', + 'rosidl_typesupport_interface/macros.h', + package_name + '/msg/rosidl_typesupport_fastrtps_c__visibility_control.h', +] }@ -#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" +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +@[ if '/' not in header_file]@ +#include <@(header_file)> +@[ else]@ +#include "@(header_file)" +@[ end if]@ +@[end for]@ #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)( +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name) +size_t get_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( 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)( +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name) +size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( bool & full_bounded, size_t current_alignment); -ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_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))(); + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])))(); #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 index bd9a503..13a73ef 100644 --- a/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em @@ -1,53 +1,47 @@ -// 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 -@# Could be either 'msg', 'srv' or 'action' -@# - 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" +@# Included from rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em @{ -header_filename = get_header_filename_from_msg_name(type) -if header_filename.endswith('__request'): - header_filename = header_filename[:-9] -elif header_filename.endswith('__response'): - header_filename = header_filename[:-10] -if header_filename.endswith('__goal'): - header_filename = header_filename[:-6] -elif header_filename.endswith('__result'): - header_filename = header_filename[:-8] -elif header_filename.endswith('__feedback'): - header_filename = header_filename[:-10] +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +from rosidl_parser.definition import Array +from rosidl_parser.definition import BaseString +from rosidl_parser.definition import BasicType +from rosidl_parser.definition import BoundedSequence +from rosidl_parser.definition import NamespacedType +from rosidl_parser.definition import NestedType +from rosidl_parser.definition import Sequence +from rosidl_parser.definition import String +from rosidl_parser.definition import WString + +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) + +header_files = [ + 'cassert', + 'limits', + 'string', + # Provides the rosidl_typesupport_fastrtps_c__identifier symbol declaration. + 'rosidl_typesupport_fastrtps_c/identifier.h', + # Provides the definition of the message_type_support_callbacks_t struct. + 'rosidl_typesupport_fastrtps_cpp/message_type_support.h', + package_name + '/msg/rosidl_typesupport_fastrtps_c__visibility_control.h', + include_base + '__struct.h', + include_base + '__functions.h', + 'fastcdr/Cdr.h', +] }@ -#include "@(pkg)/@(subfolder)/@(header_filename)__struct.h" -#include "@(pkg)/@(subfolder)/@(header_filename)__functions.h" - -#include "fastcdr/Cdr.h" +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +@[ if '/' not in header_file]@ +#include <@(header_file)> +@[ else]@ +#include "@(header_file)" +@[ end if]@ +@[end for]@ #ifndef _WIN32 # pragma GCC diagnostic push @@ -71,64 +65,88 @@ extern "C" @{ includes = {} -for field in spec.fields: +for member in message.structure.members: keys = set([]) - if field.type.is_primitive_type(): - if field.type.is_array: - keys.add('rosidl_generator_c/primitives_sequence.h') - keys.add('rosidl_generator_c/primitives_sequence_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)) + if isinstance(member.type, Sequence) and isinstance(member.type.basetype, BasicType): + keys.add('rosidl_generator_c/primitives_sequence.h') + keys.add('rosidl_generator_c/primitives_sequence_functions.h') + type_ = member.type + if isinstance(type_, NestedType): + type_ = type_.basetype + if isinstance(type_, String): + keys.add('rosidl_generator_c/string.h') + keys.add('rosidl_generator_c/string_functions.h') + elif isinstance(type_, WString): + keys.add('rosidl_generator_c/u16string.h') + keys.add('rosidl_generator_c/u16string_functions.h') + elif isinstance(type_, NamespacedType): + filename_prefix = convert_camel_case_to_lower_case_underscore(type_.name) + if filename_prefix.endswith('__request'): + filename_prefix = filename_prefix[:-9] + elif filename_prefix.endswith('__response'): + filename_prefix = filename_prefix[:-10] + if filename_prefix.endswith('__goal'): + filename_prefix = filename_prefix[:-6] + elif filename_prefix.endswith('__result'): + filename_prefix = filename_prefix[:-8] + elif filename_prefix.endswith('__feedback'): + filename_prefix = filename_prefix[:-10] + keys.add('/'.join(type_.namespaces + [filename_prefix]) + '__functions.h') for key in keys: if key not in includes: includes[key] = set([]) - includes[key].add(field.name) + includes[key].add(member.name) }@ -@[for key in sorted(includes.keys())]@ -#include "@(key)" // @(', '.join(includes[key])) +@[for header_file in sorted(includes.keys())]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" // @(', '.join(includes[header_file])) @[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) +for member in message.structure.members: + type_ = member.type + if isinstance(type_, NestedType): + type_ = type_.basetype + if isinstance(type_, NamespacedType): + key = (*type_.namespaces, type_.name) if key not in includes: forward_declares[key] = set([]) - forward_declares[key].add(field.name) + forward_declares[key].add(member.name) }@ @[for key in sorted(forward_declares.keys())]@ -@[ if key[0] != pkg]@ -ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ if key[0] != package_name]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(package_name) @[ end if]@ -size_t get_serialized_size_@(key[0])__msg__@(key[1])( +size_t get_serialized_size_@('__'.join(key))( const void * untyped_ros_message, size_t current_alignment); -@[ if key[0] != pkg]@ -ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ if key[0] != package_name]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(package_name) @[ end if]@ -size_t max_serialized_size_@(key[0])__msg__@(key[1])( +size_t max_serialized_size_@('__'.join(key))( bool & full_bounded, size_t current_alignment); -@[ if key[0] != pkg]@ -ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(pkg) +@[ if key[0] != package_name]@ +ROSIDL_TYPESUPPORT_FASTRTPS_C_IMPORT_@(package_name) @[ end if]@ const rosidl_message_type_support_t * - ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(key[0]), msg, @(key[1]))(); + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join(key)))(); @[end for]@ @# // Make callback functions specific to this message type. -using __ros_msg_type = @(pkg)__@(subfolder)__@(type); +using _@(message.structure.type.name)__ros_msg_type = @('__'.join(message.structure.type.namespaces + [message.structure.type.name])); -static bool __cdr_serialize( +static bool _@(message.structure.type.name)__cdr_serialize( const void * untyped_ros_message, eprosima::fastcdr::Cdr & cdr) { @@ -136,38 +154,37 @@ static bool __cdr_serialize( 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) + const _@(message.structure.type.name)__ros_msg_type * ros_message = static_cast(untyped_ros_message); +@[for member in message.structure.members]@ + // Field name: @(member.name) { -@[ if not field.type.is_primitive_type()]@ - const message_type_support_callbacks_t * @(field.type.pkg_name)__msg__@(field.type.type)__callbacks = +@{ +type_ = member.type +if isinstance(type_, NestedType): + type_ = type_.basetype +}@ +@[ if isinstance(type_, NamespacedType)]@ + const message_type_support_callbacks_t * callbacks = static_cast( - ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(field.type.pkg_name), msg, @(field.type.type) + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join(type_.namespaces + [type_.name])) )()->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); +@[ if isinstance(member.type, NestedType)]@ +@[ if isinstance(member.type, Array)]@ + size_t size = @(member.type.size); + auto array_ptr = ros_message->@(member.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)) { + size_t size = ros_message->@(member.name).size; + auto array_ptr = ros_message->@(member.name).data; +@[ if isinstance(member.type, BoundedSequence)]@ + if (size > @(member.type.upper_bound)) { fprintf(stderr, "array size exceeds upper bound\n"); return false; } @[ end if]@ cdr << static_cast(size); @[ end if]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type.basetype, 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) { @@ -180,19 +197,19 @@ static bool __cdr_serialize( } cdr << str->data; } -@[ elif field.type.is_primitive_type()]@ +@[ elif isinstance(member.type.basetype, BasicType)]@ 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( + if (!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); +@[ elif isinstance(member.type, String)]@ + const rosidl_generator_c__String * str = &ros_message->@(member.name); if (str->capacity == 0 || str->capacity <= str->size) { fprintf(stderr, "string capacity not greater than size\n"); return false; @@ -202,13 +219,13 @@ static bool __cdr_serialize( return false; } cdr << str->data; -@[ elif field.type.type == 'bool']@ - cdr << (ros_message->@(field.name) ? true : false); -@[ elif field.type.is_primitive_type()]@ - cdr << ros_message->@(field.name); +@[ elif isinstance(member.type, BasicType) and member.type.type == 'boolean']@ + cdr << (ros_message->@(member.name) ? true : false); +@[ elif isinstance(member.type, BasicType)]@ + cdr << ros_message->@(member.name); @[ else]@ - if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_serialize( - &ros_message->@(field.name), cdr)) + if (!callbacks->cdr_serialize( + &ros_message->@(member.name), cdr)) { return false; } @@ -219,7 +236,7 @@ static bool __cdr_serialize( return true; } -static bool __cdr_deserialize( +static bool _@(message.structure.type.name)__cdr_deserialize( eprosima::fastcdr::Cdr & cdr, void * untyped_ros_message) { @@ -227,97 +244,106 @@ static bool __cdr_deserialize( 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) + _@(message.structure.type.name)__ros_msg_type * ros_message = static_cast<_@(message.structure.type.name)__ros_msg_type *>(untyped_ros_message); +@[for member in message.structure.members]@ + // Field name: @(member.name) { -@[ if not field.type.is_primitive_type()]@ - const message_type_support_callbacks_t * @(field.type.pkg_name)__msg__@(field.type.type)__callbacks = +@{ +type_ = member.type +if isinstance(type_, NestedType): + type_ = type_.basetype +}@ +@[ if isinstance(type_, NamespacedType)]@ + const message_type_support_callbacks_t * callbacks = static_cast( - ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(field.type.pkg_name), msg, @(field.type.type) + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join(type_.namespaces + [type_.name])) )()->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); +@[ if isinstance(member.type, NestedType)]@ +@[ if isinstance(member.type, Array)]@ + size_t size = @(member.type.size); + auto array_ptr = ros_message->@(member.name); @[ else]@ @{ -if field.type.type == 'string': +if isinstance(member.type.basetype, String): array_init = 'rosidl_generator_c__String__Sequence__init' array_fini = 'rosidl_generator_c__String__Sequence__fini' -elif field.type.is_primitive_type(): - type_ = field.type.type - if type_ == 'char': - type_ = 'uint8' +elif isinstance(member.type.basetype, WString): + array_init = 'rosidl_generator_c__U16String__Sequence__init' + array_fini = 'rosidl_generator_c__U16String__Sequence__fini' +elif isinstance(member.type.basetype, BasicType): + type_ = member.type.basetype.type + type_ = type_.replace(' ', '_') array_init = 'rosidl_generator_c__{type_}__Sequence__init'.format(**locals()) array_fini = 'rosidl_generator_c__{type_}__Sequence__fini'.format(**locals()) else: - array_init = '{field.type.pkg_name}__msg__{field.type.type}__Sequence__init'.format(**locals()) - array_fini = '{field.type.pkg_name}__msg__{field.type.type}__Sequence__fini'.format(**locals()) + array_init = '__'.join(type_.namespaces + [type_.name]) + '__Sequence__init' + array_fini = '__'.join(type_.namespaces + [type_.name]) + '__Sequence__fini' }@ uint32_t cdrSize; cdr >> cdrSize; size_t size = static_cast(cdrSize); - if (ros_message->@(field.name).data) { - @(array_fini)(&ros_message->@(field.name)); + if (ros_message->@(member.name).data) { + @(array_fini)(&ros_message->@(member.name)); } - if (!@(array_init)(&ros_message->@(field.name), size)) { - return "failed to create array for field '@(field.name)'"; + if (!@(array_init)(&ros_message->@(member.name), size)) { + return "failed to create array for field '@(member.name)'"; } - auto array_ptr = ros_message->@(field.name).data; + auto array_ptr = ros_message->@(member.name).data; @[ end if]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type.basetype, BaseString)]@ +@{ +string_type = 'std::string' if isinstance(member.type.basetype, String) else 'std::u16string' +string_typename = 'rosidl_generator_c__String' if isinstance(member.type.basetype, String) else 'rosidl_generator_c__U16string' +}@ for (size_t i = 0; i < size; ++i) { - std::string tmp; + @(string_type) tmp; cdr >> tmp; auto & ros_i = array_ptr[i]; if (!ros_i.data) { - rosidl_generator_c__String__init(&ros_i); + @(string_typename)__init(&ros_i); } - bool succeeded = rosidl_generator_c__String__assign( + bool succeeded = @(string_typename)__assign( &ros_i, tmp.c_str()); if (!succeeded) { - fprintf(stderr, "failed to assign string into field '@(field.name)'\n"); + fprintf(stderr, "failed to assign string into field '@(member.name)'\n"); return false; } } -@[ elif field.type.is_primitive_type()]@ +@[ elif isinstance(member.type.basetype, BasicType)]@ 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( + if (!callbacks->cdr_deserialize( cdr, &array_ptr[i])) { return false; } } @[ end if]@ -@[ elif field.type.type == 'string']@ - std::string tmp; +@[ elif isinstance(member.type, BaseString)]@ +@{ +string_type = 'std::string' if isinstance(member.type, String) else 'std::u16string' +string_typename = 'rosidl_generator_c__String' if isinstance(member.type, String) else 'rosidl_generator_c__U16string' +}@ + @(string_type) tmp; cdr >> tmp; - if (!ros_message->@(field.name).data) { - rosidl_generator_c__String__init(&ros_message->@(field.name)); + if (!ros_message->@(member.name).data) { + @(string_typename)__init(&ros_message->@(member.name)); } - bool succeeded = rosidl_generator_c__String__assign( - &ros_message->@(field.name), + bool succeeded = @(string_typename)__assign( + &ros_message->@(member.name), tmp.c_str()); if (!succeeded) { - fprintf(stderr, "failed to assign string into field '@(field.name)'\n"); + fprintf(stderr, "failed to assign string into field '@(member.name)'\n"); return false; } -@[ elif field.type.is_primitive_type()]@ - cdr >> ros_message->@(field.name); +@[ elif isinstance(member.type, BasicType)]@ + cdr >> ros_message->@(member.name); @[ else]@ - if (!@(field.type.pkg_name)__msg__@(field.type.type)__callbacks->cdr_deserialize( - cdr, &ros_message->@(field.name))) + if (!callbacks->cdr_deserialize( + cdr, &ros_message->@(member.name))) { return false; } @@ -328,88 +354,79 @@ else: 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)( +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name) +size_t get_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( 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); + const _@(message.structure.type.name)__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]@ +@[for member in message.structure.members]@ + // field.name @(member.name) +@[ if isinstance(member.type, NestedType)]@ { -@[ 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); +@[ if isinstance(member.type, Array)]@ + size_t array_size = @(member.type.size); + auto array_ptr = ros_message->@(member.name); @[ else]@ - size_t array_size = ros_message->@(field.name).size; - auto array_ptr = ros_message->@(field.name).data; + size_t array_size = ros_message->@(member.name).size; + auto array_ptr = ros_message->@(member.name).data; current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); @[ end if]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type.basetype, 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()]@ +@[ elif isinstance(member.type.basetype, BasicType)]@ (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)( + current_alignment += get_serialized_size_@('__'.join(member.type.basetype.namespaces + [member.type.basetype.name]))( &array_ptr[index], current_alignment); } @[ end if]@ } @[ else]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type, String)]@ current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + - ros_message->@(field.name).size + 1; -@[ elif field.type.is_primitive_type()]@ + ros_message->@(member.name).size + 1; +@[ elif isinstance(member.type, BasicType)]@ { - size_t item_size = sizeof(ros_message->@(field.name)); + size_t item_size = sizeof(ros_message->@(member.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); + current_alignment += get_serialized_size_@('__'.join(member.type.namespaces + [member.type.name]))( + &(ros_message->@(member.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) +static uint32_t _@(message.structure.type.name)__get_serialized_size(const void * untyped_ros_message) { return static_cast( - get_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + get_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( 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)( +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name) +size_t max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( bool & full_bounded, size_t current_alignment) { @@ -419,16 +436,18 @@ size_t max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base (void)padding; (void)full_bounded; -@[for field in spec.fields]@ - // field.name @(field.name) +@[for member in message.structure.members]@ + // member: @(member.name) { -@[ if field.type.is_array]@ -@[ if field.type.array_size]@ - size_t array_size = @(field.type.array_size); +@[ if isinstance(member.type, NestedType)]@ +@[ if isinstance(member.type, Array)]@ + size_t array_size = @(member.type.size); +@[ elif isinstance(member.type, BoundedSequence)]@ + size_t array_size = @(member.type.upper_bound); @[ else]@ size_t array_size = 0; @[ end if]@ -@[ if not field.type.array_size or field.type.is_upper_bound]@ +@[ if isinstance(member.type, Sequence)]@ full_bounded = false; current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); @@ -437,34 +456,39 @@ size_t max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base size_t array_size = 1; @[ end if]@ -@[ if field.type.type == 'string']@ +@{ +type_ = member.type +if isinstance(type_, NestedType): + type_ = type_.basetype +}@ +@[ if isinstance(type_, String)]@ full_bounded = false; for (size_t index = 0; index < array_size; ++index) { current_alignment += padding + -@[ if field.type.string_upper_bound]@ +@[ if type_.maximum_size]@ eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + - @(field.type.string_upper_bound) + 1; + @(type_.maximum_size) + 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' ] +@[ elif isinstance(type_, BasicType)]@ +@[ if type_.type in ('boolean', 'octet', 'char', 'uint8', 'int8')]@ current_alignment += array_size * sizeof(uint8_t); -@[ elif field.type.type == 'int16' or field.type.type == 'uint16'] +@[ elif type_.type in ('wchar', 'int16', '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'] +@[ elif type_.type in ('int32', 'uint32', 'float')]@ 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'] +@[ elif type_.type in ('int64', 'uint64', 'double')]@ 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)( + max_serialized_size_@('__'.join(type_.namespaces + [type_.name]))( full_bounded, current_alignment); } @[ end if]@ @@ -474,33 +498,33 @@ size_t max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base return current_alignment - initial_alignment; } -static size_t __max_serialized_size(bool & full_bounded) +static size_t _@(message.structure.type.name)__max_serialized_size(bool & full_bounded) { - return max_serialized_size_@(spec.base_type.pkg_name)__@(subfolder)__@(spec.base_type.type)( + return max_serialized_size_@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))( 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 message_type_support_callbacks_t __callbacks_@(message.structure.type.name) = { + "@(package_name)", + "@(message.structure.type.name)", + _@(message.structure.type.name)__cdr_serialize, + _@(message.structure.type.name)__cdr_deserialize, + _@(message.structure.type.name)__get_serialized_size, + _@(message.structure.type.name)__max_serialized_size }; -static rosidl_message_type_support_t __type_support = { +static rosidl_message_type_support_t _@(message.structure.type.name)__type_support = { rosidl_typesupport_fastrtps_c__identifier, - &__callbacks, + &__callbacks_@(message.structure.type.name), 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; +ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])))() { + return &_@(message.structure.type.name)__type_support; } #if defined(__cplusplus) 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 index f261da0..c188af0 100644 --- 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 @@ -1,45 +1,30 @@ -// 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 -@# - subfolder (string) -@# The subfolder / subnamespace of the service -@# Either 'srv' or 'action' -@# - get_header_filename_from_srv_name (function) -@####################################################################### -@ +@# Included from rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @{ -header_guard_parts = [ - spec.pkg_name, subfolder, - 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]) + '_' +header_files = [ + 'rosidl_generator_c/service_type_support_struct.h', + 'rosidl_typesupport_interface/macros.h', + package_name + '/msg/rosidl_typesupport_fastrtps_c__visibility_control.h', +] }@ -#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" +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ #ifdef __cplusplus extern "C" { #endif -ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(spec.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_C_PUBLIC_@(package_name) const rosidl_service_type_support_t * - ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), @(subfolder), @(spec.srv_name))(); + ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.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 index f8d05f6..228d170 100644 --- a/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/srv__type_support_c.cpp.em @@ -1,53 +1,65 @@ -// 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 -@# - subfolder (string) -@# The subfolder / subnamespace of the message -@# Either 'srv' or 'action' -@# - get_header_filename_from_msg_name (function) -@####################################################################### -@ -#include "@(spec.pkg_name)/@(subfolder)/@(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" -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name)).h" - -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_c.h" -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_c.h" +@# Included from rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, message=service.request_message, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__type_support_c.cpp.em', + package_name=package_name, interface_path=interface_path, message=service.response_message, + include_directives=include_directives) +}@ + +@{ +from rosidl_cmake import convert_camel_case_to_lower_case_underscore + +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) + +header_files = [ + # Provides the definition of the service_type_support_callbacks_t struct. + 'rosidl_typesupport_fastrtps_cpp/service_type_support.h', + 'rosidl_typesupport_cpp/service_type_support.hpp', + 'rosidl_typesupport_fastrtps_c/identifier.h', + package_name + '/msg/rosidl_typesupport_fastrtps_c__visibility_control.h', + include_base + '.h', +] +}@ +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ #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), @(subfolder), @(spec.srv_name)_Request)(), - ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(spec.pkg_name), @(subfolder), @(spec.srv_name)_Response)(), +static service_type_support_callbacks_t @(service.structure_type.name)__callbacks = { + "@(package_name)", + "@(service.structure_type.name)", + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.name]))_Request)(), + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.name]))_Response)(), }; -static rosidl_service_type_support_t handle = { +static rosidl_service_type_support_t @(service.structure_type.name)__handle = { rosidl_typesupport_fastrtps_c__identifier, - &callbacks, + &@(service.structure_type.name)__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), @(subfolder), @(spec.srv_name))() { - return &handle; +ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_c, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.name])))() { + return &@(service.structure_type.name)__handle; } #if defined(__cplusplus) 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 index 29e484f..39aab74 100644 --- a/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in +++ b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c-extras.cmake.in @@ -13,7 +13,7 @@ if(NOT FastRTPS_FOUND) else() find_package(ament_cmake_core QUIET REQUIRED) ament_register_extension( - "rosidl_generate_interfaces" + "rosidl_generate_idl_interfaces" "rosidl_typesupport_fastrtps_c" "rosidl_typesupport_fastrtps_c_generate_interfaces.cmake") diff --git a/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py index d94af46..4dcc161 100644 --- a/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py +++ b/rosidl_typesupport_fastrtps_c/rosidl_typesupport_fastrtps_c/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2016 Open Source Robotics Foundation, Inc. +# Copyright 2016-2018 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. @@ -12,92 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os +from rosidl_cmake import generate_files -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'): +def generate_typesupport_fastrtps_c(generator_arguments_file): + mapping = { + 'idl__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, + 'idl__type_support_c.cpp.em': '%s__type_support_c.cpp', } - # 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] - subfolder = os.path.basename(os.path.dirname(idl_file)) - if extension == '.msg': - spec = parse_message_file(pkg_name, idl_file) - validate_field_types(spec, known_msg_types) - 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'], 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.srv_name)) - - data = {'spec': spec, 'subfolder': subfolder} - data.update(functions) - expand_template( - template_file, data, generated_file, - minimum_timestamp=latest_target_timestamp) - - return 0 + generate_files(generator_arguments_file, mapping) From d9f6400200bb42b77cbccefe2bb14a5dd692c514 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Mon, 26 Nov 2018 13:44:32 -0800 Subject: [PATCH 04/20] Start porting rosidl_typesupport_fastrtps_cpp to new IDL pipeline --- .../bin/rosidl_typesupport_fastrtps_cpp | 35 +---- ...ort_fastrtps_cpp_generate_interfaces.cmake | 126 +++++++++--------- .../idl__dds_fastrtps__type_support.cpp.em | 0 ...dl__rosidl_typesupport_fastrtps_cpp.hpp.em | 53 ++++++++ .../resource/msg__type_support.cpp.em | 20 +-- ...l_typesupport_fastrtps_cpp-extras.cmake.in | 2 +- .../__init__.py | 95 +------------ 7 files changed, 130 insertions(+), 201 deletions(-) create mode 100644 rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em create mode 100644 rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em diff --git a/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp b/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp index 08f9e27..523fcbf 100644 --- a/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp +++ b/rosidl_typesupport_fastrtps_cpp/bin/rosidl_typesupport_fastrtps_cpp @@ -3,12 +3,8 @@ 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:]): @@ -19,42 +15,13 @@ def main(argv=sys.argv[1:]): '--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) + return generate_cpp(args.generator_arguments_file) 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__': 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 index 15157c8..1cb512b 100644 --- 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 @@ -17,57 +17,45 @@ 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() set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp/${PROJECT_NAME}") -set(_generated_files "") -foreach(_idl_file ${rosidl_generate_interfaces_IDL_FILES}) - get_filename_component(_extension "${_idl_file}" EXT) - get_filename_component(_parent_folder "${_idl_file}" DIRECTORY) + +# Create a list of files that will be generated from each IDL file +set(_generated_sources "") +foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) + # Get second part of tuple which has form "msg/Name.idl" or "srv/Name.idl" or "action/Name.idl" + string(REGEX REPLACE ":([^:]*)$" "/\\1" _rel_idl_file "${_idl_tuple}") + get_filename_component(_parent_folder "${_rel_idl_file}" DIRECTORY) get_filename_component(_parent_folder "${_parent_folder}" NAME) - get_filename_component(_msg_name "${_idl_file}" NAME_WE) - string_camel_case_to_lower_case_underscore("${_msg_name}" _header_name) - if(_extension STREQUAL ".msg") - set(_allowed_parent_folders "msg" "srv" "action") - if(NOT _parent_folder IN_LIST _allowed_parent_folders) - message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") - endif() - elseif(_extension STREQUAL ".srv") - set(_allowed_parent_folders "srv" "action") - if(NOT _parent_folder IN_LIST _allowed_parent_folders) - message(FATAL_ERROR "Interface file with unknown parent folder: ${_idl_file}") - endif() - else() - message(FATAL_ERROR "Interface file with unknown extension: ${_idl_file}") - endif() - list(APPEND _generated_files "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_cpp.hpp") - list(APPEND _generated_files "${_output_path}/${_parent_folder}/dds_fastrtps/${_header_name}__type_support.cpp") + get_filename_component(_idl_name "${_rel_idl_file}" NAME_WE) + # Turn idl name into file names + string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name) + list(APPEND _generated_sources + "${_output_path}/${_parent_folder}/dds_fastrtps/${_header_name}__type_support.cpp" + "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_cpp.hpp" + ) endforeach() +# Create a list of IDL files from other packages that this generator should depend on 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") - set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") - normalize_path(_abs_idl_file "${_abs_idl_file}") - list(APPEND _dependency_files "${_abs_idl_file}") - list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") - endif() + foreach(_idl_file ${${_pkg_name}_IDL_FILES}) + # ${{_pkg_name}_DIR} is absolute path ending in 'share//cmake', so go back one + # directory for IDL files + set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}") + normalize_path(_abs_idl_file "${_abs_idl_file}") + list(APPEND _dependency_files "${_abs_idl_file}") + list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}") endforeach() endforeach() +# Create a list of templates and source files this generator uses, and check that they exist set(target_dependencies "${rosidl_typesupport_fastrtps_cpp_BIN}" ${rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES} + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/idl__rosidl_typesupport_fastrtps_cpp.hpp.em" + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/idl__dds_fastrtps__type_support.cpp.em" "${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" @@ -76,31 +64,27 @@ set(target_dependencies ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") - get_property(is_generated SOURCE "${dep}" PROPERTY GENERATED) - if(NOT ${_is_generated}) - message(FATAL_ERROR "Target dependency '${dep}' does not exist") - endif() + message(FATAL_ERROR "Target dependency '${dep}' does not exist") endif() endforeach() +# Write all this to a file to work around command line length limitations on some platforms 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}" + IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}" ROS_INTERFACE_DEPENDENCIES "${_dependencies}" OUTPUT_DIR "${_output_path}" TEMPLATE_DIR "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}" TARGET_DEPENDENCIES ${target_dependencies} ) -set(_idl_pp "") +# Add a command that invokes generator at build time add_custom_command( - OUTPUT ${_generated_files} + OUTPUT ${_generated_sources} 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} COMMENT "Generating C++ type support for eProsima Fast-RTPS" VERBATIM @@ -118,19 +102,27 @@ configure_file( set(_target_suffix "__rosidl_typesupport_fastrtps_cpp") -# link_directories(${fastrtps_LIBRARY_DIRS}) +# Create a library that builds the generated files add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} SHARED - ${_generated_files}) + ${_generated_sources}) + +# Change output library name if asked to 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 C++ standard set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} PROPERTIES CXX_STANDARD 14) + +# Set flag for visibility macro if(WIN32) target_compile_definitions(${rosidl_generate_interfaces_TARGET}${_target_suffix} PRIVATE "ROSIDL_TYPESUPPORT_FASTRTPS_CPP_BUILDING_DLL_${PROJECT_NAME}") endif() + +# Set compiler flags if(NOT WIN32) set(_target_compile_flags "-Wall -Wextra -Wpedantic") else() @@ -141,37 +133,49 @@ endif() string(REPLACE ";" " " _target_compile_flags "${_target_compile_flags}") set_target_properties(${rosidl_generate_interfaces_TARGET}${_target_suffix} PROPERTIES COMPILE_FLAGS "${_target_compile_flags}") + +# Include headers from other generators 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} + "fastcdr" "fastrtps" "rmw" "rosidl_typesupport_fastrtps_cpp" "rosidl_typesupport_interface") + +# Depend on dependencies 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") - set(_action_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/action/dds_fastrtps") - normalize_path(_msg_include_dir "${_msg_include_dir}") - normalize_path(_srv_include_dir "${_srv_include_dir}") - normalize_path(_action_include_dir "${_action_include_dir}") - target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} - PUBLIC - "${_msg_include_dir}" - "${_srv_include_dir}" - "${_action_include_dir}" - ) + # TODO(sloretz) parent_folder/dds_fastrtps in template instead of here + # 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") + # set(_action_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/action/dds_fastrtps") + # normalize_path(_msg_include_dir "${_msg_include_dir}") + # normalize_path(_srv_include_dir "${_srv_include_dir}") + # normalize_path(_action_include_dir "${_action_include_dir}") + # target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} + # PUBLIC + # "${_msg_include_dir}" + # "${_srv_include_dir}" + # "${_action_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) + +# target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} fastrtps fastcdr) + +# Make top level generation target depend on this library add_dependencies( ${rosidl_generate_interfaces_TARGET} ${rosidl_generate_interfaces_TARGET}${_target_suffix} ) + +# Make this library depend on target created by rosidl_generator_cpp add_dependencies( ${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_generate_interfaces_TARGET}__cpp diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em new file mode 100644 index 0000000..e69de29 diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em new file mode 100644 index 0000000..63de6c3 --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -0,0 +1,53 @@ +// generated from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_cpp.hpp.em +// generated code does not contain a copyright notice + +@{ +####################################################################### +# EmPy template for generating __rosidl_typesupport_cpp.hpp files +# +# Context: +# - package_name (string) +# - content (rosidl_parser.definition.IdlContent result of parsing IDL file) +# - interface_path (Path relative to the directory named after the package) +####################################################################### + +include_directives = set() + +####################################################################### +# Handle message +####################################################################### +from rosidl_parser.definition import Message +for message in content.get_elements_of_type(Message): + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=message, + include_directives=include_directives) + +####################################################################### +# Handle service +####################################################################### +from rosidl_parser.definition import Service +for service in content.get_elements_of_type(Service): + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=service, + include_directives=include_directives) + +####################################################################### +# Handle action +####################################################################### +from rosidl_parser.definition import Action +for action in content.get_elements_of_type(Action): + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=action.goal_service, + include_directives=include_directives) + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=action.result_service, + include_directives=include_directives) + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=action.feedback, + include_directives=include_directives) +}@ diff --git a/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em index c35969d..a88cd0b 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em @@ -1,18 +1,6 @@ -// 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 -@# Could be 'msg', 'srv' or 'action' -@# - get_header_filename_from_msg_name (function) -@####################################################################### -@ +@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em + + #include "@(spec.base_type.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.base_type.type))__rosidl_typesupport_fastrtps_cpp.hpp" #include @@ -29,7 +17,7 @@ // forward declaration of message dependencies and their conversion functions @[for field in spec.fields]@ -@[ if not field.type.is_primitive_type()]@ +@[ if isinstance(field, rosidl_parser.NestedType)]@ namespace @(field.type.pkg_name) { namespace msg 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 index 6fb87c4..fd0dc69 100644 --- a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp-extras.cmake.in +++ b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp-extras.cmake.in @@ -14,7 +14,7 @@ if(NOT FastRTPS_FOUND) else() find_package(ament_cmake_core QUIET REQUIRED) ament_register_extension( - "rosidl_generate_interfaces" + "rosidl_generate_idl_interfaces" "rosidl_typesupport_fastrtps_cpp" "rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake") diff --git a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py index 69d9fcf..deb2e94 100644 --- a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py +++ b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py @@ -12,96 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os +from rosidl_cmake import generate_files -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((idl_file, 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', +def generate_cpp(generator_arguments_file): + mapping = { + 'idl__rosidl_typesupport_fastrtps_cpp.hpp.em': '%s__rosidl_typesupport_fastrtps_cpp.hpp', + 'idl__dds_fastrtps__type_support.cpp.em': 'dds_fastrtps/%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 idl_file, spec in service_specs: - validate_field_types(spec, known_msg_types) - subfolder = os.path.basename(os.path.dirname(idl_file)) - for template_file, generated_filename in mapping_srvs.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.srv_name)) - - data = {'spec': spec, 'subfolder': subfolder} - data.update(functions) - expand_template( - template_file, data, generated_file, - minimum_timestamp=latest_target_timestamp) - + generate_files(generator_arguments_file, mapping) return 0 From 5084cd7a07027b3a4b7f8a8eabcff305e2f73b61 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 29 Nov 2018 22:45:10 -0800 Subject: [PATCH 05/20] finish C++ typesupport generator to use IDL-based extension point --- ...ort_fastrtps_cpp_generate_interfaces.cmake | 7 +- .../idl__dds_fastrtps__type_support.cpp.em | 0 ...dl__rosidl_typesupport_fastrtps_cpp.hpp.em | 44 ++- .../resource/idl__type_support.cpp.em | 62 ++++ ...sg__rosidl_typesupport_fastrtps_cpp.hpp.em | 99 ++--- .../resource/msg__type_support.cpp.em | 347 +++++++++--------- ...rv__rosidl_typesupport_fastrtps_cpp.hpp.em | 52 +-- .../resource/srv__type_support.cpp.em | 103 +++--- .../__init__.py | 2 +- 9 files changed, 388 insertions(+), 328 deletions(-) delete mode 100644 rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em create mode 100644 rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em 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 index 1cb512b..a622585 100644 --- 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 @@ -55,12 +55,12 @@ set(target_dependencies "${rosidl_typesupport_fastrtps_cpp_BIN}" ${rosidl_typesupport_fastrtps_cpp_GENERATOR_FILES} "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/idl__rosidl_typesupport_fastrtps_cpp.hpp.em" - "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/idl__dds_fastrtps__type_support.cpp.em" + "${rosidl_typesupport_fastrtps_cpp_TEMPLATE_DIR}/idl__type_support.cpp.em" "${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" - ${rosidl_generate_interfaces_IDL_FILES} + # ${rosidl_generate_interfaces_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") @@ -142,7 +142,6 @@ target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} ) ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} - "fastcdr" "fastrtps" "rmw" "rosidl_typesupport_fastrtps_cpp" @@ -167,7 +166,7 @@ foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) ${_pkg_name}) endforeach() -# target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} fastrtps fastcdr) +target_link_libraries(${rosidl_generate_interfaces_TARGET}${_target_suffix} fastrtps fastcdr) # Make top level generation target depend on this library add_dependencies( diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em deleted file mode 100644 index e69de29..0000000 diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em index 63de6c3..2687e14 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -1,25 +1,37 @@ -// generated from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_cpp.hpp.em +// generated from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em +// with input from @(package_name):@(interface_path) // generated code does not contain a copyright notice - +@ +@####################################################################### +@# EmPy template for generating __rosidl_typesupport_fastrtps_cpp.hpp files +@# +@# Context: +@# - package_name (string) +@# - interface_path (Path relative to the directory named after the package) +@# - content (IdlContent, list of elements, e.g. Messages or Services) +@####################################################################### +@ @{ -####################################################################### -# EmPy template for generating __rosidl_typesupport_cpp.hpp files -# -# Context: -# - package_name (string) -# - content (rosidl_parser.definition.IdlContent result of parsing IDL file) -# - interface_path (Path relative to the directory named after the package) -####################################################################### +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ + '__ROSIDL_TYPESUPPORT_FASTRTPS_CPP_HPP_' include_directives = set() +}@ +#ifndef @(header_guard_variable) +#define @(header_guard_variable) + +@{ ####################################################################### # Handle message ####################################################################### from rosidl_parser.definition import Message for message in content.get_elements_of_type(Message): TEMPLATE( - 'msg__type_support.cpp.em', + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, message=message, include_directives=include_directives) @@ -29,7 +41,7 @@ for message in content.get_elements_of_type(Message): from rosidl_parser.definition import Service for service in content.get_elements_of_type(Service): TEMPLATE( - 'srv__type_support.cpp.em', + 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, service=service, include_directives=include_directives) @@ -39,15 +51,17 @@ for service in content.get_elements_of_type(Service): from rosidl_parser.definition import Action for action in content.get_elements_of_type(Action): TEMPLATE( - 'srv__type_support.cpp.em', + 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, service=action.goal_service, include_directives=include_directives) TEMPLATE( - 'srv__type_support.cpp.em', + 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, service=action.result_service, include_directives=include_directives) TEMPLATE( - 'msg__type_support.cpp.em', + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, message=action.feedback, include_directives=include_directives) }@ + +#endif // @(header_guard_variable) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em new file mode 100644 index 0000000..56eb4bb --- /dev/null +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em @@ -0,0 +1,62 @@ +// generated from rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +// with input from @(package_name):@(interface_path) +// generated code does not contain a copyright notice +@ +@####################################################################### +@# EmPy template for generating __type_support.cpp files +@# +@# Context: +@# - package_name (string) +@# - interface_path (Path relative to the directory named after the package) +@# - content (IdlContent, list of elements, e.g. Messages or Services) +@####################################################################### +@ +@{ +from rosidl_cmake import convert_camel_case_to_lower_case_underscore +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) +}@ +#include "@(include_base)__rosidl_typesupport_fastrtps_cpp.hpp" + +@{ +include_directives = set() + +####################################################################### +# Handle message +####################################################################### +from rosidl_parser.definition import Message +for message in content.get_elements_of_type(Message): + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=message, + include_directives=include_directives) + +####################################################################### +# Handle service +####################################################################### +from rosidl_parser.definition import Service +for service in content.get_elements_of_type(Service): + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=service, + include_directives=include_directives) + +####################################################################### +# Handle action +####################################################################### +from rosidl_parser.definition import Action +for action in content.get_elements_of_type(Action): + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=action.goal_service, + include_directives=include_directives) + TEMPLATE( + 'srv__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, service=action.result_service, + include_directives=include_directives) + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=action.feedback, + include_directives=include_directives) +}@ 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 index 04d3936..6533d7c 100644 --- 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 @@ -1,48 +1,28 @@ -// 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) -@####################################################################### -@ +@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @{ -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]) + '_' +from rosidl_cmake import convert_camel_case_to_lower_case_underscore + +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) + +header_files = [ + 'rosidl_generator_c/message_type_support_struct.h', + 'rosidl_typesupport_interface/macros.h', + package_name + '/msg/rosidl_typesupport_fastrtps_cpp__visibility_control.h', + include_base + '__struct.hpp', +] }@ -#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" +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ -@{ -header_filename = get_header_filename_from_msg_name(spec.base_type.type) -if header_filename.endswith('__request'): - header_filename = header_filename[:-9] -elif header_filename.endswith('__response'): - header_filename = header_filename[:-10] -if header_filename.endswith('__goal'): - header_filename = header_filename[:-6] -elif header_filename.endswith('__result'): - header_filename = header_filename[:-8] -elif header_filename.endswith('__feedback'): - header_filename = header_filename[:-10] -}@ -#include "@(spec.base_type.pkg_name)/@(subfolder)/@(header_filename)__struct.hpp" #ifndef _WIN32 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-parameter" @@ -56,57 +36,54 @@ elif header_filename.endswith('__feedback'): #endif #include "fastcdr/Cdr.h" +@[for ns in message.structure.type.namespaces]@ -namespace @(spec.base_type.pkg_name) -{ - -namespace @(subfolder) +namespace @(ns) { +@[end for]@ namespace typesupport_fastrtps_cpp { bool -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) cdr_serialize( - const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + const @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & ros_message, eprosima::fastcdr::Cdr & cdr); bool -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) cdr_deserialize( eprosima::fastcdr::Cdr & cdr, - @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message); + @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & ros_message); size_t -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) get_serialized_size( - const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + const @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & 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)( +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) +max_serialized_size_@(message.structure.type.name)( bool & full_bounded, size_t current_alignment); } // namespace typesupport_fastrtps_cpp +@[ for ns in reversed(message.structure.type.namespaces)]@ -} // namespace @(subfolder) - -} // namespace @(spec.base_type.pkg_name) +} // namespace @(ns) +@[ end for]@ #ifdef __cplusplus extern "C" { #endif -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_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))(); + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])))(); #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 index a88cd0b..fcffd2c 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/msg__type_support.cpp.em @@ -1,116 +1,137 @@ -@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__dds_fastrtps__type_support.cpp.em - - -#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" +@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +@{ +from rosidl_parser.definition import Array +from rosidl_parser.definition import BasicType +from rosidl_parser.definition import BoundedSequence +from rosidl_parser.definition import NamespacedType +from rosidl_parser.definition import NestedType +from rosidl_parser.definition import Sequence +from rosidl_parser.definition import String + +header_files = [ + 'limits', + 'stdexcept', + 'string', + 'rosidl_typesupport_cpp/message_type_support.hpp', + 'rosidl_typesupport_fastrtps_cpp/identifier.hpp', + 'rosidl_typesupport_fastrtps_cpp/message_type_support.h', + 'rosidl_typesupport_fastrtps_cpp/message_type_support_decl.hpp', + 'fastcdr/Cdr.h', +] +}@ +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +@[ if '/' not in header_file]@ +#include <@(header_file)> +@[ else]@ +#include "@(header_file)" +@[ end if]@ +@[end for]@ -#include "fastcdr/Cdr.h" // forward declaration of message dependencies and their conversion functions -@[for field in spec.fields]@ -@[ if isinstance(field, rosidl_parser.NestedType)]@ -namespace @(field.type.pkg_name) -{ -namespace msg +@[for member in message.structure.members]@ +@{ +type_ = member.type +if isinstance(type_, NestedType): + type_ = type_.basetype +}@ +@[ if isinstance(type_, NamespacedType)]@ +@[ for ns in type_.namespaces]@ +namespace @(ns) { +@[ end for]@ namespace typesupport_fastrtps_cpp { bool cdr_serialize( - const @(field.type.pkg_name)::msg::@(field.type.type) &, + const @('::'.join(type_.namespaces + [type_.name])) &, eprosima::fastcdr::Cdr &); bool cdr_deserialize( eprosima::fastcdr::Cdr &, - @(field.type.pkg_name)::msg::@(field.type.type) &); + @('::'.join(type_.namespaces + [type_.name])) &); size_t get_serialized_size( - const @(field.type.pkg_name)::msg::@(field.type.type) &, + const @('::'.join(type_.namespaces + [type_.name])) &, size_t current_alignment); size_t -max_serialized_size_@(field.type.type)( +max_serialized_size_@(type_.name)( bool & full_bounded, size_t current_alignment); } // namespace typesupport_fastrtps_cpp -} // namespace msg -} // namespace @(field.type.pkg_name) +@[ for ns in reversed(type_.namespaces)]@ +} // namespace @(ns) +@[ end for]@ @[ end if]@ @[end for]@ +@ +@[ for ns in message.structure.type.namespaces]@ -namespace @(spec.base_type.pkg_name) -{ - -namespace @(subfolder) +namespace @(ns) { +@[ end for]@ namespace typesupport_fastrtps_cpp { bool -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) cdr_serialize( - const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + const @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & 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]@ +@[for member in message.structure.members]@ + // Member: @(member.name) +@[ if isinstance(member.type, NestedType)]@ { -@[ if field.type.array_size and not field.type.is_upper_bound]@ -@[ if field.type.is_primitive_type()]@ - cdr << ros_message.@(field.name); +@[ if isinstance(member.type, Array)]@ +@[ if not isinstance(member.type.basetype, NamespacedType)]@ + cdr << ros_message.@(member.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], + for (size_t i = 0; i < @(member.type.size); i++) { + @('::'.join(member.type.basetype.namespaces))::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(member.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)) { +@[ if isinstance(member.type, BoundedSequence) or isinstance(member.type.basetype, NamespacedType)]@ + size_t size = ros_message.@(member.name).size(); +@[ if isinstance(member.type, BoundedSequence)]@ + if (size > @(member.type.upper_bound)) { 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); +@[ if not isinstance(member.type.basetype, NamespacedType) and not isinstance(member.type, BoundedSequence)]@ + cdr << ros_message.@(member.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]; +@[ if isinstance(member.type.basetype, BasicType) and member.type.basetype.type == 'boolean']@ + cdr << (ros_message.@(member.name)[i] ? true : false); +@[ elif not isinstance(member.type.basetype, NamespacedType)]@ + cdr << ros_message.@(member.name)[i]; @[ else]@ - @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_serialize( - ros_message.@(field.name)[i], + @('::'.join(member.type.basetype.namespaces))::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(member.name)[i], cdr); @[ end if]@ } @[ end if]@ @[ end if]@ } -@[ elif field.type.type == 'bool']@ - cdr << (ros_message.@(field.name) ? true : false); -@[ elif field.type.is_primitive_type()]@ - cdr << ros_message.@(field.name); +@[ elif isinstance(member.type, BasicType) and member.type.type == 'boolean']@ + cdr << (ros_message.@(member.name) ? true : false); +@[ elif not isinstance(member.type, NamespacedType)]@ + cdr << ros_message.@(member.name); @[ else]@ - @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_serialize( - ros_message.@(field.name), + @('::'.join(member.type.namespaces))::typesupport_fastrtps_cpp::cdr_serialize( + ros_message.@(member.name), cdr); @[ end if]@ @[end for]@ @@ -118,63 +139,59 @@ cdr_serialize( } bool -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) cdr_deserialize( eprosima::fastcdr::Cdr & cdr, - @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message) + @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & 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]@ +@[for member in message.structure.members]@ + // Member: @(member.name) +@[ if isinstance(member.type, NestedType)]@ { -@[ if field.type.array_size and not field.type.is_upper_bound]@ -@[ if field.type.is_primitive_type()]@ - cdr >> ros_message.@(field.name); +@[ if isinstance(member.type, Array)]@ +@[ if not isinstance(member.type.basetype, NamespacedType)]@ + cdr >> ros_message.@(member.name); @[ else]@ - for (size_t i = 0; i < @(field.type.array_size); i++) { - @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( + for (size_t i = 0; i < @(member.type.size); i++) { + @('::'.join(member.type.basetype.namespaces))::typesupport_fastrtps_cpp::cdr_deserialize( cdr, - ros_message.@(field.name)[i]); + ros_message.@(member.name)[i]); } @[ end if]@ @[ else]@ -@[ if field.type.is_primitive_type() and not field.type.is_upper_bound]@ - cdr >> ros_message.@(field.name); +@[ if not isinstance(member.type.basetype, NamespacedType) and not isinstance(member.type, BoundedSequence)]@ + cdr >> ros_message.@(member.name); @[ else]@ uint32_t cdrSize; cdr >> cdrSize; size_t size = static_cast(cdrSize); - ros_message.@(field.name).resize(size); + ros_message.@(member.name).resize(size); for (size_t i = 0; i < size; i++) { -@[ if field.type.type == 'bool']@ +@[ if isinstance(member.type.basetype, BasicType) and member.type.basetype.type == 'boolean']@ 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]; + ros_message.@(member.name)[i] = tmp ? true : false; +@[ elif not isinstance(member.type.basetype, NamespacedType)]@ + cdr >> ros_message.@(member.name)[i]; @[ else]@ - @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( - cdr, ros_message.@(field.name)[i]); + @('::'.join(member.type.basetype.namespaces))::typesupport_fastrtps_cpp::cdr_deserialize( + cdr, ros_message.@(member.name)[i]); @[ end if]@ } @[ end if]@ @[ end if]@ } -@[ elif field.type.type == 'bool']@ +@[ elif isinstance(member.type, BasicType) and member.type.type == 'boolean']@ { uint8_t tmp; cdr >> tmp; - ros_message.@(field.name) = tmp ? true : false; + ros_message.@(member.name) = tmp ? true : false; } -@[ elif field.type.is_primitive_type()]@ - cdr >> ros_message.@(field.name); +@[ elif not isinstance(member.type, NamespacedType)]@ + cdr >> ros_message.@(member.name); @[ else]@ - @(field.type.pkg_name)::msg::typesupport_fastrtps_cpp::cdr_deserialize( - cdr, ros_message.@(field.name)); + @('::'.join(member.type.namespaces))::typesupport_fastrtps_cpp::cdr_deserialize( + cdr, ros_message.@(member.name)); @[ end if]@ @[end for]@ @@ -182,31 +199,26 @@ cdr_deserialize( } size_t -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) get_serialized_size( - const @(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type) & ros_message, + const @('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) & 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]@ +@[for member in message.structure.members]@ + // Member: @(member.name) +@[ if isinstance(member.type, NestedType)]@ { -@[ if field.type.array_size and not field.type.is_upper_bound]@ - size_t array_size = @(field.type.array_size); +@[ if isinstance(member.type, Array)]@ + size_t array_size = @(member.type.size); @[ else]@ - size_t array_size = ros_message.@(field.name).size(); -@[ if field.type.is_upper_bound]@ - if (array_size > @(field.type.array_size)) { + size_t array_size = ros_message.@(member.name).size(); +@[ if isinstance(member.type, BoundedSequence)]@ + if (array_size > @(member.type.upper_bound)) { throw std::runtime_error("array size exceeds upper bound"); } @[ end if]@ @@ -214,53 +226,49 @@ get_serialized_size( current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); @[ end if]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type.basetype, 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; + ros_message.@(member.name)[index].size() + 1; } -@[ elif field.type.is_primitive_type()]@ - size_t item_size = sizeof(ros_message.@(field.name)[0]); +@[ elif isinstance(member.type.basetype, BasicType)]@ + size_t item_size = sizeof(ros_message.@(member.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); + @('::'.join(member.type.basetype.namespaces))::typesupport_fastrtps_cpp::get_serialized_size( + ros_message.@(member.name)[index], current_alignment); } @[ end if]@ } @[ else]@ -@[ if field.type.type == 'string']@ +@[ if isinstance(member.type, String)]@ current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + - ros_message.@(field.name).size() + 1; -@[ elif field.type.is_primitive_type()]@ + ros_message.@(member.name).size() + 1; +@[ elif isinstance(member.type, BasicType)]@ { - size_t item_size = sizeof(ros_message.@(field.name)); + size_t item_size = sizeof(ros_message.@(member.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); + @('::'.join(member.type.namespaces))::typesupport_fastrtps_cpp::get_serialized_size( + ros_message.@(member.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)( +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) +max_serialized_size_@(message.structure.type.name)( bool & full_bounded, size_t current_alignment) { @@ -270,16 +278,18 @@ max_serialized_size_@(spec.base_type.type)( (void)padding; (void)full_bounded; -@[for field in spec.fields]@ - // field.name @(field.name) +@[for member in message.structure.members]@ + // Member: @(member.name) { -@[ if field.type.is_array]@ -@[ if field.type.array_size]@ - size_t array_size = @(field.type.array_size); +@[ if isinstance(member.type, NestedType)]@ +@[ if isinstance(member.type, Array)]@ + size_t array_size = @(member.type.size); +@[ elif isinstance(member.type, BoundedSequence)]@ + size_t array_size = @(member.type.upper_bound); @[ else]@ size_t array_size = 0; @[ end if]@ -@[ if not field.type.array_size or field.type.is_upper_bound]@ +@[ if isinstance(member.type, Sequence)]@ full_bounded = false; current_alignment += padding + eprosima::fastcdr::Cdr::alignment(current_alignment, padding); @@ -288,34 +298,39 @@ max_serialized_size_@(spec.base_type.type)( size_t array_size = 1; @[ end if]@ -@[ if field.type.type == 'string']@ +@{ +type_ = member.type +if isinstance(type_, NestedType): + type_ = type_.basetype +}@ +@[ if isinstance(type_, String)]@ full_bounded = false; for (size_t index = 0; index < array_size; ++index) { current_alignment += padding + -@[ if field.type.string_upper_bound]@ +@[ if type_.maximum_size]@ eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + - @(field.type.string_upper_bound) + 1; + @(type_.maximum_size) + 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' ] +@[ elif isinstance(type_, BasicType)]@ +@[ if type_.type in ('boolean', 'octet', 'char', 'uint8', 'int8')]@ current_alignment += array_size * sizeof(uint8_t); -@[ elif field.type.type == 'int16' or field.type.type == 'uint16'] +@[ elif type_.type in ('int16', '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'] +@[ elif type_.type in ('int32', 'uint32', 'float')]@ 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'] +@[ elif type_.type in ('int64', 'uint64', 'double')]@ 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)( + @('::'.join(type_.namespaces))::typesupport_fastrtps_cpp::max_serialized_size_@(type_.name)( full_bounded, current_alignment); } @[ end if]@ @@ -325,70 +340,70 @@ max_serialized_size_@(spec.base_type.type)( return current_alignment - initial_alignment; } -static bool __cdr_serialize( +static bool _@(message.structure.type.name)__cdr_serialize( const void * untyped_ros_message, eprosima::fastcdr::Cdr & cdr) { auto typed_message = - static_cast( + static_cast( untyped_ros_message); return cdr_serialize(*typed_message, cdr); } -static bool __cdr_deserialize( +static bool _@(message.structure.type.name)__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) *>( + static_cast<@('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])) *>( untyped_ros_message); return cdr_deserialize(cdr, *typed_message); } -static uint32_t __get_serialized_size( +static uint32_t _@(message.structure.type.name)__get_serialized_size( const void * untyped_ros_message) { auto typed_message = - static_cast( + static_cast( untyped_ros_message); return static_cast(get_serialized_size(*typed_message, 0)); } -static size_t __max_serialized_size(bool & full_bounded) +static size_t _@(message.structure.type.name)__max_serialized_size(bool & full_bounded) { - return max_serialized_size_@(spec.base_type.type)(full_bounded, 0); + return max_serialized_size_@(message.structure.type.name)(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 message_type_support_callbacks_t _@(message.structure.type.name)__callbacks = { + "@(package_name)", + "@(message.structure.type.name)", + _@(message.structure.type.name)__cdr_serialize, + _@(message.structure.type.name)__cdr_deserialize, + _@(message.structure.type.name)__get_serialized_size, + _@(message.structure.type.name)__max_serialized_size }; -static rosidl_message_type_support_t handle = { +static rosidl_message_type_support_t _@(message.structure.type.name)__handle = { rosidl_typesupport_fastrtps_cpp::typesupport_identifier, - &callbacks, + &_@(message.structure.type.name)__callbacks, get_message_typesupport_handle_function, }; } // namespace typesupport_fastrtps_cpp +@[ for ns in reversed(message.structure.type.namespaces)]@ -} // namespace @(subfolder) - -} // namespace @(spec.base_type.pkg_name) +} // namespace @(ns) +@[ end for]@ namespace rosidl_typesupport_fastrtps_cpp { template<> -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@(spec.base_type.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@(package_name) const rosidl_message_type_support_t * -get_message_type_support_handle<@(spec.base_type.pkg_name)::@(subfolder)::@(spec.base_type.type)>() +get_message_type_support_handle<@('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name]))>() { - return &@(spec.base_type.pkg_name)::@(subfolder)::typesupport_fastrtps_cpp::handle; + return &@('::'.join([package_name] + list(interface_path.parents[0].parts)))::typesupport_fastrtps_cpp::_@(message.structure.type.name)__handle; } } // namespace rosidl_typesupport_fastrtps_cpp @@ -399,8 +414,8 @@ 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; +ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.type.name])))() { + return &@('::'.join([package_name] + list(interface_path.parents[0].parts)))::typesupport_fastrtps_cpp::_@(message.structure.type.name)__handle; } #ifdef __cplusplus 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 index a88733d..4cc9936 100644 --- 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 @@ -1,47 +1,31 @@ -// 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 -@# - subfolder (string) -@# The subfolder / subnamespace of the message -@# Either 'srv' or 'action' -@# - get_header_filename_from_srv_name (function) -@####################################################################### -@ +@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @{ -header_guard_parts = [ - spec.pkg_name, subfolder, - 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]) + '_' +header_files = [ + 'rmw/types.h', + 'rosidl_typesupport_cpp/service_type_support.hpp', + 'rosidl_typesupport_interface/macros.h', + package_name + '/msg/rosidl_typesupport_fastrtps_cpp__visibility_control.h', +] }@ -#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" +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ #ifdef __cplusplus extern "C" { #endif -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(spec.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_@(package_name) const rosidl_service_type_support_t * - ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), @(subfolder), @(spec.srv_name))(); + ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.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 index 84b9ac8..3bfa56a 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em @@ -1,73 +1,82 @@ -// 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 -@# - subfolder (string) -@# The subfolder / subnamespace of the message -@# Either 'srv' or 'action' -@# - get_header_filename_from_msg_name (function) -@####################################################################### -@ -#include "@(spec.pkg_name)/@(subfolder)/@(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" +@# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +@{ +from rosidl_cmake import convert_camel_case_to_lower_case_underscore + +include_parts = [package_name] + list(interface_path.parents[0].parts) + \ + [convert_camel_case_to_lower_case_underscore(interface_path.stem)] +include_base = '/'.join(include_parts) +}@ +#include "@(include_base)__struct.hpp" @{ -header_filename = get_header_filename_from_msg_name(spec.srv_name) -if header_filename.endswith('__goal'): - header_filename = header_filename[:-6] -elif header_filename.endswith('__result'): - header_filename = header_filename[:-8] +TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=service.request_message, + include_directives=include_directives) }@ -#include "@(spec.pkg_name)/@(subfolder)/@(header_filename)__struct.hpp" -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Request'))__rosidl_typesupport_fastrtps_cpp.hpp" -#include "@(spec.pkg_name)/@(subfolder)/@(get_header_filename_from_msg_name(spec.srv_name + '_Response'))__rosidl_typesupport_fastrtps_cpp.hpp" -namespace @(spec.pkg_name) -{ +@{ +TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=service.response_message, + include_directives=include_directives) +}@ -namespace @(subfolder) +@{ +header_files = [ + 'rmw/error_handling.h', + 'rosidl_typesupport_fastrtps_cpp/identifier.hpp', + 'rosidl_typesupport_fastrtps_cpp/service_type_support.h', + 'rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp', + include_base + '__struct.hpp', +] +}@ +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ +@[ for ns in service.structure_type.namespaces]@ + +namespace @(ns) { +@[ end for]@ 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), @(subfolder), @(spec.srv_name)_Request)(), - ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), @(subfolder), @(spec.srv_name)_Response)(), +static service_type_support_callbacks_t _@(service.structure_type.name)__callbacks = { + "@(package_name)", + "@(service.structure_type.name)", + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.structure_type.name)_Request)(), + ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.structure_type.name)_Response)(), }; -static rosidl_service_type_support_t handle = { +static rosidl_service_type_support_t _@(service.structure_type.name)__handle = { rosidl_typesupport_fastrtps_cpp::typesupport_identifier, - &callbacks, + &_@(service.structure_type.name)__callbacks, get_service_typesupport_handle_function, }; } // namespace typesupport_fastrtps_cpp +@[ for ns in reversed(service.structure_type.namespaces)]@ -} // namespace @(subfolder) - -} // namespace @(spec.pkg_name) +} // namespace @(ns) +@[ end for]@ namespace rosidl_typesupport_fastrtps_cpp { template<> -ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@(spec.pkg_name) +ROSIDL_TYPESUPPORT_FASTRTPS_CPP_EXPORT_@(package_name) const rosidl_service_type_support_t * -get_service_type_support_handle<@(spec.pkg_name)::@(subfolder)::@(spec.srv_name)>() +get_service_type_support_handle<@('::'.join([package_name] + list(interface_path.parents[0].parts) + [service.structure_type.name]))>() { - return &@(spec.pkg_name)::@(subfolder)::typesupport_fastrtps_cpp::handle; + return &@('::'.join([package_name] + list(interface_path.parents[0].parts)))::typesupport_fastrtps_cpp::_@(service.structure_type.name)__handle; } } // namespace rosidl_typesupport_fastrtps_cpp @@ -78,8 +87,8 @@ extern "C" #endif const rosidl_service_type_support_t * -ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(spec.pkg_name), @(subfolder), @(spec.srv_name))() { - return &@(spec.pkg_name)::@(subfolder)::typesupport_fastrtps_cpp::handle; +ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(rosidl_typesupport_fastrtps_cpp, @(', '.join([package_name] + list(interface_path.parents[0].parts))), @(service.structure_type.name))() { + return &@('::'.join([package_name] + list(interface_path.parents[0].parts)))::typesupport_fastrtps_cpp::_@(service.structure_type.name)__handle; } #ifdef __cplusplus diff --git a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py index deb2e94..365248e 100644 --- a/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py +++ b/rosidl_typesupport_fastrtps_cpp/rosidl_typesupport_fastrtps_cpp/__init__.py @@ -18,7 +18,7 @@ def generate_cpp(generator_arguments_file): mapping = { 'idl__rosidl_typesupport_fastrtps_cpp.hpp.em': '%s__rosidl_typesupport_fastrtps_cpp.hpp', - 'idl__dds_fastrtps__type_support.cpp.em': 'dds_fastrtps/%s__type_support.cpp', + 'idl__type_support.cpp.em': 'dds_fastrtps/%s__type_support.cpp', } generate_files(generator_arguments_file, mapping) return 0 From b6a7bd892edd4beda0cc85a9457f0eee987b6191 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 30 Nov 2018 11:53:43 -0800 Subject: [PATCH 06/20] fix Windows build --- .../resource/idl__type_support.cpp.em | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em index 56eb4bb..53097ca 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em @@ -47,6 +47,18 @@ for service in content.get_elements_of_type(Service): ####################################################################### from rosidl_parser.definition import Action for action in content.get_elements_of_type(Action): + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=action.goal_request, + include_directives=include_directives) + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=action.result_response, + include_directives=include_directives) + TEMPLATE( + 'msg__type_support.cpp.em', + package_name=package_name, interface_path=interface_path, message=action.feedback, + include_directives=include_directives) TEMPLATE( 'srv__type_support.cpp.em', package_name=package_name, interface_path=interface_path, service=action.goal_service, @@ -57,6 +69,6 @@ for action in content.get_elements_of_type(Action): include_directives=include_directives) TEMPLATE( 'msg__type_support.cpp.em', - package_name=package_name, interface_path=interface_path, message=action.feedback, + package_name=package_name, interface_path=interface_path, message=action.feedback_message, include_directives=include_directives) }@ From 53a839adc74840c7d71c0290d72b971ceae53d9e Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 30 Nov 2018 17:15:11 -0800 Subject: [PATCH 07/20] lint the right files --- ...idl_typesupport_fastrtps_cpp_generate_interfaces.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index a622585..ed3670e 100644 --- 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 @@ -21,7 +21,7 @@ find_package(FastRTPS REQUIRED MODULE) set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp/${PROJECT_NAME}") # Create a list of files that will be generated from each IDL file -set(_generated_sources "") +set(_generated_files "") foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) # Get second part of tuple which has form "msg/Name.idl" or "srv/Name.idl" or "action/Name.idl" string(REGEX REPLACE ":([^:]*)$" "/\\1" _rel_idl_file "${_idl_tuple}") @@ -30,7 +30,7 @@ foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) get_filename_component(_idl_name "${_rel_idl_file}" NAME_WE) # Turn idl name into file names string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name) - list(APPEND _generated_sources + list(APPEND _generated_files "${_output_path}/${_parent_folder}/dds_fastrtps/${_header_name}__type_support.cpp" "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_fastrtps_cpp.hpp" ) @@ -82,7 +82,7 @@ rosidl_write_generator_arguments( # Add a command that invokes generator at build time add_custom_command( - OUTPUT ${_generated_sources} + OUTPUT ${_generated_files} COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_fastrtps_cpp_BIN} --generator-arguments-file "${generator_arguments_file}" DEPENDS ${target_dependencies} @@ -104,7 +104,7 @@ set(_target_suffix "__rosidl_typesupport_fastrtps_cpp") # Create a library that builds the generated files add_library(${rosidl_generate_interfaces_TARGET}${_target_suffix} SHARED - ${_generated_sources}) + ${_generated_files}) # Change output library name if asked to if(rosidl_generate_interfaces_LIBRARY_NAME) From 1d11018f5718fc89b0c2a83305fec186fbe53c3a Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 4 Dec 2018 08:14:43 -0800 Subject: [PATCH 08/20] fix repeated include warning --- .../resource/idl__type_support.cpp.em | 1 + .../resource/srv__type_support.cpp.em | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em index 53097ca..80b45ef 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em @@ -18,6 +18,7 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + \ include_base = '/'.join(include_parts) }@ #include "@(include_base)__rosidl_typesupport_fastrtps_cpp.hpp" +#include "@(include_base)__struct.hpp" @{ include_directives = set() diff --git a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em index 3bfa56a..123004a 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/srv__type_support.cpp.em @@ -6,8 +6,6 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + \ [convert_camel_case_to_lower_case_underscore(interface_path.stem)] include_base = '/'.join(include_parts) }@ -#include "@(include_base)__struct.hpp" - @{ TEMPLATE( 'msg__type_support.cpp.em', @@ -28,7 +26,6 @@ header_files = [ 'rosidl_typesupport_fastrtps_cpp/identifier.hpp', 'rosidl_typesupport_fastrtps_cpp/service_type_support.h', 'rosidl_typesupport_fastrtps_cpp/service_type_support_decl.hpp', - include_base + '__struct.hpp', ] }@ @[for header_file in header_files]@ From c16c726b7e47a362f8eb14d76f646d1cb787131f Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 4 Dec 2018 09:33:16 -0800 Subject: [PATCH 09/20] add missing request/response TS symbols --- .../srv__rosidl_typesupport_fastrtps_c.h.em | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 index c188af0..241c137 100644 --- 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 @@ -1,4 +1,18 @@ @# Included from rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=service.request_message, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=service.response_message, + include_directives=include_directives) +}@ + @{ header_files = [ 'rosidl_generator_c/service_type_support_struct.h', From 1d31348b6434c277dc242632728e439f4d394070 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 4 Dec 2018 12:13:05 -0800 Subject: [PATCH 10/20] same as previous --- .../srv__rosidl_typesupport_fastrtps_cpp.hpp.em | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 index 4cc9936..1b79b52 100644 --- 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 @@ -1,4 +1,18 @@ @# Included from rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', + package_name=package_name, interface_path=interface_path, message=service.request_message, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', + package_name=package_name, interface_path=interface_path, message=service.response_message, + include_directives=include_directives) +}@ + @{ header_files = [ 'rmw/types.h', From 5b7bf1088c64f00e6c82a76a1f4a29144e10afd1 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 4 Dec 2018 12:15:44 -0800 Subject: [PATCH 11/20] fix missing action TS symbols --- .../idl__rosidl_typesupport_fastrtps_cpp.hpp.em | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em index 2687e14..ac0c549 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -50,6 +50,18 @@ for service in content.get_elements_of_type(Service): ####################################################################### from rosidl_parser.definition import Action for action in content.get_elements_of_type(Action): + TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', + package_name=package_name, interface_path=interface_path, message=action.goal_request, + include_directives=include_directives) + TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', + package_name=package_name, interface_path=interface_path, message=action.result_response, + include_directives=include_directives) + TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', + package_name=package_name, interface_path=interface_path, message=action.feedback, + include_directives=include_directives) TEMPLATE( 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', package_name=package_name, interface_path=interface_path, service=action.goal_service, @@ -60,7 +72,7 @@ for action in content.get_elements_of_type(Action): include_directives=include_directives) TEMPLATE( 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', - package_name=package_name, interface_path=interface_path, message=action.feedback, + package_name=package_name, interface_path=interface_path, message=action.feedback_message, include_directives=include_directives) }@ From ecdf4b9f9dd2120d719977ecdb26da244dd74685 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 5 Dec 2018 09:20:29 -0800 Subject: [PATCH 12/20] fix linter warning --- .../msg__rosidl_typesupport_fastrtps_cpp.hpp.em | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 index 6533d7c..b4f6e7c 100644 --- 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 @@ -35,7 +35,20 @@ header_files = [ # pragma GCC diagnostic pop #endif -#include "fastcdr/Cdr.h" +@{ +header_files = [ + 'fastcdr/Cdr.h', +] +}@ +@[for header_file in header_files]@ +@[ if header_file in include_directives]@ +// already included above +// @ +@[ else]@ +@{include_directives.add(header_file)}@ +@[ end if]@ +#include "@(header_file)" +@[end for]@ @[for ns in message.structure.type.namespaces]@ namespace @(ns) From 39743a5415a58ae0b8b7c56803317554dbabe21d Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 5 Dec 2018 12:30:14 -0800 Subject: [PATCH 13/20] add missing C action symbols --- .../idl__rosidl_typesupport_fastrtps_c.h.em | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em index 2eb6bc0..00d3476 100644 --- a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em +++ b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @@ -65,6 +65,27 @@ from rosidl_parser.definition import Action }@ @[for action in content.get_elements_of_type(Action)]@ +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=action.goal_request, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=action.result_response, + include_directives=include_directives) +}@ + +@{ +TEMPLATE( + 'msg__rosidl_typesupport_fastrtps_c.h.em', + package_name=package_name, interface_path=interface_path, message=action.feedback, + include_directives=include_directives) +}@ + @{ TEMPLATE( 'srv__rosidl_typesupport_fastrtps_c.h.em', From 00d0a7c87af8afdad9d2857427024ee1fb80bc11 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 12 Feb 2019 11:58:05 -0800 Subject: [PATCH 14/20] match renamed action types --- .../resource/idl__rosidl_typesupport_fastrtps_c.h.em | 8 ++++---- .../resource/idl__type_support_c.cpp.em | 8 ++++---- .../resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em | 8 ++++---- .../resource/idl__type_support.cpp.em | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em index 00d3476..65f4c3b 100644 --- a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em +++ b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @@ -68,14 +68,14 @@ from rosidl_parser.definition import Action @{ TEMPLATE( 'msg__rosidl_typesupport_fastrtps_c.h.em', - package_name=package_name, interface_path=interface_path, message=action.goal_request, + package_name=package_name, interface_path=interface_path, message=action.goal, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__rosidl_typesupport_fastrtps_c.h.em', - package_name=package_name, interface_path=interface_path, message=action.result_response, + package_name=package_name, interface_path=interface_path, message=action.result, include_directives=include_directives) }@ @@ -89,14 +89,14 @@ TEMPLATE( @{ TEMPLATE( 'srv__rosidl_typesupport_fastrtps_c.h.em', - package_name=package_name, interface_path=interface_path, service=action.goal_service, + package_name=package_name, interface_path=interface_path, service=action.send_goal_service, include_directives=include_directives) }@ @{ TEMPLATE( 'srv__rosidl_typesupport_fastrtps_c.h.em', - package_name=package_name, interface_path=interface_path, service=action.result_service, + package_name=package_name, interface_path=interface_path, service=action.get_result_service, include_directives=include_directives) }@ diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em index 3bf0ec7..974f48d 100644 --- a/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em @@ -67,14 +67,14 @@ from rosidl_parser.definition import Action TEMPLATE( 'msg__type_support_c.cpp.em', package_name=package_name, interface_path=interface_path, - message=action.goal_request, include_directives=include_directives) + message=action.goal, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__type_support_c.cpp.em', package_name=package_name, interface_path=interface_path, - message=action.result_response, include_directives=include_directives) + message=action.result, include_directives=include_directives) }@ @{ @@ -88,14 +88,14 @@ TEMPLATE( TEMPLATE( 'srv__type_support_c.cpp.em', package_name=package_name, interface_path=interface_path, - service=action.goal_service, include_directives=include_directives) + service=action.send_goal_service, include_directives=include_directives) }@ @{ TEMPLATE( 'srv__type_support_c.cpp.em', package_name=package_name, interface_path=interface_path, - service=action.result_service, include_directives=include_directives) + service=action.get_result_service, include_directives=include_directives) }@ @{ diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em index ac0c549..aa6d8e6 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__rosidl_typesupport_fastrtps_cpp.hpp.em @@ -52,11 +52,11 @@ from rosidl_parser.definition import Action for action in content.get_elements_of_type(Action): TEMPLATE( 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', - package_name=package_name, interface_path=interface_path, message=action.goal_request, + package_name=package_name, interface_path=interface_path, message=action.goal, include_directives=include_directives) TEMPLATE( 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', - package_name=package_name, interface_path=interface_path, message=action.result_response, + package_name=package_name, interface_path=interface_path, message=action.result, include_directives=include_directives) TEMPLATE( 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', @@ -64,11 +64,11 @@ for action in content.get_elements_of_type(Action): include_directives=include_directives) TEMPLATE( 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', - package_name=package_name, interface_path=interface_path, service=action.goal_service, + package_name=package_name, interface_path=interface_path, service=action.send_goal_service, include_directives=include_directives) TEMPLATE( 'srv__rosidl_typesupport_fastrtps_cpp.hpp.em', - package_name=package_name, interface_path=interface_path, service=action.result_service, + package_name=package_name, interface_path=interface_path, service=action.get_result_service, include_directives=include_directives) TEMPLATE( 'msg__rosidl_typesupport_fastrtps_cpp.hpp.em', diff --git a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em index 80b45ef..cb2555a 100644 --- a/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em +++ b/rosidl_typesupport_fastrtps_cpp/resource/idl__type_support.cpp.em @@ -50,11 +50,11 @@ from rosidl_parser.definition import Action for action in content.get_elements_of_type(Action): TEMPLATE( 'msg__type_support.cpp.em', - package_name=package_name, interface_path=interface_path, message=action.goal_request, + package_name=package_name, interface_path=interface_path, message=action.goal, include_directives=include_directives) TEMPLATE( 'msg__type_support.cpp.em', - package_name=package_name, interface_path=interface_path, message=action.result_response, + package_name=package_name, interface_path=interface_path, message=action.result, include_directives=include_directives) TEMPLATE( 'msg__type_support.cpp.em', @@ -62,11 +62,11 @@ for action in content.get_elements_of_type(Action): include_directives=include_directives) TEMPLATE( 'srv__type_support.cpp.em', - package_name=package_name, interface_path=interface_path, service=action.goal_service, + package_name=package_name, interface_path=interface_path, service=action.send_goal_service, include_directives=include_directives) TEMPLATE( 'srv__type_support.cpp.em', - package_name=package_name, interface_path=interface_path, service=action.result_service, + package_name=package_name, interface_path=interface_path, service=action.get_result_service, include_directives=include_directives) TEMPLATE( 'msg__type_support.cpp.em', From 2cdb7b2ac42ccfceb0b6f0c4d6dcf40ab7bc498f Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 21 Feb 2019 15:16:17 -0800 Subject: [PATCH 15/20] remove obsolete comment --- .../rosidl_typesupport_fastrtps_c_generate_interfaces.cmake | 1 - .../rosidl_typesupport_fastrtps_cpp_generate_interfaces.cmake | 1 - 2 files changed, 2 deletions(-) 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 index d029321..dc82b7d 100644 --- 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 @@ -50,7 +50,6 @@ set(target_dependencies "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__type_support_c.cpp.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__rosidl_typesupport_fastrtps_c.h.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__type_support_c.cpp.em" - # ${rosidl_generate_interfaces_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") 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 index ed3670e..7591385 100644 --- 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 @@ -60,7 +60,6 @@ set(target_dependencies "${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" - # ${rosidl_generate_interfaces_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") From ef4fe789b85874db0c4f7b8202c98f2c66ecee99 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 22 Feb 2019 09:41:10 -0800 Subject: [PATCH 16/20] remove comment --- ...pesupport_fastrtps_cpp_generate_interfaces.cmake | 13 ------------- 1 file changed, 13 deletions(-) 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 index 7591385..a5b65d5 100644 --- 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 @@ -148,19 +148,6 @@ ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} # Depend on dependencies foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES}) - # TODO(sloretz) parent_folder/dds_fastrtps in template instead of here - # 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") - # set(_action_include_dir "${${_pkg_name}_DIR}/../../../include/${_pkg_name}/action/dds_fastrtps") - # normalize_path(_msg_include_dir "${_msg_include_dir}") - # normalize_path(_srv_include_dir "${_srv_include_dir}") - # normalize_path(_action_include_dir "${_action_include_dir}") - # target_include_directories(${rosidl_generate_interfaces_TARGET}${_target_suffix} - # PUBLIC - # "${_msg_include_dir}" - # "${_srv_include_dir}" - # "${_action_include_dir}" - # ) ament_target_dependencies(${rosidl_generate_interfaces_TARGET}${_target_suffix} ${_pkg_name}) endforeach() From 18c2ada8ce0a5f0366f4a48a74dfc6a4043265cc Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 22 Feb 2019 17:04:43 -0800 Subject: [PATCH 17/20] remove invalid comment --- .../resource/idl__rosidl_typesupport_fastrtps_c.h.em | 1 - .../resource/idl__type_support_c.cpp.em | 1 - 2 files changed, 2 deletions(-) diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em index 65f4c3b..df21f52 100644 --- a/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em +++ b/rosidl_typesupport_fastrtps_c/resource/idl__rosidl_typesupport_fastrtps_c.h.em @@ -9,7 +9,6 @@ @# - package_name (string) @# - interface_path (Path relative to the directory named after the package) @# - content (IdlContent, list of elements, e.g. Messages or Services) -@# - type_supports (list of strings, the names of the type support packages) @####################################################################### @ @{ diff --git a/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em index 974f48d..c36b0df 100644 --- a/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em @@ -9,7 +9,6 @@ @# - package_name (string) @# - interface_path (Path relative to the directory named after the package) @# - content (IdlContent, list of elements, e.g. Messages or Services) -@# - type_supports (list of strings, the names of the type support packages) @####################################################################### @ @{ From 5768263aae04b0ff0f7fbb01e0e8a5bd0cc84364 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 27 Feb 2019 09:18:12 -0800 Subject: [PATCH 18/20] deterministic order --- .../resource/msg__type_support_c.cpp.em | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 13a73ef..d730d89 100644 --- a/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em @@ -104,7 +104,7 @@ for member in message.structure.members: @[ else]@ @{include_directives.add(header_file)}@ @[ end if]@ -#include "@(header_file)" // @(', '.join(includes[header_file])) +#include "@(header_file)" // @(', '.join(sorted(includes[header_file]))) @[end for]@ // forward declare type support functions From d95cfed61b66ebda628d60b595e978bae3640295 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Thu, 28 Feb 2019 08:52:13 -0800 Subject: [PATCH 19/20] readd explicit dependency on absolute paths of idl files --- ...sidl_typesupport_fastrtps_c_generate_interfaces.cmake | 4 ++-- ...dl_typesupport_fastrtps_cpp_generate_interfaces.cmake | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) 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 index dc82b7d..82b45eb 100644 --- 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 @@ -19,8 +19,7 @@ find_package(FastRTPS REQUIRED MODULE) set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_c/${PROJECT_NAME}") set(_generated_files "") -foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) - string(REGEX REPLACE ":([^:]*)$" "/\\1" _abs_idl_file "${_idl_tuple}") +foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES}) get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY) get_filename_component(_parent_folder "${_parent_folder}" NAME) get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE) @@ -50,6 +49,7 @@ set(target_dependencies "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/msg__type_support_c.cpp.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__rosidl_typesupport_fastrtps_c.h.em" "${rosidl_typesupport_fastrtps_c_TEMPLATE_DIR}/srv__type_support_c.cpp.em" + ${rosidl_generate_interfaces_ABS_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") 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 index a5b65d5..1c192cf 100644 --- 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 @@ -22,12 +22,10 @@ set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_fastrtps_cpp/${ # Create a list of files that will be generated from each IDL file set(_generated_files "") -foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) - # Get second part of tuple which has form "msg/Name.idl" or "srv/Name.idl" or "action/Name.idl" - string(REGEX REPLACE ":([^:]*)$" "/\\1" _rel_idl_file "${_idl_tuple}") - get_filename_component(_parent_folder "${_rel_idl_file}" DIRECTORY) +foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES}) + get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY) get_filename_component(_parent_folder "${_parent_folder}" NAME) - get_filename_component(_idl_name "${_rel_idl_file}" NAME_WE) + get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE) # Turn idl name into file names string_camel_case_to_lower_case_underscore("${_idl_name}" _header_name) list(APPEND _generated_files @@ -60,6 +58,7 @@ set(target_dependencies "${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" + ${rosidl_generate_interfaces_ABS_IDL_FILES} ${_dependency_files}) foreach(dep ${target_dependencies}) if(NOT EXISTS "${dep}") From bc8644a9d4231b0c0f16511c2689d91eeb4a66e4 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 4 Mar 2019 13:38:27 -0800 Subject: [PATCH 20/20] reduce logic with all action related types being in a single file --- .../resource/msg__type_support_c.cpp.em | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) 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 index d730d89..c35e66b 100644 --- a/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em +++ b/rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em @@ -1,6 +1,9 @@ @# Included from rosidl_typesupport_fastrtps_c/resource/idl__type_support_c.cpp.em @{ from rosidl_cmake import convert_camel_case_to_lower_case_underscore +from rosidl_parser.definition import ACTION_FEEDBACK_SUFFIX +from rosidl_parser.definition import ACTION_GOAL_SUFFIX +from rosidl_parser.definition import ACTION_RESULT_SUFFIX from rosidl_parser.definition import Array from rosidl_parser.definition import BaseString from rosidl_parser.definition import BasicType @@ -80,18 +83,15 @@ for member in message.structure.members: keys.add('rosidl_generator_c/u16string.h') keys.add('rosidl_generator_c/u16string_functions.h') elif isinstance(type_, NamespacedType): - filename_prefix = convert_camel_case_to_lower_case_underscore(type_.name) - if filename_prefix.endswith('__request'): - filename_prefix = filename_prefix[:-9] - elif filename_prefix.endswith('__response'): - filename_prefix = filename_prefix[:-10] - if filename_prefix.endswith('__goal'): - filename_prefix = filename_prefix[:-6] - elif filename_prefix.endswith('__result'): - filename_prefix = filename_prefix[:-8] - elif filename_prefix.endswith('__feedback'): - filename_prefix = filename_prefix[:-10] - keys.add('/'.join(type_.namespaces + [filename_prefix]) + '__functions.h') + if ( + type_.name.endswith(ACTION_GOAL_SUFFIX) or + type_.name.endswith(ACTION_RESULT_SUFFIX) or + type_.name.endswith(ACTION_FEEDBACK_SUFFIX) + ): + typename = type_.name.rsplit('_', 1)[0] + else: + typename = type_.name + keys.add('/'.join(type_.namespaces + [convert_camel_case_to_lower_case_underscore(typename)]) + '__functions.h') for key in keys: if key not in includes: includes[key] = set([])