Skip to content

Commit 6a18bbf

Browse files
authored
Generate typesupport getter declarations for actions, messages and services. (#778)
Signed-off-by: Stefan Fabian <[email protected]>
1 parent cf3b637 commit 6a18bbf

8 files changed

+262
-0
lines changed

rosidl_generator_cpp/cmake/rosidl_generator_cpp_generate_interfaces.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
2828
"${_output_path}/${_parent_folder}/detail/${_header_name}__builder.hpp"
2929
"${_output_path}/${_parent_folder}/detail/${_header_name}__struct.hpp"
3030
"${_output_path}/${_parent_folder}/detail/${_header_name}__traits.hpp"
31+
"${_output_path}/${_parent_folder}/detail/${_header_name}__type_support.hpp"
3132
)
3233
endforeach()
3334

@@ -89,6 +90,17 @@ add_custom_command(
8990
VERBATIM
9091
)
9192

93+
# generate header to switch between export and import for a specific package
94+
set(_visibility_control_file
95+
"${_output_path}/msg/rosidl_generator_cpp__visibility_control.hpp")
96+
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
97+
configure_file(
98+
"${rosidl_generator_cpp_TEMPLATE_DIR}/rosidl_generator_cpp__visibility_control.hpp.in"
99+
"${_visibility_control_file}"
100+
@ONLY
101+
)
102+
list(APPEND _generated_headers "${_visibility_control_file}")
103+
92104
# INTERFACE libraries can't have file-level dependencies in CMake,
93105
# so make a custom target depending on the generated files
94106
# TODO(sloretz) make this target name less generic than "__cpp" when other
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@# Included from rosidl_generator_cpp/resource/action__type_support.hpp.em
2+
@{header_file = 'rosidl_typesupport_cpp/action_type_support.hpp'}@
3+
@[if header_file in include_directives]@
4+
// already included above
5+
// @
6+
@[else]@
7+
@{include_directives.add(header_file)}@
8+
@[end if]@
9+
#include "@(header_file)"
10+
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif
15+
// Forward declare the get type support functions for this type.
16+
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
17+
const rosidl_action_type_support_t *
18+
ROSIDL_TYPESUPPORT_INTERFACE__ACTION_SYMBOL_NAME(
19+
rosidl_typesupport_cpp,
20+
@(',\n '.join(action.namespaced_type.namespaced_name()))
21+
)();
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
@{
27+
TEMPLATE(
28+
'msg__type_support.hpp.em',
29+
package_name=package_name, message=action.goal,
30+
include_directives=include_directives)
31+
}@
32+
33+
@{
34+
TEMPLATE(
35+
'msg__type_support.hpp.em',
36+
package_name=package_name, message=action.result,
37+
include_directives=include_directives)
38+
}@
39+
40+
@{
41+
TEMPLATE(
42+
'msg__type_support.hpp.em',
43+
package_name=package_name, message=action.feedback,
44+
include_directives=include_directives)
45+
}@
46+
47+
@{
48+
TEMPLATE(
49+
'srv__type_support.hpp.em',
50+
package_name=package_name, service=action.send_goal_service,
51+
include_directives=include_directives)
52+
}@
53+
54+
@{
55+
TEMPLATE(
56+
'srv__type_support.hpp.em',
57+
package_name=package_name, service=action.get_result_service,
58+
include_directives=include_directives)
59+
}@
60+
61+
@{
62+
TEMPLATE(
63+
'msg__type_support.hpp.em',
64+
package_name=package_name, message=action.feedback_message,
65+
include_directives=include_directives)
66+
}@

rosidl_generator_cpp/resource/idl.hpp.em

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ include_base = '/'.join(include_parts_detail)
2525
#include "@(include_base)__struct.hpp"
2626
#include "@(include_base)__builder.hpp"
2727
#include "@(include_base)__traits.hpp"
28+
#include "@(include_base)__type_support.hpp"
2829

2930
#endif // @(header_guard_variable)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// generated from rosidl_generator_cpp/resource/idl__type_support.hpp.em
2+
// with input from @(package_name):@(interface_path)
3+
// generated code does not contain a copyright notice
4+
@
5+
@#######################################################################
6+
@# EmPy template for generating <idl>__struct.h files
7+
@#
8+
@# Context:
9+
@# - package_name (string)
10+
@# - interface_path (Path relative to the directory named after the package)
11+
@# - content (IdlContent, list of elements, e.g. Messages or Services)
12+
@#######################################################################
13+
@{
14+
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
15+
include_parts = [package_name] + list(interface_path.parents[0].parts) + [
16+
'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)]
17+
header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \
18+
'__TYPE_SUPPORT_HPP_'
19+
20+
include_directives = set()
21+
}@
22+
23+
#ifndef @(header_guard_variable)
24+
#define @(header_guard_variable)
25+
26+
#include "rosidl_typesupport_interface/macros.h"
27+
28+
#include "@(package_name)/msg/rosidl_generator_cpp__visibility_control.hpp"
29+
30+
@#######################################################################
31+
@# Handle message
32+
@#######################################################################
33+
@{
34+
from rosidl_parser.definition import Message
35+
}@
36+
@[for message in content.get_elements_of_type(Message)]@
37+
@{
38+
TEMPLATE(
39+
'msg__type_support.hpp.em',
40+
package_name=package_name, message=message,
41+
include_directives=include_directives)
42+
}@
43+
44+
@[end for]@
45+
@
46+
@#######################################################################
47+
@# Handle service
48+
@#######################################################################
49+
@{
50+
from rosidl_parser.definition import Service
51+
}@
52+
@[for service in content.get_elements_of_type(Service)]@
53+
@{
54+
TEMPLATE(
55+
'srv__type_support.hpp.em',
56+
package_name=package_name, service=service,
57+
include_directives=include_directives)
58+
}@
59+
60+
@[end for]@
61+
@
62+
@#######################################################################
63+
@# Handle action
64+
@#######################################################################
65+
@{
66+
from rosidl_parser.definition import Action
67+
}@
68+
@[for action in content.get_elements_of_type(Action)]@
69+
@{
70+
TEMPLATE(
71+
'action__type_support.hpp.em',
72+
package_name=package_name, action=action,
73+
include_directives=include_directives)
74+
}@
75+
76+
@[end for]@
77+
#endif // @(header_guard_variable)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@# Included from rosidl_generator_cpp/resource/msg__type_support.hpp.em
2+
@{header_file = 'rosidl_typesupport_cpp/message_type_support.hpp'}@
3+
@[if header_file in include_directives]@
4+
// already included above
5+
// @
6+
@[else]@
7+
@{include_directives.add(header_file)}@
8+
@[end if]@
9+
#include "@(header_file)"
10+
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif
15+
// Forward declare the get type support functions for this type.
16+
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
17+
const rosidl_message_type_support_t *
18+
ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME(
19+
rosidl_typesupport_cpp,
20+
@(',\n '.join(message.structure.namespaced_type.namespaced_name()))
21+
)();
22+
#ifdef __cplusplus
23+
}
24+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// generated from rosidl_generator_cpp/resource/rosidl_generator_cpp__visibility_control.hpp.in
2+
// generated code does not contain a copyright notice
3+
4+
#ifndef @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
5+
#define @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
6+
7+
#ifdef __cplusplus
8+
extern "C"
9+
{
10+
#endif
11+
12+
// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
13+
// https://gcc.gnu.org/wiki/Visibility
14+
15+
#if defined _WIN32 || defined __CYGWIN__
16+
#ifdef __GNUC__
17+
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((dllexport))
18+
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@ __attribute__ ((dllimport))
19+
#else
20+
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __declspec(dllexport)
21+
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@ __declspec(dllimport)
22+
#endif
23+
#ifdef ROSIDL_GENERATOR_CPP_BUILDING_DLL_@PROJECT_NAME@
24+
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@
25+
#else
26+
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@
27+
#endif
28+
#else
29+
#define ROSIDL_GENERATOR_CPP_EXPORT_@PROJECT_NAME@ __attribute__ ((visibility("default")))
30+
#define ROSIDL_GENERATOR_CPP_IMPORT_@PROJECT_NAME@
31+
#if __GNUC__ >= 4
32+
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@ __attribute__ ((visibility("default")))
33+
#else
34+
#define ROSIDL_GENERATOR_CPP_PUBLIC_@PROJECT_NAME@
35+
#endif
36+
#endif
37+
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif // @PROJECT_NAME_UPPER@__MSG__ROSIDL_GENERATOR_CPP__VISIBILITY_CONTROL_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@# Included from rosidl_generator_cpp/resource/srv__type_support.hpp.em
2+
@{header_file = 'rosidl_typesupport_cpp/service_type_support.hpp'}@
3+
@[if header_file in include_directives]@
4+
// already included above
5+
// @
6+
@[else]@
7+
@{include_directives.add(header_file)}@
8+
@[end if]@
9+
#include "@(header_file)"
10+
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif
15+
// Forward declare the get type support functions for this type.
16+
ROSIDL_GENERATOR_CPP_PUBLIC_@(package_name)
17+
const rosidl_service_type_support_t *
18+
ROSIDL_TYPESUPPORT_INTERFACE__SERVICE_SYMBOL_NAME(
19+
rosidl_typesupport_cpp,
20+
@(',\n '.join(service.namespaced_type.namespaced_name()))
21+
)();
22+
#ifdef __cplusplus
23+
}
24+
#endif
25+
26+
@{
27+
TEMPLATE(
28+
'msg__type_support.hpp.em',
29+
package_name=package_name, message=service.request_message,
30+
include_directives=include_directives)
31+
}@
32+
33+
@{
34+
TEMPLATE(
35+
'msg__type_support.hpp.em',
36+
package_name=package_name, message=service.response_message,
37+
include_directives=include_directives)
38+
}@
39+

rosidl_generator_cpp/rosidl_generator_cpp/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def generate_cpp(generator_arguments_file):
3434
'idl__builder.hpp.em': 'detail/%s__builder.hpp',
3535
'idl__struct.hpp.em': 'detail/%s__struct.hpp',
3636
'idl__traits.hpp.em': 'detail/%s__traits.hpp',
37+
'idl__type_support.hpp.em': 'detail/%s__type_support.hpp',
3738
}
3839
return generate_files(
3940
generator_arguments_file, mapping,

0 commit comments

Comments
 (0)