Skip to content
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

[20590] Feature: topic keys with non breaking ABI (iron backport) #3

Merged
merged 6 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rosidl_parser/rosidl_parser/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ def __init__(self, namespaced_type: NamespacedType, members=None):
self.namespaced_type = namespaced_type
self.members = members or []

def has_any_member_with_annotation(self, name: str):
"""
Returns whether any member has a particular annotation.

:param name: the annotation name
"""
has_any = [member.name for member in self.members if member.has_annotation(name)]
return bool(has_any)


class Include:
"""An include statement."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ extern "C"
ROSIDL_TYPESUPPORT_INTROSPECTION_C_PUBLIC
extern const char * rosidl_typesupport_introspection_c__identifier;

/// String identifying the typesupport introspection implementation in use.
ROSIDL_TYPESUPPORT_INTROSPECTION_C_PUBLIC
extern const char * rosidl_typesupport_introspection_c__identifier_v2;

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ typedef struct rosidl_typesupport_introspection_c__MessageMembers_s
void (* init_function)(void *, enum rosidl_runtime_c__message_initialization);
/// The function used to clean up the interface's in-memory representation
void (* fini_function)(void *);
/// A pointer to the array that indicates whether each field is annotated as @key
const bool * key_members_array_;
} rosidl_typesupport_introspection_c__MessageMembers;

#endif // ROSIDL_TYPESUPPORT_INTROSPECTION_C__MESSAGE_INTROSPECTION_H_
22 changes: 20 additions & 2 deletions rosidl_typesupport_introspection_c/resource/msg__type_support.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ bool @(function_prefix)__resize_function__@(message.structure.namespaced_type.na
@[ end if]@
@[ end if]@
@[end for]@

static bool @(function_prefix)__@(message.structure.namespaced_type.name)_key_members_array[@(len(message.structure.members))] = {
@{
for index, member in enumerate(message.structure.members):
if member.has_annotation('key'):
if index < len(message.structure.members) - 1:
print(' true,')
else:
print(' true')
else:
if index < len(message.structure.members) - 1:
print(' false,')
else:
print(' false')
}@
};

static rosidl_typesupport_introspection_c__MessageMember @(function_prefix)__@(message.structure.namespaced_type.name)_message_member_array[@(len(message.structure.members))] = {
@{
for index, member in enumerate(message.structure.members):
Expand Down Expand Up @@ -278,7 +295,8 @@ static const rosidl_typesupport_introspection_c__MessageMembers @(function_prefi
sizeof(@('__'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))),
@(function_prefix)__@(message.structure.namespaced_type.name)_message_member_array, // message members
@(function_prefix)__@(message.structure.namespaced_type.name)_init_function, // function to initialize message memory (memory has to be allocated)
@(function_prefix)__@(message.structure.namespaced_type.name)_fini_function // function to terminate message instance (will not free memory)
@(function_prefix)__@(message.structure.namespaced_type.name)_fini_function, // function to terminate message instance (will not free memory)
@(function_prefix)__@(message.structure.namespaced_type.name)_key_members_array // mapping to each field to know whether is keyed or not
MiguelCompany marked this conversation as resolved.
Show resolved Hide resolved
};

// this is not const since it must be initialized on first access
Expand Down Expand Up @@ -308,7 +326,7 @@ if isinstance(type_, AbstractNestedType):
@[end for]@
if (!@(function_prefix)__@(message.structure.namespaced_type.name)_message_type_support_handle.typesupport_identifier) {
@(function_prefix)__@(message.structure.namespaced_type.name)_message_type_support_handle.typesupport_identifier =
rosidl_typesupport_introspection_c__identifier;
rosidl_typesupport_introspection_c__identifier_v2;
}
return &@(function_prefix)__@(message.structure.namespaced_type.name)_message_type_support_handle;
}
Expand Down
1 change: 1 addition & 0 deletions rosidl_typesupport_introspection_c/src/identifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#include "rosidl_typesupport_introspection_c/identifier.h"

const char * rosidl_typesupport_introspection_c__identifier = "rosidl_typesupport_introspection_c";
const char * rosidl_typesupport_introspection_c__identifier_v2 = "rosidl_typesupport_introspection_c_v2";
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ namespace rosidl_typesupport_introspection_cpp
ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_IMPORT
extern const char * typesupport_identifier;

/// String identifying the typesupport introspection implementation in use.
ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_IMPORT
extern const char * typesupport_identifier_v2;

} // namespace rosidl_typesupport_introspection_cpp

#endif // ROSIDL_TYPESUPPORT_INTROSPECTION_CPP__IDENTIFIER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ typedef struct ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_PUBLIC MessageMembers_s
void (* init_function)(void *, rosidl_runtime_cpp::MessageInitialization);
/// The function used to clean up the interface's in-memory representation
void (* fini_function)(void *);
/// A pointer to the array that indicates whether each field is annotated as @key
const bool * key_members_array_;
} MessageMembers;

} // namespace rosidl_typesupport_introspection_cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ void resize_function__@(message.structure.namespaced_type.name)__@(member.name)(
@[ end if]@
@[ end if]@
@[end for]@

static const bool @(message.structure.namespaced_type.name)_key_members_array[@(len(message.structure.members))] = {
@{
for index, member in enumerate(message.structure.members):
if member.has_annotation('key'):
if index < len(message.structure.members) - 1:
print(' true,')
else:
print(' true')
else:
if index < len(message.structure.members) - 1:
print(' false,')
else:
print(' false')
}@
};

static const ::rosidl_typesupport_introspection_cpp::MessageMember @(message.structure.namespaced_type.name)_message_member_array[@(len(message.structure.members))] = {
@{
for index, member in enumerate(message.structure.members):
Expand Down Expand Up @@ -244,11 +261,12 @@ static const ::rosidl_typesupport_introspection_cpp::MessageMembers @(message.st
sizeof(@('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))),
@(message.structure.namespaced_type.name)_message_member_array, // message members
@(message.structure.namespaced_type.name)_init_function, // function to initialize message memory (memory has to be allocated)
@(message.structure.namespaced_type.name)_fini_function // function to terminate message instance (will not free memory)
@(message.structure.namespaced_type.name)_fini_function, // function to terminate message instance (will not free memory)
@(message.structure.namespaced_type.name)_key_members_array // mapping to each field to know whether is keyed or not
MiguelCompany marked this conversation as resolved.
Show resolved Hide resolved
};

static const rosidl_message_type_support_t @(message.structure.namespaced_type.name)_message_type_support_handle = {
::rosidl_typesupport_introspection_cpp::typesupport_identifier,
::rosidl_typesupport_introspection_cpp::typesupport_identifier_v2,
&@(message.structure.namespaced_type.name)_message_members,
get_message_typesupport_handle_function,
&@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_HASH_FUNC),
Expand Down
4 changes: 4 additions & 0 deletions rosidl_typesupport_introspection_cpp/src/identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ namespace rosidl_typesupport_introspection_cpp
ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_EXPORT
const char * typesupport_identifier = "rosidl_typesupport_introspection_cpp";


ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_EXPORT
const char * typesupport_identifier_v2 = "rosidl_typesupport_introspection_cpp_v2";

} // namespace rosidl_typesupport_introspection_cpp