-
Notifications
You must be signed in to change notification settings - Fork 57
Description
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.
rosidl_python/rosidl_generator_py/resource/_srv.py.em
Lines 37 to 40 in deab237
| 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.
rosidl_python/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake
Lines 52 to 67 in deab237
| 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
rosidl_python/rosidl_generator_py/resource/_msg_support.c.em
Lines 20 to 21 in deab237
| #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