Skip to content

Commit

Permalink
Add action typesupport helper
Browse files Browse the repository at this point in the history
Signed-off-by: Barry Xu <[email protected]>
  • Loading branch information
Barry-Xu-2018 committed May 16, 2024
1 parent 343b29b commit 348e22a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
20 changes: 19 additions & 1 deletion rclcpp/include/rclcpp/typesupport_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rcpputils/shared_library.hpp"
#include "rosidl_runtime_cpp/message_type_support_decl.hpp"
#include "rosidl_runtime_cpp/service_type_support_decl.hpp"
#include "rosidl_runtime_cpp/action_type_support_decl.hpp"

#include "rclcpp/visibility_control.hpp"

Expand Down Expand Up @@ -76,7 +77,7 @@ get_message_typesupport_handle(

/// Extract the service type support handle from the library.
/**
* The library needs to match the topic type. The shared library must stay loaded for the lifetime of the result.
* The library needs to match the service type. The shared library must stay loaded for the lifetime of the result.
*
* \param[in] type The service type, e.g. "std_srvs/srv/Empty"
* \param[in] typesupport_identifier Type support identifier, typically "rosidl_typesupport_cpp"
Expand All @@ -91,6 +92,23 @@ get_service_typesupport_handle(
const std::string & typesupport_identifier,
rcpputils::SharedLibrary & library);

/// Extract the action type support handle from the library.
/**
* The library needs to match the action type. The shared library must stay loaded for the lifetime of the result.
*
* \param[in] type The action type, e.g. "action_tutorials_interfaces/action/Fibonacci"
* \param[in] typesupport_identifier Type support identifier, typically "rosidl_typesupport_cpp"
* \param[in] library The shared type support library
* \throws std::runtime_error if the symbol of type not found in the library.
* \return A action type support handle
*/
RCLCPP_PUBLIC
const rosidl_action_type_support_t *
get_action_typesupport_handle(
const std::string & type,
const std::string & typesupport_identifier,
rcpputils::SharedLibrary & library);

} // namespace rclcpp

#endif // RCLCPP__TYPESUPPORT_HELPERS_HPP_
15 changes: 15 additions & 0 deletions rclcpp/src/rclcpp/typesupport_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,19 @@ const rosidl_service_type_support_t * get_service_typesupport_handle(
));
}

const rosidl_action_type_support_t * get_action_typesupport_handle(
const std::string & type,
const std::string & typesupport_identifier,
rcpputils::SharedLibrary & library)
{
static const std::string typesupport_name = "action";
static const std::string symbol_part_name = "__get_action_type_support_handle__";
static const std::string middle_module_additional = "action";

return static_cast<const rosidl_action_type_support_t *>(get_typesupport_handle_impl(
type, typesupport_identifier, typesupport_name, symbol_part_name,
middle_module_additional, library
));
}

} // namespace rclcpp

0 comments on commit 348e22a

Please sign in to comment.