-
Notifications
You must be signed in to change notification settings - Fork 4
Dynamic Subscription (BONUS: Allocators): rosidl_dynamic_typesupport #2
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
Changes from all commits
69d2518
7d0d91b
7693180
efcac65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,39 @@ | |
extern "C" { | ||
#endif | ||
|
||
#include <rcutils/allocator.h> | ||
#include <rcutils/types/rcutils_ret.h> | ||
#include <rcutils/types/uint8_array.h> | ||
#include <rosidl_dynamic_typesupport/api/serialization_support_interface.h> | ||
#include <rosidl_dynamic_typesupport/visibility_control.h> | ||
#include <rosidl_dynamic_typesupport/uchar.h> | ||
|
||
#include "rosidl_dynamic_typesupport/api/serialization_support.h" | ||
#include "rosidl_dynamic_typesupport/api/serialization_support_interface.h" | ||
#include "rosidl_dynamic_typesupport/visibility_control.h" | ||
#include "rosidl_dynamic_typesupport/types.h" | ||
#include "rosidl_dynamic_typesupport/uchar.h" | ||
|
||
// Dynamic Data Impl | ||
struct rosidl_dynamic_typesupport_dynamic_data_impl_s | ||
{ | ||
rcutils_allocator_t allocator; | ||
void * handle; | ||
}; | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rosidl_dynamic_typesupport_dynamic_data_impl_t | ||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data_impl(void); | ||
|
||
// Dynamic Data | ||
struct rosidl_dynamic_typesupport_dynamic_data_s | ||
{ | ||
rcutils_allocator_t allocator; | ||
rosidl_dynamic_typesupport_dynamic_data_impl_t impl; | ||
// !!! Lifetime is NOT managed by this struct | ||
rosidl_dynamic_typesupport_serialization_support_t * serialization_support; | ||
}; | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rosidl_dynamic_typesupport_dynamic_data_t | ||
rosidl_dynamic_typesupport_get_zero_initialized_dynamic_data(void); | ||
|
||
// =============================================================================================== | ||
// DYNAMIC DATA | ||
|
@@ -90,14 +117,21 @@ rcutils_ret_t | |
rosidl_dynamic_typesupport_dynamic_data_loan_value( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, | ||
rosidl_dynamic_typesupport_member_id_t id, | ||
rosidl_dynamic_typesupport_dynamic_data_t ** loaned_dynamic_data); // OUT | ||
rcutils_allocator_t * allocator, | ||
rosidl_dynamic_typesupport_dynamic_data_t * loaned_dynamic_data); // OUT | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_return_loaned_value( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, | ||
rosidl_dynamic_typesupport_dynamic_data_t * inner_dynamic_data); | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_return_and_destroy_loaned_value( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, | ||
rosidl_dynamic_typesupport_dynamic_data_t * inner_dynamic_data); | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_get_name( | ||
|
@@ -109,21 +143,29 @@ rosidl_dynamic_typesupport_dynamic_data_get_name( | |
// DYNAMIC DATA CONSTRUCTION ======================================================================= | ||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type_builder( | ||
rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type_builder( | ||
rosidl_dynamic_typesupport_dynamic_type_builder_t * dynamic_type_builder, | ||
rosidl_dynamic_typesupport_dynamic_data_t ** dynamic_data); // OUT | ||
rcutils_allocator_t * allocator, | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data); // OUT | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_create_from_dynamic_type( | ||
rosidl_dynamic_typesupport_dynamic_data_init_from_dynamic_type( | ||
rosidl_dynamic_typesupport_dynamic_type_t * dynamic_type, | ||
rosidl_dynamic_typesupport_dynamic_data_t ** dynamic_data); // OUT | ||
rcutils_allocator_t * allocator, | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data); // OUT | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_clone( | ||
const rosidl_dynamic_typesupport_dynamic_data_t * other_dynamic_data, | ||
rosidl_dynamic_typesupport_dynamic_data_t ** dynamic_data); // OUT | ||
rcutils_allocator_t * allocator, | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data); // OUT | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_fini( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data); | ||
Comment on lines
158
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For other reviewers, the vast majority of changes for this pr can be summed up with this diff, basically adding allocators where we do allocation and avoiding double pointers as out parameters (matching how most of the |
||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
|
@@ -136,15 +178,13 @@ ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | |
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_serialize( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, | ||
rcutils_uint8_array_t * buffer, // OUT | ||
bool * serialized); // OUT | ||
rcutils_uint8_array_t * buffer); // OUT | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_deserialize( | ||
rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, // OUT | ||
rcutils_uint8_array_t * buffer, | ||
bool * success); // OUT | ||
rcutils_uint8_array_t * buffer); | ||
|
||
|
||
// DYNAMIC DATA PRIMITIVE MEMBER GETTERS =========================================================== | ||
|
@@ -564,7 +604,9 @@ ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | |
rcutils_ret_t | ||
rosidl_dynamic_typesupport_dynamic_data_get_complex_value( | ||
const rosidl_dynamic_typesupport_dynamic_data_t * dynamic_data, | ||
rosidl_dynamic_typesupport_member_id_t id, rosidl_dynamic_typesupport_dynamic_data_t ** value); | ||
rosidl_dynamic_typesupport_member_id_t id, | ||
rcutils_allocator_t * allocator, | ||
rosidl_dynamic_typesupport_dynamic_data_t * value); | ||
|
||
ROSIDL_DYNAMIC_TYPESUPPORT_PUBLIC | ||
rcutils_ret_t | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using hidden-type
pimpl
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of doing that, but I thought it would be better to enforce that the impl is a complete type (and then defer it to the handle), so that we can enforce that the impl type has an allocator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't the the type defined just above? That is, this implementation is completely in control of that structure, and thus can guarantee that it always has an allocator, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, right.. I think I'm avoiding the use of a pointer so we don't have to keep doing null checks on the impl member as well..
The impl is unusable without the associated serialization support in either case, so in my view composition makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, actually, I largely agree with you. The only problem here is that if we want to add, remove, or change structure members in the implementation, we won't be able to backport it due to ABI concerns. But if we are OK with that limitation for now, we can leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation contains a void * handle, so that's a good escape hatch I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's good enough for now. It isn't our usual style, but it will do in a pinch.