Skip to content

Commit 38f2d1f

Browse files
committed
Added documentation for code generation
Signed-off-by: Gonzalo de Pedro <[email protected]>
1 parent 6d54c14 commit 38f2d1f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

source/Concepts/Advanced/About-Internal-Interfaces.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,58 @@ These are mainly used for error handling, commandline argument parsing, and logg
191191
The ``rcutils`` |API| and implementation are located in the `ros2/rcutils <https://github.com/ros2/rcutils>`_ repository on |GitHub|_ which contains the interface as C headers.
192192

193193
For a complete definition of the ``rcutils`` |API|, see `the rcutils docs <https://docs.ros.org/en/{DISTRO}/p/rcutils/>`_.
194+
195+
Automatic code generation using template files
196+
==============================================
197+
198+
As mentioned above, in order to deal with different DDS implementations, code has to be generated. Code generation is handled by a clever usage
199+
of CMake and Ament. To simplify the explanation of this mechanism let's separate ROS2 projects that generate or need code to be generated in two types.
200+
201+
- ``Generator`` projects, which are the ones that have the templates and logic to generate code.
202+
- ``Client`` projects, which are the ones that need code to be generated, they have the parameters to generate code.
203+
204+
For instance, typesupport packages that generate code for a particular dds implementation are *Generator* packages, same case that rosidl which
205+
generates code from ros idl (.msg, .action, etc) files.
206+
207+
*Client* projects are typically projects that define messages, actions and services. Which have .msg files with rosidl defined on them which are
208+
used by *Generator* projects to create code. A package that calls rosidl_generate_interfaces CMake macro is a *Client* project.
209+
210+
Code generation workflow
211+
------------------------
212+
213+
On workspace build, the *generator* packages, registers a portion of CMake code as an ament_extension under 'rosidl_generate_idl_interfaces' key.
214+
215+
Hook registration on CodeGenerator project build
216+
217+
.. mermaid::
218+
219+
sequenceDiagram
220+
participant CodeGenerator_cmake
221+
participant ament_package
222+
participant ament_register_extension
223+
CodeGenerator_cmake->>ament_package: CONFIG_EXTRAS
224+
ament_package->>ament_register_extension: rosidl_generate_idl_interfaces, cmake_code_hook
225+
Note right of ament_package: Execute a cmake.in template with variables and a cmake code hook.
226+
227+
228+
When the *client* package, during its build process, calls the 'rosidl_generate_interfaces' macro, the extensions that were registered for each of the
229+
*generator* packages, get called. Said extensions have the code to generate sources for each of the IDL interfaces. Then, code is added to an artifact
230+
(a library) and dependiences are exported for code to be build and installed.
231+
232+
.. mermaid::
233+
234+
sequenceDiagram
235+
participant project_with_rosidl_files
236+
participant rosidl_generate_interfaces
237+
participant rosidl_generate_idl_interfaces_HOOK
238+
participant generate_arguments_file
239+
participant rosidl_generator
240+
project_with_rosidl_files->>rosidl_generate_interfaces: path_to_idl_files
241+
loop ForEach Hook
242+
rosidl_generate_interfaces->>rosidl_generate_idl_interfaces_HOOK: path_to_idl_files, parameters
243+
rosidl_generate_idl_interfaces_HOOK->>generate_arguments_file: template_parameters
244+
activate generate_arguments_file
245+
generate_arguments_file->>rosidl_generate_idl_interfaces_HOOK: arguments_file
246+
deactivate generate_arguments_file
247+
rosidl_generate_idl_interfaces_HOOK->>rosidl_generator: arguments_file
248+
end

0 commit comments

Comments
 (0)