Skip to content

Allow generating messages and services in the module action #13

@sloretz

Description

@sloretz

Feature request

It must be possible to generate python classes for messages and services in a module action.

Feature description

Multiple services and messages need to be generated for an action. The python objects for these messages and services should be generated in an action module so they don't conflict with other messages and services.

Implementation considerations

Service request and response imports

The python type for a service allows importing python messages Request and Response in the module srv.

for field_name in [srv_name + '__request', srv_name + '__response']:
print('%sfrom %s.srv import %s' % (' ' * 4 * 3, package_name, field_name))
print('%sif %s.Metaclass._TYPE_SUPPORT is None:' % (' ' * 4 * 3, field_name))
print('%s%s.Metaclass.__import_type_support__()' % (' ' * 4 * 4, field_name))

Since services and messages for actions will be generated in the action module, the python type for a service should be able to include the Request and Response python types from action instead.

CMake generated files

CMake needs to be aware of generated files. Currently it's aware of files in the folders msg and srv. The folder action should be added to this list.

if(_parent_folder STREQUAL "msg")
list(APPEND _generated_msg_py_files
"${_output_path}/${_parent_folder}/_${_module_name}.py"
)
list(APPEND _generated_msg_c_files
"${_output_path}/${_parent_folder}/_${_module_name}_s.c"
)
elseif(_parent_folder STREQUAL "srv")
if("_${_module_name}_s.c" MATCHES "(.*)__response(.*)" OR "_${_module_name}_s.c" MATCHES "(.*)__request(.*)")
list(APPEND _generated_srv_c_files
"${_output_path}/${_parent_folder}/_${_module_name}_s.c"
)
endif()
list(APPEND _generated_srv_py_files
"${_output_path}/${_parent_folder}/_${_module_name}.py"
)

Importing C typesupport

Since python representations make use of the C ones, the included C files will need to be aware that the C typesupport includes also have action in them. This should come for free with the subfolder variable

#include <@(spec.base_type.pkg_name)/@(subfolder)/@(module_name)__struct.h>
#include <@(spec.base_type.pkg_name)/@(subfolder)/@(module_name)__functions.h>

connects to ros2/rosidl#301

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions