diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 0ab7b35b..e536e517 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -20,6 +20,7 @@ endif() find_package(ament_cmake_ros REQUIRED) find_package(rcutils REQUIRED) +find_package(rosidl_dynamic_typesupport REQUIRED) find_package(rosidl_runtime_c REQUIRED) include(cmake/configure_rmw_library.cmake) @@ -28,6 +29,7 @@ set(rmw_sources "src/allocators.c" "src/convert_rcutils_ret_to_rmw_ret.c" "src/discovery_options.c" + "src/dynamic_message_type_support.c" "src/event.c" "src/init.c" "src/init_options.c" @@ -54,6 +56,9 @@ add_library(${PROJECT_NAME} ${rmw_sources}) target_include_directories(${PROJECT_NAME} PUBLIC "$" "$") +target_link_libraries(${PROJECT_NAME} + rosidl_dynamic_typesupport::rosidl_dynamic_typesupport +) if(BUILD_TESTING AND NOT RCUTILS_DISABLE_FAULT_INJECTION) target_compile_definitions(${PROJECT_NAME} PUBLIC RCUTILS_ENABLE_FAULT_INJECTION) @@ -67,6 +72,7 @@ configure_rmw_library(${PROJECT_NAME} LANGUAGE "C") ament_export_dependencies( rcutils + rosidl_dynamic_typesupport rosidl_runtime_c ) diff --git a/rmw/include/rmw/dynamic_message_type_support.h b/rmw/include/rmw/dynamic_message_type_support.h new file mode 100644 index 00000000..64c58d28 --- /dev/null +++ b/rmw/include/rmw/dynamic_message_type_support.h @@ -0,0 +1,87 @@ +// Copyright 2022 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RMW__DYNAMIC_MESSAGE_TYPE_SUPPORT_H_ +#define RMW__DYNAMIC_MESSAGE_TYPE_SUPPORT_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include +#include +#include + +#include +#include +#include + +#include "rmw/features.h" +#include "rmw/serialized_message.h" +#include "rmw/visibility_control.h" + +/// Interfaces for runtime interface reflection + +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_take_dynamic_message( + const rmw_subscription_t * subscription, + rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message, + bool * taken, + rmw_subscription_allocation_t * allocation); + +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_take_dynamic_message_with_info( + const rmw_subscription_t * subscription, + rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message, + bool * taken, + rmw_message_info_t * message_info, + rmw_subscription_allocation_t * allocation); + +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_get_serialization_support( + const char * serialization_lib_name, + rosidl_dynamic_typesupport_serialization_support_t ** serialization_support); // OUT + +// TODO(methylDragon): Nice to have only +// RMW_PUBLIC +// RMW_WARN_UNUSED +// rmw_ret_t +// rmw_get_dynamic_type_from_middleware( +// const rmw_node_t * node, +// const char * topic_name, +// const rosidl_message_type_support_t type_support, +// rosidl_dynamic_typesupport_dynamic_type_t * dynamic_message_type); +// +// RMW_PUBLIC +// RMW_WARN_UNUSED +// rmw_ret_t +// rmw_get_dynamic_data_from_middleware( +// const rmw_node_t * node, +// const char * topic_name, +// const rosidl_message_type_support_t type_support, +// rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message); + +#ifdef __cplusplus +} +#endif + +#endif // RMW__DYNAMIC_MESSAGE_TYPE_SUPPORT_H_ diff --git a/rmw/include/rmw/features.h b/rmw/include/rmw/features.h index 367b586e..18ef2fb6 100644 --- a/rmw/include/rmw/features.h +++ b/rmw/include/rmw/features.h @@ -46,6 +46,11 @@ typedef enum RMW_PUBLIC_TYPE rmw_feature_e /// `rmw_message_info_t.reception_sequence_number` is filled correctly /// by the rmw implementation. RMW_FEATURE_MESSAGE_INFO_RECEPTION_SEQUENCE_NUMBER = 1, + /// deferred description dynamic type rosidl_message_type_support_t structs are allowed, and the + /// middleware MUST populate them on type discovery + RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY = 2, + /// dynamic type subscriptions will use take_dynamic_message_with_info() + RMW_MIDDLEWARE_CAN_TAKE_DYNAMIC_MESSAGE = 3, } rmw_feature_t; /// Query if a feature is supported by the rmw implementation. diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index d9a5e5d9..164f47dc 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -106,6 +106,7 @@ extern "C" #include "rmw/message_sequence.h" #include "rmw/publisher_options.h" #include "rmw/qos_profiles.h" +#include "rmw/dynamic_message_type_support.h" #include "rmw/subscription_options.h" #include "rmw/types.h" #include "rmw/visibility_control.h" diff --git a/rmw/package.xml b/rmw/package.xml index d5aa2838..3bd0ec8d 100644 --- a/rmw/package.xml +++ b/rmw/package.xml @@ -19,10 +19,12 @@ rcutils rosidl_runtime_c + rosidl_dynamic_typesupport rcutils rosidl_runtime_c + rosidl_dynamic_typesupport ament_cmake_gmock ament_lint_auto