Skip to content

Commit 1ba34df

Browse files
committed
Take ownership of description, add print, and update ser support API
Signed-off-by: methylDragon <methylDragon@gmail.com>
1 parent 78f338e commit 1ba34df

File tree

5 files changed

+95
-24
lines changed

5 files changed

+95
-24
lines changed

rclcpp/include/rclcpp/dynamic_typesupport/dynamic_message_type_support.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ class DynamicMessageTypeSupport : public std::enable_shared_from_this<DynamicMes
145145
DynamicMessage::ConstSharedPtr
146146
get_shared_dynamic_message() const;
147147

148+
149+
// METHODS =======================================================================================
150+
RCLCPP_PUBLIC
151+
void
152+
print_description() const;
153+
148154
protected:
149155
RCLCPP_DISABLE_COPY(DynamicMessageTypeSupport)
150156

@@ -179,7 +185,7 @@ class DynamicMessageTypeSupport : public std::enable_shared_from_this<DynamicMes
179185
DynamicSerializationSupport::SharedPtr serialization_support,
180186
DynamicMessageType::SharedPtr dynamic_message_type,
181187
DynamicMessage::SharedPtr dynamic_message,
182-
const rosidl_runtime_c__type_description__TypeDescription * description);
188+
rosidl_runtime_c__type_description__TypeDescription * description);
183189
};
184190

185191

rclcpp/include/rclcpp/dynamic_typesupport/dynamic_serialization_support.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DynamicSerializationSupport : public std::enable_shared_from_this<DynamicS
5757

5858
/// Copy shared pointer
5959
RCLCPP_PUBLIC
60-
DynamicSerializationSupport( // NOLINT(explicit)
60+
DynamicSerializationSupport(
6161
std::shared_ptr<rosidl_dynamic_typesupport_serialization_support_t> serialization_support);
6262

6363
/// Move constructor

rclcpp/include/rclcpp/dynamic_typesupport/dynamic_type_builder.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,30 @@ class DynamicTypeBuilder : public std::enable_shared_from_this<DynamicTypeBuilde
282282
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
283283
DynamicType & nested_type, size_t sequence_bound);
284284

285+
RCLCPP_PUBLIC
286+
void
287+
add_complex_member_builder(
288+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
289+
DynamicTypeBuilder & nested_type_builder);
290+
291+
RCLCPP_PUBLIC
292+
void
293+
add_complex_array_member_builder(
294+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
295+
DynamicTypeBuilder & nested_type_builder, size_t array_length);
296+
297+
RCLCPP_PUBLIC
298+
void
299+
add_complex_unbounded_sequence_member_builder(
300+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
301+
DynamicTypeBuilder & nested_type_builder);
302+
303+
RCLCPP_PUBLIC
304+
void
305+
add_complex_bounded_sequence_member_builder(
306+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
307+
DynamicTypeBuilder & nested_type_builder, size_t sequence_bound);
308+
285309
protected:
286310
// NOTE(methylDragon):
287311
// This is just here to extend the lifetime of the serialization support

rclcpp/src/rclcpp/dynamic_typesupport/dynamic_message_type_support.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <rosidl_dynamic_typesupport/types.h>
3131
#include <rosidl_runtime_c/message_type_support_struct.h>
32+
#include "rosidl_runtime_c/type_description_utils.h"
3233
#include <rosidl_runtime_c/type_description/type_description__functions.h>
3334
#include <rosidl_runtime_c/type_description/type_description__struct.h>
3435

@@ -225,7 +226,7 @@ DynamicMessageTypeSupport::init_rosidl_message_type_support_(
225226
DynamicSerializationSupport::SharedPtr serialization_support,
226227
DynamicMessageType::SharedPtr dynamic_message_type,
227228
DynamicMessage::SharedPtr dynamic_message,
228-
const rosidl_runtime_c__type_description__TypeDescription * description)
229+
rosidl_runtime_c__type_description__TypeDescription * description)
229230
{
230231
bool middleware_supports_type_discovery =
231232
rmw_feature_supported(RMW_MIDDLEWARE_SUPPORTS_TYPE_DISCOVERY);
@@ -242,8 +243,11 @@ DynamicMessageTypeSupport::init_rosidl_message_type_support_(
242243
}
243244

244245
// NOTE(methylDragon): We don't finalize the rosidl_message_type_support->data since its members
245-
// are they're managed by the passed in SharedPtr wrapper classes
246-
rosidl_message_type_support_ = std::make_shared<rosidl_message_type_support_t>();
246+
// are managed by the passed in SharedPtr wrapper classes
247+
rosidl_message_type_support_.reset(
248+
new rosidl_message_type_support_t(),
249+
[](rosidl_message_type_support_t * ts) -> void {free(const_cast<void *>(ts->data));}
250+
);
247251

248252
if (!rosidl_message_type_support_) {
249253
RCUTILS_LOG_ERROR_NAMED(
@@ -270,26 +274,8 @@ DynamicMessageTypeSupport::init_rosidl_message_type_support_(
270274
ts_impl->serialization_support = serialization_support->get_rosidl_serialization_support();
271275
ts_impl->dynamic_type = dynamic_message_type->get_rosidl_dynamic_type();
272276
ts_impl->dynamic_data = dynamic_message->get_rosidl_dynamic_data();
277+
ts_impl->description = description;
273278
rosidl_message_type_support_->func = get_message_typesupport_handle_function;
274-
275-
if (description) {
276-
ts_impl->description = rosidl_runtime_c__type_description__TypeDescription__create();
277-
if (ts_impl->description == NULL) {
278-
RCUTILS_LOG_ERROR_NAMED(
279-
rmw_dynamic_typesupport_c__identifier,
280-
"Could not create type description to assign into");
281-
rosidl_message_type_support_.reset();
282-
}
283-
284-
if (!rosidl_runtime_c__type_description__TypeDescription__copy(
285-
description, ts_impl->description))
286-
{
287-
RCUTILS_LOG_ERROR_NAMED(
288-
rmw_dynamic_typesupport_c__identifier,
289-
"Could not copy type description");
290-
rosidl_message_type_support_.reset();
291-
}
292-
}
293279
}
294280

295281

@@ -397,3 +383,14 @@ DynamicMessageTypeSupport::get_shared_dynamic_message() const
397383
{
398384
return dynamic_message_;
399385
}
386+
387+
388+
// METHODS =========================================================================================
389+
void
390+
DynamicMessageTypeSupport::print_description() const
391+
{
392+
if (!description_) {
393+
RCUTILS_LOG_ERROR("Can't print description, no bound description!");
394+
}
395+
rosidl_runtime_c_type_description_utils_print_type_description(description_.get());
396+
}

rclcpp/src/rclcpp/dynamic_typesupport/dynamic_type_builder.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,47 @@ DynamicTypeBuilder::add_complex_bounded_sequence_member(
490490
get_rosidl_dynamic_type_builder(), id, name.c_str(), name.size(),
491491
nested_type.get_rosidl_dynamic_type(), sequence_bound);
492492
}
493+
494+
495+
void
496+
DynamicTypeBuilder::add_complex_member_builder(
497+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
498+
DynamicTypeBuilder & nested_type_builder)
499+
{
500+
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_member_builder(
501+
get_rosidl_dynamic_type_builder(), id, name.c_str(), name.size(),
502+
nested_type_builder.get_rosidl_dynamic_type_builder());
503+
}
504+
505+
506+
void
507+
DynamicTypeBuilder::add_complex_array_member_builder(
508+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
509+
DynamicTypeBuilder & nested_type_builder, size_t array_length)
510+
{
511+
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_array_member_builder(
512+
get_rosidl_dynamic_type_builder(), id, name.c_str(), name.size(),
513+
nested_type_builder.get_rosidl_dynamic_type_builder(), array_length);
514+
}
515+
516+
517+
void
518+
DynamicTypeBuilder::add_complex_unbounded_sequence_member_builder(
519+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
520+
DynamicTypeBuilder & nested_type_builder)
521+
{
522+
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_unbounded_sequence_member_builder(
523+
get_rosidl_dynamic_type_builder(), id, name.c_str(), name.size(),
524+
nested_type_builder.get_rosidl_dynamic_type_builder());
525+
}
526+
527+
528+
void
529+
DynamicTypeBuilder::add_complex_bounded_sequence_member_builder(
530+
rosidl_dynamic_typesupport_member_id_t id, const std::string & name,
531+
DynamicTypeBuilder & nested_type_builder, size_t sequence_bound)
532+
{
533+
rosidl_dynamic_typesupport_dynamic_type_builder_add_complex_bounded_sequence_member_builder(
534+
get_rosidl_dynamic_type_builder(), id, name.c_str(), name.size(),
535+
nested_type_builder.get_rosidl_dynamic_type_builder(), sequence_bound);
536+
}

0 commit comments

Comments
 (0)