From 555d1a45526276e2f5ee2e08273afcbba928fb43 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Thu, 30 Mar 2023 13:44:37 -0700 Subject: [PATCH 01/19] Add ability to disable C description codegen Signed-off-by: Emerson Knapp --- rosidl_generator_c/bin/rosidl_generator_c | 6 +- ...sidl_generator_c_generate_interfaces.cmake | 8 ++ .../resource/empty__description.c.em | 36 ++++++ .../resource/full__description.c.em | 100 +++++++++++++++++ .../resource/idl__description.c.em | 103 ++---------------- .../rosidl_generator_c/__init__.py | 7 +- 6 files changed, 165 insertions(+), 95 deletions(-) create mode 100644 rosidl_generator_c/resource/empty__description.c.em create mode 100644 rosidl_generator_c/resource/full__description.c.em diff --git a/rosidl_generator_c/bin/rosidl_generator_c b/rosidl_generator_c/bin/rosidl_generator_c index 1b0def38d..e1d45678a 100755 --- a/rosidl_generator_c/bin/rosidl_generator_c +++ b/rosidl_generator_c/bin/rosidl_generator_c @@ -29,9 +29,13 @@ def main(argv=sys.argv[1:]): '--generator-arguments-file', required=True, help='The location of the file containing the generator arguments') + parser.add_argument( + '--disable-description-codegen', action='store_true', + help='If set, disable the generation of static type description ' + 'code to reduce binary size.') args = parser.parse_args(argv) - generate_c(args.generator_arguments_file) + generate_c(args.generator_arguments_file, args.disable_description_codegen) if __name__ == '__main__': diff --git a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake index 7724b4e78..ad79375c6 100644 --- a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake +++ b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake @@ -55,6 +55,8 @@ set(target_dependencies ${rosidl_generator_c_GENERATOR_FILES} "${rosidl_generator_c_TEMPLATE_DIR}/action__type_support.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/action__type_support.c.em" + "${rosidl_generator_c_TEMPLATE_DIR}/empty__description.c.em" + "${rosidl_generator_c_TEMPLATE_DIR}/full__description.c.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl.h.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__description.c.em" "${rosidl_generator_c_TEMPLATE_DIR}/idl__functions.c.em" @@ -90,11 +92,17 @@ rosidl_write_generator_arguments( find_package(Python3 REQUIRED COMPONENTS Interpreter) +set(disable_description_codegen_arg) +if(ROSIDL_GENERATOR_C_DISABLE_TYPE_DESCRIPTION_CODEGEN) + set(disable_description_codegen_arg "--disable-description-codegen") +endif() + add_custom_command( OUTPUT ${_generated_headers} ${_generated_sources} COMMAND Python3::Interpreter ARGS ${rosidl_generator_c_BIN} --generator-arguments-file "${generator_arguments_file}" + ${disable_description_codegen_arg} DEPENDS ${target_dependencies} COMMENT "Generating C code for ROS interfaces" VERBATIM diff --git a/rosidl_generator_c/resource/empty__description.c.em b/rosidl_generator_c/resource/empty__description.c.em new file mode 100644 index 000000000..b9dd65fdb --- /dev/null +++ b/rosidl_generator_c/resource/empty__description.c.em @@ -0,0 +1,36 @@ +@# Included from rosidl_generator_c/resource/idl__description.c.em +@{ +from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_SOURCES_FUNC + +def typename_to_c(typename): + return typename.replace('/', '__') +}@ + +/// Define exported TypeDescriptions and TypeSources +@[for msg in full_type_descriptions]@ +@{ +td_typename = msg['type_description']['type_name'] +td_c_typename = typename_to_c(td_typename) +}@ + +const rosidl_runtime_c__type_description__TypeDescription * +@(td_c_typename)__@(GET_DESCRIPTION_FUNC)() +{ + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {NULL, 0, 0}, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }; + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +@(td_c_typename)__@(GET_SOURCES_FUNC)() +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} +@[end for]@ diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em new file mode 100644 index 000000000..9732cfbc9 --- /dev/null +++ b/rosidl_generator_c/resource/full__description.c.em @@ -0,0 +1,100 @@ +@# Included from rosidl_generator_c/resource/idl__description.c.em +@{ +from rosidl_generator_c import escape_string +from rosidl_generator_type_description import FIELD_TYPE_ID_TO_NAME +from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_SOURCES_FUNC + +def typename_to_c(typename): + return typename.replace('/', '__') + +def static_seq(varname, values): + """Statically define a runtime Sequence or String type.""" + if values: + return f'{{{varname}, {len(values)}, {len(values)}}}' + return '{NULL, 0, 0}' + +def represent_default(default_value): + # Encode to UTF-8 in case of WStrings, then remove the b'' from the representation. + return repr(default_value.encode('utf-8'))[2:-1] +}@ + +// Declare and define all type names, field names, and default values +@[for itype_description in all_type_descriptions]@ +@{ +td_c_typename = typename_to_c(itype_description['type_name']) +}@ +static char @(td_c_typename)__TYPE_NAME[] = "@(itype_description['type_name'])"; +@[ for field in itype_description['fields']]@ +static char @(td_c_typename)__FIELD_NAME__@(field['name'])[] = "@(field['name'])"; +@[ if field['default_value']]@ +static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(escape_string(represent_default(field['default_value'])))"; +@[ end if]@ +@[ end for]@ + +@[end for]@ +@ +/// Define all arrays of Fields +@[for itype_description in all_type_descriptions]@ +@{ +td_c_typename = typename_to_c(itype_description['type_name']) +}@ + +@[ if itype_description['fields']]@ +static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { +@[ for field in itype_description['fields']]@ + { + @(static_seq(f"{td_c_typename}__FIELD_NAME__{field['name']}", field['name'])), + { + rosidl_runtime_c__type_description__FieldType__@(FIELD_TYPE_ID_TO_NAME[field['type']['type_id']]), + @(field['type']['capacity']), + @(field['type']['string_capacity']), + @(static_seq(f"{typename_to_c(field['type']['nested_type_name'])}__TYPE_NAME", field['type']['nested_type_name'])), + }, + @(static_seq(f"{td_c_typename}__DEFAULT_VALUE__{field['name']}", field['default_value'])), + }, +@[ end for]@ +}; +@[ end if]@ +@[end for]@ + +/// Define exported TypeDescriptions and TypeSources +@[for msg in full_type_descriptions]@ +@{ +td_typename = msg['type_description']['type_name'] +td_c_typename = typename_to_c(td_typename) +ref_tds = msg['referenced_type_descriptions'] +}@ + +@[ if ref_tds]@ +static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { +@[ for ref_td in ref_tds]@ + { + @(static_seq(f"{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])), + @(static_seq(f"{typename_to_c(ref_td['type_name'])}__FIELDS", ref_td['fields'])), + }, +@[ end for]@ +}; +@[ end if]@ + +const rosidl_runtime_c__type_description__TypeDescription * +@(td_c_typename)__@(GET_DESCRIPTION_FUNC)() +{ + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), + @(static_seq(f'{td_c_typename}__FIELDS', msg['type_description']['fields'])), + }, + @(static_seq(f'{td_c_typename}__REFERENCED_TYPE_DESCRIPTIONS', ref_tds)), + }; + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +@(td_c_typename)__@(GET_SOURCES_FUNC)() +{ +@# TODO(emersonknapp) Implement raw source code embedding/generation. This sequence is left empty for now. + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = @(static_seq(None, '')); + return &sources; +} +@[end for]@ diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 6d21d75d1..13d3ba1a0 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -10,13 +10,10 @@ @# - interface_path (Path relative to the directory named after the package) @# - content (IdlContent, list of elements, e.g. Messages or Services) @# - type_description_info (HashedTypeDescription.schema.json dict) +@# - disable_description_codegen (bool) @####################################################################### @{ -from rosidl_generator_c import escape_string from rosidl_generator_type_description import extract_subinterface -from rosidl_generator_type_description import FIELD_TYPE_ID_TO_NAME -from rosidl_generator_type_description import GET_DESCRIPTION_FUNC -from rosidl_generator_type_description import GET_SOURCES_FUNC from rosidl_parser.definition import Action from rosidl_parser.definition import Service from rosidl_pycommon import convert_camel_case_to_lower_case_underscore @@ -51,99 +48,21 @@ for action in content.get_elements_of_type(Action): full_type_descriptions.append(extract_subinterface(get_result_service, 'event_message')) full_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback_message')) - -def typename_to_c(typename): - return typename.replace('/', '__') - -def static_seq(varname, values): - """Statically define a runtime Sequence or String type.""" - if values: - return f'{{{varname}, {len(values)}, {len(values)}}}' - return '{NULL, 0, 0}' - -def represent_default(default_value): - # Encode to UTF-8 in case of WStrings, then remove the b'' from the representation. - return repr(default_value.encode('utf-8'))[2:-1] }@ #include "@(include_base)__functions.h" -// Declare and define all type names, field names, and default values -@[for itype_description in all_type_descriptions]@ -@{ -td_c_typename = typename_to_c(itype_description['type_name']) -}@ -static char @(td_c_typename)__TYPE_NAME[] = "@(itype_description['type_name'])"; -@[ for field in itype_description['fields']]@ -static char @(td_c_typename)__FIELD_NAME__@(field['name'])[] = "@(field['name'])"; -@[ if field['default_value']]@ -static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(escape_string(represent_default(field['default_value'])))"; -@[ end if]@ -@[ end for]@ - -@[end for]@ -@ -/// Define all arrays of Fields -@[for itype_description in all_type_descriptions]@ +@[if disable_description_codegen]@ @{ -td_c_typename = typename_to_c(itype_description['type_name']) +TEMPLATE( + 'empty__description.c.em', + full_type_descriptions=full_type_descriptions) }@ - -@[ if itype_description['fields']]@ -static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { -@[ for field in itype_description['fields']]@ - { - @(static_seq(f"{td_c_typename}__FIELD_NAME__{field['name']}", field['name'])), - { - rosidl_runtime_c__type_description__FieldType__@(FIELD_TYPE_ID_TO_NAME[field['type']['type_id']]), - @(field['type']['capacity']), - @(field['type']['string_capacity']), - @(static_seq(f"{typename_to_c(field['type']['nested_type_name'])}__TYPE_NAME", field['type']['nested_type_name'])), - }, - @(static_seq(f"{td_c_typename}__DEFAULT_VALUE__{field['name']}", field['default_value'])), - }, -@[ end for]@ -}; -@[ end if]@ -@[end for]@ - -/// Define exported TypeDescriptions and TypeSources -@[for msg in full_type_descriptions]@ +@[else]@ @{ -td_typename = msg['type_description']['type_name'] -td_c_typename = typename_to_c(td_typename) -ref_tds = msg['referenced_type_descriptions'] +TEMPLATE( + 'full__description.c.em', + all_type_descriptions=all_type_descriptions, + full_type_descriptions=full_type_descriptions) }@ - -@[ if ref_tds]@ -static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { -@[ for ref_td in ref_tds]@ - { - @(static_seq(f"{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])), - @(static_seq(f"{typename_to_c(ref_td['type_name'])}__FIELDS", ref_td['fields'])), - }, -@[ end for]@ -}; -@[ end if]@ - -const rosidl_runtime_c__type_description__TypeDescription * -@(td_c_typename)__@(GET_DESCRIPTION_FUNC)() -{ - static const rosidl_runtime_c__type_description__TypeDescription description = { - { - @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), - @(static_seq(f'{td_c_typename}__FIELDS', msg['type_description']['fields'])), - }, - @(static_seq(f'{td_c_typename}__REFERENCED_TYPE_DESCRIPTIONS', ref_tds)), - }; - return &description; -} - -const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(td_c_typename)__@(GET_SOURCES_FUNC)() -{ -@# TODO(emersonknapp) Implement raw source code embedding/generation. This sequence is left empty for now. - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = @(static_seq(None, '')); - return &sources; -} -@[end for]@ +@[end if]@ diff --git a/rosidl_generator_c/rosidl_generator_c/__init__.py b/rosidl_generator_c/rosidl_generator_c/__init__.py index 0ad09f2c2..50bb60b9e 100644 --- a/rosidl_generator_c/rosidl_generator_c/__init__.py +++ b/rosidl_generator_c/rosidl_generator_c/__init__.py @@ -28,7 +28,7 @@ from rosidl_pycommon import generate_files -def generate_c(generator_arguments_file): +def generate_c(generator_arguments_file, disable_description_codegen=False): mapping = { 'idl.h.em': '%s.h', 'idl__description.c.em': 'detail/%s__description.c', @@ -40,7 +40,10 @@ def generate_c(generator_arguments_file): } return generate_files( generator_arguments_file, mapping, - post_process_callback=prefix_with_bom_if_necessary) + post_process_callback=prefix_with_bom_if_necessary, + additional_context={ + 'disable_description_codegen': disable_description_codegen + }) def prefix_with_bom_if_necessary(content): From e6fd1854ec1f78caa23e384c58e02d059cb4f4cf Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Fri, 31 Mar 2023 14:48:08 -0700 Subject: [PATCH 02/19] WIP include referenced type descriptions Signed-off-by: Emerson Knapp --- .../cmake/rosidl_generate_interfaces.cmake | 1 + ...sidl_generator_c_generate_interfaces.cmake | 3 ++ .../resource/full__description.c.em | 37 +++++++------------ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake b/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake index c0273e66d..e8f4c96ef 100644 --- a/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake +++ b/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake @@ -240,6 +240,7 @@ macro(rosidl_generate_interfaces target) endif() endforeach() + message(WARNING "NonIdlFiles ${_non_idl_files}") add_custom_target( ${target} ALL DEPENDS diff --git a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake index ad79375c6..bd6d0a50f 100644 --- a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake +++ b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake @@ -78,6 +78,9 @@ foreach(dep ${target_dependencies}) endif() endforeach() +get_target_property(_target_sources ${rosidl_generate_interfaces_TARGET} SOURCES) +message(WARNING "TARGET SOURCES ${_target_sources}") + set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c__arguments.json") rosidl_write_generator_arguments( "${generator_arguments_file}" diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 9732cfbc9..0b264c0c3 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -19,12 +19,19 @@ def represent_default(default_value): return repr(default_value.encode('utf-8'))[2:-1] }@ -// Declare and define all type names, field names, and default values @[for itype_description in all_type_descriptions]@ +static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; +@[end for]@ + +@[for msg in full_type_descriptions]@ @{ -td_c_typename = typename_to_c(itype_description['type_name']) +itype_description = msg['type_description'] +td_typename = itype_description['type_name'] +td_c_typename = typename_to_c(td_typename) +ref_tds = msg['referenced_type_descriptions'] }@ -static char @(td_c_typename)__TYPE_NAME[] = "@(itype_description['type_name'])"; +@ +// Define type names, field names, and default values @[ for field in itype_description['fields']]@ static char @(td_c_typename)__FIELD_NAME__@(field['name'])[] = "@(field['name'])"; @[ if field['default_value']]@ @@ -32,14 +39,8 @@ static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(escape_stri @[ end if]@ @[ end for]@ -@[end for]@ +/// Define arrays of Fields @ -/// Define all arrays of Fields -@[for itype_description in all_type_descriptions]@ -@{ -td_c_typename = typename_to_c(itype_description['type_name']) -}@ - @[ if itype_description['fields']]@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { @[ for field in itype_description['fields']]@ @@ -56,23 +57,12 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { @[ end for]@ }; @[ end if]@ -@[end for]@ - -/// Define exported TypeDescriptions and TypeSources -@[for msg in full_type_descriptions]@ -@{ -td_typename = msg['type_description']['type_name'] -td_c_typename = typename_to_c(td_typename) -ref_tds = msg['referenced_type_descriptions'] -}@ +/// Define exported TypeDescription and TypeSources @[ if ref_tds]@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { @[ for ref_td in ref_tds]@ - { - @(static_seq(f"{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])), - @(static_seq(f"{typename_to_c(ref_td['type_name'])}__FIELDS", ref_td['fields'])), - }, + *@(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(), @[ end for]@ }; @[ end if]@ @@ -80,6 +70,7 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_type const rosidl_runtime_c__type_description__TypeDescription * @(td_c_typename)__@(GET_DESCRIPTION_FUNC)() { + // static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), From faa114a4d82ab29149f176747d29713a860eb832 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Sat, 1 Apr 2023 20:16:44 -0700 Subject: [PATCH 03/19] Including referenced descriptions Signed-off-by: Emerson Knapp --- .../resource/empty__description.c.em | 2 +- .../resource/full__description.c.em | 41 ++++++++++++++++++- .../resource/idl__description.c.em | 40 +++++++++--------- 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/rosidl_generator_c/resource/empty__description.c.em b/rosidl_generator_c/resource/empty__description.c.em index b9dd65fdb..2ec1f0332 100644 --- a/rosidl_generator_c/resource/empty__description.c.em +++ b/rosidl_generator_c/resource/empty__description.c.em @@ -8,7 +8,7 @@ def typename_to_c(typename): }@ /// Define exported TypeDescriptions and TypeSources -@[for msg in full_type_descriptions]@ +@[for msg in [toplevel_type_description] + implicit_type_descriptions]@ @{ td_typename = msg['type_description']['type_name'] td_c_typename = typename_to_c(td_typename) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 0b264c0c3..d0d537ad2 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -1,6 +1,8 @@ @# Included from rosidl_generator_c/resource/idl__description.c.em @{ from rosidl_generator_c import escape_string +from rosidl_generator_c import idl_structure_type_to_c_include_prefix +from rosidl_parser.definition import NamespacedType from rosidl_generator_type_description import FIELD_TYPE_ID_TO_NAME from rosidl_generator_type_description import GET_DESCRIPTION_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC @@ -17,8 +19,28 @@ def static_seq(varname, values): def represent_default(default_value): # Encode to UTF-8 in case of WStrings, then remove the b'' from the representation. return repr(default_value.encode('utf-8'))[2:-1] + +implicit_type_names = set(td['type_description']['type_name'] for td in implicit_type_descriptions) + +includes = set() +for referenced_td in toplevel_type_description['referenced_type_descriptions']: + if referenced_td['type_name'] in implicit_type_names: + continue + names = referenced_td['type_name'].split('/') + _type = NamespacedType(names[:-1], names[-1]) + include_prefix = idl_structure_type_to_c_include_prefix(_type, 'detail') + includes.add(include_prefix + '__functions.h') + +full_type_descriptions = [toplevel_type_description] + implicit_type_descriptions +all_type_descriptions = [toplevel_type_description['type_description']] + toplevel_type_description['referenced_type_descriptions'] }@ +// Include directives for referenced types +@[for header_file in includes]@ +#include "@(header_file)" +@[end for]@ + +// Names for all types @[for itype_description in all_type_descriptions]@ static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; @[end for]@ @@ -62,7 +84,10 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { @[ if ref_tds]@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { @[ for ref_td in ref_tds]@ - *@(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(), + { + @(static_seq(f"{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])), + {NULL, 0, 0}, + }, @[ end for]@ }; @[ end if]@ @@ -70,7 +95,7 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_type const rosidl_runtime_c__type_description__TypeDescription * @(td_c_typename)__@(GET_DESCRIPTION_FUNC)() { - // static bool constructed = false; + static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), @@ -78,6 +103,18 @@ const rosidl_runtime_c__type_description__TypeDescription * }, @(static_seq(f'{td_c_typename}__REFERENCED_TYPE_DESCRIPTIONS', ref_tds)), }; + if (!constructed) { + // TODO(ek) check hashes for consistency +@[ for idx, ref_td in enumerate(ref_tds)]@ + { + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(); + description.referenced_type_descriptions.data[@(idx)].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[@(idx)].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[@(idx)].fields.capacity = ref_desc->type_description.fields.capacity; + } +@[ end for]@ + constructed = true; + } return &description; } diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 13d3ba1a0..be3438ace 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -19,35 +19,34 @@ from rosidl_parser.definition import Service from rosidl_pycommon import convert_camel_case_to_lower_case_underscore type_description_msg = type_description_info['type_description_msg'] -all_type_descriptions = [type_description_msg['type_description']] + type_description_msg['referenced_type_descriptions'] include_parts = [package_name] + list(interface_path.parents[0].parts) + [ 'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)] include_base = '/'.join(include_parts) -full_type_descriptions = [type_description_msg] +implicit_type_descriptions = [] for service in content.get_elements_of_type(Service): - full_type_descriptions.append(extract_subinterface(type_description_msg, 'request_message')) - full_type_descriptions.append(extract_subinterface(type_description_msg, 'response_message')) - full_type_descriptions.append(extract_subinterface(type_description_msg, 'event_message')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'request_message')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'response_message')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'event_message')) for action in content.get_elements_of_type(Action): - full_type_descriptions.append(extract_subinterface(type_description_msg, 'goal')) - full_type_descriptions.append(extract_subinterface(type_description_msg, 'result')) - full_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'goal')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'result')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback')) send_goal_service = extract_subinterface(type_description_msg, 'send_goal_service') - full_type_descriptions.append(send_goal_service) - full_type_descriptions.append(extract_subinterface(send_goal_service, 'request_message')) - full_type_descriptions.append(extract_subinterface(send_goal_service, 'response_message')) - full_type_descriptions.append(extract_subinterface(send_goal_service, 'event_message')) + implicit_type_descriptions.append(send_goal_service) + implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'request_message')) + implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'response_message')) + implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'event_message')) get_result_service = extract_subinterface(type_description_msg, 'get_result_service') - full_type_descriptions.append(get_result_service) - full_type_descriptions.append(extract_subinterface(get_result_service, 'request_message')) - full_type_descriptions.append(extract_subinterface(get_result_service, 'response_message')) - full_type_descriptions.append(extract_subinterface(get_result_service, 'event_message')) + implicit_type_descriptions.append(get_result_service) + implicit_type_descriptions.append(extract_subinterface(get_result_service, 'request_message')) + implicit_type_descriptions.append(extract_subinterface(get_result_service, 'response_message')) + implicit_type_descriptions.append(extract_subinterface(get_result_service, 'event_message')) - full_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback_message')) + implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback_message')) }@ #include "@(include_base)__functions.h" @@ -56,13 +55,14 @@ for action in content.get_elements_of_type(Action): @{ TEMPLATE( 'empty__description.c.em', - full_type_descriptions=full_type_descriptions) + toplevel_type_description=type_description_msg, + implicit_type_descriptions=implicit_type_descriptions) }@ @[else]@ @{ TEMPLATE( 'full__description.c.em', - all_type_descriptions=all_type_descriptions, - full_type_descriptions=full_type_descriptions) + toplevel_type_description=type_description_msg, + implicit_type_descriptions=implicit_type_descriptions) }@ @[end if]@ From d0d7ffa050daab17fc4478e708c6ce2e28de0b4f Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Sun, 2 Apr 2023 14:10:19 -0700 Subject: [PATCH 04/19] Type hash functions, new getter signatures Signed-off-by: Emerson Knapp --- .../resource/full__description.c.em | 20 +++--- .../resource/idl__description.c.em | 56 +++++++++++------ .../resource/idl__functions.h.em | 41 ++++++++++--- rosidl_generator_c/resource/idl__struct.h.em | 55 +++++------------ .../resource/msg__functions.h.em | 10 ++- rosidl_generator_c/resource/msg__struct.h.em | 5 -- .../resource/action__struct.hpp.em | 22 ++----- .../resource/msg__struct.hpp.em | 7 --- .../resource/srv__struct.hpp.em | 12 +--- .../rosidl_generator_c/test_descriptions.c | 28 ++++----- .../HashedTypeDescription.schema.json | 61 +++---------------- .../__init__.py | 2 +- .../action_type_support_struct.h | 17 ++++-- .../message_type_support_struct.h | 15 +++-- .../service_type_support_struct.h | 17 ++++-- .../resource/msg__type_support.c.em | 4 +- .../resource/srv__type_support.c.em | 4 +- .../resource/msg__type_support.cpp.em | 4 +- .../resource/srv__type_support.cpp.em | 4 +- 19 files changed, 180 insertions(+), 204 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index d0d537ad2..8118213c1 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -20,10 +20,11 @@ def represent_default(default_value): # Encode to UTF-8 in case of WStrings, then remove the b'' from the representation. return repr(default_value.encode('utf-8'))[2:-1] -implicit_type_names = set(td['type_description']['type_name'] for td in implicit_type_descriptions) - +implicit_type_names = set(td['type_description']['type_name'] for td, _ in implicit_type_descriptions) includes = set() -for referenced_td in toplevel_type_description['referenced_type_descriptions']: +toplevel_msg, _ = toplevel_type_description + +for referenced_td in toplevel_msg['referenced_type_descriptions']: if referenced_td['type_name'] in implicit_type_names: continue names = referenced_td['type_name'].split('/') @@ -32,7 +33,7 @@ for referenced_td in toplevel_type_description['referenced_type_descriptions']: includes.add(include_prefix + '__functions.h') full_type_descriptions = [toplevel_type_description] + implicit_type_descriptions -all_type_descriptions = [toplevel_type_description['type_description']] + toplevel_type_description['referenced_type_descriptions'] +all_type_descriptions = [toplevel_msg['type_description']] + toplevel_msg['referenced_type_descriptions'] }@ // Include directives for referenced types @@ -45,7 +46,7 @@ all_type_descriptions = [toplevel_type_description['type_description']] + toplev static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; @[end for]@ -@[for msg in full_type_descriptions]@ +@[for msg, interface_type in full_type_descriptions]@ @{ itype_description = msg['type_description'] td_typename = itype_description['type_name'] @@ -93,7 +94,7 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_type @[ end if]@ const rosidl_runtime_c__type_description__TypeDescription * -@(td_c_typename)__@(GET_DESCRIPTION_FUNC)() +@(td_c_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_@(interface_type)_type_support_t *) { static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { @@ -107,7 +108,8 @@ const rosidl_runtime_c__type_description__TypeDescription * // TODO(ek) check hashes for consistency @[ for idx, ref_td in enumerate(ref_tds)]@ { - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @ + @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(NULL); description.referenced_type_descriptions.data[@(idx)].fields.data = ref_desc->type_description.fields.data; description.referenced_type_descriptions.data[@(idx)].fields.size = ref_desc->type_description.fields.size; description.referenced_type_descriptions.data[@(idx)].fields.capacity = ref_desc->type_description.fields.capacity; @@ -119,9 +121,9 @@ const rosidl_runtime_c__type_description__TypeDescription * } const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(td_c_typename)__@(GET_SOURCES_FUNC)() +@(td_c_typename)__@(GET_SOURCES_FUNC)(const rosidl_@(interface_type)_type_support_t *) { -@# TODO(emersonknapp) Implement raw source code embedding/generation. This sequence is left empty for now. +@# TODO(ek) Implement raw source code embedding/generation. This sequence is left empty for now. static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = @(static_seq(None, '')); return &sources; } diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index be3438ace..82ec5dcf3 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -14,6 +14,7 @@ @####################################################################### @{ from rosidl_generator_type_description import extract_subinterface +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_parser.definition import Action from rosidl_parser.definition import Service from rosidl_pycommon import convert_camel_case_to_lower_case_underscore @@ -25,44 +26,61 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + [ include_base = '/'.join(include_parts) implicit_type_descriptions = [] +toplevel_type_description = (type_description_msg, 'message') for service in content.get_elements_of_type(Service): - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'request_message')) - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'response_message')) - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'event_message')) + toplevel_type_description = (type_description_msg, 'service') + implicit_type_descriptions.extend([ + (extract_subinterface(type_description_msg, 'request_message'), 'message'), + (extract_subinterface(type_description_msg, 'response_message'), 'message'), + (extract_subinterface(type_description_msg, 'event_message'), 'message'), + ]) for action in content.get_elements_of_type(Action): - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'goal')) - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'result')) - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback')) - + toplevel_type_description = (type_description_msg, 'action') send_goal_service = extract_subinterface(type_description_msg, 'send_goal_service') - implicit_type_descriptions.append(send_goal_service) - implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'request_message')) - implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'response_message')) - implicit_type_descriptions.append(extract_subinterface(send_goal_service, 'event_message')) - get_result_service = extract_subinterface(type_description_msg, 'get_result_service') - implicit_type_descriptions.append(get_result_service) - implicit_type_descriptions.append(extract_subinterface(get_result_service, 'request_message')) - implicit_type_descriptions.append(extract_subinterface(get_result_service, 'response_message')) - implicit_type_descriptions.append(extract_subinterface(get_result_service, 'event_message')) + implicit_type_descriptions.extend([ + (extract_subinterface(type_description_msg, 'goal'), 'message'), + (extract_subinterface(type_description_msg, 'result'), 'message'), + (extract_subinterface(type_description_msg, 'feedback'), 'message'), - implicit_type_descriptions.append(extract_subinterface(type_description_msg, 'feedback_message')) + (send_goal_service, 'service'), + (extract_subinterface(send_goal_service, 'request_message'), 'message'), + (extract_subinterface(send_goal_service, 'response_message'), 'message'), + (extract_subinterface(send_goal_service, 'event_message'), 'message'), + + (get_result_service, 'service'), + (extract_subinterface(get_result_service, 'request_message'), 'message'), + (extract_subinterface(get_result_service, 'response_message'), 'message'), + (extract_subinterface(get_result_service, 'event_message'), 'message'), + (extract_subinterface(type_description_msg, 'feedback_message'), 'message'), + ]) }@ #include "@(include_base)__functions.h" +@[for msg, interface_type in [toplevel_type_description] + implicit_type_descriptions]@ +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(msg['type_description']['type_name'].replace('/', '__'))__@(GET_HASH_FUNC)(const rosidl_@(interface_type)_type_support_t *) +{ + // TODO(ek) + static rosidl_type_hash_t hash; + return &hash; +} +@[end for]@ + @[if disable_description_codegen]@ @{ TEMPLATE( 'empty__description.c.em', - toplevel_type_description=type_description_msg, + toplevel_type_description=toplevel_type_description, implicit_type_descriptions=implicit_type_descriptions) }@ @[else]@ @{ TEMPLATE( 'full__description.c.em', - toplevel_type_description=type_description_msg, + toplevel_type_description=toplevel_type_description, implicit_type_descriptions=implicit_type_descriptions) }@ @[end if]@ diff --git a/rosidl_generator_c/resource/idl__functions.h.em b/rosidl_generator_c/resource/idl__functions.h.em index 5f613a495..102f7e12e 100644 --- a/rosidl_generator_c/resource/idl__functions.h.em +++ b/rosidl_generator_c/resource/idl__functions.h.em @@ -13,6 +13,7 @@ @{ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC from rosidl_pycommon import convert_camel_case_to_lower_case_underscore include_parts = [package_name] + list(interface_path.parents[0].parts) + [ @@ -33,8 +34,12 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" #include "rosidl_runtime_c/type_description/type_description__struct.h" #include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "@(package_name)/msg/rosidl_generator_c__visibility_control.h" @@ -66,15 +71,20 @@ from rosidl_parser.definition import Service @{ service_typename = idl_structure_type_to_c_typename(service.namespaced_type) }@ +/// Retrieve pointer to the hash of the description of the service type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(service_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); + /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(service_typename)__@(GET_DESCRIPTION_FUNC)(); +@(service_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(service_typename)__@(GET_SOURCES_FUNC)(); +@(service_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); @{ TEMPLATE( @@ -110,15 +120,20 @@ action_typename = idl_structure_type_to_c_typename(action.namespaced_type) send_goal_srv_typename = idl_structure_type_to_c_typename(action.send_goal_service.namespaced_type) get_result_srv_typename = idl_structure_type_to_c_typename(action.get_result_service.namespaced_type) }@ +/// Retrieve pointer to the hash of the description of the service type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(action_typename)__@(GET_HASH_FUNC)(const rosidl_action_type_support_t *); + /// Retrieve pointer to the description of the action type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(action_typename)__@(GET_DESCRIPTION_FUNC)(); +@(action_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_action_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the action type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(action_typename)__@(GET_SOURCES_FUNC)(); +@(action_typename)__@(GET_SOURCES_FUNC)(const rosidl_action_type_support_t *); @{ TEMPLATE( @@ -141,15 +156,20 @@ TEMPLATE( message=action.feedback) }@ +/// Retrieve pointer to the hash of the description of the service type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(send_goal_srv_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); + /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(send_goal_srv_typename)__@(GET_DESCRIPTION_FUNC)(); +@(send_goal_srv_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(send_goal_srv_typename)__@(GET_SOURCES_FUNC)(); +@(send_goal_srv_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); @{ TEMPLATE( @@ -172,15 +192,20 @@ TEMPLATE( message=action.send_goal_service.event_message) }@ +/// Retrieve pointer to the hash of the description of the service type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(get_result_srv_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); + /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(get_result_srv_typename)__@(GET_DESCRIPTION_FUNC)(); +@(get_result_srv_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(get_result_srv_typename)__@(GET_SOURCES_FUNC)(); +@(get_result_srv_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); @{ TEMPLATE( diff --git a/rosidl_generator_c/resource/idl__struct.h.em b/rosidl_generator_c/resource/idl__struct.h.em index 74b58109a..1bea018f2 100644 --- a/rosidl_generator_c/resource/idl__struct.h.em +++ b/rosidl_generator_c/resource/idl__struct.h.em @@ -9,12 +9,9 @@ @# - package_name (string) @# - interface_path (Path relative to the directory named after the package) @# - content (IdlContent, list of elements, e.g. Messages or Services) -@# - type_description_info (HashedTypeDescription.schema.json dict) @####################################################################### @{ from rosidl_generator_c import idl_structure_type_to_c_typename -from rosidl_generator_c import type_hash_to_c_definition -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_pycommon import convert_camel_case_to_lower_case_underscore include_parts = [package_name] + list(interface_path.parents[0].parts) + [ 'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)] @@ -22,7 +19,6 @@ header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ '__STRUCT_H_' include_directives = set() -type_hash = type_description_info['hashes'] }@ #ifndef @(header_guard_variable) @@ -37,8 +33,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - @####################################################################### @# Handle message @####################################################################### @@ -50,7 +44,7 @@ from rosidl_parser.definition import Message TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=message, include_directives=include_directives, type_hash=type_hash) + message=message, include_directives=include_directives) }@ @[end for]@ @@ -63,30 +57,25 @@ from rosidl_parser.definition import Service }@ @[for service in content.get_elements_of_type(Service)]@ -static const rosidl_type_hash_t @(idl_structure_type_to_c_typename(service.namespaced_type))__@(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['service'])); - @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=service.request_message, include_directives=include_directives, - type_hash=type_hash['request_message']) + message=service.request_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=service.response_message, include_directives=include_directives, - type_hash=type_hash['response_message']) + message=service.response_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=service.event_message, include_directives=include_directives, - type_hash=type_hash['event_message']) + message=service.event_message, include_directives=include_directives) }@ @[end for]@ @@ -99,90 +88,74 @@ from rosidl_parser.definition import Action }@ @[for action in content.get_elements_of_type(Action)]@ -static const rosidl_type_hash_t @(idl_structure_type_to_c_typename(action.namespaced_type))__@(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['action'])); - @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.goal, include_directives=include_directives, - type_hash=type_hash['goal']) + message=action.goal, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.result, include_directives=include_directives, - type_hash=type_hash['result']) + message=action.result, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.feedback, include_directives=include_directives, - type_hash=type_hash['feedback']) + message=action.feedback, include_directives=include_directives) }@ -static const rosidl_type_hash_t @(idl_structure_type_to_c_typename(action.send_goal_service.namespaced_type))__@(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['send_goal_service']['service'])); - @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.send_goal_service.request_message, include_directives=include_directives, - type_hash=type_hash['send_goal_service']['request_message']) + message=action.send_goal_service.request_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.send_goal_service.response_message, include_directives=include_directives, - type_hash=type_hash['send_goal_service']['response_message']) + message=action.send_goal_service.response_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.send_goal_service.event_message, include_directives=include_directives, - type_hash=type_hash['send_goal_service']['event_message']) + message=action.send_goal_service.event_message, include_directives=include_directives) }@ -static const rosidl_type_hash_t @(idl_structure_type_to_c_typename(action.get_result_service.namespaced_type))__@(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['get_result_service']['service'])); - @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.get_result_service.request_message, include_directives=include_directives, - type_hash=type_hash['get_result_service']['request_message']) + message=action.get_result_service.request_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.get_result_service.response_message, include_directives=include_directives, - type_hash=type_hash['get_result_service']['response_message']) + message=action.get_result_service.response_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.get_result_service.event_message, include_directives=include_directives, - type_hash=type_hash['get_result_service']['event_message']) + message=action.get_result_service.event_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.h.em', package_name=package_name, interface_path=interface_path, - message=action.feedback_message, include_directives=include_directives, - type_hash=type_hash['feedback_message']) + message=action.feedback_message, include_directives=include_directives) }@ @[end for]@ diff --git a/rosidl_generator_c/resource/msg__functions.h.em b/rosidl_generator_c/resource/msg__functions.h.em index db1e96332..bd5f79c56 100644 --- a/rosidl_generator_c/resource/msg__functions.h.em +++ b/rosidl_generator_c/resource/msg__functions.h.em @@ -4,6 +4,7 @@ from rosidl_generator_c import idl_structure_type_sequence_to_c_typename from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_c import interface_path_to_string from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC message_typename = idl_structure_type_to_c_typename(message.structure.namespaced_type) @@ -88,15 +89,20 @@ bool const @(message_typename) * input, @(message_typename) * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_type_hash_t * +@(message_typename)__@(GET_HASH_FUNC)(const rosidl_message_type_support_t *); + /// Retrieve pointer to the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(message_typename)__@(GET_DESCRIPTION_FUNC)(); +@(message_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_message_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(message_typename)__@(GET_SOURCES_FUNC)(); +@(message_typename)__@(GET_SOURCES_FUNC)(const rosidl_message_type_support_t *); @####################################################################### @# array functions diff --git a/rosidl_generator_c/resource/msg__struct.h.em b/rosidl_generator_c/resource/msg__struct.h.em index 838eababf..f0b99e166 100644 --- a/rosidl_generator_c/resource/msg__struct.h.em +++ b/rosidl_generator_c/resource/msg__struct.h.em @@ -21,9 +21,7 @@ from rosidl_generator_c import idl_structure_type_sequence_to_c_typename from rosidl_generator_c import idl_structure_type_to_c_include_prefix from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_c import interface_path_to_string -from rosidl_generator_c import type_hash_to_c_definition from rosidl_generator_c import value_to_c -from rosidl_generator_type_description import TYPE_HASH_VAR }@ @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @# Collect necessary include directives for all members @@ -64,9 +62,6 @@ for member in message.structure.members: @#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -// Type Hash for interface -static const rosidl_type_hash_t @(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['message'])); - // Constants defined in the message @[for constant in message.constants]@ diff --git a/rosidl_generator_cpp/resource/action__struct.hpp.em b/rosidl_generator_cpp/resource/action__struct.hpp.em index efb630496..020455074 100644 --- a/rosidl_generator_cpp/resource/action__struct.hpp.em +++ b/rosidl_generator_cpp/resource/action__struct.hpp.em @@ -1,7 +1,5 @@ @# Included from rosidl_generator_cpp/resource/idl__struct.hpp.em @{ -from rosidl_generator_c import type_hash_to_c_definition -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import ACTION_FEEDBACK_MESSAGE_SUFFIX from rosidl_parser.definition import ACTION_FEEDBACK_SUFFIX from rosidl_parser.definition import ACTION_GOAL_SERVICE_SUFFIX @@ -19,48 +17,42 @@ action_name = '::'.join(action.namespaced_type.namespaced_name()) TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=action.goal, include_directives=include_directives, - type_hash=type_hash['goal']) + message=action.goal, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=action.result, include_directives=include_directives, - type_hash=type_hash['result']) + message=action.result, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=action.feedback, include_directives=include_directives, - type_hash=type_hash['feedback']) + message=action.feedback, include_directives=include_directives) }@ @{ TEMPLATE( 'srv__struct.hpp.em', package_name=package_name, interface_path=interface_path, - service=action.send_goal_service, include_directives=include_directives, - type_hash=type_hash['send_goal_service']) + service=action.send_goal_service, include_directives=include_directives) }@ @{ TEMPLATE( 'srv__struct.hpp.em', package_name=package_name, interface_path=interface_path, - service=action.get_result_service, include_directives=include_directives, - type_hash=type_hash['get_result_service']) + service=action.get_result_service, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=action.feedback_message, include_directives=include_directives, - type_hash=type_hash['feedback_message']) + message=action.feedback_message, include_directives=include_directives) }@ @[for header_file in action_includes]@ @@ -80,8 +72,6 @@ namespace @(ns) @[end for]@ struct @(action.namespaced_type.name) { - static constexpr const rosidl_type_hash_t @(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['action'], indent=4)); - /// The goal message defined in the action definition. using Goal = @(action_name)@(ACTION_GOAL_SUFFIX); /// The result message defined in the action definition. diff --git a/rosidl_generator_cpp/resource/msg__struct.hpp.em b/rosidl_generator_cpp/resource/msg__struct.hpp.em index bea08a923..02097f15e 100644 --- a/rosidl_generator_cpp/resource/msg__struct.hpp.em +++ b/rosidl_generator_cpp/resource/msg__struct.hpp.em @@ -1,12 +1,10 @@ @# Included from rosidl_generator_cpp/resource/idl__struct.hpp.em @{ -from rosidl_generator_c import type_hash_to_c_definition from rosidl_generator_cpp import create_init_alloc_and_member_lists from rosidl_generator_cpp import escape_string from rosidl_generator_cpp import escape_wstring from rosidl_generator_cpp import msg_type_to_cpp from rosidl_generator_cpp import MSG_TYPE_TO_CPP -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractString from rosidl_parser.definition import AbstractWString @@ -103,8 +101,6 @@ struct @(message.structure.namespaced_type.name)_ { using Type = @(message.structure.namespaced_type.name)_; - constexpr static const rosidl_type_hash_t @(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['message'], indent=4)); - @{ # The creation of the constructors for messages is a bit complicated. The goal # is to have a constructor where the user can control how the fields of the @@ -361,9 +357,6 @@ u@ using @(message.structure.namespaced_type.name) = @(message_typename)_>; -template -constexpr const rosidl_type_hash_t @(message.structure.namespaced_type.name)_::@(TYPE_HASH_VAR); - // constant definitions @[for c in message.constants]@ @[ if c.name in msvc_common_macros]@ diff --git a/rosidl_generator_cpp/resource/srv__struct.hpp.em b/rosidl_generator_cpp/resource/srv__struct.hpp.em index 9a1f75644..69d4422ed 100644 --- a/rosidl_generator_cpp/resource/srv__struct.hpp.em +++ b/rosidl_generator_cpp/resource/srv__struct.hpp.em @@ -1,7 +1,6 @@ @# Included from rosidl_generator_cpp/resource/idl__struct.hpp.em @{ from rosidl_generator_c import type_hash_to_c_definition -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import SERVICE_EVENT_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_REQUEST_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX @@ -10,24 +9,21 @@ from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=service.request_message, include_directives=include_directives, - type_hash=type_hash['request_message']) + message=service.request_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=service.response_message, include_directives=include_directives, - type_hash=type_hash['response_message']) + message=service.response_message, include_directives=include_directives) }@ @{ TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=service.event_message, include_directives=include_directives, - type_hash=type_hash['event_message']) + message=service.event_message, include_directives=include_directives) }@ @[for ns in service.namespaced_type.namespaces]@ @@ -41,8 +37,6 @@ struct @(service.namespaced_type.name) @{ service_typename = '::'.join(service.namespaced_type.namespaced_name()) }@ - static constexpr const rosidl_type_hash_t @(TYPE_HASH_VAR) = @(type_hash_to_c_definition(type_hash['service'], indent=4)); - using Request = @(service_typename)@(SERVICE_REQUEST_MESSAGE_SUFFIX); using Response = @(service_typename)@(SERVICE_RESPONSE_MESSAGE_SUFFIX); using Event = @(service_typename)@(SERVICE_EVENT_MESSAGE_SUFFIX); diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index 7acadff87..b35d1359a 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -53,8 +53,8 @@ int main(int argc, char ** argv) // Message if (0 != test_basic( - rosidl_generator_tests__msg__Defaults__get_type_description(), - rosidl_generator_tests__msg__Defaults__get_type_description_sources(), + rosidl_generator_tests__msg__Defaults__get_type_description(NULL), + rosidl_generator_tests__msg__Defaults__get_type_description_sources(NULL), "rosidl_generator_tests/msg/Defaults")) { return 1; @@ -62,16 +62,16 @@ int main(int argc, char ** argv) // Service if (0 != test_basic( - rosidl_generator_tests__srv__Empty__get_type_description(), - rosidl_generator_tests__srv__Empty__get_type_description_sources(), + rosidl_generator_tests__srv__Empty__get_type_description(NULL), + rosidl_generator_tests__srv__Empty__get_type_description_sources(NULL), "rosidl_generator_tests/srv/Empty")) { return 1; } // Implicit message of a service if (0 != test_basic( - rosidl_generator_tests__srv__Empty_Request__get_type_description(), - rosidl_generator_tests__srv__Empty_Request__get_type_description_sources(), + rosidl_generator_tests__srv__Empty_Request__get_type_description(NULL), + rosidl_generator_tests__srv__Empty_Request__get_type_description_sources(NULL), "rosidl_generator_tests/srv/Empty_Request")) { return 1; @@ -79,32 +79,32 @@ int main(int argc, char ** argv) // Action if (0 != test_basic( - rosidl_generator_tests__action__Fibonacci__get_type_description(), - rosidl_generator_tests__action__Fibonacci__get_type_description_sources(), + rosidl_generator_tests__action__Fibonacci__get_type_description(NULL), + rosidl_generator_tests__action__Fibonacci__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci")) { return 1; } // Implicit message of an action if (0 != test_basic( - rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description(), - rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description_sources(), + rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description(NULL), + rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci_Feedback")) { return 1; } // Implicit service of an action if (0 != test_basic( - rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description(), - rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description_sources(), + rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description(NULL), + rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci_SendGoal")) { return 1; } // Implicit message of implicit service of an action if (0 != test_basic( - rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description(), - rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description_sources(), + rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description(NULL), + rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci_GetResult_Request")) { return 1; diff --git a/rosidl_generator_type_description/resource/HashedTypeDescription.schema.json b/rosidl_generator_type_description/resource/HashedTypeDescription.schema.json index 78c9918d6..c53a07e37 100644 --- a/rosidl_generator_type_description/resource/HashedTypeDescription.schema.json +++ b/rosidl_generator_type_description/resource/HashedTypeDescription.schema.json @@ -5,63 +5,22 @@ "description": "Contains hashes and full type description for a ROS 2 interface. TypeDescription, IndividualTypeDescription, Field, and FieldType are exact representations of type_description_interfaces/msg types, see their .msg files for semantic comments.", "type": "object", "properties": { - "hashes": { - "type": "object", - "oneOf": [ - { "$ref": "#/$defs/MessageHash" }, - { "$ref": "#/$defs/ServiceHashes" }, - { "$ref": "#/$defs/ActionHashes" } - ] - }, - "type_description_msg": { "$ref": "#/$defs/TypeDescription" } + "type_description_msg": { "$ref": "#/$defs/TypeDescription" }, + "type_hashes": { + "type": "array", + "items": { "$ref": "#/$defs/TypeNameAndHash" } + } }, - "required": ["hashes", "type_description_msg"], + "required": ["type_description_msg", "type_hashes"], "additionalProperties": false, "$defs": { - "MessageHash": { - "type": "object", - "properties": { - "message": { "type": "string" } - }, - "required": [ "message" ], - "additionalProperties": false - }, - "ServiceHashes": { - "type": "object", - "properties": { - "service": { "type": "string" }, - "request_message": { "$ref": "#/$defs/MessageHash" }, - "response_message": { "$ref": "#/$defs/MessageHash" }, - "event_message": { "$ref": "#/$defs/MessageHash" } - }, - "required": [ - "service", - "request_message", - "response_message", - "event_message" - ], - "additionalProperties": false - }, - "ActionHashes": { + "TypeNameAndHash": { "type": "object", "properties": { - "action": { "type": "string" }, - "goal": { "$ref": "#/$defs/MessageHash" }, - "result": { "$ref": "#/$defs/MessageHash" }, - "feedback": { "$ref": "#/$defs/MessageHash" }, - "send_goal_service": { "$ref": "#/$defs/ServiceHashes" }, - "get_result_service": { "$ref": "#/$defs/ServiceHashes" }, - "feedback_message": { "$ref": "#/$defs/MessageHash" } + "type_name": { "type": "string" }, + "hash_string": { "type": "string" } }, - "required": [ - "action", - "goal", - "result", - "feedback", - "send_goal_service", - "get_result_service", - "feedback_message" - ], + "required": [ "type_name", "hash_string" ], "additionalProperties": false }, "TypeDescription": { diff --git a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py index 4bf271c65..2bd74c0de 100644 --- a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py +++ b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py @@ -34,8 +34,8 @@ # Used by code generators to create variable names GET_DESCRIPTION_FUNC = 'get_type_description' +GET_HASH_FUNC = 'get_type_hash' GET_SOURCES_FUNC = 'get_type_description_sources' -TYPE_HASH_VAR = 'TYPE_HASH' def generate_type_hash(generator_arguments_file: str) -> List[str]: diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/action_type_support_struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/action_type_support_struct.h index d2adebfe9..62b45b036 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/action_type_support_struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/action_type_support_struct.h @@ -28,6 +28,15 @@ extern "C" typedef struct rosidl_action_type_support_t rosidl_action_type_support_t; +typedef const rosidl_type_hash_t * +(* rosidl_action_get_type_hash_function)(const rosidl_action_type_support_t *); + +typedef const rosidl_runtime_c__type_description__TypeDescription * +(* rosidl_action_get_type_description_function)(const rosidl_action_type_support_t *); + +typedef const rosidl_runtime_c__type_description__TypeSource__Sequence * +(* rosidl_action_get_type_description_sources_function)(const rosidl_action_type_support_t *); + /// Contains rosidl action type support data. /* * Actions are built based on services(goal, result and cancel) and message (feedback and status). @@ -39,12 +48,12 @@ struct rosidl_action_type_support_t const rosidl_service_type_support_t * cancel_service_type_support; const rosidl_message_type_support_t * feedback_message_type_support; const rosidl_message_type_support_t * status_message_type_support; - /// Hash of the action's description - const rosidl_type_hash_t * type_hash; + /// Pointer to function to get the hash of the action's description + rosidl_action_get_type_hash_function get_type_hash_func; /// Pointer to function to get the description of the type - rosidl_get_type_description_function get_type_description_func; + rosidl_action_get_type_description_function get_type_description_func; /// Pointer to function to get the text of the sources that defined the description of the type - rosidl_get_type_description_sources_function get_type_description_sources_func; + rosidl_action_get_type_description_sources_function get_type_description_sources_func; }; /// Get the action type support given a provided action and package. diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/message_type_support_struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/message_type_support_struct.h index 49c4130de..08a254f6b 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/message_type_support_struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/message_type_support_struct.h @@ -31,11 +31,14 @@ typedef struct rosidl_message_type_support_t rosidl_message_type_support_t; typedef const rosidl_message_type_support_t * (* rosidl_message_typesupport_handle_function)( const rosidl_message_type_support_t *, const char *); +typedef const rosidl_type_hash_t * +(* rosidl_message_get_type_hash_function)(const rosidl_message_type_support_t *); + typedef const rosidl_runtime_c__type_description__TypeDescription * -(* rosidl_get_type_description_function)(); +(* rosidl_message_get_type_description_function)(const rosidl_message_type_support_t *); typedef const rosidl_runtime_c__type_description__TypeSource__Sequence * -(* rosidl_get_type_description_sources_function)(); +(* rosidl_message_get_type_description_sources_function)(const rosidl_message_type_support_t *); /// Contains rosidl message type support data struct rosidl_message_type_support_t @@ -46,12 +49,12 @@ struct rosidl_message_type_support_t const void * data; /// Pointer to the message type support handler function rosidl_message_typesupport_handle_function func; - /// Hash of the message's description - const rosidl_type_hash_t * type_hash; + /// Pointer to function to get the hash of the message's description + rosidl_message_get_type_hash_function get_type_hash_func; /// Pointer to function to get the description of the type - rosidl_get_type_description_function get_type_description_func; + rosidl_message_get_type_description_function get_type_description_func; /// Pointer to function to get the text of the sources that defined the description of the type - rosidl_get_type_description_sources_function get_type_description_sources_func; + rosidl_message_get_type_description_sources_function get_type_description_sources_func; }; /// Get the message type support handle specific to this identifier. diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/service_type_support_struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/service_type_support_struct.h index be562ef04..c6009ecd3 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/service_type_support_struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/service_type_support_struct.h @@ -73,6 +73,15 @@ typedef bool (* rosidl_event_message_destroy_handle_function_function)( void * event_message, rcutils_allocator_t * allocator); +typedef const rosidl_type_hash_t * +(* rosidl_service_get_type_hash_function)(const rosidl_service_type_support_t *); + +typedef const rosidl_runtime_c__type_description__TypeDescription * +(* rosidl_service_get_type_description_function)(const rosidl_service_type_support_t *); + +typedef const rosidl_runtime_c__type_description__TypeSource__Sequence * +(* rosidl_service_get_type_description_sources_function)(const rosidl_service_type_support_t *); + /// Contains rosidl service type support data struct rosidl_service_type_support_t { @@ -92,12 +101,12 @@ struct rosidl_service_type_support_t rosidl_event_message_create_handle_function_function event_message_create_handle_function; /// Pointer to function to finalize the introspection message rosidl_event_message_destroy_handle_function_function event_message_destroy_handle_function; - /// Hash of the service's description - const rosidl_type_hash_t * type_hash; + /// Pointer to function to get the hash of the message's description + rosidl_service_get_type_hash_function get_type_hash_func; /// Pointer to function to get the description of the type - rosidl_get_type_description_function get_type_description_func; + rosidl_service_get_type_description_function get_type_description_func; /// Pointer to function to get the text of the sources that defined the description of the type - rosidl_get_type_description_sources_function get_type_description_sources_func; + rosidl_service_get_type_description_sources_function get_type_description_sources_func; }; /// Get the service type support handle specific to this identifier. 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 baa82e9b3..de392983f 100644 --- a/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em +++ b/rosidl_typesupport_introspection_c/resource/msg__type_support.c.em @@ -4,8 +4,8 @@ from rosidl_pycommon import convert_camel_case_to_lower_case_underscore from rosidl_generator_c import idl_structure_type_to_c_include_prefix from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence @@ -287,7 +287,7 @@ static rosidl_message_type_support_t @(function_prefix)__@(message.structure.nam 0, &@(function_prefix)__@(message.structure.namespaced_type.name)_message_members, get_message_typesupport_handle_function, - &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(TYPE_HASH_VAR), + &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_HASH_FUNC), &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_DESCRIPTION_FUNC), &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_SOURCES_FUNC), }; diff --git a/rosidl_typesupport_introspection_c/resource/srv__type_support.c.em b/rosidl_typesupport_introspection_c/resource/srv__type_support.c.em index 6b789cb21..1977a86e9 100644 --- a/rosidl_typesupport_introspection_c/resource/srv__type_support.c.em +++ b/rosidl_typesupport_introspection_c/resource/srv__type_support.c.em @@ -23,8 +23,8 @@ TEMPLATE( @{ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import SERVICE_EVENT_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_REQUEST_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX @@ -89,7 +89,7 @@ static rosidl_service_type_support_t @(function_prefix)__@(service.namespaced_ty rosidl_typesupport_c, @(',\n '.join(service.namespaced_type.namespaced_name())) ), - &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(TYPE_HASH_VAR), + &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_HASH_FUNC), &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_DESCRIPTION_FUNC), &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_SOURCES_FUNC), }; 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 3d232ebdc..679907386 100644 --- a/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em +++ b/rosidl_typesupport_introspection_cpp/resource/msg__type_support.cpp.em @@ -2,8 +2,8 @@ @{ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import AbstractGenericString from rosidl_parser.definition import AbstractNestedType from rosidl_parser.definition import AbstractSequence @@ -251,7 +251,7 @@ static const rosidl_message_type_support_t @(message.structure.namespaced_type.n ::rosidl_typesupport_introspection_cpp::typesupport_identifier, &@(message.structure.namespaced_type.name)_message_members, get_message_typesupport_handle_function, - &@('::'.join(message.structure.namespaced_type.namespaced_name()))::@(TYPE_HASH_VAR), + &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_HASH_FUNC), &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_DESCRIPTION_FUNC), &@(idl_structure_type_to_c_typename(message.structure.namespaced_type))__@(GET_SOURCES_FUNC), }; diff --git a/rosidl_typesupport_introspection_cpp/resource/srv__type_support.cpp.em b/rosidl_typesupport_introspection_cpp/resource/srv__type_support.cpp.em index 67699eceb..227d1915e 100644 --- a/rosidl_typesupport_introspection_cpp/resource/srv__type_support.cpp.em +++ b/rosidl_typesupport_introspection_cpp/resource/srv__type_support.cpp.em @@ -23,8 +23,8 @@ TEMPLATE( @{ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC -from rosidl_generator_type_description import TYPE_HASH_VAR from rosidl_parser.definition import SERVICE_EVENT_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_REQUEST_MESSAGE_SUFFIX from rosidl_parser.definition import SERVICE_RESPONSE_MESSAGE_SUFFIX @@ -84,7 +84,7 @@ static const rosidl_service_type_support_t @(service.namespaced_type.name)_servi ::rosidl_typesupport_introspection_cpp::get_message_type_support_handle<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))@(SERVICE_EVENT_MESSAGE_SUFFIX)>(), &::rosidl_typesupport_cpp::service_create_event_message<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))>, &::rosidl_typesupport_cpp::service_destroy_event_message<@('::'.join([package_name, *interface_path.parents[0].parts, service.namespaced_type.name]))>, - &@('::'.join(service.namespaced_type.namespaced_name()))::@(TYPE_HASH_VAR), + &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_HASH_FUNC), &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_DESCRIPTION_FUNC), &@(idl_structure_type_to_c_typename(service.namespaced_type))__@(GET_SOURCES_FUNC), }; From 96f373b95728b05649d06e43992ee25ab9dadda8 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Sun, 2 Apr 2023 15:14:43 -0700 Subject: [PATCH 05/19] Generating hashes in usable form and putting in description function Signed-off-by: Emerson Knapp --- .../resource/full__description.c.em | 3 +- .../resource/idl__description.c.em | 16 ++++-- .../rosidl_generator_c/test_descriptions.c | 3 +- .../__init__.py | 56 +++++++++++++------ 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 8118213c1..e0bfae666 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -108,8 +108,7 @@ const rosidl_runtime_c__type_description__TypeDescription * // TODO(ek) check hashes for consistency @[ for idx, ref_td in enumerate(ref_tds)]@ { - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @ - @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(NULL); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(NULL); description.referenced_type_descriptions.data[@(idx)].fields.data = ref_desc->type_description.fields.data; description.referenced_type_descriptions.data[@(idx)].fields.size = ref_desc->type_description.fields.size; description.referenced_type_descriptions.data[@(idx)].fields.capacity = ref_desc->type_description.fields.capacity; diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 82ec5dcf3..188b4488c 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -13,6 +13,7 @@ @# - disable_description_codegen (bool) @####################################################################### @{ +from rosidl_generator_c import type_hash_to_c_definition from rosidl_generator_type_description import extract_subinterface from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_parser.definition import Action @@ -20,6 +21,10 @@ from rosidl_parser.definition import Service from rosidl_pycommon import convert_camel_case_to_lower_case_underscore type_description_msg = type_description_info['type_description_msg'] +hash_lookup = { + val['type_name']: val['hash_string'] + for val in type_description_info['type_hashes'] +} include_parts = [package_name] + list(interface_path.parents[0].parts) + [ 'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)] @@ -58,13 +63,16 @@ for action in content.get_elements_of_type(Action): #include "@(include_base)__functions.h" -@[for msg, interface_type in [toplevel_type_description] + implicit_type_descriptions]@ +@[for type_description_msg, interface_type in [toplevel_type_description] + implicit_type_descriptions]@ +@{ +typename = type_description_msg['type_description']['type_name'] +c_typename = typename.replace('/', '__') +}@ ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(msg['type_description']['type_name'].replace('/', '__'))__@(GET_HASH_FUNC)(const rosidl_@(interface_type)_type_support_t *) +@(c_typename)__@(GET_HASH_FUNC)(const rosidl_@(interface_type)_type_support_t *) { - // TODO(ek) - static rosidl_type_hash_t hash; + static rosidl_type_hash_t hash = @(type_hash_to_c_definition(hash_lookup[typename])); return &hash; } @[end for]@ diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index b35d1359a..7cdb068ca 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -104,7 +104,8 @@ int main(int argc, char ** argv) // Implicit message of implicit service of an action if (0 != test_basic( rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description(NULL), - rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description_sources(NULL), + rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description_sources( + NULL), "rosidl_generator_tests/action/Fibonacci_GetResult_Request")) { return 1; diff --git a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py index 2bd74c0de..70faba76a 100644 --- a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py +++ b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py @@ -78,9 +78,12 @@ def generate_type_hash(generator_arguments_file: str) -> List[str]: hasher = InterfaceHasher.from_idl(idl_file) hashers[hasher.namespaced_type.namespaced_name()] = hasher - # Generate output files + # Generate output representation for hasher in hashers.values(): - generated_files += hasher.write_unified_json(output_dir, hashers, include_map) + hasher.generate_full_description(output_dir, hashers, include_map) + # Calculate hashes and write to generated json file + for hasher in hashers.values(): + generated_files += hasher.write_unified_json(output_dir) return generated_files @@ -392,6 +395,8 @@ def __init__(self, interface): self.individual_type_description = serialize_individual_type_description( self.namespaced_type, self.members) + self.all_type_hashes = {} + self.pending_local_hashes = set() # Determine needed includes from member fields self.includes = [] @@ -407,14 +412,11 @@ def __init__(self, interface): self.rel_path = Path(*self.namespaced_type.namespaced_name()[1:]) self.include_path = Path(*self.namespaced_type.namespaced_name()) - def write_unified_json( + def generate_full_description( self, output_dir: Path, local_hashers: dict, includes_map: dict - ) -> List[Path]: - generated_files = [] + ) -> None: referenced_types = {} - for key, val in self.subinterfaces.items(): - generated_files += val.write_unified_json(output_dir, local_hashers, includes_map) def add_referenced_type(individual_type_description): type_name = individual_type_description['type_name'] @@ -431,9 +433,11 @@ def add_referenced_type(individual_type_description): # A type in this package may refer to types, and hasn't been unrolled yet, # so process its includes breadth first - if process_type in local_hashers: - add_referenced_type(local_hashers[process_type].individual_type_description) - process_includes += local_hashers[process_type].includes + local_hasher = local_hashers.get(process_type, None) + if local_hasher is not None: + add_referenced_type(local_hasher.individual_type_description) + process_includes += local_hasher.includes + self.pending_local_hashes.add(local_hasher) continue # All nonlocal descriptions will have all recursively referenced types baked in @@ -445,6 +449,10 @@ def add_referenced_type(individual_type_description): include_json = json.load(include_file) type_description_msg = include_json['type_description_msg'] + self.all_type_hashes.update({ + val['type_name']: val['hash_string'] + for val in include_json['type_hashes'] + }) add_referenced_type(type_description_msg['type_description']) for rt in type_description_msg['referenced_type_descriptions']: add_referenced_type(rt) @@ -455,9 +463,23 @@ def add_referenced_type(individual_type_description): referenced_types.values(), key=lambda td: td['type_name']) } + def write_unified_json( + self, output_dir: Path + ) -> List[Path]: + generated_files = [] + for val in self.subinterfaces.values(): + generated_files += val.write_unified_json(output_dir) + + self.all_type_hashes.update(self._calculate_type_hashes()) + for local_hasher in self.pending_local_hashes: + self.all_type_hashes.update(local_hasher._calculate_type_hashes()) + type_hash_list = [ + { 'type_name': key, 'hash_string': val } + for key, val in self.all_type_hashes.items() + ] hashed_type_description = { - 'hashes': self._calculate_hash_tree(), 'type_description_msg': self.full_type_description, + 'type_hashes': type_hash_list, } json_path = output_dir / self.rel_path.with_suffix('.json') @@ -465,7 +487,7 @@ def add_referenced_type(individual_type_description): json_file.write(json.dumps(hashed_type_description, indent=2)) return generated_files + [json_path] - def _calculate_hash_tree(self) -> dict: + def _calculate_type_hashes(self) -> dict: # Create a copy of the description, removing all default values hashable_dict = deepcopy(self.full_type_description) for field in hashable_dict['type_description']['fields']: @@ -489,13 +511,13 @@ def _calculate_hash_tree(self) -> dict: sha.update(hashable_repr.encode('utf-8')) type_hash = RIHS01_PREFIX + sha.hexdigest() - type_hash_infos = { - self.interface_type: type_hash, + type_hashes = { + self.individual_type_description['type_name']: type_hash, } - for key, val in self.subinterfaces.items(): - type_hash_infos[key] = val._calculate_hash_tree() + for hasher in self.subinterfaces.values(): + type_hashes.update(hasher._calculate_type_hashes()) - return type_hash_infos + return type_hashes def extract_subinterface(type_description_msg: dict, field_name: str): From cd1587987f9701b1fa1a4c9a223e36176e9683dc Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Sun, 2 Apr 2023 15:15:36 -0700 Subject: [PATCH 06/19] Pass hash lookup to full_description Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/idl__description.c.em | 3 ++- rosidl_generator_cpp/resource/idl__struct.hpp.em | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 188b4488c..b304e83f9 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -89,6 +89,7 @@ TEMPLATE( TEMPLATE( 'full__description.c.em', toplevel_type_description=toplevel_type_description, - implicit_type_descriptions=implicit_type_descriptions) + implicit_type_descriptions=implicit_type_descriptions, + hash_lookup=hash_lookup) }@ @[end if]@ diff --git a/rosidl_generator_cpp/resource/idl__struct.hpp.em b/rosidl_generator_cpp/resource/idl__struct.hpp.em index 2e7e1d7c2..e29a1f89e 100644 --- a/rosidl_generator_cpp/resource/idl__struct.hpp.em +++ b/rosidl_generator_cpp/resource/idl__struct.hpp.em @@ -18,7 +18,6 @@ header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ '__STRUCT_HPP_' include_directives = set() -type_hash = type_description_info['hashes'] }@ #ifndef @(header_guard_variable) @@ -30,7 +29,6 @@ type_hash = type_description_info['hashes'] #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -45,7 +43,7 @@ from rosidl_parser.definition import Message TEMPLATE( 'msg__struct.hpp.em', package_name=package_name, interface_path=interface_path, - message=message, include_directives=include_directives, type_hash=type_hash) + message=message, include_directives=include_directives) }@ @[end for]@ @@ -61,7 +59,7 @@ from rosidl_parser.definition import Service TEMPLATE( 'srv__struct.hpp.em', package_name=package_name, interface_path=interface_path, service=service, - include_directives=include_directives, type_hash=type_hash) + include_directives=include_directives) }@ @[end for]@ @@ -77,7 +75,7 @@ from rosidl_parser.definition import Action TEMPLATE( 'action__struct.hpp.em', package_name=package_name, interface_path=interface_path, action=action, - include_directives=include_directives, type_hash=type_hash) + include_directives=include_directives) }@ @[end for]@ From 9cb608faf95504c875bc7fbc3d285ace3de54058 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 01:41:00 -0700 Subject: [PATCH 07/19] Type description generator refactor complete Signed-off-by: Emerson Knapp --- .../cmake/rosidl_generate_interfaces.cmake | 1 - .../resource/idl__description.c.em | 3 +- rosidl_generator_c/resource/msg__struct.h.em | 2 +- .../__init__.py | 396 +++++++++--------- 4 files changed, 190 insertions(+), 212 deletions(-) diff --git a/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake b/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake index e8f4c96ef..c0273e66d 100644 --- a/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake +++ b/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake @@ -240,7 +240,6 @@ macro(rosidl_generate_interfaces target) endif() endforeach() - message(WARNING "NonIdlFiles ${_non_idl_files}") add_custom_target( ${target} ALL DEPENDS diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index b304e83f9..8b182c4b2 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -57,6 +57,7 @@ for action in content.get_elements_of_type(Action): (extract_subinterface(get_result_service, 'request_message'), 'message'), (extract_subinterface(get_result_service, 'response_message'), 'message'), (extract_subinterface(get_result_service, 'event_message'), 'message'), + (extract_subinterface(type_description_msg, 'feedback_message'), 'message'), ]) }@ @@ -72,7 +73,7 @@ ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(c_typename)__@(GET_HASH_FUNC)(const rosidl_@(interface_type)_type_support_t *) { - static rosidl_type_hash_t hash = @(type_hash_to_c_definition(hash_lookup[typename])); + static rosidl_type_hash_t hash = @(type_hash_to_c_definition(hash_lookup[typename], indent=4)); return &hash; } @[end for]@ diff --git a/rosidl_generator_c/resource/msg__struct.h.em b/rosidl_generator_c/resource/msg__struct.h.em index f0b99e166..23414ed45 100644 --- a/rosidl_generator_c/resource/msg__struct.h.em +++ b/rosidl_generator_c/resource/msg__struct.h.em @@ -60,7 +60,7 @@ for member in message.structure.members: member_names.append(member.name) }@ @#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - +@ @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Constants defined in the message @[for constant in message.constants]@ diff --git a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py index 70faba76a..e7785e8ea 100644 --- a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py +++ b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py @@ -38,6 +38,55 @@ GET_SOURCES_FUNC = 'get_type_description_sources' +def to_type_name(namespaced_type): + return '/'.join(namespaced_type.namespaced_name()) + + +class GenericInterface: + def __init__( + self, namespaced_type: definition.NamespacedType, members: List[definition.Member] + ): + self.namespaced_type = namespaced_type + self.members = members + + +def add_msg(msg: definition.Message, to_dict: dict): + to_dict[to_type_name(msg.structure.namespaced_type)] = GenericInterface( + msg.structure.namespaced_type, msg.structure.members) + + +def add_srv(srv: definition.Service, to_dict: dict): + service_members = [ + definition.Member(srv.request_message.structure.namespaced_type, 'request_message'), + definition.Member(srv.response_message.structure.namespaced_type, 'response_message'), + definition.Member(srv.event_message.structure.namespaced_type, 'event_message'), + ] + to_dict[to_type_name(srv.namespaced_type)] = GenericInterface( + srv.namespaced_type, service_members) + add_msg(srv.request_message, to_dict) + add_msg(srv.response_message, to_dict) + add_msg(srv.event_message, to_dict) + + +def add_action(action, to_dict): + action_members = [ + definition.Member(action.goal.structure.namespaced_type, 'goal'), + definition.Member(action.result.structure.namespaced_type, 'result'), + definition.Member(action.feedback.structure.namespaced_type, 'feedback'), + definition.Member(action.send_goal_service.namespaced_type, 'send_goal_service'), + definition.Member(action.get_result_service.namespaced_type, 'get_result_service'), + definition.Member(action.feedback_message.structure.namespaced_type, 'feedback_message'), + ] + to_dict[to_type_name(action.namespaced_type)] = GenericInterface( + action.namespaced_type, action_members) + add_msg(action.goal, to_dict) + add_msg(action.result, to_dict) + add_msg(action.feedback, to_dict) + add_srv(action.send_goal_service, to_dict) + add_srv(action.get_result_service, to_dict) + add_msg(action.feedback_message, to_dict) + + def generate_type_hash(generator_arguments_file: str) -> List[str]: with open(generator_arguments_file, 'r') as f: args = json.load(f) @@ -56,10 +105,8 @@ def generate_type_hash(generator_arguments_file: str) -> List[str]: include_package_name, include_base_path = include_parts include_map[include_package_name] = Path(include_base_path) - generated_files = [] - hashers = {} - - # Initialize all local types first so they can be referenced by other local types + # Define all local IndividualTypeDescriptions + individual_types = {} for idl_tuple in idl_tuples: idl_parts = idl_tuple.rsplit(':', 1) assert len(idl_parts) == 2 @@ -74,16 +121,94 @@ def generate_type_hash(generator_arguments_file: str) -> List[str]: idl_rel_path = Path(idl_parts[1]) generate_to_dir = (output_dir / idl_rel_path).parent generate_to_dir.mkdir(parents=True, exist_ok=True) + for el in idl_file.content.elements: + if isinstance(el, definition.Message): + add_msg(el, individual_types) + elif isinstance(el, definition.Service): + add_srv(el, individual_types) + elif isinstance(el, definition.Action): + add_action(el, individual_types) + + # Determine needed includes for types from other packages + pending_includes = set() + for individual_type in individual_types.values(): + for member in individual_type.members: + if isinstance(member.type, definition.NamespacedType): + member_type = member.type + elif ( + isinstance(member.type, definition.AbstractNestedType) and + isinstance(member.type.value_type, definition.NamespacedType) + ): + member_type = member.type.value_type + else: + continue - hasher = InterfaceHasher.from_idl(idl_file) - hashers[hasher.namespaced_type.namespaced_name()] = hasher + if to_type_name(member_type) not in individual_types: + pending_includes.add(Path(*member_type.namespaced_name())) - # Generate output representation - for hasher in hashers.values(): - hasher.generate_full_description(output_dir, hashers, include_map) - # Calculate hashes and write to generated json file - for hasher in hashers.values(): - generated_files += hasher.write_unified_json(output_dir) + # Load all included types, create lookup maps of included individual descriptions and hashes + serialized_type_lookup = { + key: serialize_individual_type_description(val.namespaced_type, val.members) + for key, val in individual_types.items() + } + hash_lookup = {} + while pending_includes: + process_include = pending_includes.pop() + p_path = process_include.with_suffix('.json') + pkg = p_path.parts[0] + pkg_dir = include_map[pkg] + include_path = pkg_dir / p_path.relative_to(pkg) + with include_path.open('r') as include_file: + include_json = json.load(include_file) + + type_description_msg = include_json['type_description_msg'] + try: + hash_lookup.update({ + val['type_name']: val['hash_string'] for val in include_json['type_hashes'] + }) + except KeyError: + raise Exception(f'Key "type_hashes" not found in {include_path}') + + # TODO(ek) check for diff def + # if ( + # type_name in referenced_types and + # referenced_types[type_name] != individual_type_description + # ): + # raise Exception('Encountered two definitions of the same referenced type') + serialized_type_lookup[type_description_msg['type_description']['type_name']] = \ + type_description_msg['type_description'] + for referenced_type in type_description_msg['referenced_type_descriptions']: + serialized_type_lookup[referenced_type['type_name']] = referenced_type + + # Create fully-unrolled TypeDescription instances for local full types, and calculate hashes + full_types = [] + for type_name, individual_type in individual_types.items(): + full_type_description = extract_full_type_description(type_name, serialized_type_lookup) + full_types.append(full_type_description) + hash_lookup[type_name] = calculate_type_hash(full_type_description) + + # Write JSON output for each full TypeDescription + generated_files = [] + for full_type_description in full_types: + top_type_name = full_type_description['type_description']['type_name'] + hashes = [{ + 'type_name': top_type_name, + 'hash_string': hash_lookup[top_type_name], + }] + for referenced_type in full_type_description['referenced_type_descriptions']: + hashes.append({ + 'type_name': referenced_type['type_name'], + 'hash_string': hash_lookup[referenced_type['type_name']], + }) + json_content = { + 'type_description_msg': full_type_description, + 'type_hashes': hashes, + } + rel_path = Path(*top_type_name.split('/')[1:]) + json_path = output_dir / rel_path.with_suffix('.json') + with json_path.open('w', encoding='utf-8') as json_file: + json_file.write(json.dumps(json_content, indent=2)) + generated_files.append(json_path) return generated_files @@ -339,209 +464,38 @@ def serialize_individual_type_description( namespaced_type: definition.NamespacedType, members: List[definition.Member] ) -> dict: return { - 'type_name': '/'.join(namespaced_type.namespaced_name()), + 'type_name': to_type_name(namespaced_type), 'fields': [serialize_field(member) for member in members] } -class InterfaceHasher: - """Contains context about subinterfaces for a given interface description.""" - - @classmethod - def from_idl(cls, idl: definition.IdlFile): - for el in idl.content.elements: - if any(isinstance(el, type_) for type_ in [ - definition.Message, definition.Service, definition.Action - ]): - return InterfaceHasher(el) - raise ValueError('No interface found in IDL') - - def __init__(self, interface): - self.interface = interface - self.subinterfaces = {} - - # Determine top level interface, and member fields based on that - if isinstance(interface, definition.Message): - self.namespaced_type = interface.structure.namespaced_type - self.interface_type = 'message' - self.members = interface.structure.members - elif isinstance(interface, definition.Service): - self.namespaced_type = interface.namespaced_type - self.interface_type = 'service' - self.subinterfaces = { - 'request_message': InterfaceHasher(interface.request_message), - 'response_message': InterfaceHasher(interface.response_message), - 'event_message': InterfaceHasher(interface.event_message), - } - self.members = [ - definition.Member(hasher.namespaced_type, field_name) - for field_name, hasher in self.subinterfaces.items() - ] - elif isinstance(interface, definition.Action): - self.namespaced_type = interface.namespaced_type - self.interface_type = 'action' - self.subinterfaces = { - 'goal': InterfaceHasher(interface.goal), - 'result': InterfaceHasher(interface.result), - 'feedback': InterfaceHasher(interface.feedback), - 'send_goal_service': InterfaceHasher(interface.send_goal_service), - 'get_result_service': InterfaceHasher(interface.get_result_service), - 'feedback_message': InterfaceHasher(interface.feedback_message), - } - self.members = [ - definition.Member(hasher.namespaced_type, field_name) - for field_name, hasher in self.subinterfaces.items() - ] - - self.individual_type_description = serialize_individual_type_description( - self.namespaced_type, self.members) - self.all_type_hashes = {} - self.pending_local_hashes = set() - - # Determine needed includes from member fields - self.includes = [] - for member in self.members: - if isinstance(member.type, definition.NamespacedType): - self.includes.append(member.type.namespaced_name()) - elif ( - isinstance(member.type, definition.AbstractNestedType) and - isinstance(member.type.value_type, definition.NamespacedType) - ): - self.includes.append(member.type.value_type.namespaced_name()) - - self.rel_path = Path(*self.namespaced_type.namespaced_name()[1:]) - self.include_path = Path(*self.namespaced_type.namespaced_name()) - - def generate_full_description( - self, output_dir: Path, local_hashers: dict, includes_map: dict - ) -> None: - referenced_types = {} - - - def add_referenced_type(individual_type_description): - type_name = individual_type_description['type_name'] - if ( - type_name in referenced_types and - referenced_types[type_name] != individual_type_description - ): - raise Exception('Encountered two definitions of the same referenced type') - referenced_types[type_name] = individual_type_description - - process_includes = self.includes[:] - while process_includes: - process_type = process_includes.pop() - - # A type in this package may refer to types, and hasn't been unrolled yet, - # so process its includes breadth first - local_hasher = local_hashers.get(process_type, None) - if local_hasher is not None: - add_referenced_type(local_hasher.individual_type_description) - process_includes += local_hasher.includes - self.pending_local_hashes.add(local_hasher) - continue - - # All nonlocal descriptions will have all recursively referenced types baked in - p_path = Path(*process_type).with_suffix('.json') - pkg = p_path.parts[0] - pkg_dir = includes_map[pkg] - include_path = pkg_dir / p_path.relative_to(pkg) - with include_path.open('r') as include_file: - include_json = json.load(include_file) - - type_description_msg = include_json['type_description_msg'] - self.all_type_hashes.update({ - val['type_name']: val['hash_string'] - for val in include_json['type_hashes'] - }) - add_referenced_type(type_description_msg['type_description']) - for rt in type_description_msg['referenced_type_descriptions']: - add_referenced_type(rt) - - self.full_type_description = { - 'type_description': self.individual_type_description, - 'referenced_type_descriptions': sorted( - referenced_types.values(), key=lambda td: td['type_name']) - } - - def write_unified_json( - self, output_dir: Path - ) -> List[Path]: - generated_files = [] - for val in self.subinterfaces.values(): - generated_files += val.write_unified_json(output_dir) - - self.all_type_hashes.update(self._calculate_type_hashes()) - for local_hasher in self.pending_local_hashes: - self.all_type_hashes.update(local_hasher._calculate_type_hashes()) - type_hash_list = [ - { 'type_name': key, 'hash_string': val } - for key, val in self.all_type_hashes.items() - ] - hashed_type_description = { - 'type_description_msg': self.full_type_description, - 'type_hashes': type_hash_list, - } - - json_path = output_dir / self.rel_path.with_suffix('.json') - with json_path.open('w', encoding='utf-8') as json_file: - json_file.write(json.dumps(hashed_type_description, indent=2)) - return generated_files + [json_path] - - def _calculate_type_hashes(self) -> dict: - # Create a copy of the description, removing all default values - hashable_dict = deepcopy(self.full_type_description) - for field in hashable_dict['type_description']['fields']: +def calculate_type_hash(serialized_type_description): + # Create a copy of the description, removing all default values + hashable_dict = deepcopy(serialized_type_description) + for field in hashable_dict['type_description']['fields']: + del field['default_value'] + for referenced_td in hashable_dict['referenced_type_descriptions']: + for field in referenced_td['fields']: del field['default_value'] - for referenced_td in hashable_dict['referenced_type_descriptions']: - for field in referenced_td['fields']: - del field['default_value'] - - hashable_repr = json.dumps( - hashable_dict, - skipkeys=False, - ensure_ascii=True, - check_circular=True, - allow_nan=False, - indent=None, - # note: libyaml in C doesn't allow for tweaking these separators, this is its builtin - separators=(', ', ': '), - sort_keys=False - ) - sha = hashlib.sha256() - sha.update(hashable_repr.encode('utf-8')) - type_hash = RIHS01_PREFIX + sha.hexdigest() - - type_hashes = { - self.individual_type_description['type_name']: type_hash, - } - for hasher in self.subinterfaces.values(): - type_hashes.update(hasher._calculate_type_hashes()) - - return type_hashes - - -def extract_subinterface(type_description_msg: dict, field_name: str): - """ - Filter full TypeDescription to produce a TypeDescription for one of its fields' types. - - Given the name of a field, finds its type, and finds all its referenced type descriptions - by doing a DAG traversal on the referenced type descriptions of the input type. - """ - output_type_name = next( - field['type']['nested_type_name'] - for field in type_description_msg['type_description']['fields'] - if field['name'] == field_name) - assert output_type_name, 'Given field is not a nested type' - - # Create a lookup map for matching names to type descriptions - toplevel_type = type_description_msg['type_description'] - referenced_types = type_description_msg['referenced_type_descriptions'] - type_map = { - individual_type['type_name']: individual_type - for individual_type - in [toplevel_type] + referenced_types - } + hashable_repr = json.dumps( + hashable_dict, + skipkeys=False, + ensure_ascii=True, + check_circular=True, + allow_nan=False, + indent=None, + # note: libyaml in C doesn't allow for tweaking these separators, this is its builtin + separators=(', ', ': '), + sort_keys=False + ) + sha = hashlib.sha256() + sha.update(hashable_repr.encode('utf-8')) + type_hash = RIHS01_PREFIX + sha.hexdigest() + return type_hash + + +def extract_full_type_description(output_type_name, type_map): # Traverse reference graph to narrow down the references for the output type output_type = type_map[output_type_name] output_references = set() @@ -566,3 +520,27 @@ def extract_subinterface(type_description_msg: dict, field_name: str): type_map[type_name] for type_name in sorted(output_references) ], } + + +def extract_subinterface(type_description_msg: dict, field_name: str): + """ + Filter full TypeDescription to produce a TypeDescription for one of its fields' types. + + Given the name of a field, finds its type, and finds all its referenced type descriptions + by doing a DAG traversal on the referenced type descriptions of the input type. + """ + output_type_name = next( + field['type']['nested_type_name'] + for field in type_description_msg['type_description']['fields'] + if field['name'] == field_name) + assert output_type_name, 'Given field is not a nested type' + + # Create a lookup map for matching names to type descriptions + toplevel_type = type_description_msg['type_description'] + referenced_types = type_description_msg['referenced_type_descriptions'] + type_map = { + individual_type['type_name']: individual_type + for individual_type + in [toplevel_type] + referenced_types + } + return extract_full_type_description(output_type_name, type_map) From 2de7c69fb6041296a7011100162250122a087a33 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 02:58:38 -0700 Subject: [PATCH 08/19] Check against expected type hashes Signed-off-by: Emerson Knapp --- .../resource/full__description.c.em | 25 +++++++++++++++++-- .../resource/idl__description.c.em | 3 ++- .../__init__.py | 6 ----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index e0bfae666..edc23f248 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -2,9 +2,11 @@ @{ from rosidl_generator_c import escape_string from rosidl_generator_c import idl_structure_type_to_c_include_prefix +from rosidl_generator_c import type_hash_to_c_definition from rosidl_parser.definition import NamespacedType from rosidl_generator_type_description import FIELD_TYPE_ID_TO_NAME from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_HASH_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC def typename_to_c(typename): @@ -33,14 +35,28 @@ for referenced_td in toplevel_msg['referenced_type_descriptions']: includes.add(include_prefix + '__functions.h') full_type_descriptions = [toplevel_type_description] + implicit_type_descriptions +full_type_names = [t['type_description']['type_name'] for t, _ in full_type_descriptions] all_type_descriptions = [toplevel_msg['type_description']] + toplevel_msg['referenced_type_descriptions'] }@ +#include +#include // Include directives for referenced types @[for header_file in includes]@ #include "@(header_file)" @[end for]@ +// Expected hashes for externally referenced types +@[for referenced_type_description in toplevel_msg['referenced_type_descriptions']]@ +@{ +type_name = referenced_type_description['type_name'] +c_typename = type_name.replace('/', '__') +}@ +@[ if type_name not in full_type_names]@ +static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_definition(hash_lookup[type_name])); +@[ end if]@ +@[end for]@ + // Names for all types @[for itype_description in all_type_descriptions]@ static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; @@ -105,10 +121,15 @@ const rosidl_runtime_c__type_description__TypeDescription * @(static_seq(f'{td_c_typename}__REFERENCED_TYPE_DESCRIPTIONS', ref_tds)), }; if (!constructed) { - // TODO(ek) check hashes for consistency @[ for idx, ref_td in enumerate(ref_tds)]@ +@{ +c_typename = typename_to_c(ref_td['type_name']) +}@ { - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(typename_to_c(ref_td['type_name']))__@(GET_DESCRIPTION_FUNC)(NULL); +@[ if ref_td['type_name'] not in full_type_names]@ + assert(0 == memcmp(&@(c_typename)__EXPECTED_HASH, @(c_typename)__@(GET_HASH_FUNC)(NULL), sizeof(rosidl_type_hash_t))); +@[ end if]@ + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(c_typename)__@(GET_DESCRIPTION_FUNC)(NULL); description.referenced_type_descriptions.data[@(idx)].fields.data = ref_desc->type_description.fields.data; description.referenced_type_descriptions.data[@(idx)].fields.size = ref_desc->type_description.fields.size; description.referenced_type_descriptions.data[@(idx)].fields.capacity = ref_desc->type_description.fields.capacity; diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 8b182c4b2..9df38baad 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -76,8 +76,9 @@ const rosidl_type_hash_t * static rosidl_type_hash_t hash = @(type_hash_to_c_definition(hash_lookup[typename], indent=4)); return &hash; } -@[end for]@ +@[end for]@ +@ @[if disable_description_codegen]@ @{ TEMPLATE( diff --git a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py index e7785e8ea..7e2810fab 100644 --- a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py +++ b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py @@ -169,12 +169,6 @@ def generate_type_hash(generator_arguments_file: str) -> List[str]: except KeyError: raise Exception(f'Key "type_hashes" not found in {include_path}') - # TODO(ek) check for diff def - # if ( - # type_name in referenced_types and - # referenced_types[type_name] != individual_type_description - # ): - # raise Exception('Encountered two definitions of the same referenced type') serialized_type_lookup[type_description_msg['type_description']['type_name']] = \ type_description_msg['type_description'] for referenced_type in type_description_msg['referenced_type_descriptions']: From 74cb4840d3a0d27e2cde0f654f275a3b41b4da7c Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 11:27:24 -0700 Subject: [PATCH 09/19] Add test for copied sources against installed versions to detect out of date Signed-off-by: Emerson Knapp --- .../resource/idl__functions.h.em | 36 +++-- .../resource/msg__functions.h.em | 9 +- rosidl_generator_tests/CMakeLists.txt | 2 + rosidl_generator_tests/package.xml | 3 +- .../rosidl_generator_c/test_descriptions.c | 107 ++++++++++--- .../type_description/field__functions.h | 23 +++ .../type_description/field__struct.h | 11 -- .../type_description/field_type__functions.h | 23 +++ .../type_description/field_type__struct.h | 11 -- .../individual_type_description__functions.h | 23 +++ .../individual_type_description__struct.h | 11 -- .../type_description/key_value__functions.h | 23 +++ .../type_description/key_value__struct.h | 11 -- .../type_description__functions.h | 23 +++ .../type_description__struct.h | 11 -- .../type_description/type_source__functions.h | 23 +++ .../type_description/type_source__struct.h | 11 -- .../src/type_description/field__description.c | 115 ++++++++++++++ .../field_type__description.c | 106 +++++++++++++ ...individual_type_description__description.c | 123 +++++++++++++++ .../type_description/key_value__description.c | 83 ++++++++++ .../type_description__description.c | 142 ++++++++++++++++++ .../type_source__description.c | 94 ++++++++++++ .../type_description/field__struct.hpp | 11 -- .../type_description/field_type__struct.hpp | 11 -- .../individual_type_description__struct.hpp | 11 -- .../type_description/key_value__struct.hpp | 11 -- .../type_description__struct.hpp | 11 -- .../type_description/type_source__struct.hpp | 11 -- ...py_type_description_generated_sources.bash | 7 +- scripts/type_description.fingerprint | 42 +++--- 31 files changed, 947 insertions(+), 192 deletions(-) create mode 100644 rosidl_runtime_c/src/type_description/field__description.c create mode 100644 rosidl_runtime_c/src/type_description/field_type__description.c create mode 100644 rosidl_runtime_c/src/type_description/individual_type_description__description.c create mode 100644 rosidl_runtime_c/src/type_description/key_value__description.c create mode 100644 rosidl_runtime_c/src/type_description/type_description__description.c create mode 100644 rosidl_runtime_c/src/type_description/type_source__description.c diff --git a/rosidl_generator_c/resource/idl__functions.h.em b/rosidl_generator_c/resource/idl__functions.h.em index 102f7e12e..f23659729 100644 --- a/rosidl_generator_c/resource/idl__functions.h.em +++ b/rosidl_generator_c/resource/idl__functions.h.em @@ -74,17 +74,20 @@ service_typename = idl_structure_type_to_c_typename(service.namespaced_type) /// Retrieve pointer to the hash of the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(service_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); +@(service_typename)__@(GET_HASH_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(service_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); +@(service_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(service_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); +@(service_typename)__@(GET_SOURCES_FUNC)( + const rosidl_service_type_support_t *); @{ TEMPLATE( @@ -123,17 +126,20 @@ get_result_srv_typename = idl_structure_type_to_c_typename(action.get_result_ser /// Retrieve pointer to the hash of the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(action_typename)__@(GET_HASH_FUNC)(const rosidl_action_type_support_t *); +@(action_typename)__@(GET_HASH_FUNC)( + const rosidl_action_type_support_t *); /// Retrieve pointer to the description of the action type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(action_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_action_type_support_t *); +@(action_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_action_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the action type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(action_typename)__@(GET_SOURCES_FUNC)(const rosidl_action_type_support_t *); +@(action_typename)__@(GET_SOURCES_FUNC)( + const rosidl_action_type_support_t *); @{ TEMPLATE( @@ -159,17 +165,20 @@ TEMPLATE( /// Retrieve pointer to the hash of the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(send_goal_srv_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); +@(send_goal_srv_typename)__@(GET_HASH_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(send_goal_srv_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); +@(send_goal_srv_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(send_goal_srv_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); +@(send_goal_srv_typename)__@(GET_SOURCES_FUNC)( + const rosidl_service_type_support_t *); @{ TEMPLATE( @@ -195,17 +204,20 @@ TEMPLATE( /// Retrieve pointer to the hash of the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(get_result_srv_typename)__@(GET_HASH_FUNC)(const rosidl_service_type_support_t *); +@(get_result_srv_typename)__@(GET_HASH_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(get_result_srv_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_service_type_support_t *); +@(get_result_srv_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_service_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the service type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(get_result_srv_typename)__@(GET_SOURCES_FUNC)(const rosidl_service_type_support_t *); +@(get_result_srv_typename)__@(GET_SOURCES_FUNC)( + const rosidl_service_type_support_t *); @{ TEMPLATE( diff --git a/rosidl_generator_c/resource/msg__functions.h.em b/rosidl_generator_c/resource/msg__functions.h.em index bd5f79c56..7397f70e0 100644 --- a/rosidl_generator_c/resource/msg__functions.h.em +++ b/rosidl_generator_c/resource/msg__functions.h.em @@ -92,17 +92,20 @@ bool /// Retrieve pointer to the hash of the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(message_typename)__@(GET_HASH_FUNC)(const rosidl_message_type_support_t *); +@(message_typename)__@(GET_HASH_FUNC)( + const rosidl_message_type_support_t *); /// Retrieve pointer to the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * -@(message_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_message_type_support_t *); +@(message_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_message_type_support_t *); /// Retrieve pointer to the raw source texts that defined the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(message_typename)__@(GET_SOURCES_FUNC)(const rosidl_message_type_support_t *); +@(message_typename)__@(GET_SOURCES_FUNC)( + const rosidl_message_type_support_t *); @####################################################################### @# array functions diff --git a/rosidl_generator_tests/CMakeLists.txt b/rosidl_generator_tests/CMakeLists.txt index 85aafa85c..4510a9221 100644 --- a/rosidl_generator_tests/CMakeLists.txt +++ b/rosidl_generator_tests/CMakeLists.txt @@ -27,6 +27,7 @@ if(BUILD_TESTING) find_package(rosidl_runtime_c REQUIRED) find_package(rosidl_runtime_cpp REQUIRED) find_package(test_interface_files REQUIRED) + find_package(type_description_interfaces REQUIRED) ament_lint_auto_find_test_dependencies() rosidl_generate_interfaces(${PROJECT_NAME} @@ -124,6 +125,7 @@ if(BUILD_TESTING) target_link_libraries(test_descriptions_c ${c_generator_target} rosidl_runtime_c::rosidl_runtime_c + ${type_description_interfaces_TARGETS} ) ament_add_pytest_test(test_hash_generator test/rosidl_generator_type_description diff --git a/rosidl_generator_tests/package.xml b/rosidl_generator_tests/package.xml index 449bf8ef8..5b6fab565 100644 --- a/rosidl_generator_tests/package.xml +++ b/rosidl_generator_tests/package.xml @@ -31,8 +31,9 @@ rosidl_generator_type_description rosidl_runtime_c rosidl_runtime_cpp - test_interface_files service_msgs + test_interface_files + type_description_interfaces ament_cmake diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index 7cdb068ca..77eea1621 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -19,17 +19,29 @@ #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" #include "rosidl_runtime_c/string.h" +#include "rosidl_runtime_c/type_description/field__functions.h" +#include "rosidl_runtime_c/type_description/field_type__functions.h" +#include "rosidl_runtime_c/type_description/individual_type_description__functions.h" +#include "rosidl_runtime_c/type_description/key_value__functions.h" +#include "rosidl_runtime_c/type_description/type_description__functions.h" #include "rosidl_runtime_c/type_description/type_description__struct.h" +#include "rosidl_runtime_c/type_description/type_source__functions.h" #include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_generator_tests/action/fibonacci.h" #include "rosidl_generator_tests/msg/defaults.h" #include "rosidl_generator_tests/srv/empty.h" +#include "type_description_interfaces/msg/field.h" +#include "type_description_interfaces/msg/field_type.h" +#include "type_description_interfaces/msg/individual_type_description.h" +#include "type_description_interfaces/msg/key_value.h" +#include "type_description_interfaces/msg/type_description.h" +#include "type_description_interfaces/msg/type_source.h" -int test_basic( + +int description_namecheck( const rosidl_runtime_c__type_description__TypeDescription * description, - const rosidl_runtime_c__type_description__TypeSource__Sequence * sources, const char * expected_name) { const rosidl_runtime_c__String * typename = &description->type_description.type_name; @@ -37,75 +49,84 @@ int test_basic( fprintf(stderr, "Typename incorrect, expected %s\n", expected_name); return 1; } - if (sources->size != 0) { - fprintf(stderr, "Encountered non-empty type sources unexpectedly.\n"); - return 1; - } return 0; } +int test_description_linkage(); +int test_copied_type_description_struct_hashes(); -int main(int argc, char ** argv) +int main(void) { - // Smoke test linkage and basic values for msg, srv, action - (void)argc; - (void)argv; + int rc = 0; + printf("Testing rosidl_generator_tests description linkage...\n"); + if (test_description_linkage()) { + fprintf(stderr, "test_description_linkage() FAILED\n"); + rc++; + } + printf("Testing rosidl_generator_tests copied type description struct hashes...\n"); + if (test_copied_type_description_struct_hashes()) { + fprintf(stderr, "test_copied_type_description_struct_hashes() FAILED\n"); + rc++; + } + if (rc != 0) { + fprintf(stderr, "Some tests failed!\n"); + } else { + printf("All tests were good!\n"); + } + return rc != 0; +} + +int test_description_linkage() +{ + // Smoke test linkage and basic values for msg, srv, action // Message - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__msg__Defaults__get_type_description(NULL), - rosidl_generator_tests__msg__Defaults__get_type_description_sources(NULL), "rosidl_generator_tests/msg/Defaults")) { return 1; } // Service - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__srv__Empty__get_type_description(NULL), - rosidl_generator_tests__srv__Empty__get_type_description_sources(NULL), "rosidl_generator_tests/srv/Empty")) { return 1; } // Implicit message of a service - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__srv__Empty_Request__get_type_description(NULL), - rosidl_generator_tests__srv__Empty_Request__get_type_description_sources(NULL), "rosidl_generator_tests/srv/Empty_Request")) { return 1; } // Action - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__action__Fibonacci__get_type_description(NULL), - rosidl_generator_tests__action__Fibonacci__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci")) { return 1; } // Implicit message of an action - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description(NULL), - rosidl_generator_tests__action__Fibonacci_Feedback__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci_Feedback")) { return 1; } // Implicit service of an action - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description(NULL), - rosidl_generator_tests__action__Fibonacci_SendGoal__get_type_description_sources(NULL), "rosidl_generator_tests/action/Fibonacci_SendGoal")) { return 1; } // Implicit message of implicit service of an action - if (0 != test_basic( + if (0 != description_namecheck( rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description(NULL), - rosidl_generator_tests__action__Fibonacci_GetResult_Request__get_type_description_sources( - NULL), "rosidl_generator_tests/action/Fibonacci_GetResult_Request")) { return 1; @@ -113,3 +134,39 @@ int main(int argc, char ** argv) return 0; } + +int test_copied_type_description_struct_hashes() +{ + #define runtimehash(x) rosidl_runtime_c__type_description__ ## x ## __get_type_hash(NULL) + #define msghash(x) type_description_interfaces__msg__ ## x ## __get_type_hash(NULL) + #define hashcompare(x) memcmp(runtimehash(x), msghash(x), sizeof(rosidl_type_hash_t)) + int rc = 0; + if (hashcompare(Field)) { + fprintf(stderr, "Field hash NO MATCH\n"); + rc++; + } + if (hashcompare(FieldType)) { + fprintf(stderr, "FieldType hash NO MATCH\n"); + rc++; + } + if (hashcompare(IndividualTypeDescription)) { + fprintf(stderr, "IndividualTypeDescription hash NO MATCH\n"); + rc++; + } + if (hashcompare(KeyValue)) { + fprintf(stderr, "KeyValue hash NO MATCH\n"); + rc++; + } + if (hashcompare(TypeDescription)) { + fprintf(stderr, "TypeDescription hash NO MATCH\n"); + rc++; + } + if (hashcompare(TypeSource)) { + fprintf(stderr, "TypeSource hash NO MATCH\n"); + rc++; + } + #undef hashcompare + #undef msghash + #undef runtimehash + return rc; +} diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h index 2d8c3c08d..93ed6a95e 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/field__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__Field__copy( const rosidl_runtime_c__type_description__Field * input, rosidl_runtime_c__type_description__Field * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__Field__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__Field__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__Field__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/Field messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__struct.h index effcf1d6d..418468f3b 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__TYPE_HASH = {1, { - 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, - 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, - 0x96, 0x8f, 0x85, 0x5f, 0x7c, 0x5e, 0x41, 0x61, - 0x4f, 0xf5, 0xd7, 0xa8, 0x54, 0xef, 0xef, 0x7c, - }}; - // Constants defined in the message // Include directives for member types diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h index a7680302c..0d20af464 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/field_type__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__FieldType__copy( const rosidl_runtime_c__type_description__FieldType * input, rosidl_runtime_c__type_description__FieldType * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__FieldType__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__FieldType__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__FieldType__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/FieldType messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__struct.h index dac56a7f5..012340fb4 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__TYPE_HASH = {1, { - 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, - 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, - 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, - 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, - }}; - // Constants defined in the message /// Constant 'FIELD_TYPE_NOT_SET'. diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h index 574ade2a2..9bb9616e0 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/individual_type_description__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__copy( const rosidl_runtime_c__type_description__IndividualTypeDescription * input, rosidl_runtime_c__type_description__IndividualTypeDescription * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/IndividualTypeDescription messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__struct.h index ab406a4cb..247f22e01 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_HASH = {1, { - 0x55, 0xc8, 0x27, 0xd8, 0x6c, 0x3c, 0x14, 0x1b, - 0xdd, 0x31, 0x8f, 0xe6, 0xc2, 0x2e, 0x11, 0x19, - 0x0e, 0x4d, 0x3b, 0x37, 0xc8, 0xf4, 0xf9, 0x75, - 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, - }}; - // Constants defined in the message // Include directives for member types diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h index f88d54e1c..2259d6843 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/key_value__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__KeyValue__copy( const rosidl_runtime_c__type_description__KeyValue * input, rosidl_runtime_c__type_description__KeyValue * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__KeyValue__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__KeyValue__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__KeyValue__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/KeyValue messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__struct.h index d1c343129..7ce5dc83d 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__KeyValue__TYPE_HASH = {1, { - 0x27, 0x4f, 0xe5, 0x6b, 0xf1, 0x4f, 0x33, 0xc7, - 0x51, 0x2e, 0x34, 0xc6, 0x46, 0xa3, 0x75, 0x79, - 0xee, 0x36, 0x77, 0x9f, 0x74, 0x5f, 0x04, 0x9a, - 0x97, 0x60, 0x76, 0x3e, 0x81, 0x7f, 0x0c, 0x42, - }}; - // Constants defined in the message // Include directives for member types diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h index 6ae47d25b..d2ecff5f2 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/type_description__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__TypeDescription__copy( const rosidl_runtime_c__type_description__TypeDescription * input, rosidl_runtime_c__type_description__TypeDescription * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__TypeDescription__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__TypeDescription__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/TypeDescription messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__struct.h index f98843ce1..49c72939a 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__TypeDescription__TYPE_HASH = {1, { - 0x73, 0x9f, 0x25, 0x08, 0xc9, 0xfa, 0x3a, 0x6f, - 0x33, 0x09, 0x13, 0xff, 0x5b, 0x9d, 0x25, 0xfb, - 0x74, 0x15, 0x9a, 0x07, 0x7d, 0xa7, 0x1e, 0x10, - 0x87, 0xf5, 0x1a, 0x60, 0xc1, 0x2a, 0x08, 0x0b, - }}; - // Constants defined in the message // Include directives for member types diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h index 033c0239f..8f15f7ddc 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h @@ -14,6 +14,11 @@ extern "C" #include #include +#include "rosidl_runtime_c/action_type_support_struct.h" +#include "rosidl_runtime_c/message_type_support_struct.h" +#include "rosidl_runtime_c/service_type_support_struct.h" +#include "rosidl_runtime_c/type_description/type_source__struct.h" +#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" #include "rosidl_runtime_c/type_description/type_source__struct.h" @@ -93,6 +98,24 @@ rosidl_runtime_c__type_description__TypeSource__copy( const rosidl_runtime_c__type_description__TypeSource * input, rosidl_runtime_c__type_description__TypeSource * output); +/// Retrieve pointer to the hash of the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__TypeSource__get_type_hash( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__TypeSource__get_type_description( + const rosidl_message_type_support_t *); + +/// Retrieve pointer to the raw source texts that defined the description of the message type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__TypeSource__get_type_description_sources( + const rosidl_message_type_support_t *); + /// Initialize array of msg/TypeSource messages. /** * It allocates the memory for the number of elements and calls diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__struct.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__struct.h index 5219dd99a..d1e2bc585 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__struct.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__struct.h @@ -15,17 +15,6 @@ extern "C" #include #include -#include "rosidl_runtime_c/type_hash.h" - - -// Type Hash for interface -static const rosidl_type_hash_t rosidl_runtime_c__type_description__TypeSource__TYPE_HASH = {1, { - 0xfa, 0xea, 0xec, 0x75, 0x96, 0xc0, 0x4e, 0xcf, - 0x5b, 0x6e, 0x99, 0xad, 0x22, 0x5e, 0x4c, 0x7c, - 0xbb, 0x99, 0x7a, 0xd5, 0x43, 0x5f, 0x79, 0x35, - 0x26, 0xfb, 0x39, 0x84, 0xd0, 0x11, 0xaa, 0xe5, - }}; - // Constants defined in the message // Include directives for member types diff --git a/rosidl_runtime_c/src/type_description/field__description.c b/rosidl_runtime_c/src/type_description/field__description.c new file mode 100644 index 000000000..2cc96b9ad --- /dev/null +++ b/rosidl_runtime_c/src/type_description/field__description.c @@ -0,0 +1,115 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/Field.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/field__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__Field__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, + 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, + 0x96, 0x8f, 0x85, 0x5f, 0x7c, 0x5e, 0x41, 0x61, + 0x4f, 0xf5, 0xd7, 0xa8, 0x54, 0xef, 0xef, 0x7c, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types +#include "rosidl_runtime_c/type_description/field_type__functions.h" + +// Expected hashes for externally referenced types +static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH = {1, { + 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, + 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, + 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, + 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, + }}; + +// Names for all types +static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; +static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__Field__FIELD_NAME__name[] = "name"; +static char rosidl_runtime_c__type_description__Field__FIELD_NAME__type[] = "type"; +static char rosidl_runtime_c__type_description__Field__FIELD_NAME__default_value[] = "default_value"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__Field__FIELDS[] = { + { + {rosidl_runtime_c__type_description__Field__FIELD_NAME__name, 4, 4}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__Field__FIELD_NAME__type, 4, 4}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_NESTED_TYPE, + 0, + 0, + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__Field__FIELD_NAME__default_value, 13, 13}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources +static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__Field__REFERENCED_TYPE_DESCRIPTIONS[] = { + { + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + {NULL, 0, 0}, + }, +}; + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__Field__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, + {rosidl_runtime_c__type_description__Field__FIELDS, 3, 3}, + }, + {rosidl_runtime_c__type_description__Field__REFERENCED_TYPE_DESCRIPTIONS, 1, 1}, + }; + if (!constructed) { + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); + description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; + } + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__Field__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_c/src/type_description/field_type__description.c b/rosidl_runtime_c/src/type_description/field_type__description.c new file mode 100644 index 000000000..f882bc3f6 --- /dev/null +++ b/rosidl_runtime_c/src/type_description/field_type__description.c @@ -0,0 +1,106 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/FieldType.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/field_type__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__FieldType__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, + 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, + 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, + 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types + +// Expected hashes for externally referenced types + +// Names for all types +static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__type_id[] = "type_id"; +static char rosidl_runtime_c__type_description__FieldType__DEFAULT_VALUE__type_id[] = "0"; +static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__capacity[] = "capacity"; +static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__string_capacity[] = "string_capacity"; +static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__nested_type_name[] = "nested_type_name"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__FieldType__FIELDS[] = { + { + {rosidl_runtime_c__type_description__FieldType__FIELD_NAME__type_id, 7, 7}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_UINT8, + 0, + 0, + {NULL, 0, 0}, + }, + {rosidl_runtime_c__type_description__FieldType__DEFAULT_VALUE__type_id, 1, 1}, + }, + { + {rosidl_runtime_c__type_description__FieldType__FIELD_NAME__capacity, 8, 8}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_UINT64, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__FieldType__FIELD_NAME__string_capacity, 15, 15}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_UINT64, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__FieldType__FIELD_NAME__nested_type_name, 16, 16}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_BOUNDED_STRING, + 0, + 255, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__FieldType__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + {rosidl_runtime_c__type_description__FieldType__FIELDS, 4, 4}, + }, + {NULL, 0, 0}, + }; + if (!constructed) { + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__FieldType__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_c/src/type_description/individual_type_description__description.c b/rosidl_runtime_c/src/type_description/individual_type_description__description.c new file mode 100644 index 000000000..2877cae3c --- /dev/null +++ b/rosidl_runtime_c/src/type_description/individual_type_description__description.c @@ -0,0 +1,123 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/IndividualTypeDescription.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/individual_type_description__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0x55, 0xc8, 0x27, 0xd8, 0x6c, 0x3c, 0x14, 0x1b, + 0xdd, 0x31, 0x8f, 0xe6, 0xc2, 0x2e, 0x11, 0x19, + 0x0e, 0x4d, 0x3b, 0x37, 0xc8, 0xf4, 0xf9, 0x75, + 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types +#include "rosidl_runtime_c/type_description/field_type__functions.h" +#include "rosidl_runtime_c/type_description/field__functions.h" + +// Expected hashes for externally referenced types +static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { + 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, + 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, + 0x96, 0x8f, 0x85, 0x5f, 0x7c, 0x5e, 0x41, 0x61, + 0x4f, 0xf5, 0xd7, 0xa8, 0x54, 0xef, 0xef, 0x7c, + }}; +static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH = {1, { + 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, + 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, + 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, + 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, + }}; + +// Names for all types +static char rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/IndividualTypeDescription"; +static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; +static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__type_name[] = "type_name"; +static char rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__fields[] = "fields"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__IndividualTypeDescription__FIELDS[] = { + { + {rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__type_name, 9, 9}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_BOUNDED_STRING, + 0, + 255, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__fields, 6, 6}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE, + 0, + 0, + {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources +static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__IndividualTypeDescription__REFERENCED_TYPE_DESCRIPTIONS[] = { + { + {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + {NULL, 0, 0}, + }, +}; + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME, 57, 57}, + {rosidl_runtime_c__type_description__IndividualTypeDescription__FIELDS, 2, 2}, + }, + {rosidl_runtime_c__type_description__IndividualTypeDescription__REFERENCED_TYPE_DESCRIPTIONS, 2, 2}, + }; + if (!constructed) { + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__Field__get_type_description(NULL); + description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; + } + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); + description.referenced_type_descriptions.data[1].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[1].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[1].fields.capacity = ref_desc->type_description.fields.capacity; + } + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_c/src/type_description/key_value__description.c b/rosidl_runtime_c/src/type_description/key_value__description.c new file mode 100644 index 000000000..2e1483f6a --- /dev/null +++ b/rosidl_runtime_c/src/type_description/key_value__description.c @@ -0,0 +1,83 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/KeyValue.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/key_value__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__KeyValue__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0x27, 0x4f, 0xe5, 0x6b, 0xf1, 0x4f, 0x33, 0xc7, + 0x51, 0x2e, 0x34, 0xc6, 0x46, 0xa3, 0x75, 0x79, + 0xee, 0x36, 0x77, 0x9f, 0x74, 0x5f, 0x04, 0x9a, + 0x97, 0x60, 0x76, 0x3e, 0x81, 0x7f, 0x0c, 0x42, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types + +// Expected hashes for externally referenced types + +// Names for all types +static char rosidl_runtime_c__type_description__KeyValue__TYPE_NAME[] = "type_description_interfaces/msg/KeyValue"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__key[] = "key"; +static char rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__value[] = "value"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__KeyValue__FIELDS[] = { + { + {rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__key, 3, 3}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__value, 5, 5}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__KeyValue__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__KeyValue__TYPE_NAME, 40, 40}, + {rosidl_runtime_c__type_description__KeyValue__FIELDS, 2, 2}, + }, + {NULL, 0, 0}, + }; + if (!constructed) { + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__KeyValue__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_c/src/type_description/type_description__description.c b/rosidl_runtime_c/src/type_description/type_description__description.c new file mode 100644 index 000000000..1867485d9 --- /dev/null +++ b/rosidl_runtime_c/src/type_description/type_description__description.c @@ -0,0 +1,142 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/TypeDescription.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/type_description__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__TypeDescription__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0x73, 0x9f, 0x25, 0x08, 0xc9, 0xfa, 0x3a, 0x6f, + 0x33, 0x09, 0x13, 0xff, 0x5b, 0x9d, 0x25, 0xfb, + 0x74, 0x15, 0x9a, 0x07, 0x7d, 0xa7, 0x1e, 0x10, + 0x87, 0xf5, 0x1a, 0x60, 0xc1, 0x2a, 0x08, 0x0b, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types +#include "rosidl_runtime_c/type_description/individual_type_description__functions.h" +#include "rosidl_runtime_c/type_description/field_type__functions.h" +#include "rosidl_runtime_c/type_description/field__functions.h" + +// Expected hashes for externally referenced types +static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { + 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, + 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, + 0x96, 0x8f, 0x85, 0x5f, 0x7c, 0x5e, 0x41, 0x61, + 0x4f, 0xf5, 0xd7, 0xa8, 0x54, 0xef, 0xef, 0x7c, + }}; +static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH = {1, { + 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, + 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, + 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, + 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, + }}; +static const rosidl_type_hash_t rosidl_runtime_c__type_description__IndividualTypeDescription__EXPECTED_HASH = {1, { + 0x55, 0xc8, 0x27, 0xd8, 0x6c, 0x3c, 0x14, 0x1b, + 0xdd, 0x31, 0x8f, 0xe6, 0xc2, 0x2e, 0x11, 0x19, + 0x0e, 0x4d, 0x3b, 0x37, 0xc8, 0xf4, 0xf9, 0x75, + 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, + }}; + +// Names for all types +static char rosidl_runtime_c__type_description__TypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/TypeDescription"; +static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; +static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; +static char rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/IndividualTypeDescription"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__type_description[] = "type_description"; +static char rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__referenced_type_descriptions[] = "referenced_type_descriptions"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__TypeDescription__FIELDS[] = { + { + {rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__type_description, 16, 16}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_NESTED_TYPE, + 0, + 0, + {rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME, 57, 57}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__referenced_type_descriptions, 28, 28}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE, + 0, + 0, + {rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME, 57, 57}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources +static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__TypeDescription__REFERENCED_TYPE_DESCRIPTIONS[] = { + { + {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME, 57, 57}, + {NULL, 0, 0}, + }, +}; + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__TypeDescription__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__TypeDescription__TYPE_NAME, 47, 47}, + {rosidl_runtime_c__type_description__TypeDescription__FIELDS, 2, 2}, + }, + {rosidl_runtime_c__type_description__TypeDescription__REFERENCED_TYPE_DESCRIPTIONS, 3, 3}, + }; + if (!constructed) { + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__Field__get_type_description(NULL); + description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; + } + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); + description.referenced_type_descriptions.data[1].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[1].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[1].fields.capacity = ref_desc->type_description.fields.capacity; + } + { + assert(0 == memcmp(&rosidl_runtime_c__type_description__IndividualTypeDescription__EXPECTED_HASH, rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description(NULL); + description.referenced_type_descriptions.data[2].fields.data = ref_desc->type_description.fields.data; + description.referenced_type_descriptions.data[2].fields.size = ref_desc->type_description.fields.size; + description.referenced_type_descriptions.data[2].fields.capacity = ref_desc->type_description.fields.capacity; + } + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_c/src/type_description/type_source__description.c b/rosidl_runtime_c/src/type_description/type_source__description.c new file mode 100644 index 000000000..393fcab91 --- /dev/null +++ b/rosidl_runtime_c/src/type_description/type_source__description.c @@ -0,0 +1,94 @@ +// DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash +// generated from rosidl_generator_c/resource/idl__description.c.em +// with input from type_description_interfaces:msg/TypeSource.idl +// generated code does not contain a copyright notice + +#include "rosidl_runtime_c/type_description/type_source__functions.h" + +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_type_hash_t * +rosidl_runtime_c__type_description__TypeSource__get_type_hash(const rosidl_message_type_support_t *) +{ + static rosidl_type_hash_t hash = {1, { + 0xfa, 0xea, 0xec, 0x75, 0x96, 0xc0, 0x4e, 0xcf, + 0x5b, 0x6e, 0x99, 0xad, 0x22, 0x5e, 0x4c, 0x7c, + 0xbb, 0x99, 0x7a, 0xd5, 0x43, 0x5f, 0x79, 0x35, + 0x26, 0xfb, 0x39, 0x84, 0xd0, 0x11, 0xaa, 0xe5, + }}; + return &hash; +} + + +#include +#include +// Include directives for referenced types + +// Expected hashes for externally referenced types + +// Names for all types +static char rosidl_runtime_c__type_description__TypeSource__TYPE_NAME[] = "type_description_interfaces/msg/TypeSource"; + +// Define type names, field names, and default values +static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__type_name[] = "type_name"; +static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__encoding[] = "encoding"; +static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__raw_file_contents[] = "raw_file_contents"; + +/// Define arrays of Fields +static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__TypeSource__FIELDS[] = { + { + {rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__type_name, 9, 9}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__encoding, 8, 8}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, + { + {rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__raw_file_contents, 17, 17}, + { + rosidl_runtime_c__type_description__FieldType__FIELD_TYPE_STRING, + 0, + 0, + {NULL, 0, 0}, + }, + {NULL, 0, 0}, + }, +}; + +/// Define exported TypeDescription and TypeSources + +const rosidl_runtime_c__type_description__TypeDescription * +rosidl_runtime_c__type_description__TypeSource__get_type_description(const rosidl_message_type_support_t *) +{ + static bool constructed = false; + static const rosidl_runtime_c__type_description__TypeDescription description = { + { + {rosidl_runtime_c__type_description__TypeSource__TYPE_NAME, 42, 42}, + {rosidl_runtime_c__type_description__TypeSource__FIELDS, 3, 3}, + }, + {NULL, 0, 0}, + }; + if (!constructed) { + constructed = true; + } + return &description; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +rosidl_runtime_c__type_description__TypeSource__get_type_description_sources(const rosidl_message_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; + return &sources; +} diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field__struct.hpp index fbf03d694..210af6b71 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -39,13 +38,6 @@ struct Field_ { using Type = Field_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, - 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, - 0x96, 0x8f, 0x85, 0x5f, 0x7c, 0x5e, 0x41, 0x61, - 0x4f, 0xf5, 0xd7, 0xa8, 0x54, 0xef, 0xef, 0x7c, - }}; - explicit Field_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) : type(_init) { @@ -164,9 +156,6 @@ struct Field_ using Field = rosidl_runtime_cpp::type_description::Field_>; -template -constexpr const rosidl_type_hash_t Field_::TYPE_HASH; - // constant definitions } // namespace type_description diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field_type__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field_type__struct.hpp index 932b482bc..63cb2a55c 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field_type__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/field_type__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -35,13 +34,6 @@ struct FieldType_ { using Type = FieldType_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, - 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, - 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, - 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, - }}; - explicit FieldType_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) { if (rosidl_runtime_cpp::MessageInitialization::ALL == _init || @@ -369,9 +361,6 @@ struct FieldType_ using FieldType = rosidl_runtime_cpp::type_description::FieldType_>; -template -constexpr const rosidl_type_hash_t FieldType_::TYPE_HASH; - // constant definitions template constexpr uint8_t FieldType_::FIELD_TYPE_NOT_SET; diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/individual_type_description__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/individual_type_description__struct.hpp index 158337716..890a396b9 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/individual_type_description__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/individual_type_description__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -39,13 +38,6 @@ struct IndividualTypeDescription_ { using Type = IndividualTypeDescription_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0x55, 0xc8, 0x27, 0xd8, 0x6c, 0x3c, 0x14, 0x1b, - 0xdd, 0x31, 0x8f, 0xe6, 0xc2, 0x2e, 0x11, 0x19, - 0x0e, 0x4d, 0x3b, 0x37, 0xc8, 0xf4, 0xf9, 0x75, - 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, - }}; - explicit IndividualTypeDescription_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) { if (rosidl_runtime_cpp::MessageInitialization::ALL == _init || @@ -147,9 +139,6 @@ struct IndividualTypeDescription_ using IndividualTypeDescription = rosidl_runtime_cpp::type_description::IndividualTypeDescription_>; -template -constexpr const rosidl_type_hash_t IndividualTypeDescription_::TYPE_HASH; - // constant definitions } // namespace type_description diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/key_value__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/key_value__struct.hpp index 0a1fce963..7cd25f6c1 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/key_value__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/key_value__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -35,13 +34,6 @@ struct KeyValue_ { using Type = KeyValue_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0x27, 0x4f, 0xe5, 0x6b, 0xf1, 0x4f, 0x33, 0xc7, - 0x51, 0x2e, 0x34, 0xc6, 0x46, 0xa3, 0x75, 0x79, - 0xee, 0x36, 0x77, 0x9f, 0x74, 0x5f, 0x04, 0x9a, - 0x97, 0x60, 0x76, 0x3e, 0x81, 0x7f, 0x0c, 0x42, - }}; - explicit KeyValue_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) { if (rosidl_runtime_cpp::MessageInitialization::ALL == _init || @@ -146,9 +138,6 @@ struct KeyValue_ using KeyValue = rosidl_runtime_cpp::type_description::KeyValue_>; -template -constexpr const rosidl_type_hash_t KeyValue_::TYPE_HASH; - // constant definitions } // namespace type_description diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_description__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_description__struct.hpp index 23871b70d..a56949cd2 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_description__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_description__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -40,13 +39,6 @@ struct TypeDescription_ { using Type = TypeDescription_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0x73, 0x9f, 0x25, 0x08, 0xc9, 0xfa, 0x3a, 0x6f, - 0x33, 0x09, 0x13, 0xff, 0x5b, 0x9d, 0x25, 0xfb, - 0x74, 0x15, 0x9a, 0x07, 0x7d, 0xa7, 0x1e, 0x10, - 0x87, 0xf5, 0x1a, 0x60, 0xc1, 0x2a, 0x08, 0x0b, - }}; - explicit TypeDescription_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) : type_description(_init) { @@ -141,9 +133,6 @@ struct TypeDescription_ using TypeDescription = rosidl_runtime_cpp::type_description::TypeDescription_>; -template -constexpr const rosidl_type_hash_t TypeDescription_::TYPE_HASH; - // constant definitions } // namespace type_description diff --git a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_source__struct.hpp b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_source__struct.hpp index 9a7c20ec3..7ee8385e8 100644 --- a/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_source__struct.hpp +++ b/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description/type_source__struct.hpp @@ -12,7 +12,6 @@ #include #include -#include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_cpp/bounded_vector.hpp" #include "rosidl_runtime_cpp/message_initialization.hpp" @@ -35,13 +34,6 @@ struct TypeSource_ { using Type = TypeSource_; - constexpr static const rosidl_type_hash_t TYPE_HASH = {1, { - 0xfa, 0xea, 0xec, 0x75, 0x96, 0xc0, 0x4e, 0xcf, - 0x5b, 0x6e, 0x99, 0xad, 0x22, 0x5e, 0x4c, 0x7c, - 0xbb, 0x99, 0x7a, 0xd5, 0x43, 0x5f, 0x79, 0x35, - 0x26, 0xfb, 0x39, 0x84, 0xd0, 0x11, 0xaa, 0xe5, - }}; - explicit TypeSource_(rosidl_runtime_cpp::MessageInitialization _init = rosidl_runtime_cpp::MessageInitialization::ALL) { if (rosidl_runtime_cpp::MessageInitialization::ALL == _init || @@ -161,9 +153,6 @@ struct TypeSource_ using TypeSource = rosidl_runtime_cpp::type_description::TypeSource_>; -template -constexpr const rosidl_type_hash_t TypeSource_::TYPE_HASH; - // constant definitions } // namespace type_description diff --git a/scripts/copy_type_description_generated_sources.bash b/scripts/copy_type_description_generated_sources.bash index 9027b1a7c..c669472fa 100755 --- a/scripts/copy_type_description_generated_sources.bash +++ b/scripts/copy_type_description_generated_sources.bash @@ -28,6 +28,8 @@ C_SRC_DEST=$ROSIDL_SRC_DIR/rosidl_runtime_c/src/type_description CPP_DETAIL=$BUILD_DIR/$CPP_DETAIL_SUBPATH CPP_INCLUDE_DEST=$ROSIDL_SRC_DIR/rosidl_runtime_cpp/include/rosidl_runtime_cpp/type_description +_all_copied="" + # C structs mkdir -p $C_INCLUDE_DEST rm -f $C_INCLUDE_DEST/*.h @@ -35,8 +37,10 @@ mkdir -p $C_SRC_DEST rm -f $C_SRC_DEST/*.c cp $C_DETAIL/*__struct.h $C_INCLUDE_DEST/ +cp $C_DETAIL/*__description.c $C_SRC_DEST/ cp $C_DETAIL/*__functions.h $C_INCLUDE_DEST/ cp $C_DETAIL/*__functions.c $C_SRC_DEST/ +_all_copied="$_all_copied $C_DETAIL_SUBPATH/*__struct.h $C_DETAIL_SUBPATH/*__functions.h $C_DETAIL_SUBPATH/*__functions.c $C_DETAIL_SUBPATH/*__description.c" # add copy notice sed -i '1s/^/\/\/ DO NOT EDIT MANUALLY - this copied file managed by copy_type_description_generated_sources.bash\n/' $C_INCLUDE_DEST/*.h $C_SRC_DEST/*.c @@ -57,6 +61,7 @@ mkdir -p $CPP_INCLUDE_DEST rm -f $CPP_INCLUDE_DEST/*.hpp cp $CPP_DETAIL/*__struct.hpp $CPP_INCLUDE_DEST +_all_copied="$_all_copied $CPP_DETAIL_SUBPATH/*__struct.hpp" pushd $CPP_INCLUDE_DEST # add copy notice @@ -82,5 +87,5 @@ cat << EOF > $SCRIPT_DIR/type_description.fingerprint # INTENTIONALLY CHANGING THIS FILE OUTSIDE THE SCRIPT WILL RESULT IN UNDEFINED BEHAVIOR FOR ALL OF ROS 2 CORE EOF pushd $BUILD_DIR -sha256sum --tag $C_DETAIL_SUBPATH/*__struct.h $C_DETAIL_SUBPATH/*__functions.h $C_DETAIL_SUBPATH/*__functions.c $CPP_DETAIL_SUBPATH/*__struct.hpp >> $SCRIPT_DIR/type_description.fingerprint +sha256sum --tag $_all_copied >> $SCRIPT_DIR/type_description.fingerprint popd diff --git a/scripts/type_description.fingerprint b/scripts/type_description.fingerprint index dc8ea2d93..d24ec840d 100644 --- a/scripts/type_description.fingerprint +++ b/scripts/type_description.fingerprint @@ -1,26 +1,32 @@ # DO NOT EDIT MANUALLY - managed by scripts/copy_type_description_generated_sources.bash # INTENTIONALLY CHANGING THIS FILE OUTSIDE THE SCRIPT WILL RESULT IN UNDEFINED BEHAVIOR FOR ALL OF ROS 2 CORE -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__struct.h) = 8e8d4bda083418457e6672f48d9b40ba6d5874bb6e45b01d1ccbf4b6c00754f6 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__struct.h) = 464743d024e0b36dd71ea3344ef0fc6a05b160f975336b9d3833fc65882f4d77 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__struct.h) = 7d137429ca2061199b6fbe328d69c5ae3a8506873c45c0bf27e23939d73161a8 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__struct.h) = 755b7d58c60a260d2524b962979b7328ba39da663f38f4534034d53ae5d32f6c -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__struct.h) = 61e682c4b4c2e90a167a0c5aa3016ac5159c85e389747fca0e83b76d1c625975 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__struct.h) = 97c6161b949400146863f228c51be6dc9e0902d7fb5d5322d81d2dc89f73612b -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.h) = 7200d2723bc2afca31e53654537373b9ea579179a838387d4cdf381a8503597d -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.h) = 9d25952ff75b4091928fe6ed7f25794520db2b772cca518478ecb5cc8c291f50 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.h) = 1ad5fb69750cdfbf442345f5fa3e8ed62349a3276490f603a38b1c485d1c1f70 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.h) = e238fe5e1c477314a9a94817bc927bcc10a8bdf1ecb4aa011bd76925e4998a6f -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.h) = 6992f56d5d8dad46409ee0d92f2e6f9be22c9b263c87d65aea4e61bbfc905d35 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.h) = f3646278e48d68030d08dc112834f2e3a2fc251b6a49fb6de18ed7c366b6874f +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__struct.h) = 7421637a2fdc6badff265e003b278b1d0a7d00fff978649cf1ea3b8310d6d783 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__struct.h) = 268f7eba672e58e3aff74819ff5069e3af71a9f5a61889b097c6235e2d31009c +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__struct.h) = 3fc7cae4450d127d0b84e3aad9894e987372fc49bb75223d95df4ca3184fb163 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__struct.h) = cf45271cd5edb8763c7be0f1c1beb0662f0084b9fc1dd893bfa668b37024ad96 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__struct.h) = b5c3f3a5b21325ee0607ffabfd6a41ce3ff8cf636e37bf52526ff1ea7e15b915 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__struct.h) = 6114c833ebe8bfc48ee4e03fabe1da222e35256ef49b8de7dca80a7d71dab279 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.h) = c65a6eea6802f78ae0d7dee024dc1dc37011b47900f6e33c705cec32697b8cfc +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.h) = 00c0ada3cedc765eb83a8b7e8a83ffb52c35c665ea4ea78017a8e3b51738c96d +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.h) = 9b1ff0df0030fc02e7211901add1806c28ce23d415e4f086101e168a0e4f8710 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.h) = ad33933e81622aa7cd42b648df978e556fa44bdf8cde7e54e5b12f332255d88a +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.h) = 20af0d5be11a8ba85706e10b099da069a98da6225f6d5cadf626b20c0fde8f92 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.h) = 8480a2caa6e6c7732d27954f25fcac9e63bdf02ba81574d69923a91dbdb7e1a3 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.c) = f88b95cf0f78b0b36ff7c19f7b4bae91b5ca09c5051f43fde0231ac49f72dbbb SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.c) = bc462cc468f6db949ebcb78a19e864fce8217d06c64f4ce0cc0a12c9c314569c SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.c) = d0580962fcb537e62c62a837fd98c9063c8882f86af8a07dda8b738786e6ae15 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.c) = 26c004570511e86490d2fe6fdb52c866264ff6c47e8671052476ca440b2fe705 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.c) = bfa6460a62d08b9759893f475c4e6e65cd912017ab5e8a984475c13ea94f8018 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.c) = 710482d1bf1dd5c332f07f1c16e7eb8dd3a9b1badd3f6cd47de19132ae934448 -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field__struct.hpp) = 68e7ded90c66561698cdc33bcf42d27e18e412bd2187c709c0dff17947124507 -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field_type__struct.hpp) = 9157fc0f8c7920a881aa60d76a028bc9439405a52dff8f693ecd443e272cfc9d -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/individual_type_description__struct.hpp) = 62ba41e7cf88df593e92f56507c4c6034d280a73f4e30cfbad3571f139a8704a -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/key_value__struct.hpp) = df504d6a50d975be55cb1d94210f58b4be03aa79a6e7c8a026b4fe048159bed0 -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/type_description__struct.hpp) = e6dccdd0c1feb68f409a95584a6f35e06500219c368cb6d5ef766315cfe694e0 -SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/type_source__struct.hpp) = ec9b144a0c1f244ca425c6aa2c591fb0e240c58a0ee4bb8a50e09e3d02245327 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = 76c14f2cad6991e5e314a799c0703590df7f6a50ecebc180061dc5e3a63d81e3 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = 2081fb90df365e01afad4c4e95aa4d509166a0544a9705b94ca392a4484b8ead +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 790e7c0ea3a446e4d7a80ef5e6edddce05a081a313acd0b4f7198561c03dd51d +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = f3d6e0374ecf8d8c6a84e3bd6b129de36741c0eafb790e1df8b3160482a397a9 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 8b632dc09e0a9c69d936d312284d8c343664a757cb17ca455b6050f7f0262e26 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = b29c7d58ddda3266688a2ce383f99fead5032987b71a51f0fe8ec265557d5723 +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field__struct.hpp) = 95ae3d90f9fbae81a4ffa950fa3ca6e546b8b1f5f853141fc82db40b68be298c +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field_type__struct.hpp) = 4bdc3c22cba31e96ba9d26f667451b9cfe1f683e6f45f4997ad05c3439e4aa46 +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/individual_type_description__struct.hpp) = eda96246cb0fc9fc42ea861b651b8f2f91326c398c2ebc152fe50194118bfa10 +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/key_value__struct.hpp) = 82fb90dd4491c00cbea9210aea6df39900d45cdc262c303ba6811fd9362ee50b +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/type_description__struct.hpp) = 6c7080681f57b5f86d6564cedebc8032d4e428d134be1241fe3f9d5763f5ede5 +SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/type_source__struct.hpp) = 2768df2e93c46191706edbf58a6ab8550f15392127970b005ab6a8d16650dd8f From 3405deb2b63d00aaf7f5260944af03f1e48683c4 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 16:48:59 -0700 Subject: [PATCH 10/19] Generate full type description raw sources Signed-off-by: Emerson Knapp --- ...sidl_generator_c_generate_interfaces.cmake | 3 +- .../resource/full__description.c.em | 79 +++++++++++++++++-- .../resource/idl__description.c.em | 3 +- .../resource/msg__functions.h.em | 6 ++ .../rosidl_generator_c/test_descriptions.c | 42 ++++++++++ .../__init__.py | 1 + rosidl_pycommon/rosidl_pycommon/__init__.py | 6 ++ 7 files changed, 131 insertions(+), 9 deletions(-) diff --git a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake index bd6d0a50f..85706d0a4 100644 --- a/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake +++ b/rosidl_generator_c/cmake/rosidl_generator_c_generate_interfaces.cmake @@ -79,8 +79,6 @@ foreach(dep ${target_dependencies}) endforeach() get_target_property(_target_sources ${rosidl_generate_interfaces_TARGET} SOURCES) -message(WARNING "TARGET SOURCES ${_target_sources}") - set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c__arguments.json") rosidl_write_generator_arguments( "${generator_arguments_file}" @@ -91,6 +89,7 @@ rosidl_write_generator_arguments( TEMPLATE_DIR "${rosidl_generator_c_TEMPLATE_DIR}" TARGET_DEPENDENCIES ${target_dependencies} TYPE_DESCRIPTION_TUPLES "${${rosidl_generate_interfaces_TARGET}__DESCRIPTION_TUPLES}" + ROS_INTERFACE_FILES "${_target_sources}" ) find_package(Python3 REQUIRED COMPONENTS Interpreter) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index edc23f248..ee4d3f178 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -7,11 +7,18 @@ from rosidl_parser.definition import NamespacedType from rosidl_generator_type_description import FIELD_TYPE_ID_TO_NAME from rosidl_generator_type_description import GET_DESCRIPTION_FUNC from rosidl_generator_type_description import GET_HASH_FUNC +from rosidl_generator_type_description import GET_INDIVIDUAL_SOURCE_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC def typename_to_c(typename): return typename.replace('/', '__') +def static_seq_n(varname, n): + """Statically define a runtime Sequence or String type.""" + if n > 0: + return f'{{{varname}, {n}, {n}}}' + return '{NULL, 0, 0}' + def static_seq(varname, values): """Statically define a runtime Sequence or String type.""" if values: @@ -37,6 +44,10 @@ for referenced_td in toplevel_msg['referenced_type_descriptions']: full_type_descriptions = [toplevel_type_description] + implicit_type_descriptions full_type_names = [t['type_description']['type_name'] for t, _ in full_type_descriptions] all_type_descriptions = [toplevel_msg['type_description']] + toplevel_msg['referenced_type_descriptions'] + +toplevel_encoding = type_source_file.suffix[1:] +with open(type_source_file, 'r') as f: + raw_source_content = f.read() }@ #include @@ -62,6 +73,9 @@ static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_ static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; @[end for]@ +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Define all values going into each local type +@ @[for msg, interface_type in full_type_descriptions]@ @{ itype_description = msg['type_description'] @@ -78,7 +92,6 @@ static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(escape_stri @[ end if]@ @[ end for]@ -/// Define arrays of Fields @ @[ if itype_description['fields']]@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { @@ -97,7 +110,6 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { }; @[ end if]@ -/// Define exported TypeDescription and TypeSources @[ if ref_tds]@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { @[ for ref_td in ref_tds]@ @@ -139,12 +151,67 @@ c_typename = typename_to_c(ref_td['type_name']) } return &description; } +@[end for]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Define Raw Sources +@[if raw_source_content]@ +static char toplevel_type_raw_source[] = ""@ +@[ for line in raw_source_content.splitlines()] +"@(escape_string(line))\n"@ +@[ end for]@ +; +@[end if]@ +@ +static char @(toplevel_encoding)_encoding[] = "@(toplevel_encoding)"; +@[if implicit_type_descriptions]@ +static char implicit_encoding[] = "implicit"; +@[end if]@ +@ +@[for type_description_msg, interface_type in full_type_descriptions]@ +@{ +itype_description = type_description_msg['type_description'] +td_typename = itype_description['type_name'] +td_c_typename = typename_to_c(td_typename) +encoding = 'implicit' if td_typename in implicit_type_names else toplevel_encoding +contents = None if td_typename in implicit_type_names else raw_source_content +}@ + +const rosidl_runtime_c__type_description__TypeSource * +@(td_c_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_@(interface_type)_type_support_t *) +{ + static const rosidl_runtime_c__type_description__TypeSource source = { + @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), + @(static_seq(f'{encoding}_encoding', encoding)), + @(static_seq('toplevel_type_raw_source', contents)), + }; + return &source; +} +@[end for]@ +@ +@[for type_description_msg, interface_type in full_type_descriptions]@ +@{ +ref_tds = type_description_msg['referenced_type_descriptions'] +num_sources = len(ref_tds) + 1 +td_c_typename = typename_to_c(type_description_msg['type_description']['type_name']) +}@ const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(td_c_typename)__@(GET_SOURCES_FUNC)(const rosidl_@(interface_type)_type_support_t *) +@(td_c_typename)__@(GET_SOURCES_FUNC)( + const rosidl_@(interface_type)_type_support_t *) { -@# TODO(ek) Implement raw source code embedding/generation. This sequence is left empty for now. - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = @(static_seq(None, '')); - return &sources; + static rosidl_runtime_c__type_description__TypeSource sources[@(num_sources)]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = @(static_seq_n('sources', num_sources)); + static bool constructed = false; + if (!constructed) { + sources[0] = *@(td_c_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)(NULL), +@[ for idx, ref_td in enumerate(ref_tds)]@ + sources[@(idx)] = *@(typename_to_c(ref_td['type_name']))__@(GET_INDIVIDUAL_SOURCE_FUNC)(NULL); +@[ end for]@ + constructed = true; + } + return &source_sequence; } @[end for]@ diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 9df38baad..224f0439c 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -92,6 +92,7 @@ TEMPLATE( 'full__description.c.em', toplevel_type_description=toplevel_type_description, implicit_type_descriptions=implicit_type_descriptions, - hash_lookup=hash_lookup) + hash_lookup=hash_lookup, + type_source_file=type_source_file) }@ @[end if]@ diff --git a/rosidl_generator_c/resource/msg__functions.h.em b/rosidl_generator_c/resource/msg__functions.h.em index 7397f70e0..1324d1cde 100644 --- a/rosidl_generator_c/resource/msg__functions.h.em +++ b/rosidl_generator_c/resource/msg__functions.h.em @@ -5,6 +5,7 @@ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_c import interface_path_to_string from rosidl_generator_type_description import GET_DESCRIPTION_FUNC from rosidl_generator_type_description import GET_HASH_FUNC +from rosidl_generator_type_description import GET_INDIVIDUAL_SOURCE_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC message_typename = idl_structure_type_to_c_typename(message.structure.namespaced_type) @@ -101,6 +102,11 @@ const rosidl_runtime_c__type_description__TypeDescription * @(message_typename)__@(GET_DESCRIPTION_FUNC)( const rosidl_message_type_support_t *); +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_runtime_c__type_description__TypeSource * +@(message_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_message_type_support_t *); + /// Retrieve pointer to the raw source texts that defined the description of the message type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index 77eea1621..f907102dc 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -54,6 +54,7 @@ int description_namecheck( int test_description_linkage(); int test_copied_type_description_struct_hashes(); +int test_source_defined(); int main(void) { @@ -68,6 +69,11 @@ int main(void) fprintf(stderr, "test_copied_type_description_struct_hashes() FAILED\n"); rc++; } + printf("Testing rosidl_generator_tests embedded raw sources...\n"); + if (test_source_defined()) { + fprintf(stderr, "test_source_defined() FAILED\n"); + rc++; + } if (rc != 0) { fprintf(stderr, "Some tests failed!\n"); @@ -135,6 +141,42 @@ int test_description_linkage() return 0; } +int test_source_defined() +{ + // Smoke test that definitions are present for raw type sources + // Message + if (!rosidl_generator_tests__msg__Defaults__get_type_description_sources(NULL)) { + return 1; + } + + // Service + if (!rosidl_generator_tests__srv__Empty__get_type_description_sources(NULL)) { + return 1; + } + // Implicit message of a service + if (!rosidl_generator_tests__srv__Empty_Response__get_type_description_sources(NULL)) { + return 1; + } + + // Action + if (!rosidl_generator_tests__action__Fibonacci__get_type_description_sources(NULL)) { + return 1; + } + // Implicit message of an action + if (!rosidl_generator_tests__action__Fibonacci_Goal__get_type_description_sources(NULL)) { + return 1; + } + // Implicit service of an action + if (!rosidl_generator_tests__action__Fibonacci_GetResult__get_type_description_sources(NULL)) { + return 1; + } + // Implicit message of implicit service of an action + if (!rosidl_generator_tests__action__Fibonacci_SendGoal_Response__get_type_description_sources(NULL)) { + return 1; + } + return 0; +} + int test_copied_type_description_struct_hashes() { #define runtimehash(x) rosidl_runtime_c__type_description__ ## x ## __get_type_hash(NULL) diff --git a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py index 7e2810fab..a940a04fb 100644 --- a/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py +++ b/rosidl_generator_type_description/rosidl_generator_type_description/__init__.py @@ -35,6 +35,7 @@ # Used by code generators to create variable names GET_DESCRIPTION_FUNC = 'get_type_description' GET_HASH_FUNC = 'get_type_hash' +GET_INDIVIDUAL_SOURCE_FUNC = 'get_individual_type_description_source' GET_SOURCES_FUNC = 'get_type_description_sources' diff --git a/rosidl_pycommon/rosidl_pycommon/__init__.py b/rosidl_pycommon/rosidl_pycommon/__init__.py index a8b4ff14b..b9ba04913 100644 --- a/rosidl_pycommon/rosidl_pycommon/__init__.py +++ b/rosidl_pycommon/rosidl_pycommon/__init__.py @@ -67,6 +67,10 @@ def generate_files( tuple_parts = description_tuple.split(':', 1) assert len(tuple_parts) == 2 type_description_files[tuple_parts[0]] = tuple_parts[1] + ros_interface_files = {} + for ros_interface_file in args.get('ros_interface_files', []): + p = pathlib.Path(ros_interface_file) + ros_interface_files[p.stem] = p for idl_tuple in args.get('idl_tuples', []): idl_parts = idl_tuple.rsplit(':', 1) @@ -81,6 +85,7 @@ def generate_files( type_description_info = json.load(f) idl_stem = idl_rel_path.stem + type_source_file = ros_interface_files.get(idl_stem, locator.get_absolute_path()) if not keep_case: idl_stem = convert_camel_case_to_lower_case_underscore(idl_stem) try: @@ -95,6 +100,7 @@ def generate_files( 'interface_path': idl_rel_path, 'content': idl_file.content, 'type_description_info': type_description_info, + 'type_source_file': type_source_file, } if additional_context is not None: data.update(additional_context) From a6b610bf7e5e55c6ea57b1a81a7631fe5d1b5fdd Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 17:07:36 -0700 Subject: [PATCH 11/19] Add names to variables in function signatures Signed-off-by: Emerson Knapp --- .../resource/empty__description.c.em | 23 +++++- .../resource/full__description.c.em | 28 ++++--- .../resource/idl__description.c.em | 4 +- .../resource/idl__functions.h.em | 73 +++++++++++++------ .../resource/msg__functions.h.em | 15 ++-- .../rosidl_generator_c/test_descriptions.c | 4 +- 6 files changed, 100 insertions(+), 47 deletions(-) diff --git a/rosidl_generator_c/resource/empty__description.c.em b/rosidl_generator_c/resource/empty__description.c.em index 2ec1f0332..2c6e4210f 100644 --- a/rosidl_generator_c/resource/empty__description.c.em +++ b/rosidl_generator_c/resource/empty__description.c.em @@ -8,15 +8,17 @@ def typename_to_c(typename): }@ /// Define exported TypeDescriptions and TypeSources -@[for msg in [toplevel_type_description] + implicit_type_descriptions]@ +@[for msg, interface_type in [toplevel_type_description] + implicit_type_descriptions]@ @{ td_typename = msg['type_description']['type_name'] td_c_typename = typename_to_c(td_typename) }@ const rosidl_runtime_c__type_description__TypeDescription * -@(td_c_typename)__@(GET_DESCRIPTION_FUNC)() +@(td_c_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; static const rosidl_runtime_c__type_description__TypeDescription description = { { {NULL, 0, 0}, @@ -28,8 +30,23 @@ const rosidl_runtime_c__type_description__TypeDescription * } const rosidl_runtime_c__type_description__TypeSource__Sequence * -@(td_c_typename)__@(GET_SOURCES_FUNC)() +@(td_c_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {NULL, 0, 0}, + {NULL, 0, 0}, + {NULL, 0, 0} + }; + return &source; +} + +const rosidl_runtime_c__type_description__TypeSource__Sequence * +@(td_c_typename)__@(GET_SOURCES_FUNC)( + const rosidl_@(interface_type)_type_support_t * type_support) +{ + (void)type_support; static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; return &sources; } diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index ee4d3f178..23b3d83ef 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -122,8 +122,10 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_type @[ end if]@ const rosidl_runtime_c__type_description__TypeDescription * -@(td_c_typename)__@(GET_DESCRIPTION_FUNC)(const rosidl_@(interface_type)_type_support_t *) +@(td_c_typename)__@(GET_DESCRIPTION_FUNC)( + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -157,18 +159,19 @@ c_typename = typename_to_c(ref_td['type_name']) @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @# Define Raw Sources @[if raw_source_content]@ -static char toplevel_type_raw_source[] = ""@ -@[ for line in raw_source_content.splitlines()] -"@(escape_string(line))\n"@ -@[ end for]@ -; +static char toplevel_type_raw_source[] =@ +@[ for line in raw_source_content.splitlines()[:-1]] + "@(escape_string(line))\n"@ +@[ end for] + "@(escape_string(raw_source_content.splitlines()[-1]))"; @[end if]@ -@ + static char @(toplevel_encoding)_encoding[] = "@(toplevel_encoding)"; @[if implicit_type_descriptions]@ static char implicit_encoding[] = "implicit"; @[end if]@ -@ + +// Define all individual source functions @[for type_description_msg, interface_type in full_type_descriptions]@ @{ itype_description = type_description_msg['type_description'] @@ -180,8 +183,9 @@ contents = None if td_typename in implicit_type_names else raw_source_content const rosidl_runtime_c__type_description__TypeSource * @(td_c_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( - const rosidl_@(interface_type)_type_support_t *) + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; static const rosidl_runtime_c__type_description__TypeSource source = { @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), @(static_seq(f'{encoding}_encoding', encoding)), @@ -190,7 +194,8 @@ const rosidl_runtime_c__type_description__TypeSource * return &source; } @[end for]@ -@ + +// Define all full source sequence functions @[for type_description_msg, interface_type in full_type_descriptions]@ @{ ref_tds = type_description_msg['referenced_type_descriptions'] @@ -200,8 +205,9 @@ td_c_typename = typename_to_c(type_description_msg['type_description']['type_nam const rosidl_runtime_c__type_description__TypeSource__Sequence * @(td_c_typename)__@(GET_SOURCES_FUNC)( - const rosidl_@(interface_type)_type_support_t *) + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; static rosidl_runtime_c__type_description__TypeSource sources[@(num_sources)]; static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = @(static_seq_n('sources', num_sources)); static bool constructed = false; diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index 224f0439c..d95195e6e 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -71,8 +71,10 @@ c_typename = typename.replace('/', '__') }@ ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * -@(c_typename)__@(GET_HASH_FUNC)(const rosidl_@(interface_type)_type_support_t *) +@(c_typename)__@(GET_HASH_FUNC)( + const rosidl_@(interface_type)_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = @(type_hash_to_c_definition(hash_lookup[typename], indent=4)); return &hash; } diff --git a/rosidl_generator_c/resource/idl__functions.h.em b/rosidl_generator_c/resource/idl__functions.h.em index f23659729..dd892aec3 100644 --- a/rosidl_generator_c/resource/idl__functions.h.em +++ b/rosidl_generator_c/resource/idl__functions.h.em @@ -14,6 +14,7 @@ from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_generator_type_description import GET_DESCRIPTION_FUNC from rosidl_generator_type_description import GET_HASH_FUNC +from rosidl_generator_type_description import GET_INDIVIDUAL_SOURCE_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC from rosidl_pycommon import convert_camel_case_to_lower_case_underscore include_parts = [package_name] + list(interface_path.parents[0].parts) + [ @@ -71,23 +72,29 @@ from rosidl_parser.definition import Service @{ service_typename = idl_structure_type_to_c_typename(service.namespaced_type) }@ -/// Retrieve pointer to the hash of the description of the service type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(service_typename)__@(GET_HASH_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the description of the service type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * @(service_typename)__@(GET_DESCRIPTION_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the service type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_runtime_c__type_description__TypeSource * +@(service_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_service_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * @(service_typename)__@(GET_SOURCES_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); @{ TEMPLATE( @@ -123,23 +130,29 @@ action_typename = idl_structure_type_to_c_typename(action.namespaced_type) send_goal_srv_typename = idl_structure_type_to_c_typename(action.send_goal_service.namespaced_type) get_result_srv_typename = idl_structure_type_to_c_typename(action.get_result_service.namespaced_type) }@ -/// Retrieve pointer to the hash of the description of the service type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(action_typename)__@(GET_HASH_FUNC)( - const rosidl_action_type_support_t *); + const rosidl_action_type_support_t * type_support); -/// Retrieve pointer to the description of the action type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * @(action_typename)__@(GET_DESCRIPTION_FUNC)( - const rosidl_action_type_support_t *); + const rosidl_action_type_support_t * type_support); + +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_runtime_c__type_description__TypeSource * +@(action_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_action_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the action type. +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * @(action_typename)__@(GET_SOURCES_FUNC)( - const rosidl_action_type_support_t *); + const rosidl_action_type_support_t * type_support); @{ TEMPLATE( @@ -162,23 +175,29 @@ TEMPLATE( message=action.feedback) }@ -/// Retrieve pointer to the hash of the description of the service type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(send_goal_srv_typename)__@(GET_HASH_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the description of the service type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * @(send_goal_srv_typename)__@(GET_DESCRIPTION_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the service type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_runtime_c__type_description__TypeSource * +@(send_goal_srv_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_service_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * @(send_goal_srv_typename)__@(GET_SOURCES_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); @{ TEMPLATE( @@ -201,23 +220,29 @@ TEMPLATE( message=action.send_goal_service.event_message) }@ -/// Retrieve pointer to the hash of the description of the service type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(get_result_srv_typename)__@(GET_HASH_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the description of the service type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * @(get_result_srv_typename)__@(GET_DESCRIPTION_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); + +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC_@(package_name) +const rosidl_runtime_c__type_description__TypeSource * +@(get_result_srv_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( + const rosidl_service_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the service type. +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * @(get_result_srv_typename)__@(GET_SOURCES_FUNC)( - const rosidl_service_type_support_t *); + const rosidl_service_type_support_t * type_support); @{ TEMPLATE( diff --git a/rosidl_generator_c/resource/msg__functions.h.em b/rosidl_generator_c/resource/msg__functions.h.em index 1324d1cde..af8b208c8 100644 --- a/rosidl_generator_c/resource/msg__functions.h.em +++ b/rosidl_generator_c/resource/msg__functions.h.em @@ -90,28 +90,29 @@ bool const @(message_typename) * input, @(message_typename) * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_type_hash_t * @(message_typename)__@(GET_HASH_FUNC)( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeDescription * @(message_typename)__@(GET_DESCRIPTION_FUNC)( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); +/// Retrieve pointer to the single raw source text that defined this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource * @(message_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC_@(package_name) const rosidl_runtime_c__type_description__TypeSource__Sequence * @(message_typename)__@(GET_SOURCES_FUNC)( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); @####################################################################### @# array functions diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index f907102dc..af44fe425 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -171,7 +171,9 @@ int test_source_defined() return 1; } // Implicit message of implicit service of an action - if (!rosidl_generator_tests__action__Fibonacci_SendGoal_Response__get_type_description_sources(NULL)) { + if (!rosidl_generator_tests__action__Fibonacci_SendGoal_Response__get_type_description_sources( + NULL)) + { return 1; } return 0; From feb0503fcec6d600201438856ce66c6a036b95ea Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 17:35:08 -0700 Subject: [PATCH 12/19] Update runtime_c sources Signed-off-by: Emerson Knapp --- .../type_description/field__functions.h | 19 +- .../type_description/field_type__functions.h | 19 +- .../individual_type_description__functions.h | 19 +- .../type_description/key_value__functions.h | 19 +- .../type_description__functions.h | 19 +- .../type_description/type_source__functions.h | 19 +- .../src/type_description/field__description.c | 55 ++++- .../field_type__description.c | 201 +++++++++++++++++- ...individual_type_description__description.c | 60 +++++- .../type_description/key_value__description.c | 49 ++++- .../type_description__description.c | 56 ++++- .../type_source__description.c | 61 +++++- ...py_type_description_generated_sources.bash | 1 + scripts/type_description.fingerprint | 24 +-- 14 files changed, 523 insertions(+), 98 deletions(-) diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h index 93ed6a95e..4ae248dd6 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__Field__copy( const rosidl_runtime_c__type_description__Field * input, rosidl_runtime_c__type_description__Field * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__Field__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__Field__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__Field__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__Field__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/Field messages. /** diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h index 0d20af464..8b05af417 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/field_type__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__FieldType__copy( const rosidl_runtime_c__type_description__FieldType * input, rosidl_runtime_c__type_description__FieldType * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__FieldType__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__FieldType__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__FieldType__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/FieldType messages. /** diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h index 9bb9616e0..eb297b611 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/individual_type_description__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__copy( const rosidl_runtime_c__type_description__IndividualTypeDescription * input, rosidl_runtime_c__type_description__IndividualTypeDescription * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/IndividualTypeDescription messages. /** diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h index 2259d6843..61503b9d2 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/key_value__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__KeyValue__copy( const rosidl_runtime_c__type_description__KeyValue * input, rosidl_runtime_c__type_description__KeyValue * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__KeyValue__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__KeyValue__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__KeyValue__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__KeyValue__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/KeyValue messages. /** diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h index d2ecff5f2..384a0ab10 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_description__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__TypeDescription__copy( const rosidl_runtime_c__type_description__TypeDescription * input, rosidl_runtime_c__type_description__TypeDescription * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__TypeDescription__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__TypeDescription__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__TypeDescription__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/TypeDescription messages. /** diff --git a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h index 8f15f7ddc..49fcfffe8 100644 --- a/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h +++ b/rosidl_runtime_c/include/rosidl_runtime_c/type_description/type_source__functions.h @@ -17,7 +17,6 @@ extern "C" #include "rosidl_runtime_c/action_type_support_struct.h" #include "rosidl_runtime_c/message_type_support_struct.h" #include "rosidl_runtime_c/service_type_support_struct.h" -#include "rosidl_runtime_c/type_description/type_source__struct.h" #include "rosidl_runtime_c/type_hash.h" #include "rosidl_runtime_c/visibility_control.h" @@ -98,23 +97,29 @@ rosidl_runtime_c__type_description__TypeSource__copy( const rosidl_runtime_c__type_description__TypeSource * input, rosidl_runtime_c__type_description__TypeSource * output); -/// Retrieve pointer to the hash of the description of the message type. +/// Retrieve pointer to the hash of the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * rosidl_runtime_c__type_description__TypeSource__get_type_hash( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the description of the message type. +/// Retrieve pointer to the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__TypeSource__get_type_description( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); + +/// Retrieve pointer to the single raw source text that defined this type. +ROSIDL_GENERATOR_C_PUBLIC +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__TypeSource__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support); -/// Retrieve pointer to the raw source texts that defined the description of the message type. +/// Retrieve pointer to the recursive raw sources that defined the description of this type. ROSIDL_GENERATOR_C_PUBLIC const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__TypeSource__get_type_description_sources( - const rosidl_message_type_support_t *); + const rosidl_message_type_support_t * type_support); /// Initialize array of msg/TypeSource messages. /** diff --git a/rosidl_runtime_c/src/type_description/field__description.c b/rosidl_runtime_c/src/type_description/field__description.c index 2cc96b9ad..6225be342 100644 --- a/rosidl_runtime_c/src/type_description/field__description.c +++ b/rosidl_runtime_c/src/type_description/field__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__Field__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__Field__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, @@ -41,7 +43,6 @@ static char rosidl_runtime_c__type_description__Field__FIELD_NAME__name[] = "nam static char rosidl_runtime_c__type_description__Field__FIELD_NAME__type[] = "type"; static char rosidl_runtime_c__type_description__Field__FIELD_NAME__default_value[] = "default_value"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__Field__FIELDS[] = { { {rosidl_runtime_c__type_description__Field__FIELD_NAME__name, 4, 4}, @@ -75,7 +76,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__Field__REFERENCED_TYPE_DESCRIPTIONS[] = { { {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, @@ -84,8 +84,10 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runt }; const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__Field__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__Field__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -107,9 +109,48 @@ rosidl_runtime_c__type_description__Field__get_type_description(const rosidl_mes return &description; } +static char toplevel_type_raw_source[] = + "# Represents a single field in a type.\n" + "\n" + "# Name of the field.\n" + "string name\n" + "# Type of the field, including details about the type like length, nested name, etc.\n" + "FieldType type\n" + "# Literal default value of the field as a string, as it appeared in the original\n" + "# message description file, whether that be .msg/.srv/.action or .idl.\n" + "string default_value"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__Field__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 346, 346}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__Field__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__Field__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[2]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 2, 2}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__Field__get_individual_type_description_source(NULL), + sources[0] = *rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source(NULL); + constructed = true; + } + return &source_sequence; } diff --git a/rosidl_runtime_c/src/type_description/field_type__description.c b/rosidl_runtime_c/src/type_description/field_type__description.c index f882bc3f6..c7013a139 100644 --- a/rosidl_runtime_c/src/type_description/field_type__description.c +++ b/rosidl_runtime_c/src/type_description/field_type__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__FieldType__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__FieldType__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, @@ -35,7 +37,6 @@ static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__capacity[ static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__string_capacity[] = "string_capacity"; static char rosidl_runtime_c__type_description__FieldType__FIELD_NAME__nested_type_name[] = "nested_type_name"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__FieldType__FIELDS[] = { { {rosidl_runtime_c__type_description__FieldType__FIELD_NAME__type_id, 7, 7}, @@ -79,11 +80,12 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__FieldType__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__FieldType__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -98,9 +100,194 @@ rosidl_runtime_c__type_description__FieldType__get_type_description(const rosidl return &description; } +static char toplevel_type_raw_source[] = + "# Represents the type of a field and related meta-data.\n" + "\n" + "# A constant for each type supported according to:\n" + "# http://design.ros2.org/articles/legacy_interface_definition.html\n" + "# and:\n" + "# http://design.ros2.org/articles/idl_interface_definition.html\n" + "# Order is loosely coupled to the order of appearance in the IDL 4.2 spec:\n" + "# https://www.omg.org/spec/IDL/4.2\n" + "\n" + "# Layout of constants across the 0-255 decimal values in the uint8:\n" + "#\n" + "# - 000 : Reserved for \"not set\"\n" + "# - 001-048: Primitive types, strings, and reserved space for future primitive types\n" + "# - 049-096: Fixed sized array of primitive and string types\n" + "# - 097-144: Bounded Sequences of primitive and string types\n" + "# - 145-192: Unbounded Sequences of primitive and string types\n" + "# - 193-255: Reserved space for future array/sequence-like types\n" + "\n" + "uint8 FIELD_TYPE_NOT_SET = 0\n" + "\n" + "# Nested type defined in other .msg/.idl files.\n" + "uint8 FIELD_TYPE_NESTED_TYPE = 1\n" + "\n" + "# Integer Types\n" + "uint8 FIELD_TYPE_INT8 = 2\n" + "uint8 FIELD_TYPE_UINT8 = 3\n" + "uint8 FIELD_TYPE_INT16 = 4\n" + "uint8 FIELD_TYPE_UINT16 = 5\n" + "uint8 FIELD_TYPE_INT32 = 6\n" + "uint8 FIELD_TYPE_UINT32 = 7\n" + "uint8 FIELD_TYPE_INT64 = 8\n" + "uint8 FIELD_TYPE_UINT64 = 9\n" + "\n" + "# Floating-Point Types\n" + "uint8 FIELD_TYPE_FLOAT = 10\n" + "uint8 FIELD_TYPE_DOUBLE = 11\n" + "uint8 FIELD_TYPE_LONG_DOUBLE = 12\n" + "\n" + "# Char and WChar Types\n" + "uint8 FIELD_TYPE_CHAR = 13\n" + "uint8 FIELD_TYPE_WCHAR = 14\n" + "\n" + "# Boolean Type\n" + "uint8 FIELD_TYPE_BOOLEAN = 15\n" + "\n" + "# Byte/Octet Type\n" + "uint8 FIELD_TYPE_BYTE = 16\n" + "\n" + "# String Types\n" + "uint8 FIELD_TYPE_STRING = 17\n" + "uint8 FIELD_TYPE_WSTRING = 18\n" + "\n" + "# Fixed String Types\n" + "uint8 FIELD_TYPE_FIXED_STRING = 19\n" + "uint8 FIELD_TYPE_FIXED_WSTRING = 20\n" + "\n" + "# Bounded String Types\n" + "uint8 FIELD_TYPE_BOUNDED_STRING = 21\n" + "uint8 FIELD_TYPE_BOUNDED_WSTRING = 22\n" + "\n" + "# Fixed Sized Array Types\n" + "uint8 FIELD_TYPE_NESTED_TYPE_ARRAY = 49\n" + "uint8 FIELD_TYPE_INT8_ARRAY = 50\n" + "uint8 FIELD_TYPE_UINT8_ARRAY = 51\n" + "uint8 FIELD_TYPE_INT16_ARRAY = 52\n" + "uint8 FIELD_TYPE_UINT16_ARRAY = 53\n" + "uint8 FIELD_TYPE_INT32_ARRAY = 54\n" + "uint8 FIELD_TYPE_UINT32_ARRAY = 55\n" + "uint8 FIELD_TYPE_INT64_ARRAY = 56\n" + "uint8 FIELD_TYPE_UINT64_ARRAY = 57\n" + "uint8 FIELD_TYPE_FLOAT_ARRAY = 58\n" + "uint8 FIELD_TYPE_DOUBLE_ARRAY = 59\n" + "uint8 FIELD_TYPE_LONG_DOUBLE_ARRAY = 60\n" + "uint8 FIELD_TYPE_CHAR_ARRAY = 61\n" + "uint8 FIELD_TYPE_WCHAR_ARRAY = 62\n" + "uint8 FIELD_TYPE_BOOLEAN_ARRAY = 63\n" + "uint8 FIELD_TYPE_BYTE_ARRAY = 64\n" + "uint8 FIELD_TYPE_STRING_ARRAY = 65\n" + "uint8 FIELD_TYPE_WSTRING_ARRAY = 66\n" + "uint8 FIELD_TYPE_FIXED_STRING_ARRAY = 67\n" + "uint8 FIELD_TYPE_FIXED_WSTRING_ARRAY = 68\n" + "uint8 FIELD_TYPE_BOUNDED_STRING_ARRAY = 69\n" + "uint8 FIELD_TYPE_BOUNDED_WSTRING_ARRAY = 70\n" + "\n" + "# Bounded Sequence Types\n" + "uint8 FIELD_TYPE_NESTED_TYPE_BOUNDED_SEQUENCE = 97\n" + "uint8 FIELD_TYPE_INT8_BOUNDED_SEQUENCE = 98\n" + "uint8 FIELD_TYPE_UINT8_BOUNDED_SEQUENCE = 99\n" + "uint8 FIELD_TYPE_INT16_BOUNDED_SEQUENCE = 100\n" + "uint8 FIELD_TYPE_UINT16_BOUNDED_SEQUENCE = 101\n" + "uint8 FIELD_TYPE_INT32_BOUNDED_SEQUENCE = 102\n" + "uint8 FIELD_TYPE_UINT32_BOUNDED_SEQUENCE = 103\n" + "uint8 FIELD_TYPE_INT64_BOUNDED_SEQUENCE = 104\n" + "uint8 FIELD_TYPE_UINT64_BOUNDED_SEQUENCE = 105\n" + "uint8 FIELD_TYPE_FLOAT_BOUNDED_SEQUENCE = 106\n" + "uint8 FIELD_TYPE_DOUBLE_BOUNDED_SEQUENCE = 107\n" + "uint8 FIELD_TYPE_LONG_DOUBLE_BOUNDED_SEQUENCE = 108\n" + "uint8 FIELD_TYPE_CHAR_BOUNDED_SEQUENCE = 109\n" + "uint8 FIELD_TYPE_WCHAR_BOUNDED_SEQUENCE = 110\n" + "uint8 FIELD_TYPE_BOOLEAN_BOUNDED_SEQUENCE = 111\n" + "uint8 FIELD_TYPE_BYTE_BOUNDED_SEQUENCE = 112\n" + "uint8 FIELD_TYPE_STRING_BOUNDED_SEQUENCE = 113\n" + "uint8 FIELD_TYPE_WSTRING_BOUNDED_SEQUENCE = 114\n" + "uint8 FIELD_TYPE_FIXED_STRING_BOUNDED_SEQUENCE = 115\n" + "uint8 FIELD_TYPE_FIXED_WSTRING_BOUNDED_SEQUENCE = 116\n" + "uint8 FIELD_TYPE_BOUNDED_STRING_BOUNDED_SEQUENCE = 117\n" + "uint8 FIELD_TYPE_BOUNDED_WSTRING_BOUNDED_SEQUENCE = 118\n" + "\n" + "# Unbounded Sequence Types\n" + "uint8 FIELD_TYPE_NESTED_TYPE_UNBOUNDED_SEQUENCE = 145\n" + "uint8 FIELD_TYPE_INT8_UNBOUNDED_SEQUENCE = 146\n" + "uint8 FIELD_TYPE_UINT8_UNBOUNDED_SEQUENCE = 147\n" + "uint8 FIELD_TYPE_INT16_UNBOUNDED_SEQUENCE = 148\n" + "uint8 FIELD_TYPE_UINT16_UNBOUNDED_SEQUENCE = 149\n" + "uint8 FIELD_TYPE_INT32_UNBOUNDED_SEQUENCE = 150\n" + "uint8 FIELD_TYPE_UINT32_UNBOUNDED_SEQUENCE = 151\n" + "uint8 FIELD_TYPE_INT64_UNBOUNDED_SEQUENCE = 152\n" + "uint8 FIELD_TYPE_UINT64_UNBOUNDED_SEQUENCE = 153\n" + "uint8 FIELD_TYPE_FLOAT_UNBOUNDED_SEQUENCE = 154\n" + "uint8 FIELD_TYPE_DOUBLE_UNBOUNDED_SEQUENCE = 155\n" + "uint8 FIELD_TYPE_LONG_DOUBLE_UNBOUNDED_SEQUENCE = 156\n" + "uint8 FIELD_TYPE_CHAR_UNBOUNDED_SEQUENCE = 157\n" + "uint8 FIELD_TYPE_WCHAR_UNBOUNDED_SEQUENCE = 158\n" + "uint8 FIELD_TYPE_BOOLEAN_UNBOUNDED_SEQUENCE = 159\n" + "uint8 FIELD_TYPE_BYTE_UNBOUNDED_SEQUENCE = 160\n" + "uint8 FIELD_TYPE_STRING_UNBOUNDED_SEQUENCE = 161\n" + "uint8 FIELD_TYPE_WSTRING_UNBOUNDED_SEQUENCE = 162\n" + "uint8 FIELD_TYPE_FIXED_STRING_UNBOUNDED_SEQUENCE = 163\n" + "uint8 FIELD_TYPE_FIXED_WSTRING_UNBOUNDED_SEQUENCE = 164\n" + "uint8 FIELD_TYPE_BOUNDED_STRING_UNBOUNDED_SEQUENCE = 165\n" + "uint8 FIELD_TYPE_BOUNDED_WSTRING_UNBOUNDED_SEQUENCE = 166\n" + "\n" + "# Identifying number for the type of the field, using one of the above constants.\n" + "uint8 type_id 0\n" + "\n" + "# Only used when the type is an array or a bounded sequence.\n" + "# In the case of an array, this is the fixed capacity of the array.\n" + "# In the case of a bounded sequence, this is the maximum capacity of the sequence.\n" + "# In all other cases this field is unused.\n" + "uint64 capacity\n" + "\n" + "# Only used when the type is a fixed or bounded string/wstring, or a array/sequence of those.\n" + "# In the case of a fixed string/wstring, it is the fixed length of the string.\n" + "# In the case of a bounded string/wstring, it is the maximum capacity of the string.\n" + "# In the case of an array/sequence of fixed string/wstring, it is the fixed length of the strings.\n" + "# In the case of an array/sequence of bounded string/wstring, it is the maximum capacity of the strings.\n" + "# It is not currently possible to have different string capacities per element in the array/sequence.\n" + "uint64 string_capacity\n" + "\n" + "# Only used when the type is a nested type or array/sequence of nested types.\n" + "# This is limited to 255 characters.\n" + "# TODO(wjwwood): this 255 character limit was chosen due to this being the limit\n" + "# for DDSI-RTPS based middlewares, which is the most commonly used right now.\n" + "# We lack a ROS 2 specific limit in our design documents, but we should update\n" + "# this and/or link to the design doc when that is available.\n" + "string<=255 nested_type_name"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__FieldType__TYPE_NAME, 41, 41}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 6162, 6162}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__FieldType__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__FieldType__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[1]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 1, 1}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source(NULL), + constructed = true; + } + return &source_sequence; } diff --git a/rosidl_runtime_c/src/type_description/individual_type_description__description.c b/rosidl_runtime_c/src/type_description/individual_type_description__description.c index 2877cae3c..99b0dacc0 100644 --- a/rosidl_runtime_c/src/type_description/individual_type_description__description.c +++ b/rosidl_runtime_c/src/type_description/individual_type_description__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0x55, 0xc8, 0x27, 0xd8, 0x6c, 0x3c, 0x14, 0x1b, 0xdd, 0x31, 0x8f, 0xe6, 0xc2, 0x2e, 0x11, 0x19, @@ -22,8 +24,8 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(con #include #include // Include directives for referenced types -#include "rosidl_runtime_c/type_description/field_type__functions.h" #include "rosidl_runtime_c/type_description/field__functions.h" +#include "rosidl_runtime_c/type_description/field_type__functions.h" // Expected hashes for externally referenced types static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { @@ -48,7 +50,6 @@ static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_d static char rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__type_name[] = "type_name"; static char rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__fields[] = "fields"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__IndividualTypeDescription__FIELDS[] = { { {rosidl_runtime_c__type_description__IndividualTypeDescription__FIELD_NAME__type_name, 9, 9}, @@ -72,7 +73,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__IndividualTypeDescription__REFERENCED_TYPE_DESCRIPTIONS[] = { { {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, @@ -85,8 +85,10 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runt }; const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -115,9 +117,51 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_descript return &description; } +static char toplevel_type_raw_source[] = + "# Represents a single type, without the types it references, if any.\n" + "\n" + "# Name of the type.\n" + "# This is limited to 255 characters.\n" + "# TODO(wjwwood): this 255 character limit was chosen due to this being the limit\n" + "# for DDSI-RTPS based middlewares, which is the most commonly used right now.\n" + "# We lack a ROS 2 specific limit in our design documents, but we should update\n" + "# this and/or link to the design doc when that is available.\n" + "string<=255 type_name\n" + "# Fields of the type.\n" + "Field[] fields"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__IndividualTypeDescription__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME, 57, 57}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 491, 491}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[3]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 3, 3}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__IndividualTypeDescription__get_individual_type_description_source(NULL), + sources[0] = *rosidl_runtime_c__type_description__Field__get_individual_type_description_source(NULL); + sources[1] = *rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source(NULL); + constructed = true; + } + return &source_sequence; } diff --git a/rosidl_runtime_c/src/type_description/key_value__description.c b/rosidl_runtime_c/src/type_description/key_value__description.c index 2e1483f6a..76c836478 100644 --- a/rosidl_runtime_c/src/type_description/key_value__description.c +++ b/rosidl_runtime_c/src/type_description/key_value__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__KeyValue__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__KeyValue__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0x27, 0x4f, 0xe5, 0x6b, 0xf1, 0x4f, 0x33, 0xc7, 0x51, 0x2e, 0x34, 0xc6, 0x46, 0xa3, 0x75, 0x79, @@ -32,7 +34,6 @@ static char rosidl_runtime_c__type_description__KeyValue__TYPE_NAME[] = "type_de static char rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__key[] = "key"; static char rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__value[] = "value"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__KeyValue__FIELDS[] = { { {rosidl_runtime_c__type_description__KeyValue__FIELD_NAME__key, 3, 3}, @@ -56,11 +57,12 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__KeyValue__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__KeyValue__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -75,9 +77,42 @@ rosidl_runtime_c__type_description__KeyValue__get_type_description(const rosidl_ return &description; } +static char toplevel_type_raw_source[] = + "# Represents an arbitrary key-value pair for application-specific information.\n" + "\n" + "string key\n" + "string value"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__KeyValue__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__KeyValue__TYPE_NAME, 40, 40}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 104, 104}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__KeyValue__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__KeyValue__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[1]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 1, 1}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__KeyValue__get_individual_type_description_source(NULL), + constructed = true; + } + return &source_sequence; } diff --git a/rosidl_runtime_c/src/type_description/type_description__description.c b/rosidl_runtime_c/src/type_description/type_description__description.c index 1867485d9..207378240 100644 --- a/rosidl_runtime_c/src/type_description/type_description__description.c +++ b/rosidl_runtime_c/src/type_description/type_description__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__TypeDescription__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeDescription__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0x73, 0x9f, 0x25, 0x08, 0xc9, 0xfa, 0x3a, 0x6f, 0x33, 0x09, 0x13, 0xff, 0x5b, 0x9d, 0x25, 0xfb, @@ -22,9 +24,9 @@ rosidl_runtime_c__type_description__TypeDescription__get_type_hash(const rosidl_ #include #include // Include directives for referenced types +#include "rosidl_runtime_c/type_description/field__functions.h" #include "rosidl_runtime_c/type_description/individual_type_description__functions.h" #include "rosidl_runtime_c/type_description/field_type__functions.h" -#include "rosidl_runtime_c/type_description/field__functions.h" // Expected hashes for externally referenced types static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { @@ -56,7 +58,6 @@ static char rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_ static char rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__type_description[] = "type_description"; static char rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__referenced_type_descriptions[] = "referenced_type_descriptions"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__TypeDescription__FIELDS[] = { { {rosidl_runtime_c__type_description__TypeDescription__FIELD_NAME__type_description, 16, 16}, @@ -80,7 +81,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runtime_c__type_description__TypeDescription__REFERENCED_TYPE_DESCRIPTIONS[] = { { {rosidl_runtime_c__type_description__Field__TYPE_NAME, 37, 37}, @@ -97,8 +97,10 @@ static rosidl_runtime_c__type_description__IndividualTypeDescription rosidl_runt }; const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__TypeDescription__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeDescription__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -134,9 +136,47 @@ rosidl_runtime_c__type_description__TypeDescription__get_type_description(const return &description; } +static char toplevel_type_raw_source[] = + "# Represents a complete type description, including the type itself as well as the types it references.\n" + "\n" + "# Description of the type.\n" + "IndividualTypeDescription type_description\n" + "# Descriptions of all referenced types, recursively.\n" + "IndividualTypeDescription[] referenced_type_descriptions"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__TypeDescription__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__TypeDescription__TYPE_NAME, 47, 47}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 285, 285}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[4]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 4, 4}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__TypeDescription__get_individual_type_description_source(NULL), + sources[0] = *rosidl_runtime_c__type_description__Field__get_individual_type_description_source(NULL); + sources[1] = *rosidl_runtime_c__type_description__FieldType__get_individual_type_description_source(NULL); + sources[2] = *rosidl_runtime_c__type_description__IndividualTypeDescription__get_individual_type_description_source(NULL); + constructed = true; + } + return &source_sequence; } diff --git a/rosidl_runtime_c/src/type_description/type_source__description.c b/rosidl_runtime_c/src/type_description/type_source__description.c index 393fcab91..e49ae9cee 100644 --- a/rosidl_runtime_c/src/type_description/type_source__description.c +++ b/rosidl_runtime_c/src/type_description/type_source__description.c @@ -7,8 +7,10 @@ ROSIDL_GENERATOR_C_PUBLIC const rosidl_type_hash_t * -rosidl_runtime_c__type_description__TypeSource__get_type_hash(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeSource__get_type_hash( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static rosidl_type_hash_t hash = {1, { 0xfa, 0xea, 0xec, 0x75, 0x96, 0xc0, 0x4e, 0xcf, 0x5b, 0x6e, 0x99, 0xad, 0x22, 0x5e, 0x4c, 0x7c, @@ -33,7 +35,6 @@ static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__type_nam static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__encoding[] = "encoding"; static char rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__raw_file_contents[] = "raw_file_contents"; -/// Define arrays of Fields static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_description__TypeSource__FIELDS[] = { { {rosidl_runtime_c__type_description__TypeSource__FIELD_NAME__type_name, 9, 9}, @@ -67,11 +68,12 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; -/// Define exported TypeDescription and TypeSources const rosidl_runtime_c__type_description__TypeDescription * -rosidl_runtime_c__type_description__TypeSource__get_type_description(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeSource__get_type_description( + const rosidl_message_type_support_t * type_support) { + (void)type_support; static bool constructed = false; static const rosidl_runtime_c__type_description__TypeDescription description = { { @@ -86,9 +88,54 @@ rosidl_runtime_c__type_description__TypeSource__get_type_description(const rosid return &description; } +static char toplevel_type_raw_source[] = + "# Represents the original source of a ROS 2 interface definition.\n" + "\n" + "# ROS interface type name, in PACKAGE/NAMESPACE/TYPENAME format.\n" + "string type_name\n" + "\n" + "# The type of the original source file, typically matching the file extension.\n" + "# Well-known encodings: \"idl\", \"msg\", \"srv\", \"action\", \"dynamic\", \"implicit\".\n" + "# \"dynamic\" specifies a type created programmatically by a user, thus having no source.\n" + "# \"implicit\" specifies a type created automatically as a subtype of a\n" + "# complex type (service or action) - such as the request message for a service.\n" + "# Implicit types will have no contents, the full source will be available on the parent srv/action.\n" + "string encoding\n" + "\n" + "# Dumped contents of the interface definition source file.\n" + "# If `encoding` is \"dynamic\" or \"implicit\", this field will be empty.\n" + "string raw_file_contents"; + +static char msg_encoding[] = "msg"; + +// Define all individual source functions + +const rosidl_runtime_c__type_description__TypeSource * +rosidl_runtime_c__type_description__TypeSource__get_individual_type_description_source( + const rosidl_message_type_support_t * type_support) +{ + (void)type_support; + static const rosidl_runtime_c__type_description__TypeSource source = { + {rosidl_runtime_c__type_description__TypeSource__TYPE_NAME, 42, 42}, + {msg_encoding, 3, 3}, + {toplevel_type_raw_source, 816, 816}, + }; + return &source; +} + +// Define all full source sequence functions + const rosidl_runtime_c__type_description__TypeSource__Sequence * -rosidl_runtime_c__type_description__TypeSource__get_type_description_sources(const rosidl_message_type_support_t *) +rosidl_runtime_c__type_description__TypeSource__get_type_description_sources( + const rosidl_message_type_support_t * type_support) { - static const rosidl_runtime_c__type_description__TypeSource__Sequence sources = {NULL, 0, 0}; - return &sources; + (void)type_support; + static rosidl_runtime_c__type_description__TypeSource sources[1]; + static const rosidl_runtime_c__type_description__TypeSource__Sequence source_sequence = {sources, 1, 1}; + static bool constructed = false; + if (!constructed) { + sources[0] = *rosidl_runtime_c__type_description__TypeSource__get_individual_type_description_source(NULL), + constructed = true; + } + return &source_sequence; } diff --git a/scripts/copy_type_description_generated_sources.bash b/scripts/copy_type_description_generated_sources.bash index c669472fa..bfddfed2b 100755 --- a/scripts/copy_type_description_generated_sources.bash +++ b/scripts/copy_type_description_generated_sources.bash @@ -47,6 +47,7 @@ sed -i '1s/^/\/\/ DO NOT EDIT MANUALLY - this copied file managed by copy_type_d # remove unnecessary includes (before doing replacements) sed -i '/type_description_interfaces\/msg\/rosidl_generator_c__visibility_control.h/d' $C_INCLUDE_DEST/*.h $C_SRC_DEST/*.c sed -i '/#include "rosidl_runtime_c\/type_description\/type_description__struct.h/d' $C_INCLUDE_DEST/*.h $C_SRC_DEST/*.c +sed -i '/#include "rosidl_runtime_c\/type_description\/type_source__struct.h/d' $C_INCLUDE_DEST/*.h $C_SRC_DEST/*.c # include guards sed -i -e 's/TYPE_DESCRIPTION_INTERFACES__MSG__DETAIL__/ROSIDL_RUNTIME_C__TYPE_DESCRIPTION__/g' $C_INCLUDE_DEST/*.h $C_SRC_DEST/*.c # visibility macros diff --git a/scripts/type_description.fingerprint b/scripts/type_description.fingerprint index d24ec840d..224936d3b 100644 --- a/scripts/type_description.fingerprint +++ b/scripts/type_description.fingerprint @@ -6,24 +6,24 @@ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_typ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__struct.h) = cf45271cd5edb8763c7be0f1c1beb0662f0084b9fc1dd893bfa668b37024ad96 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__struct.h) = b5c3f3a5b21325ee0607ffabfd6a41ce3ff8cf636e37bf52526ff1ea7e15b915 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__struct.h) = 6114c833ebe8bfc48ee4e03fabe1da222e35256ef49b8de7dca80a7d71dab279 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.h) = c65a6eea6802f78ae0d7dee024dc1dc37011b47900f6e33c705cec32697b8cfc -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.h) = 00c0ada3cedc765eb83a8b7e8a83ffb52c35c665ea4ea78017a8e3b51738c96d -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.h) = 9b1ff0df0030fc02e7211901add1806c28ce23d415e4f086101e168a0e4f8710 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.h) = ad33933e81622aa7cd42b648df978e556fa44bdf8cde7e54e5b12f332255d88a -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.h) = 20af0d5be11a8ba85706e10b099da069a98da6225f6d5cadf626b20c0fde8f92 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.h) = 8480a2caa6e6c7732d27954f25fcac9e63bdf02ba81574d69923a91dbdb7e1a3 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.h) = 236841c1ee21672bcc382bf92da64d7575978afffe3cdbd4f56b133cee65c6d1 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.h) = 5829ddc30a8af7d4567caea1deed2ef91e30c9f8ce193732702caa27b0d9b042 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.h) = c13ba5bf66f01b719fa186c9d003da26a5a1bcc0a2772b839f2ca1ef0430bdf8 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.h) = c3e563a96047dcf3bb3f2f3044e48890e1913cb741c4af0478a03c10594e7b46 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.h) = 8a87c32f052e2b3288ad85f859143b6a29b4ec17ff07acfc98f1f2f55578add9 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.h) = cf192720c1af20227ec3c9ab5ed113fbbf5d5640276f651c86026f21f0c0c91b SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__functions.c) = f88b95cf0f78b0b36ff7c19f7b4bae91b5ca09c5051f43fde0231ac49f72dbbb SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__functions.c) = bc462cc468f6db949ebcb78a19e864fce8217d06c64f4ce0cc0a12c9c314569c SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__functions.c) = d0580962fcb537e62c62a837fd98c9063c8882f86af8a07dda8b738786e6ae15 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.c) = 26c004570511e86490d2fe6fdb52c866264ff6c47e8671052476ca440b2fe705 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.c) = bfa6460a62d08b9759893f475c4e6e65cd912017ab5e8a984475c13ea94f8018 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.c) = 710482d1bf1dd5c332f07f1c16e7eb8dd3a9b1badd3f6cd47de19132ae934448 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = 76c14f2cad6991e5e314a799c0703590df7f6a50ecebc180061dc5e3a63d81e3 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = 2081fb90df365e01afad4c4e95aa4d509166a0544a9705b94ca392a4484b8ead -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 790e7c0ea3a446e4d7a80ef5e6edddce05a081a313acd0b4f7198561c03dd51d -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = f3d6e0374ecf8d8c6a84e3bd6b129de36741c0eafb790e1df8b3160482a397a9 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 8b632dc09e0a9c69d936d312284d8c343664a757cb17ca455b6050f7f0262e26 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = b29c7d58ddda3266688a2ce383f99fead5032987b71a51f0fe8ec265557d5723 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = fbc4236052056af0975cc757d4046d05be6804b356a10f8c0a612880d68789b3 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = 0727e199305da5244a56b82fbec0ddcd1a60bd397a388f270c3a58105421ae25 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 8f5cd0bc71e95a803a28af4518e005ea2d4a14aff8f66ce2387b2fcf323a9e81 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = 372743353e670a8e4a11dd2c3e628932435b61862d9654ff6b50e910b6de2b99 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 7a5401e2755c7f13a1126c06f0f98cc212451bc5ece373f73fd7baed747228f8 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = ccf854c9dbf21bf469aa32ec16ff47c0b9625c1fe1838801efe2c6df19923946 SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field__struct.hpp) = 95ae3d90f9fbae81a4ffa950fa3ca6e546b8b1f5f853141fc82db40b68be298c SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field_type__struct.hpp) = 4bdc3c22cba31e96ba9d26f667451b9cfe1f683e6f45f4997ad05c3439e4aa46 SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/individual_type_description__struct.hpp) = eda96246cb0fc9fc42ea861b651b8f2f91326c398c2ebc152fe50194118bfa10 From 69fa2b5fb7a925c3b6a39524f22c3a9f5fcd33b2 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 18:12:37 -0700 Subject: [PATCH 13/19] Generated code aesthetic cleanup Signed-off-by: Emerson Knapp --- .../resource/full__description.c.em | 33 +++++++++-------- .../resource/idl__description.c.em | 7 ++++ .../src/type_description/field__description.c | 16 +++------ .../field_type__description.c | 8 ++--- ...individual_type_description__description.c | 25 ++++--------- .../type_description/key_value__description.c | 8 ++--- .../type_description__description.c | 36 +++++-------------- .../type_source__description.c | 8 ++--- scripts/type_description.fingerprint | 12 +++---- 9 files changed, 57 insertions(+), 96 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 23b3d83ef..80ca59642 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -49,15 +49,18 @@ toplevel_encoding = type_source_file.suffix[1:] with open(type_source_file, 'r') as f: raw_source_content = f.read() }@ - +@ #include #include + // Include directives for referenced types @[for header_file in includes]@ #include "@(header_file)" @[end for]@ -// Expected hashes for externally referenced types +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Cache expected hashes for externally referenced types, for error checking +// Hashes for external referenced types @[for referenced_type_description in toplevel_msg['referenced_type_descriptions']]@ @{ type_name = referenced_type_description['type_name'] @@ -67,11 +70,14 @@ c_typename = type_name.replace('/', '__') static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_definition(hash_lookup[type_name])); @[ end if]@ @[end for]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -// Names for all types +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Names for all types @[for itype_description in all_type_descriptions]@ static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])"; @[end for]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @# Define all values going into each local type @@ -109,8 +115,9 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = { @[ end for]@ }; @[ end if]@ - +@ @[ if ref_tds]@ + static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = { @[ for ref_td in ref_tds]@ { @@ -139,15 +146,10 @@ const rosidl_runtime_c__type_description__TypeDescription * @{ c_typename = typename_to_c(ref_td['type_name']) }@ - { @[ if ref_td['type_name'] not in full_type_names]@ - assert(0 == memcmp(&@(c_typename)__EXPECTED_HASH, @(c_typename)__@(GET_HASH_FUNC)(NULL), sizeof(rosidl_type_hash_t))); + assert(0 == memcmp(&@(c_typename)__EXPECTED_HASH, @(c_typename)__@(GET_HASH_FUNC)(NULL), sizeof(rosidl_type_hash_t))); @[ end if]@ - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = @(c_typename)__@(GET_DESCRIPTION_FUNC)(NULL); - description.referenced_type_descriptions.data[@(idx)].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[@(idx)].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[@(idx)].fields.capacity = ref_desc->type_description.fields.capacity; - } + description.referenced_type_descriptions.data[@(idx)].fields = @(c_typename)__@(GET_DESCRIPTION_FUNC)(NULL)->type_description.fields; @[ end for]@ constructed = true; } @@ -157,7 +159,7 @@ c_typename = typename_to_c(ref_td['type_name']) @#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -@# Define Raw Sources +@# Define individual raw sources @[if raw_source_content]@ static char toplevel_type_raw_source[] =@ @[ for line in raw_source_content.splitlines()[:-1]] @@ -194,8 +196,10 @@ const rosidl_runtime_c__type_description__TypeSource * return &source; } @[end for]@ - -// Define all full source sequence functions +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +@ +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Define full raw source sequences @[for type_description_msg, interface_type in full_type_descriptions]@ @{ ref_tds = type_description_msg['referenced_type_descriptions'] @@ -221,3 +225,4 @@ const rosidl_runtime_c__type_description__TypeSource__Sequence * return &source_sequence; } @[end for]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/rosidl_generator_c/resource/idl__description.c.em b/rosidl_generator_c/resource/idl__description.c.em index d95195e6e..7b96d7817 100644 --- a/rosidl_generator_c/resource/idl__description.c.em +++ b/rosidl_generator_c/resource/idl__description.c.em @@ -10,6 +10,7 @@ @# - interface_path (Path relative to the directory named after the package) @# - content (IdlContent, list of elements, e.g. Messages or Services) @# - type_description_info (HashedTypeDescription.schema.json dict) +@# - type_source_file (absolute Path to original source definition file for this interface) @# - disable_description_codegen (bool) @####################################################################### @{ @@ -64,6 +65,8 @@ for action in content.get_elements_of_type(Action): #include "@(include_base)__functions.h" +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Define get_type_hash functions @[for type_description_msg, interface_type in [toplevel_type_description] + implicit_type_descriptions]@ @{ typename = type_description_msg['type_description']['type_name'] @@ -80,7 +83,10 @@ const rosidl_type_hash_t * } @[end for]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @ +@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +@# Descriptions and sources functions (optionally disabled) @[if disable_description_codegen]@ @{ TEMPLATE( @@ -98,3 +104,4 @@ TEMPLATE( type_source_file=type_source_file) }@ @[end if]@ +@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/rosidl_runtime_c/src/type_description/field__description.c b/rosidl_runtime_c/src/type_description/field__description.c index 6225be342..21198c7f5 100644 --- a/rosidl_runtime_c/src/type_description/field__description.c +++ b/rosidl_runtime_c/src/type_description/field__description.c @@ -20,13 +20,13 @@ rosidl_runtime_c__type_description__Field__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types #include "rosidl_runtime_c/type_description/field_type__functions.h" -// Expected hashes for externally referenced types +// Hashes for external referenced types static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH = {1, { 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, @@ -34,7 +34,6 @@ static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__E 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, }}; -// Names for all types static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; @@ -97,13 +96,8 @@ rosidl_runtime_c__type_description__Field__get_type_description( {rosidl_runtime_c__type_description__Field__REFERENCED_TYPE_DESCRIPTIONS, 1, 1}, }; if (!constructed) { - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); - description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; - } + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[0].fields = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL)->type_description.fields; constructed = true; } return &description; @@ -137,8 +131,6 @@ rosidl_runtime_c__type_description__Field__get_individual_type_description_sourc return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__Field__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/rosidl_runtime_c/src/type_description/field_type__description.c b/rosidl_runtime_c/src/type_description/field_type__description.c index c7013a139..87216a5f3 100644 --- a/rosidl_runtime_c/src/type_description/field_type__description.c +++ b/rosidl_runtime_c/src/type_description/field_type__description.c @@ -20,14 +20,13 @@ rosidl_runtime_c__type_description__FieldType__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types -// Expected hashes for externally referenced types +// Hashes for external referenced types -// Names for all types static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; // Define type names, field names, and default values @@ -80,7 +79,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; - const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__FieldType__get_type_description( const rosidl_message_type_support_t * type_support) @@ -275,8 +273,6 @@ rosidl_runtime_c__type_description__FieldType__get_individual_type_description_s return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__FieldType__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/rosidl_runtime_c/src/type_description/individual_type_description__description.c b/rosidl_runtime_c/src/type_description/individual_type_description__description.c index 99b0dacc0..a542a72a2 100644 --- a/rosidl_runtime_c/src/type_description/individual_type_description__description.c +++ b/rosidl_runtime_c/src/type_description/individual_type_description__description.c @@ -20,14 +20,14 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types #include "rosidl_runtime_c/type_description/field__functions.h" #include "rosidl_runtime_c/type_description/field_type__functions.h" -// Expected hashes for externally referenced types +// Hashes for external referenced types static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, @@ -41,7 +41,6 @@ static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__E 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, }}; -// Names for all types static char rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/IndividualTypeDescription"; static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; @@ -98,20 +97,10 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_descript {rosidl_runtime_c__type_description__IndividualTypeDescription__REFERENCED_TYPE_DESCRIPTIONS, 2, 2}, }; if (!constructed) { - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__Field__get_type_description(NULL); - description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; - } - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); - description.referenced_type_descriptions.data[1].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[1].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[1].fields.capacity = ref_desc->type_description.fields.capacity; - } + assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[0].fields = rosidl_runtime_c__type_description__Field__get_type_description(NULL)->type_description.fields; + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[1].fields = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL)->type_description.fields; constructed = true; } return &description; @@ -147,8 +136,6 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_individual_ty return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/rosidl_runtime_c/src/type_description/key_value__description.c b/rosidl_runtime_c/src/type_description/key_value__description.c index 76c836478..5bef4cf1a 100644 --- a/rosidl_runtime_c/src/type_description/key_value__description.c +++ b/rosidl_runtime_c/src/type_description/key_value__description.c @@ -20,14 +20,13 @@ rosidl_runtime_c__type_description__KeyValue__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types -// Expected hashes for externally referenced types +// Hashes for external referenced types -// Names for all types static char rosidl_runtime_c__type_description__KeyValue__TYPE_NAME[] = "type_description_interfaces/msg/KeyValue"; // Define type names, field names, and default values @@ -57,7 +56,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; - const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__KeyValue__get_type_description( const rosidl_message_type_support_t * type_support) @@ -100,8 +98,6 @@ rosidl_runtime_c__type_description__KeyValue__get_individual_type_description_so return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__KeyValue__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/rosidl_runtime_c/src/type_description/type_description__description.c b/rosidl_runtime_c/src/type_description/type_description__description.c index 207378240..dac5b0831 100644 --- a/rosidl_runtime_c/src/type_description/type_description__description.c +++ b/rosidl_runtime_c/src/type_description/type_description__description.c @@ -20,15 +20,15 @@ rosidl_runtime_c__type_description__TypeDescription__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types -#include "rosidl_runtime_c/type_description/field__functions.h" #include "rosidl_runtime_c/type_description/individual_type_description__functions.h" +#include "rosidl_runtime_c/type_description/field__functions.h" #include "rosidl_runtime_c/type_description/field_type__functions.h" -// Expected hashes for externally referenced types +// Hashes for external referenced types static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, @@ -48,7 +48,6 @@ static const rosidl_type_hash_t rosidl_runtime_c__type_description__IndividualTy 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, }}; -// Names for all types static char rosidl_runtime_c__type_description__TypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/TypeDescription"; static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; @@ -110,27 +109,12 @@ rosidl_runtime_c__type_description__TypeDescription__get_type_description( {rosidl_runtime_c__type_description__TypeDescription__REFERENCED_TYPE_DESCRIPTIONS, 3, 3}, }; if (!constructed) { - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__Field__get_type_description(NULL); - description.referenced_type_descriptions.data[0].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[0].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[0].fields.capacity = ref_desc->type_description.fields.capacity; - } - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL); - description.referenced_type_descriptions.data[1].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[1].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[1].fields.capacity = ref_desc->type_description.fields.capacity; - } - { - assert(0 == memcmp(&rosidl_runtime_c__type_description__IndividualTypeDescription__EXPECTED_HASH, rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); - const rosidl_runtime_c__type_description__TypeDescription * ref_desc = rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description(NULL); - description.referenced_type_descriptions.data[2].fields.data = ref_desc->type_description.fields.data; - description.referenced_type_descriptions.data[2].fields.size = ref_desc->type_description.fields.size; - description.referenced_type_descriptions.data[2].fields.capacity = ref_desc->type_description.fields.capacity; - } + assert(0 == memcmp(&rosidl_runtime_c__type_description__Field__EXPECTED_HASH, rosidl_runtime_c__type_description__Field__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[0].fields = rosidl_runtime_c__type_description__Field__get_type_description(NULL)->type_description.fields; + assert(0 == memcmp(&rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH, rosidl_runtime_c__type_description__FieldType__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[1].fields = rosidl_runtime_c__type_description__FieldType__get_type_description(NULL)->type_description.fields; + assert(0 == memcmp(&rosidl_runtime_c__type_description__IndividualTypeDescription__EXPECTED_HASH, rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash(NULL), sizeof(rosidl_type_hash_t))); + description.referenced_type_descriptions.data[2].fields = rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_description(NULL)->type_description.fields; constructed = true; } return &description; @@ -161,8 +145,6 @@ rosidl_runtime_c__type_description__TypeDescription__get_individual_type_descrip return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__TypeDescription__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/rosidl_runtime_c/src/type_description/type_source__description.c b/rosidl_runtime_c/src/type_description/type_source__description.c index e49ae9cee..b0c4fd811 100644 --- a/rosidl_runtime_c/src/type_description/type_source__description.c +++ b/rosidl_runtime_c/src/type_description/type_source__description.c @@ -20,14 +20,13 @@ rosidl_runtime_c__type_description__TypeSource__get_type_hash( return &hash; } - #include #include + // Include directives for referenced types -// Expected hashes for externally referenced types +// Hashes for external referenced types -// Names for all types static char rosidl_runtime_c__type_description__TypeSource__TYPE_NAME[] = "type_description_interfaces/msg/TypeSource"; // Define type names, field names, and default values @@ -68,7 +67,6 @@ static rosidl_runtime_c__type_description__Field rosidl_runtime_c__type_descript }, }; - const rosidl_runtime_c__type_description__TypeDescription * rosidl_runtime_c__type_description__TypeSource__get_type_description( const rosidl_message_type_support_t * type_support) @@ -123,8 +121,6 @@ rosidl_runtime_c__type_description__TypeSource__get_individual_type_description_ return &source; } -// Define all full source sequence functions - const rosidl_runtime_c__type_description__TypeSource__Sequence * rosidl_runtime_c__type_description__TypeSource__get_type_description_sources( const rosidl_message_type_support_t * type_support) diff --git a/scripts/type_description.fingerprint b/scripts/type_description.fingerprint index 224936d3b..7bb3f4273 100644 --- a/scripts/type_description.fingerprint +++ b/scripts/type_description.fingerprint @@ -18,12 +18,12 @@ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_typ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.c) = 26c004570511e86490d2fe6fdb52c866264ff6c47e8671052476ca440b2fe705 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.c) = bfa6460a62d08b9759893f475c4e6e65cd912017ab5e8a984475c13ea94f8018 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.c) = 710482d1bf1dd5c332f07f1c16e7eb8dd3a9b1badd3f6cd47de19132ae934448 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = fbc4236052056af0975cc757d4046d05be6804b356a10f8c0a612880d68789b3 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = 0727e199305da5244a56b82fbec0ddcd1a60bd397a388f270c3a58105421ae25 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 8f5cd0bc71e95a803a28af4518e005ea2d4a14aff8f66ce2387b2fcf323a9e81 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = 372743353e670a8e4a11dd2c3e628932435b61862d9654ff6b50e910b6de2b99 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 7a5401e2755c7f13a1126c06f0f98cc212451bc5ece373f73fd7baed747228f8 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = ccf854c9dbf21bf469aa32ec16ff47c0b9625c1fe1838801efe2c6df19923946 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = e91ec985bf4b3bce0ce7498b7195d99152f27dc19c7f66dafb0277a8782f38ef +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = a169220b12d7593bc117ca0500c6277024477ff8e110697be922891d731d8f47 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 911e4f9f0557cd688624ad753a457206540b8e6e1bedf30493eafcffc06b4f16 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = 8d565a1cf456d7802f7c8a53024e963f65fbdb1c83b9e13fd6afdce5c526b1f3 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 005e073cf652a9f9f816a8487937bbfb522249ca5e5a048c39c82a02b579f17e +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = 652459538efac7ed2fd62a79de5c2036a8e4c96612f35069acb783cf0656328c SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field__struct.hpp) = 95ae3d90f9fbae81a4ffa950fa3ca6e546b8b1f5f853141fc82db40b68be298c SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field_type__struct.hpp) = 4bdc3c22cba31e96ba9d26f667451b9cfe1f683e6f45f4997ad05c3439e4aa46 SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/individual_type_description__struct.hpp) = eda96246cb0fc9fc42ea861b651b8f2f91326c398c2ebc152fe50194118bfa10 From 133755e7eefecc192d094c19f0fe0781d1c4310d Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 20:59:04 -0700 Subject: [PATCH 14/19] Utf8 encode wstrings Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/full__description.c.em | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 80ca59642..3a99bc9ba 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -25,9 +25,10 @@ def static_seq(varname, values): return f'{{{varname}, {len(values)}, {len(values)}}}' return '{NULL, 0, 0}' -def represent_default(default_value): - # Encode to UTF-8 in case of WStrings, then remove the b'' from the representation. - return repr(default_value.encode('utf-8'))[2:-1] +def utf8_encode(value_string): + from rosidl_generator_c import escape_string + # Slice removes the b'' from the representation. + return escape_string(repr(value_string.encode('utf-8'))[2:-1]) implicit_type_names = set(td['type_description']['type_name'] for td, _ in implicit_type_descriptions) includes = set() @@ -94,7 +95,7 @@ ref_tds = msg['referenced_type_descriptions'] @[ for field in itype_description['fields']]@ static char @(td_c_typename)__FIELD_NAME__@(field['name'])[] = "@(field['name'])"; @[ if field['default_value']]@ -static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(escape_string(represent_default(field['default_value'])))"; +static char @(td_c_typename)__DEFAULT_VALUE__@(field['name'])[] = "@(utf8_encode(field['default_value']))"; @[ end if]@ @[ end for]@ @@ -163,9 +164,9 @@ c_typename = typename_to_c(ref_td['type_name']) @[if raw_source_content]@ static char toplevel_type_raw_source[] =@ @[ for line in raw_source_content.splitlines()[:-1]] - "@(escape_string(line))\n"@ + "@(utf8_encode(line))\n"@ @[ end for] - "@(escape_string(raw_source_content.splitlines()[-1]))"; + "@(utf8_encode(raw_source_content.splitlines()[-1]))"; @[end if]@ static char @(toplevel_encoding)_encoding[] = "@(toplevel_encoding)"; From 6fb6d6e1e620f28fa047581190ad7df3249aaa50 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Mon, 3 Apr 2023 21:11:26 -0700 Subject: [PATCH 15/19] hide expected hash definitions behind debug flag to fix warning Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/full__description.c.em | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 3a99bc9ba..7693d0f2f 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -62,6 +62,7 @@ with open(type_source_file, 'r') as f: @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @# Cache expected hashes for externally referenced types, for error checking // Hashes for external referenced types +#ifndef NDEBUG @[for referenced_type_description in toplevel_msg['referenced_type_descriptions']]@ @{ type_name = referenced_type_description['type_name'] @@ -71,6 +72,7 @@ c_typename = type_name.replace('/', '__') static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_definition(hash_lookup[type_name])); @[ end if]@ @[end for]@ +#endif @#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< From 97bacbb1e63a5db28d8c61468a0ccc0168c32304 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Tue, 4 Apr 2023 09:12:35 -0700 Subject: [PATCH 16/19] Utf8 encoding on file read also Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/full__description.c.em | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 7693d0f2f..3d84b4268 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -47,7 +47,7 @@ full_type_names = [t['type_description']['type_name'] for t, _ in full_type_desc all_type_descriptions = [toplevel_msg['type_description']] + toplevel_msg['referenced_type_descriptions'] toplevel_encoding = type_source_file.suffix[1:] -with open(type_source_file, 'r') as f: +with open(type_source_file, 'r', encoding='utf-8') as f: raw_source_content = f.read() }@ @ From 3352ecdf45a6d830753878dd3368a0fc5f49c921 Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Tue, 4 Apr 2023 10:31:23 -0700 Subject: [PATCH 17/19] Fix empty build Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/empty__description.c.em | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rosidl_generator_c/resource/empty__description.c.em b/rosidl_generator_c/resource/empty__description.c.em index 2c6e4210f..c7d8bfd7d 100644 --- a/rosidl_generator_c/resource/empty__description.c.em +++ b/rosidl_generator_c/resource/empty__description.c.em @@ -1,6 +1,7 @@ @# Included from rosidl_generator_c/resource/idl__description.c.em @{ from rosidl_generator_type_description import GET_DESCRIPTION_FUNC +from rosidl_generator_type_description import GET_INDIVIDUAL_SOURCE_FUNC from rosidl_generator_type_description import GET_SOURCES_FUNC def typename_to_c(typename): @@ -29,7 +30,7 @@ const rosidl_runtime_c__type_description__TypeDescription * return &description; } -const rosidl_runtime_c__type_description__TypeSource__Sequence * +const rosidl_runtime_c__type_description__TypeSource * @(td_c_typename)__@(GET_INDIVIDUAL_SOURCE_FUNC)( const rosidl_@(interface_type)_type_support_t * type_support) { From 5cbbedc3e5ff7870a4614c64c426d4d154ad8a7b Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Tue, 4 Apr 2023 14:20:20 -0700 Subject: [PATCH 18/19] Update copyright notice year Signed-off-by: Emerson Knapp --- .../test/rosidl_generator_c/test_descriptions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c index af44fe425..b2d80c936 100644 --- a/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c +++ b/rosidl_generator_tests/test/rosidl_generator_c/test_descriptions.c @@ -1,4 +1,4 @@ -// Copyright 2015 Open Source Robotics Foundation, Inc. +// Copyright 2023 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From f58117686d63cde6571b7163c711c63273f5befb Mon Sep 17 00:00:00 2001 From: Emerson Knapp Date: Tue, 4 Apr 2023 16:22:09 -0700 Subject: [PATCH 19/19] Copy latest ndebug generated source bits Signed-off-by: Emerson Knapp --- rosidl_generator_c/resource/full__description.c.em | 12 +++++++++--- .../src/type_description/field__description.c | 2 ++ .../src/type_description/field_type__description.c | 2 ++ .../individual_type_description__description.c | 2 ++ .../src/type_description/key_value__description.c | 2 ++ .../type_description/type_description__description.c | 4 +++- .../src/type_description/type_source__description.c | 2 ++ scripts/type_description.fingerprint | 12 ++++++------ 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index 3d84b4268..621ac3482 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -182,8 +182,14 @@ static char implicit_encoding[] = "implicit"; itype_description = type_description_msg['type_description'] td_typename = itype_description['type_name'] td_c_typename = typename_to_c(td_typename) -encoding = 'implicit' if td_typename in implicit_type_names else toplevel_encoding -contents = None if td_typename in implicit_type_names else raw_source_content +if td_typename in implicit_type_names: + encoding = 'implicit' + contents_var = None + contents = None +else: + encoding = toplevel_encoding + contents_var = 'toplevel_type_raw_source' + contents = raw_source_content }@ const rosidl_runtime_c__type_description__TypeSource * @@ -194,7 +200,7 @@ const rosidl_runtime_c__type_description__TypeSource * static const rosidl_runtime_c__type_description__TypeSource source = { @(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)), @(static_seq(f'{encoding}_encoding', encoding)), - @(static_seq('toplevel_type_raw_source', contents)), + @(static_seq(contents_var, contents)), }; return &source; } diff --git a/rosidl_runtime_c/src/type_description/field__description.c b/rosidl_runtime_c/src/type_description/field__description.c index 21198c7f5..dcb2aad96 100644 --- a/rosidl_runtime_c/src/type_description/field__description.c +++ b/rosidl_runtime_c/src/type_description/field__description.c @@ -27,12 +27,14 @@ rosidl_runtime_c__type_description__Field__get_type_hash( #include "rosidl_runtime_c/type_description/field_type__functions.h" // Hashes for external referenced types +#ifndef NDEBUG static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__EXPECTED_HASH = {1, { 0xa7, 0x0b, 0x6d, 0xd9, 0x19, 0x64, 0x5a, 0x03, 0xa3, 0x58, 0x6f, 0x7f, 0x82, 0x1d, 0xef, 0xbc, 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, }}; +#endif static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; diff --git a/rosidl_runtime_c/src/type_description/field_type__description.c b/rosidl_runtime_c/src/type_description/field_type__description.c index 87216a5f3..828a95bf1 100644 --- a/rosidl_runtime_c/src/type_description/field_type__description.c +++ b/rosidl_runtime_c/src/type_description/field_type__description.c @@ -26,6 +26,8 @@ rosidl_runtime_c__type_description__FieldType__get_type_hash( // Include directives for referenced types // Hashes for external referenced types +#ifndef NDEBUG +#endif static char rosidl_runtime_c__type_description__FieldType__TYPE_NAME[] = "type_description_interfaces/msg/FieldType"; diff --git a/rosidl_runtime_c/src/type_description/individual_type_description__description.c b/rosidl_runtime_c/src/type_description/individual_type_description__description.c index a542a72a2..9d1f9c61d 100644 --- a/rosidl_runtime_c/src/type_description/individual_type_description__description.c +++ b/rosidl_runtime_c/src/type_description/individual_type_description__description.c @@ -28,6 +28,7 @@ rosidl_runtime_c__type_description__IndividualTypeDescription__get_type_hash( #include "rosidl_runtime_c/type_description/field_type__functions.h" // Hashes for external referenced types +#ifndef NDEBUG static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, @@ -40,6 +41,7 @@ static const rosidl_type_hash_t rosidl_runtime_c__type_description__FieldType__E 0x88, 0x6e, 0xa3, 0xe5, 0x31, 0xa1, 0xd9, 0x5c, 0xc0, 0xf3, 0x80, 0xa3, 0x97, 0x3c, 0xca, 0xa6, }}; +#endif static char rosidl_runtime_c__type_description__IndividualTypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/IndividualTypeDescription"; static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; diff --git a/rosidl_runtime_c/src/type_description/key_value__description.c b/rosidl_runtime_c/src/type_description/key_value__description.c index 5bef4cf1a..3662c9d19 100644 --- a/rosidl_runtime_c/src/type_description/key_value__description.c +++ b/rosidl_runtime_c/src/type_description/key_value__description.c @@ -26,6 +26,8 @@ rosidl_runtime_c__type_description__KeyValue__get_type_hash( // Include directives for referenced types // Hashes for external referenced types +#ifndef NDEBUG +#endif static char rosidl_runtime_c__type_description__KeyValue__TYPE_NAME[] = "type_description_interfaces/msg/KeyValue"; diff --git a/rosidl_runtime_c/src/type_description/type_description__description.c b/rosidl_runtime_c/src/type_description/type_description__description.c index dac5b0831..04a6626cd 100644 --- a/rosidl_runtime_c/src/type_description/type_description__description.c +++ b/rosidl_runtime_c/src/type_description/type_description__description.c @@ -24,11 +24,12 @@ rosidl_runtime_c__type_description__TypeDescription__get_type_hash( #include // Include directives for referenced types -#include "rosidl_runtime_c/type_description/individual_type_description__functions.h" #include "rosidl_runtime_c/type_description/field__functions.h" +#include "rosidl_runtime_c/type_description/individual_type_description__functions.h" #include "rosidl_runtime_c/type_description/field_type__functions.h" // Hashes for external referenced types +#ifndef NDEBUG static const rosidl_type_hash_t rosidl_runtime_c__type_description__Field__EXPECTED_HASH = {1, { 0xc0, 0xb0, 0x13, 0x79, 0xcd, 0x42, 0x26, 0x28, 0x12, 0x85, 0xcc, 0xaf, 0x6b, 0xe4, 0x66, 0x53, @@ -47,6 +48,7 @@ static const rosidl_type_hash_t rosidl_runtime_c__type_description__IndividualTy 0x0e, 0x4d, 0x3b, 0x37, 0xc8, 0xf4, 0xf9, 0x75, 0x1a, 0x08, 0x4a, 0xa0, 0x5c, 0xe9, 0x65, 0x60, }}; +#endif static char rosidl_runtime_c__type_description__TypeDescription__TYPE_NAME[] = "type_description_interfaces/msg/TypeDescription"; static char rosidl_runtime_c__type_description__Field__TYPE_NAME[] = "type_description_interfaces/msg/Field"; diff --git a/rosidl_runtime_c/src/type_description/type_source__description.c b/rosidl_runtime_c/src/type_description/type_source__description.c index b0c4fd811..c2fdeb21b 100644 --- a/rosidl_runtime_c/src/type_description/type_source__description.c +++ b/rosidl_runtime_c/src/type_description/type_source__description.c @@ -26,6 +26,8 @@ rosidl_runtime_c__type_description__TypeSource__get_type_hash( // Include directives for referenced types // Hashes for external referenced types +#ifndef NDEBUG +#endif static char rosidl_runtime_c__type_description__TypeSource__TYPE_NAME[] = "type_description_interfaces/msg/TypeSource"; diff --git a/scripts/type_description.fingerprint b/scripts/type_description.fingerprint index 7bb3f4273..c357678d4 100644 --- a/scripts/type_description.fingerprint +++ b/scripts/type_description.fingerprint @@ -18,12 +18,12 @@ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_typ SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__functions.c) = 26c004570511e86490d2fe6fdb52c866264ff6c47e8671052476ca440b2fe705 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__functions.c) = bfa6460a62d08b9759893f475c4e6e65cd912017ab5e8a984475c13ea94f8018 SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__functions.c) = 710482d1bf1dd5c332f07f1c16e7eb8dd3a9b1badd3f6cd47de19132ae934448 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = e91ec985bf4b3bce0ce7498b7195d99152f27dc19c7f66dafb0277a8782f38ef -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = a169220b12d7593bc117ca0500c6277024477ff8e110697be922891d731d8f47 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 911e4f9f0557cd688624ad753a457206540b8e6e1bedf30493eafcffc06b4f16 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = 8d565a1cf456d7802f7c8a53024e963f65fbdb1c83b9e13fd6afdce5c526b1f3 -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 005e073cf652a9f9f816a8487937bbfb522249ca5e5a048c39c82a02b579f17e -SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = 652459538efac7ed2fd62a79de5c2036a8e4c96612f35069acb783cf0656328c +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field__description.c) = 08c1c4613433c79990a7bc4bc7574cdc1d69a652fe8e2a687dc37c102ea36234 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/field_type__description.c) = 7b234d7686a761e0d9bc79a88e4d1ed6b2efef81f181dfefac2af4456eda55d1 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/individual_type_description__description.c) = 5dc02a2911baf9a041fc89d6a91a01d9f8f4bc0fd6648e56762e36b518e3c0b1 +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/key_value__description.c) = 052ff1c4a3ae8144dfea1f904e74a540564e71d022fc1d45872ec50579b93a9a +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_description__description.c) = 1763518e0c23403f8ad68713c5c3e3b9f8c9588a18a5a16a772458906cab456b +SHA256 (rosidl_generator_c/type_description_interfaces/msg/detail/type_source__description.c) = afc09f4bb4eee00e6bc9e4d266e7322ca27849d2a2b1ab1b92522cc81b92ddcf SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field__struct.hpp) = 95ae3d90f9fbae81a4ffa950fa3ca6e546b8b1f5f853141fc82db40b68be298c SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/field_type__struct.hpp) = 4bdc3c22cba31e96ba9d26f667451b9cfe1f683e6f45f4997ad05c3439e4aa46 SHA256 (rosidl_generator_cpp/type_description_interfaces/msg/detail/individual_type_description__struct.hpp) = eda96246cb0fc9fc42ea861b651b8f2f91326c398c2ebc152fe50194118bfa10