Skip to content

Commit f338b56

Browse files
committed
Refactor dynamic message type support impl to use allocators
* Implement runtime type typesupport struct Signed-off-by: methylDragon <[email protected]> * Implement first cut Signed-off-by: methylDragon <[email protected]> * Migrate to rosidl_dynamic_typesupport and update field IDs Signed-off-by: methylDragon <[email protected]> * Migrate to type description interfaces Signed-off-by: methylDragon <[email protected]> * Fix const Signed-off-by: methylDragon <[email protected]> * Refine signatures and use return types Signed-off-by: methylDragon <[email protected]> * Fix C linkage Signed-off-by: methylDragon <[email protected]> * Migrate methods to use return types Signed-off-by: methylDragon <[email protected]> * Lint Signed-off-by: methylDragon <[email protected]> * Support type hashes Signed-off-by: methylDragon <[email protected]> * Remove identifier alias Signed-off-by: methylDragon <[email protected]> * Change fini to destroy Signed-off-by: methylDragon <[email protected]> * Use create instead of init Signed-off-by: methylDragon <[email protected]> * Add rcutils conversion function and remove rmw interfaces Signed-off-by: methylDragon <[email protected]> * Clean up some comments Signed-off-by: methylDragon <[email protected]> --------- Signed-off-by: methylDragon <[email protected]>
1 parent de367f3 commit f338b56

File tree

2 files changed

+179
-116
lines changed

2 files changed

+179
-116
lines changed

include/rosidl_dynamic_typesupport/dynamic_message_type_support_struct.h

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,37 @@ 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 bound 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.
80+
81+
* The caller is responsible for deallocating the returned pointer.
8182
*
8283
* <hr>
8384
* Attribute | Adherence
@@ -89,21 +90,53 @@ typedef struct rosidl_dynamic_message_type_support_impl_s
8990
*/
9091
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC
9192
rcutils_ret_t
92-
rosidl_dynamic_message_type_support_handle_create(
93+
rosidl_dynamic_message_type_support_handle_init(
9394
rosidl_dynamic_typesupport_serialization_support_t * serialization_support,
9495
const rosidl_type_hash_t * type_hash,
9596
const rosidl_runtime_c__type_description__TypeDescription * type_description,
9697
const rosidl_runtime_c__type_description__TypeSource__Sequence * type_description_sources,
97-
rosidl_message_type_support_t ** ts); // OUT
98+
rcutils_allocator_t * allocator,
99+
rosidl_message_type_support_t * ts); // OUT
98100

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

108141
/// Return type_hash member in rosidl_dynamic_message_type_support_impl_t
109142
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC

0 commit comments

Comments
 (0)