Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate typesupport declarations for actions, messages and services #703

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
"${_output_path}/${_parent_folder}/detail/${_header_name}__builder.hpp"
"${_output_path}/${_parent_folder}/detail/${_header_name}__struct.hpp"
"${_output_path}/${_parent_folder}/detail/${_header_name}__traits.hpp"
"${_output_path}/${_parent_folder}/detail/${_header_name}__type_support.hpp"
)
endforeach()

Expand All @@ -48,16 +49,20 @@ set(target_dependencies
"${rosidl_generator_cpp_TEMPLATE_DIR}/action__builder.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/action__struct.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/action__traits.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/action__type_support.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/idl.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/idl__builder.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/idl__struct.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/idl__traits.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/idl__type_support.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/msg__builder.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/msg__struct.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/msg__traits.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/msg__type_support.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/srv__builder.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/srv__struct.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/srv__traits.hpp.em"
"${rosidl_generator_cpp_TEMPLATE_DIR}/srv__type_support.hpp.em"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files})
foreach(dep ${target_dependencies})
Expand Down Expand Up @@ -90,6 +95,18 @@ add_custom_command(
VERBATIM
)

# generate header to switch between export and import for a specific package
set(_visibility_control_file
"${_output_path}/msg/rosidl_generator_cpp__visibility_control.hpp")
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
configure_file(
"${rosidl_generator_cpp_TEMPLATE_DIR}/rosidl_generator_cpp__visibility_control.hpp.in"
"${_visibility_control_file}"
@ONLY
)
list(APPEND _generated_msg_headers "${_visibility_control_file}")
StefanFabian marked this conversation as resolved.
Show resolved Hide resolved


# INTERFACE libraries can't have file-level dependencies in CMake,
# so make a custom target depending on the generated files
# TODO(sloretz) make this target name less generic than "__cpp" when other
Expand Down
66 changes: 66 additions & 0 deletions rosidl_generator_cpp/resource/action__type_support.hpp.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@# Included from rosidl_generator_cpp/resource/action__type_support.hpp.em
@{header_file = 'rosidl_typesupport_cpp/action_type_support.hpp'}@
@[if header_file in include_directives]@
// already included above
// @
@[else]@
@{include_directives.add(header_file)}@
@[end if]@
#include "@(header_file)"

#ifdef __cplusplus
extern "C"
{
#endif
// Forward declare the get type support functions for this type.
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
const rosidl_action_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__ACTION_SYMBOL_NAME(
rosidl_typesupport_cpp,
@(',\n '.join(action.namespaced_type.namespaced_name()))
)();
#ifdef __cplusplus
}
#endif

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=action.goal,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=action.result,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=action.feedback,
include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__type_support.hpp.em',
package_name=package_name, service=action.send_goal_service,
include_directives=include_directives)
}@

@{
TEMPLATE(
'srv__type_support.hpp.em',
package_name=package_name, service=action.get_result_service,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=action.feedback_message,
include_directives=include_directives)
}@
1 change: 1 addition & 0 deletions rosidl_generator_cpp/resource/idl.hpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ include_base = '/'.join(include_parts_detail)
#include "@(include_base)__struct.hpp"
#include "@(include_base)__builder.hpp"
#include "@(include_base)__traits.hpp"
#include "@(include_base)__type_support.hpp"

#endif // @(header_guard_variable)
77 changes: 77 additions & 0 deletions rosidl_generator_cpp/resource/idl__type_support.hpp.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// generated from rosidl_generator_cpp/resource/idl__type_support.hpp.em
// with input from @(package_name):@(interface_path)
// generated code does not contain a copyright notice
@
@#######################################################################
@# EmPy template for generating <idl>__struct.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)
@#######################################################################
@{
from rosidl_pycommon import convert_camel_case_to_lower_case_underscore
include_parts = [package_name] + list(interface_path.parents[0].parts) + [
'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)]
header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \
'__TYPE_SUPPORT_HPP_'

include_directives = set()
}@

#ifndef @(header_guard_variable)
#define @(header_guard_variable)

#include "rosidl_typesupport_interface/macros.h"

#include "@(package_name)/msg/rosidl_generator_cpp__visibility_control.hpp"

@#######################################################################
@# Handle message
@#######################################################################
@{
from rosidl_parser.definition import Message
}@
@[for message in content.get_elements_of_type(Message)]@
@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, 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.hpp.em',
package_name=package_name, 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(
'action__type_support.hpp.em',
package_name=package_name, action=action,
include_directives=include_directives)
}@

@[end for]@
#endif // @(header_guard_variable)
24 changes: 24 additions & 0 deletions rosidl_generator_cpp/resource/msg__type_support.hpp.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@# Included from rosidl_generator_cpp/resource/msg__type_support.hpp.em
@{header_file = 'rosidl_typesupport_cpp/message_type_support.hpp'}@
@[if header_file in include_directives]@
// already included above
// @
@[else]@
@{include_directives.add(header_file)}@
@[end if]@
#include "@(header_file)"

#ifdef __cplusplus
extern "C"
{
#endif
// Forward declare the get type support functions for this type.
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
const rosidl_message_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
rosidl_typesupport_cpp,
@(',\n '.join(message.structure.namespaced_type.namespaced_name()))
)();
#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// generated from rosidl_generator_cpp/resource/rosidl_generator_cpp__visibility_control.hpp.in
// generated code does not contain a copyright notice

#ifndef @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
#define @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_

#ifdef __cplusplus
extern "C"
{
#endif

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((dllexport))
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@ __attribute__ ((dllimport))
#else
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __declspec(dllexport)
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@ __declspec(dllimport)
#endif
#ifdef ROSIDL_GENERATOR_CPP_BUILDING_DLL_@PROJECT_NAME@
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@
#else
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@
#endif
#else
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((visibility("default")))
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@
#if __GNUC__ >= 4
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ __attribute__ ((visibility("default")))
#else
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@
#endif
#endif

#ifdef __cplusplus
}
#endif

#endif // @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
39 changes: 39 additions & 0 deletions rosidl_generator_cpp/resource/srv__type_support.hpp.em
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@# Included from rosidl_generator_cpp/resource/srv__type_support.hpp.em
@{header_file = 'rosidl_typesupport_cpp/service_type_support.hpp'}@
@[if header_file in include_directives]@
// already included above
// @
@[else]@
@{include_directives.add(header_file)}@
@[end if]@
#include "@(header_file)"

#ifdef __cplusplus
extern "C"
{
#endif
// Forward declare the get type support functions for this type.
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
const rosidl_service_type_support_t *
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
rosidl_typesupport_cpp,
@(',\n '.join(service.namespaced_type.namespaced_name()))
)();
#ifdef __cplusplus
}
#endif

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=service.request_message,
include_directives=include_directives)
}@

@{
TEMPLATE(
'msg__type_support.hpp.em',
package_name=package_name, message=service.response_message,
include_directives=include_directives)
}@

1 change: 1 addition & 0 deletions rosidl_generator_cpp/rosidl_generator_cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def generate_cpp(generator_arguments_file):
'idl__builder.hpp.em': 'detail/%s__builder.hpp',
'idl__struct.hpp.em': 'detail/%s__struct.hpp',
'idl__traits.hpp.em': 'detail/%s__traits.hpp',
'idl__type_support.hpp.em': 'detail/%s__type_support.hpp',
}
return generate_files(
generator_arguments_file, mapping,
Expand Down