Skip to content

Commit

Permalink
Migrate to rosidl_dynamic_typesupport and update field IDs
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <methylDragon@gmail.com>
  • Loading branch information
methylDragon committed Feb 28, 2023
1 parent b887765 commit 51423ad
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 28 deletions.
8 changes: 4 additions & 4 deletions rcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ find_package(service_msgs REQUIRED)
find_package(tracetools REQUIRED)

# TODO(methylDragon): TEMPORARY! REMOVE EVENTUALLY WHEN WE HAVE A TYPE DESCRIPTION MESSAGE IN RMW
find_package(serialization_support_lib REQUIRED)
find_package(rosidl_dynamic_typesupport REQUIRED)

include(cmake/rcl_set_symbol_visibility_hidden.cmake)
include(cmake/get_default_rcl_logging_implementation.cmake)
Expand All @@ -37,7 +37,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

set(${PROJECT_NAME}_sources
src/rcl/rcl_typesupport_runtime_type_introspection_c/message_introspection.c
src/rcl/rcl_dynamic_typesupport_c/message_introspection.c

src/rcl/arguments.c
src/rcl/client.c
Expand Down Expand Up @@ -82,7 +82,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC

# TODO(methylDragon): THIS TARGET_LINK_LIBRARIES IS TEMPORARY! REMOVE EVENTUALLY
target_link_libraries(${PROJECT_NAME}
serialization_support_lib::serialization_support_lib # TODO(methylDragon): TEMPORARY! REMOVE EVENTUALLY
rosidl_dynamic_typesupport::rosidl_dynamic_typesupport # TODO(methylDragon): TEMPORARY! REMOVE EVENTUALLY
)
# specific order: dependents before dependencies
ament_target_dependencies(${PROJECT_NAME}
Expand Down Expand Up @@ -127,7 +127,7 @@ ament_export_targets(${PROJECT_NAME})

# specific order: dependents before dependencies
ament_export_dependencies(ament_cmake)
ament_export_dependencies(serialization_support_lib) # TODO(methylDragon): TEMPORARY! REMOVE EVENTUALLY
ament_export_dependencies(rosidl_dynamic_typesupport) # TODO(methylDragon): TEMPORARY! REMOVE EVENTUALLY
ament_export_dependencies(rcl_interfaces)
ament_export_dependencies(rcl_logging_interface)
ament_export_dependencies(rcl_yaml_param_parser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__IDENTIFIER_H_
#define RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__IDENTIFIER_H_
#ifndef RCL_DYNAMIC_TYPESUPPORT_C__IDENTIFIER_H_
#define RCL_DYNAMIC_TYPESUPPORT_C__IDENTIFIER_H_

#include "rmw/runtime_type.h"
#include "rmw/dynamic_typesupport.h"

#ifdef __cplusplus
extern "C" {
#endif

#define rcl_typesupport_runtime_type_introspection_c__identifier \
rmw_typesupport_runtime_type_introspection_c__identifier
#define rcl_dynamic_typesupport_c__identifier \
rmw_dynamic_typesupport_c__identifier

#ifdef __cplusplus
}
#endif

#endif // RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__IDENTIFIER_H_
#endif // RCL_DYNAMIC_TYPESUPPORT_C__IDENTIFIER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__MESSAGE_INTROSPECTION_H_
#define RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__MESSAGE_INTROSPECTION_H_
#ifndef RCL_DYNAMIC_TYPESUPPORT_C__MESSAGE_INTROSPECTION_H_
#define RCL_DYNAMIC_TYPESUPPORT_C__MESSAGE_INTROSPECTION_H_

#include "serialization_support_lib/description.h"
#include "rosidl_dynamic_typesupport/description.h"

#include "rosidl_runtime_c/message_type_support_struct.h"
#include "rcl/macros.h"
Expand All @@ -29,28 +29,28 @@ extern "C" {

// TODO(methylDragon): !!! Document that the user is in charge of the lifetime of the struct...
// TODO(methylDragon): ...
// NOTE(methylDragon): My use of the serialization_support_lib::type_description_t struct is for
// NOTE(methylDragon): My use of the rosidl_dynamic_typesupport::type_description_t struct is for
// convenience only. We should be passing the TypeDescription message

/// If the user passes a NULL desc, it is deferred instead, the middleware is responsibile for
/// populating the fields on type discovery!!!
RCL_PUBLIC
RCL_WARN_UNUSED
rosidl_message_type_support_t *
rcl_get_runtime_type_message_typesupport_handle(
rcl_get_dynamic_message_typesupport_handle(
const char * serialization_lib_name,
type_description_t * desc);

/// Finalize a rosidl_message_type_support_t obtained with
/// rcl_get_runtime_type_message_typesupport_handle
/// rcl_get_dynamic_message_typesupport_handle
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_runtime_type_message_typesupport_handle_fini(rosidl_message_type_support_t * ts);
rcl_dynamic_message_typesupport_handle_fini(rosidl_message_type_support_t * ts);


#ifdef __cplusplus
}
#endif

#endif // RCL_TYPESUPPORT_RUNTIME_TYPE_INTROSPECTION_C__MESSAGE_INTROSPECTION_H_
#endif // RCL_DYNAMIC_TYPESUPPORT_C__MESSAGE_INTROSPECTION_H_
39 changes: 39 additions & 0 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern "C"
#include "rcl/visibility_control.h"

#include "rmw/message_sequence.h"
#include "rmw/dynamic_typesupport.h"


/// Internal rcl implementation struct.
typedef struct rcl_subscription_impl_s rcl_subscription_impl_t;
Expand Down Expand Up @@ -599,6 +601,43 @@ rcl_take_serialized_message(
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation);

/// Take a runtime type message from a topic using a rcl subscription.
/**
* In contrast to rcl_take(), this function takes a runtime type message with dynamic data taken
* directly from the middleware.
* It is the job of the caller to ensure that the type associated with the subscription
* matches, and that the subscription uses the runtime type rosidl_message_type_support_t.
*
* Apart from the differences above, this function behaves like rcl_take().
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | Yes
*
* \param[in] subscription the handle to the subscription from which to take
* \param[inout] dynamic_message pointer to a (pre-allocated) runtime type message.
* \param[out] message_info rmw struct which contains meta-data for the message
* \param[in] allocation structure pointer used for memory preallocation (may be NULL)
* \return #RCL_RET_OK if the message was taken, or
* \return #RCL_RET_INVALID_ARGUMENT if any arguments are invalid, or
* \return #RCL_RET_SUBSCRIPTION_INVALID if the subscription is invalid, or
* \return #RCL_RET_BAD_ALLOC if allocating memory failed, or
* \return #RCL_RET_SUBSCRIPTION_TAKE_FAILED if take failed but no error
* occurred in the middleware, or
* \return #RCL_RET_ERROR if an unspecified error occurs.
*/
rcl_ret_t
rcl_take_dynamic_message(
const rcl_subscription_t * subscription,
// TODO(methylDragon): Replace this with rcl_dynamic_message_t
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message,
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation);

/// Take a loaned message from a topic using a rcl subscription.
/**
* Depending on the middleware, incoming messages can be loaned to the user's callback
Expand Down
2 changes: 1 addition & 1 deletion rcl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<build_export_depend>rmw</build_export_depend>

<depend>serialization_support_lib</depend> <!-- TODO(methylDragon): TEMPORARY. Remove eventually -->
<depend>rosidl_dynamic_typesupport</depend> <!-- TODO(methylDragon): TEMPORARY. Remove eventually -->
<depend>rcl_interfaces</depend>
<depend>rcl_logging_interface</depend>
<depend>rcl_logging_spdlog</depend> <!-- the default logging impl -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ extern "C"
{
#endif

#include "serialization_support_lib/description.h"
#include "rmw/runtime_type.h"
#include "rosidl_dynamic_typesupport/description.h"
#include "rmw/dynamic_typesupport.h"

#include "rcl/types.h"
#include "rcl/error_handling.h"
#include "rcl/rcl_typesupport_runtime_type_introspection_c/identifier.h"
#include "rcl/rcl_typesupport_runtime_type_introspection_c/message_introspection.h"
#include "rcl/rcl_dynamic_typesupport_c/identifier.h"
#include "rcl/rcl_dynamic_typesupport_c/message_introspection.h"

#include "rcutils/logging_macros.h"
#include "rosidl_runtime_c/message_type_support_struct.h"


// NOTE(methylDragon): My use of the serialization_support_lib::type_description_t struct is for
// NOTE(methylDragon): My use of the rosidl_dynamic_typesupport::type_description_t struct is for
// convenience only. We should be passing the TypeDescription message

/// Create a rosidl_message_type_support_t from a TypeDescription message
RCL_PUBLIC
RCL_WARN_UNUSED
rosidl_message_type_support_t *
rcl_get_runtime_type_message_typesupport_handle(
rcl_get_dynamic_message_typesupport_handle(
const char * serialization_lib_name,
type_description_t * desc)
{
return rmw_get_runtime_type_message_typesupport_handle(
return rmw_get_dynamic_message_typesupport_handle(
rmw_get_serialization_support(serialization_lib_name),
rmw_feature_supported(RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY),
rmw_feature_supported(RMW_MIDDLEWARE_CAN_TAKE_DYNAMIC_DATA),
Expand All @@ -50,10 +50,10 @@ rcl_get_runtime_type_message_typesupport_handle(


rcl_ret_t
rcl_runtime_type_message_typesupport_handle_fini(rosidl_message_type_support_t * ts)
rcl_dynamic_message_typesupport_handle_fini(rosidl_message_type_support_t * ts)
{
RCL_CHECK_ARGUMENT_FOR_NULL(ts, RCL_RET_INVALID_ARGUMENT);
return rmw_runtime_type_message_typesupport_handle_fini(ts);
return rmw_dynamic_message_typesupport_handle_fini(ts);
}

#ifdef __cplusplus
Expand Down
35 changes: 35 additions & 0 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern "C"
#include "rcutils/strdup.h"
#include "rcutils/types/string_array.h"
#include "rmw/error_handling.h"
#include "rmw/dynamic_typesupport.h"
#include "rmw/subscription_content_filter_options.h"
#include "rmw/validate_full_topic_name.h"
#include "tracetools/tracetools.h"
Expand Down Expand Up @@ -620,6 +621,40 @@ rcl_take_serialized_message(
return RCL_RET_OK;
}

rcl_ret_t
rcl_take_dynamic_message(
const rcl_subscription_t * subscription,
// TODO(methylDragon): Replace this with rclcpp::DynamicMessage
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message,
rmw_message_info_t * message_info,
rmw_subscription_allocation_t * allocation
)
{
RCUTILS_LOG_DEBUG_NAMED(ROS_PACKAGE_NAME, "Subscription taking runtime type message");
if (!rcl_subscription_is_valid(subscription)) {
return RCL_RET_SUBSCRIPTION_INVALID; // error already set
}
RCL_CHECK_ARGUMENT_FOR_NULL(dynamic_message, RCL_RET_INVALID_ARGUMENT);
// If message_info is NULL, use a place holder which can be discarded.
rmw_message_info_t dummy_message_info;
rmw_message_info_t * message_info_local = message_info ? message_info : &dummy_message_info;
*message_info_local = rmw_get_zero_initialized_message_info();
// Call take with info
bool taken = false;
rmw_ret_t ret = rmw_take_dynamic_message_with_info(
subscription->impl->rmw_handle, dynamic_message, &taken, message_info_local, allocation);
if (ret != RMW_RET_OK) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
return rcl_convert_rmw_ret_to_rcl_ret(ret);
}
RCUTILS_LOG_DEBUG_NAMED(
ROS_PACKAGE_NAME, "Subscription runtime type take succeeded: %s", taken ? "true" : "false");
if (!taken) {
return RCL_RET_SUBSCRIPTION_TAKE_FAILED;
}
return RCL_RET_OK;
}

rcl_ret_t
rcl_take_loaned_message(
const rcl_subscription_t * subscription,
Expand Down

0 comments on commit 51423ad

Please sign in to comment.