Skip to content

Commit 69d2518

Browse files
committed
Refactor dynamic message type support impl to use allocators
Signed-off-by: methylDragon <[email protected]>
1 parent de367f3 commit 69d2518

File tree

2 files changed

+175
-116
lines changed

2 files changed

+175
-116
lines changed

include/rosidl_dynamic_typesupport/dynamic_message_type_support_struct.h

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,35 @@ extern "C"
4848
// outlives those downstream classes.
4949
typedef struct rosidl_dynamic_message_type_support_impl_s
5050
{
51-
rosidl_type_hash_t * type_hash;
52-
rosidl_runtime_c__type_description__TypeDescription * type_description;
51+
rcutils_allocator_t allocator;
52+
53+
rosidl_type_hash_t type_hash;
54+
rosidl_runtime_c__type_description__TypeDescription type_description;
55+
56+
// Unused for now, but placed here just in case
57+
rosidl_runtime_c__type_description__TypeSource__Sequence type_description_sources;
5358

54-
// NOTE(methylDragon): Unused for now, but placed here just in case
55-
rosidl_runtime_c__type_description__TypeSource__Sequence * type_description_sources;
5659
rosidl_dynamic_typesupport_serialization_support_t * serialization_support;
5760

58-
// NOTE(methylDragon): I'm unsure if these are necessary. Though I think they are convenient.
59-
// dynamic_message_type moreso than dynamic_message.
60-
//
61-
// I'd err on including them to be able to support more middlewares
62-
//
63-
// The dynamic_message_type allows us to do a one time alloc and reuse it for
64-
// subscription creation and data creation
65-
// The dynamic_message allows us to either reuse it, or clone it, but it's
66-
// technically redundant because data can be created from dynamic_message_type
61+
// The dynamic_message_type allows us to do a one time alloc and reuse it for subscription
62+
// creation and data creation
6763
rosidl_dynamic_typesupport_dynamic_type_t * dynamic_message_type;
64+
65+
// The dynamic_message allows us to either reuse it, or clone it, but it's technically redundant
66+
// because data can be created from dynamic_message_type
6867
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_message;
6968
} rosidl_dynamic_message_type_support_impl_t;
7069

71-
/// Create a dynamic type message typesupport with bound message description
70+
/// Initialize a dynamic type message type support with encapsulated message description
7271
/**
73-
* NOTE: Take note of the ownership rules for the returned struct and the `description` argument!
72+
* Take note of the ownership rules for the returned struct and the `description` argument.
7473
*
74+
* The `rosidl_message_type_support_t *` returned from this function has different ownership rules
75+
* compared to the statically allocated `rosidl_message_type_support_t` structs from code-generated
76+
* types.
7577
*
76-
* Ownership:
77-
* - The `rosidl_message_type_support_t *` returned from this function has different ownership
78-
* rules compared to the statically allocated `rosidl_message_type_support_t` structs from
79-
* code-generated types!
80-
* - The caller is responsible for deallocating the returned pointer
78+
* The `type_hash`, `type_description`, `type_description_sources`, and `allocator` arguments are
79+
* copied.
8180
*
8281
* <hr>
8382
* Attribute | Adherence
@@ -89,21 +88,51 @@ typedef struct rosidl_dynamic_message_type_support_impl_s
8988
*/
9089
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC
9190
rcutils_ret_t
92-
rosidl_dynamic_message_type_support_handle_create(
91+
rosidl_dynamic_message_type_support_handle_init(
9392
rosidl_dynamic_typesupport_serialization_support_t * serialization_support,
9493
const rosidl_type_hash_t * type_hash,
9594
const rosidl_runtime_c__type_description__TypeDescription * type_description,
9695
const rosidl_runtime_c__type_description__TypeSource__Sequence * type_description_sources,
97-
rosidl_message_type_support_t ** ts); // OUT
96+
rcutils_allocator_t * allocator,
97+
rosidl_message_type_support_t * ts); // OUT
9898

99-
/// Destroy a rosidl_message_type_support_t obtained with
100-
/// `rosidl_dynamic_message_type_support_handle_create()`, which has dynamically allocated members
99+
/// Finalize a rosidl_message_type_support_t obtained with
100+
/// `rosidl_dynamic_message_type_support_handle_init()`, which has dynamically allocated members
101101
///
102102
/// NOTE: Using this on a statically allocated typesupport will cause undefined behavior!
103103
/// (Static memory will get freed in that case.)
104104
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC
105105
rcutils_ret_t
106-
rosidl_dynamic_message_type_support_handle_destroy(rosidl_message_type_support_t * ts);
106+
rosidl_dynamic_message_type_support_handle_fini(rosidl_message_type_support_t * ts);
107+
108+
/// Initialized a `rosidl_dynamic_message_type_support_impl_t` with bound message description
109+
/**
110+
* The `type_hash`, `type_description`, `type_description_sources`, and `allocator` arguments are
111+
* copied.
112+
*
113+
* <hr>
114+
* Attribute | Adherence
115+
* ------------------ | -------------
116+
* Allocates Memory | Yes
117+
* Thread-Safe | No
118+
* Uses Atomics | No
119+
* Lock-Free | Yes
120+
*/
121+
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC
122+
rcutils_ret_t
123+
rosidl_dynamic_message_type_support_handle_impl_init(
124+
rosidl_dynamic_typesupport_serialization_support_t * serialization_support,
125+
const rosidl_type_hash_t * type_hash,
126+
const rosidl_runtime_c__type_description__TypeDescription * type_description,
127+
const rosidl_runtime_c__type_description__TypeSource__Sequence * type_description_sources,
128+
rcutils_allocator_t * allocator,
129+
rosidl_dynamic_message_type_support_impl_t * ts_impl); // OUT
130+
131+
/// Finalize a `rosidl_dynamic_message_type_support_impl_t`
132+
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC
133+
rcutils_ret_t
134+
rosidl_dynamic_message_type_support_handle_impl_fini(
135+
rosidl_dynamic_message_type_support_impl_t * ts_impl);
107136

108137
/// Return type_hash member in rosidl_dynamic_message_type_support_impl_t
109138
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC

0 commit comments

Comments
 (0)