Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Type Adaptations #2285

Open
wants to merge 10 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
381 changes: 323 additions & 58 deletions rclcpp/include/rclcpp/any_service_callback.hpp

Large diffs are not rendered by default.

639 changes: 537 additions & 102 deletions rclcpp/include/rclcpp/client.hpp

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions rclcpp/include/rclcpp/get_service_type_support_handle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright 2023 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 RCLCPP__GET_SERVICE_TYPE_SUPPORT_HANDLE_HPP_
#define RCLCPP__GET_SERVICE_TYPE_SUPPORT_HANDLE_HPP_

#include <stdexcept>
#include <type_traits>

#include "rosidl_runtime_cpp/traits.hpp"
#include "rosidl_runtime_cpp/service_type_support_decl.hpp"
#include "rosidl_typesupport_cpp/service_type_support.hpp"

#include "rclcpp/type_adapter.hpp"
#include "type_adapter.hpp"

namespace rclcpp
{

#ifdef DOXYGEN_ONLY

/// Returns the service type support for the given `ServiceT` type.
/**
* \tparam ServiceT an actual ROS service type or an adapted type using `rclcpp::TypeAdapter`
*/
template<typename ServiceT>
constexpr const rosidl_service_type_support_t & get_service_type_support_handle();

#else

template<typename ServiceT>
constexpr
std::enable_if_t<
rosidl_generator_traits::is_service<ServiceT>::value,
const rosidl_service_type_support_t &
>
get_service_type_support_handle()
{
auto handle = rosidl_typesupport_cpp::get_service_type_support_handle<ServiceT>();
if (!handle) {
throw std::runtime_error("Type support handle unexpectedly nullptr");
}
return *handle;
}

/// Checking the TypeAdapter struct when using custom or ROS types.
template<typename AdaptedTypeStruct>
constexpr
std::enable_if_t<
!rosidl_generator_traits::is_service<AdaptedTypeStruct>::value &&
rclcpp::TypeAdapter<AdaptedTypeStruct>::is_specialized::value,
const rosidl_service_type_support_t &
>
get_service_type_support_handle()
{
using CustomType = typename TypeAdapter<AdaptedTypeStruct>::ros_message_type;
auto handle = rosidl_typesupport_cpp::get_service_type_support_handle<CustomType>();

if (!handle) {
throw std::runtime_error("Type support handle unexpectedly nullptr");
}
return *handle;
}

// This specialization is a pass through runtime check, which allows a better
// static_assert to catch this issue further down the line.
// This should never get to be called in practice, and is purely defensive.
template<typename AdaptedTypeStruct>
constexpr
typename std::enable_if_t<
!rosidl_generator_traits::is_service<AdaptedTypeStruct>::value &&
!TypeAdapter<AdaptedTypeStruct>::is_specialized::value,
const rosidl_service_type_support_t &
>
get_service_type_support_handle()
{
throw std::runtime_error(
"this specialization of rclcpp::get_service_type_support_handle() "
"should never be called");
}

#endif // DOXYGEN_ONLY

} // namespace rclcpp

#endif // RCLCPP__GET_SERVICE_TYPE_SUPPORT_HANDLE_HPP_
8 changes: 8 additions & 0 deletions rclcpp/include/rclcpp/is_ros_compatible_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ struct is_ros_compatible_type
rclcpp::TypeAdapter<T>::is_specialized::value;
};

template<typename T>
struct is_ros_compatible_service_type
{
static constexpr bool value =
rosidl_generator_traits::is_service<T>::value ||
rclcpp::TypeAdapter<T>::is_specialized::value;
};

} // namespace rclcpp

#endif // RCLCPP__IS_ROS_COMPATIBLE_TYPE_HPP_
Loading