From 24dcffc76eb648f11119304830c21c4e814ecd16 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 19 Dec 2023 11:40:57 +0000 Subject: [PATCH 1/6] Refs #20156: Add is_key_ field to identify member as key Signed-off-by: Mario Dominguez --- .../rosidl_typesupport_introspection_c/message_introspection.h | 2 ++ .../resource/msg__type_support.c.em | 2 ++ .../message_introspection.hpp | 2 ++ .../resource/msg__type_support.cpp.em | 2 ++ 4 files changed, 8 insertions(+) diff --git a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h index 0d16e5923..646c11751 100644 --- a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h +++ b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h @@ -39,6 +39,8 @@ typedef struct rosidl_typesupport_introspection_c__MessageMember_s /// If the type_id_ value is rosidl_typesupport_introspection_c__ROS_TYPE_MESSAGE, /// this points to an array describing the fields of the sub-interface. const rosidl_message_type_support_t * members_; + /// True if this field is a keyed field, false otherwise. + bool is_key_; /// True if this field is an array type, false if it is any other type. An /// array has the same value for / type_id_. bool is_array_; diff --git a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em index de392983f..faaa784cc 100644 --- a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em +++ b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em @@ -238,6 +238,8 @@ for index, member in enumerate(message.structure.members): print(' 0, // upper bound of string') # const rosidl_message_type_support_t * members_ print(' NULL, // members of sub message (initialized later)') + # bool is_key_ + print(' %s, // is key' % ('true' if member.has_annotation('key') else 'false')) # bool is_array_ print(' %s, // is array' % ('true' if isinstance(member.type, AbstractNestedType) else 'false')) # size_t array_size_ diff --git a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp index 6c01c2ce8..45befff26 100644 --- a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp +++ b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp @@ -41,6 +41,8 @@ typedef struct ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_PUBLIC MessageMember_s /// If the type_id_ value is rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE /// this points to an array describing the fields of the sub-interface. const rosidl_message_type_support_t * members_; + /// True if this field is a keyed field, false otherwise. + bool is_key_; /// True if this field is an array, false if it is a unary type. An array has the same value for /// type_id_. bool is_array_; diff --git a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em index 679907386..a68a67586 100644 --- a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em @@ -204,6 +204,8 @@ for index, member in enumerate(message.structure.members): print(' 0, // upper bound of string') # const rosidl_message_type_support_t * members_ print(' ::rosidl_typesupport_introspection_cpp::get_message_type_support_handle<%s>(), // members of sub message' % '::'.join(type_.namespaced_name())) + # bool is_key_ + print(' %s, // is key' % ('true' if member.has_annotation('key') else 'false')) # bool is_array_ print(' %s, // is array' % ('true' if isinstance(member.type, AbstractNestedType) else 'false')) # size_t array_size_ From 35775986c1bdf68aee857a8d2283dca880a10aad Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Wed, 20 Dec 2023 12:28:09 +0000 Subject: [PATCH 2/6] Refs #20156: Add has_any_member_with_annotation() method for a struct Signed-off-by: Mario Dominguez --- rosidl_parser/rosidl_parser/definition.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rosidl_parser/rosidl_parser/definition.py b/rosidl_parser/rosidl_parser/definition.py index 689b71384..07c9ef575 100644 --- a/rosidl_parser/rosidl_parser/definition.py +++ b/rosidl_parser/rosidl_parser/definition.py @@ -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.""" From a997464b42f249b1663bb57d3b0e076cfb40a0f7 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Thu, 8 Feb 2024 09:36:36 +0000 Subject: [PATCH 3/6] Refs #20310: Define v2 ABI identifier Signed-off-by: Mario Dominguez --- .../include/rosidl_typesupport_introspection_c/identifier.h | 4 ++++ rosidl_typesupport_introspection_c/src/identifier.c | 1 + .../rosidl_typesupport_introspection_cpp/identifier.hpp | 4 ++++ rosidl_typesupport_introspection_cpp/src/identifier.cpp | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/identifier.h b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/identifier.h index 32f545536..787f6d255 100644 --- a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/identifier.h +++ b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/identifier.h @@ -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 diff --git a/rosidl_typesupport_introspection_c/src/identifier.c b/rosidl_typesupport_introspection_c/src/identifier.c index 60da35ce3..7691710a0 100644 --- a/rosidl_typesupport_introspection_c/src/identifier.c +++ b/rosidl_typesupport_introspection_c/src/identifier.c @@ -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"; \ No newline at end of file diff --git a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/identifier.hpp b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/identifier.hpp index 26d875511..097a97116 100644 --- a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/identifier.hpp +++ b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/identifier.hpp @@ -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_ diff --git a/rosidl_typesupport_introspection_cpp/src/identifier.cpp b/rosidl_typesupport_introspection_cpp/src/identifier.cpp index 4df544e23..d830962e7 100644 --- a/rosidl_typesupport_introspection_cpp/src/identifier.cpp +++ b/rosidl_typesupport_introspection_cpp/src/identifier.cpp @@ -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 From d9f0b7a174ef1315d8e7945a93869de38cb1aa80 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Thu, 8 Feb 2024 09:39:54 +0000 Subject: [PATCH 4/6] Refs #20310: Update Message introspection with a new static key_members_array in the parent messagemembers Signed-off-by: Mario Dominguez --- .../message_introspection.h | 5 ++-- .../resource/msg__type_support.c.em | 24 +++++++++++++++---- .../message_introspection.hpp | 5 ++-- .../resource/msg__type_support.cpp.em | 24 +++++++++++++++---- 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h index 646c11751..5a67b0ddd 100644 --- a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h +++ b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h @@ -39,8 +39,6 @@ typedef struct rosidl_typesupport_introspection_c__MessageMember_s /// If the type_id_ value is rosidl_typesupport_introspection_c__ROS_TYPE_MESSAGE, /// this points to an array describing the fields of the sub-interface. const rosidl_message_type_support_t * members_; - /// True if this field is a keyed field, false otherwise. - bool is_key_; /// True if this field is an array type, false if it is any other type. An /// array has the same value for / type_id_. bool is_array_; @@ -98,6 +96,9 @@ 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 *); + /// Array of the same size as the numebr of fields that indicates + /// whether a field is keyed or not + const bool * key_members_array_; } rosidl_typesupport_introspection_c__MessageMembers; #endif // ROSIDL_TYPESUPPORT_INTROSPECTION_C__MESSAGE_INTROSPECTION_H_ diff --git a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em index faaa784cc..b2c780ca5 100644 --- a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em +++ b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em @@ -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): @@ -238,8 +255,6 @@ for index, member in enumerate(message.structure.members): print(' 0, // upper bound of string') # const rosidl_message_type_support_t * members_ print(' NULL, // members of sub message (initialized later)') - # bool is_key_ - print(' %s, // is key' % ('true' if member.has_annotation('key') else 'false')) # bool is_array_ print(' %s, // is array' % ('true' if isinstance(member.type, AbstractNestedType) else 'false')) # size_t array_size_ @@ -280,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 }; // this is not const since it must be initialized on first access @@ -310,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; } diff --git a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp index 45befff26..d9a0eb075 100644 --- a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp +++ b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp @@ -41,8 +41,6 @@ typedef struct ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_PUBLIC MessageMember_s /// If the type_id_ value is rosidl_typesupport_introspection_cpp::ROS_TYPE_MESSAGE /// this points to an array describing the fields of the sub-interface. const rosidl_message_type_support_t * members_; - /// True if this field is a keyed field, false otherwise. - bool is_key_; /// True if this field is an array, false if it is a unary type. An array has the same value for /// type_id_. bool is_array_; @@ -105,6 +103,9 @@ 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 *); + /// Array of the same size as the numebr of fields that indicates + /// whether a field is keyed or not + const bool * key_members_array_; } MessageMembers; } // namespace rosidl_typesupport_introspection_cpp diff --git a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em index a68a67586..bc3b47145 100644 --- a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em @@ -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): @@ -204,8 +221,6 @@ for index, member in enumerate(message.structure.members): print(' 0, // upper bound of string') # const rosidl_message_type_support_t * members_ print(' ::rosidl_typesupport_introspection_cpp::get_message_type_support_handle<%s>(), // members of sub message' % '::'.join(type_.namespaced_name())) - # bool is_key_ - print(' %s, // is key' % ('true' if member.has_annotation('key') else 'false')) # bool is_array_ print(' %s, // is array' % ('true' if isinstance(member.type, AbstractNestedType) else 'false')) # size_t array_size_ @@ -246,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 }; 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), From ee0309a389af2807b53d174742ca5a3316658362 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 27 Feb 2024 17:00:32 +0000 Subject: [PATCH 5/6] Refs #20310: Review suggestions Signed-off-by: Mario Dominguez --- .../rosidl_typesupport_introspection_c/message_introspection.h | 3 +-- .../message_introspection.hpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h index 5a67b0ddd..711d50426 100644 --- a/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h +++ b/rosidl_typesupport_introspection_c/include/rosidl_typesupport_introspection_c/message_introspection.h @@ -96,8 +96,7 @@ 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 *); - /// Array of the same size as the numebr of fields that indicates - /// whether a field is keyed or not + /// A pointer to the array that indicates whether each field is annotated as @key const bool * key_members_array_; } rosidl_typesupport_introspection_c__MessageMembers; diff --git a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp index d9a0eb075..d94a1289b 100644 --- a/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp +++ b/rosidl_typesupport_introspection_cpp/include/rosidl_typesupport_introspection_cpp/message_introspection.hpp @@ -103,8 +103,7 @@ 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 *); - /// Array of the same size as the numebr of fields that indicates - /// whether a field is keyed or not + /// A pointer to the array that indicates whether each field is annotated as @key const bool * key_members_array_; } MessageMembers; From e07e437b7c0472a5f6eed1aa746aba28344889d8 Mon Sep 17 00:00:00 2001 From: Mario Dominguez Date: Tue, 5 Mar 2024 17:18:07 +0000 Subject: [PATCH 6/6] Refs #20310: NITs Signed-off-by: Mario Dominguez --- .../resource/msg__type_support.c.em | 2 +- .../resource/msg__type_support.cpp.em | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em index b2c780ca5..b2df9c7fb 100644 --- a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em +++ b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em @@ -296,7 +296,7 @@ static const rosidl_typesupport_introspection_c__MessageMembers @(function_prefi @(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)_key_members_array // mapping to each field to know whether is keyed or not + @(function_prefix)__@(message.structure.namespaced_type.name)_key_members_array // mapping to each field to know whether it is keyed or not }; // this is not const since it must be initialized on first access diff --git a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em index bc3b47145..68107a42d 100644 --- a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em @@ -262,7 +262,7 @@ static const ::rosidl_typesupport_introspection_cpp::MessageMembers @(message.st @(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)_key_members_array // mapping to each field to know whether is keyed or not + @(message.structure.namespaced_type.name)_key_members_array // mapping to each field to know whether it is keyed or not }; static const rosidl_message_type_support_t @(message.structure.namespaced_type.name)_message_type_support_handle = {