Skip to content

Commit 885fa3f

Browse files
committed
Compile generated action-related services (#140)
* Remove redundant code generation The request and response messages are already generated as part of the srv template. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Strip action service suffixes from C include prefix The generated C headers for actions are included in a single header named after the action. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Generate Java code for SendGoal and GetResult service definitions Though not strictly necessary, it is nice to have definitions for these action-specific services for the purpose of writing unit tests. Signed-off-by: Jacob Perron <jacob@openrobotics.org> * Compile generated service definitions for actions Previously, though we were generated service definitions for actions we were not compiling them. Signed-off-by: Jacob Perron <jacob@openrobotics.org>
1 parent b3a25b1 commit 885fa3f

File tree

5 files changed

+54
-18
lines changed

5 files changed

+54
-18
lines changed

rosidl_generator_java/cmake/rosidl_generator_java_generate_interfaces.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
8181
"${_output_path}/${_parent_folder}/${_idl_name}_Goal.java"
8282
"${_output_path}/${_parent_folder}/${_idl_name}_Result.java"
8383
"${_output_path}/${_parent_folder}/${_idl_name}_Feedback.java"
84+
"${_output_path}/${_parent_folder}/${_idl_name}_SendGoal.java"
85+
"${_output_path}/${_parent_folder}/${_idl_name}_SendGoal_Request.java"
86+
"${_output_path}/${_parent_folder}/${_idl_name}_SendGoal_Response.java"
87+
"${_output_path}/${_parent_folder}/${_idl_name}_GetResult.java"
88+
"${_output_path}/${_parent_folder}/${_idl_name}_GetResult_Request.java"
89+
"${_output_path}/${_parent_folder}/${_idl_name}_GetResult_Response.java"
8490
)
8591
foreach(_typesupport_impl ${_typesupport_impls})
8692
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_Goal.ep.${_typesupport_impl}.cpp")
8793
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_Result.ep.${_typesupport_impl}.cpp")
8894
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_Feedback.ep.${_typesupport_impl}.cpp")
95+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_SendGoal.ep.${_typesupport_impl}.cpp")
96+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_SendGoal_Request.ep.${_typesupport_impl}.cpp")
97+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_SendGoal_Response.ep.${_typesupport_impl}.cpp")
98+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_GetResult.ep.${_typesupport_impl}.cpp")
99+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_GetResult_Request.ep.${_typesupport_impl}.cpp")
100+
list(APPEND _generated_extension_${_typesupport_impl}_files "${_output_path}/${_parent_folder}/${_idl_name}_GetResult_Response.ep.${_typesupport_impl}.cpp")
89101
endforeach()
90102
endif()
91103

rosidl_generator_java/resource/action.cpp.em

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,8 @@ expand_template(
5858
data,
5959
output_file)
6060

61-
# Generate SendGoal message type
62-
data.update({'msg': action.send_goal_service.request_message})
63-
output_file = os.path.join(output_dir, *namespaces[1:], '{0}.ep.{1}.cpp'.format(send_goal_type_name, typesupport_impl))
64-
expand_template(
65-
'msg.cpp.em',
66-
data,
67-
output_file)
68-
69-
# Generate GetResult message type
70-
data.update({'msg': action.get_result_service.request_message})
71-
output_file = os.path.join(output_dir, *namespaces[1:], '{0}.ep.{1}.cpp'.format(send_goal_type_name, typesupport_impl))
72-
expand_template(
73-
'msg.cpp.em',
74-
data,
75-
output_file)
76-
7761
data = {
7862
'package_name': package_name,
79-
'interface_path': interface_path,
8063
'output_dir': output_dir,
8164
'template_basepath': template_basepath,
8265
'typesupport_impl': typesupport_impl,

rosidl_generator_java/resource/action.java.em

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type_name = action.namespaced_type.name
1313
goal_type_name = action.goal.structure.namespaced_type.name
1414
result_type_name = action.result.structure.namespaced_type.name
1515
feedback_type_name = action.feedback.structure.namespaced_type.name
16+
send_goal_type_name = action.send_goal_service.namespaced_type.name
17+
get_result_type_name = action.get_result_service.namespaced_type.name
1618

1719
data = {
1820
'package_name': package_name,
@@ -44,6 +46,22 @@ expand_template(
4446
output_file,
4547
template_basepath=template_basepath)
4648

49+
data.update({'service': action.send_goal_service})
50+
output_file = os.path.join(output_dir, *namespaces[1:], send_goal_type_name + '.java')
51+
expand_template(
52+
'srv.java.em',
53+
data,
54+
output_file,
55+
template_basepath=template_basepath)
56+
57+
data.update({'service': action.get_result_service})
58+
output_file = os.path.join(output_dir, *namespaces[1:], get_result_type_name + '.java')
59+
expand_template(
60+
'srv.java.em',
61+
data,
62+
output_file,
63+
template_basepath=template_basepath)
64+
4765
action_imports = [
4866
'org.ros2.rcljava.common.JNIUtils',
4967
'org.ros2.rcljava.interfaces.ActionDefinition',

rosidl_generator_java/resource/msg.cpp.em

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ for member in message.structure.members:
6262
namespaced_types.add(get_jni_type(type_))
6363
include_prefix = idl_structure_type_to_c_include_prefix(type_)
6464
# TODO(jacobperron): Remove this logic after https://github.com/ros2/rosidl/pull/432 (Foxy)
65+
# and https://github.com/ros2/rosidl/pull/538
6566
# Strip off any service or action suffix
6667
# There are several types that actions and services are composed of, but they are included
6768
# a common header that is based on the action or service name
@@ -76,10 +77,15 @@ for member in message.structure.members:
7677
include_prefix = include_prefix[:-8]
7778
elif include_prefix.endswith('__feedback'):
7879
include_prefix = include_prefix[:-10]
80+
elif include_prefix.endswith('__send_goal'):
81+
include_prefix = include_prefix[:-11]
82+
elif include_prefix.endswith('__get_result'):
83+
include_prefix = include_prefix[:-12]
7984
member_includes.add(include_prefix + '.h')
8085
}@
8186
@{
8287
# TODO(jacobperron): Remove this logic after https://github.com/ros2/rosidl/pull/432 (Foxy)
88+
# and https://github.com/ros2/rosidl/pull/538
8389
message_c_include_prefix = idl_structure_type_to_c_include_prefix(message.structure.namespaced_type)
8490
# Strip off any service or action suffix
8591
if message_c_include_prefix.endswith('__request'):
@@ -92,6 +98,10 @@ elif message_c_include_prefix.endswith('__result'):
9298
message_c_include_prefix = message_c_include_prefix[:-8]
9399
elif message_c_include_prefix.endswith('__feedback'):
94100
message_c_include_prefix = message_c_include_prefix[:-10]
101+
elif message_c_include_prefix.endswith('__send_goal'):
102+
message_c_include_prefix = message_c_include_prefix[:-11]
103+
elif message_c_include_prefix.endswith('__get_result'):
104+
message_c_include_prefix = message_c_include_prefix[:-12]
95105
}@
96106

97107
#include <jni.h>

rosidl_generator_java/resource/srv.cpp.em

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ expand_template(
4040

4141
#include "rosidl_generator_c/service_type_support_struct.h"
4242

43-
#include "@(idl_structure_type_to_c_include_prefix(service.namespaced_type)).h"
43+
@{
44+
include_prefix = idl_structure_type_to_c_include_prefix(service.namespaced_type)
45+
# TODO(jacobperron): Remove this logic after https://github.com/ros2/rosidl/pull/538
46+
# Strip off any service suffix
47+
# There are a couple service types that actions are composed of, but they are included
48+
# a common header that is based on the action name
49+
# ie. there are not separate headers for each type
50+
if include_prefix.endswith('__send_goal'):
51+
include_prefix = include_prefix[:-11]
52+
elif include_prefix.endswith('__get_result'):
53+
include_prefix = include_prefix[:-12]
54+
}@
55+
56+
#include "@(include_prefix).h"
4457

4558
// Ensure that a jlong is big enough to store raw pointers
4659
static_assert(sizeof(jlong) >= sizeof(std::intptr_t), "jlong must be able to store pointers");

0 commit comments

Comments
 (0)