Skip to content

Generate C++ typesupport for actions #303

@sloretz

Description

@sloretz

Feature request

There should be a c++ file importable by #include <package_name/action/actionname.hpp> which contains everything needed to use an action type in c++.

Feature description

It needs to be possible to generate a header file that describes an action, and has all the information needed to create topics and services. Since services already are an example of a typesupport that needs to include messages, actions should use the same strategy.

Implementation considerations

Output files

Services have a top level header which includes two files: traits and struct. Traits indicates whether either the request or response is bounded or unbounded in size. I don't think there needs to be a traits file for the whole action.

#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name))__traits.hpp"
#include "@(spec.pkg_name)/srv/@(get_header_filename_from_msg_name(spec.srv_name))__struct.hpp"

The struct file includes the request and response message, as well as defines a struct with a using directive that indicates which message is which

struct @(spec.srv_name)
{
using Request = @(spec.pkg_name)::srv::@(spec.srv_name)_Request;
using Response = @(spec.pkg_name)::srv::@(spec.srv_name)_Response;
};

The action struct template could look something like this

#include "@(spec.pkg_name)/action/@(get_header_filename_from_msg_name(spec.action_name))__sendgoal.hpp"
#include "@(spec.pkg_name)/action/@(get_header_filename_from_msg_name(spec.action_name))__get_result.hpp"
#include "@(spec.pkg_name)/action/@(get_header_filename_from_msg_name(spec.action_name))__feedback.hpp"
// Convenience include for common service and message definition
#include <rcl_interfaces/srv/cancel_action.hpp>
#include <rcl_interfaces/srv/goal_status.hpp>

 struct @(spec.action_name) 
 { 
   using SendGoalService = @(spec.pkg_name)::action::@(spec.action_name)_SendGoal; 
   using GetResultService = @(spec.pkg_name)::action::@(spec.action_name)_GetResult; 
   using FeedbacMessage = @(spec.pkg_name)::action::@(spec.action_name)_Feedback; 
};
CMake targets

The CMake target needs to be aware of the generated output files so that it can rebuild stuff downstream when they change. Awareness of the files generated by .action needs to be included here

if(_parent_folder STREQUAL "msg")
list(APPEND _generated_msg_files
"${_output_path}/${_parent_folder}/${_header_name}.hpp"
"${_output_path}/${_parent_folder}/${_header_name}__struct.hpp"
"${_output_path}/${_parent_folder}/${_header_name}__traits.hpp"
)
elseif(_parent_folder STREQUAL "srv")
list(APPEND _generated_srv_files
"${_output_path}/${_parent_folder}/${_header_name}.hpp"
"${_output_path}/${_parent_folder}/${_header_name}__struct.hpp"
"${_output_path}/${_parent_folder}/${_header_name}__traits.hpp"
)

connects to ros2/ros2#583

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions