def generate_cpp(generator_arguments_file): args = read_generator_arguments(generator_arguments_file) template_dir = args['template_dir'] mapping_msgs = { os.path.join(template_dir, 'msg__type_support.cpp.template'): '%s__type_support.cpp', } mapping_srvs = { os.path.join(template_dir, 'srv__type_support.cpp.template'): '%s__type_support.cpp', } for template_file in mapping_msgs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file for template_file in mapping_srvs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file pkg_name = args['package_name'] known_msg_types = extract_message_types( pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) functions = { 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, } latest_target_timestamp = get_newest_modification_time(args['target_dependencies']) for ros_interface_file in args['ros_interface_files']: extension = os.path.splitext(ros_interface_file)[1] subfolder = os.path.basename(os.path.dirname(ros_interface_file)) if extension == '.msg': spec = parse_message_file(pkg_name, ros_interface_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_msgs.items(): generated_file = os.path.join( args['output_dir'], subfolder, generated_filename % convert_camel_case_to_lower_case_underscore(spec.base_type.type)) data = {'spec': spec, 'subfolder': subfolder} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) elif extension == '.srv': spec = parse_service_file(pkg_name, ros_interface_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_srvs.items(): generated_file = os.path.join( args['output_dir'], subfolder, generated_filename % convert_camel_case_to_lower_case_underscore(spec.srv_name)) data = {'spec': spec} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) return 0
def generate_cpp(generator_arguments_file): args = read_generator_arguments(generator_arguments_file) template_dir = args['template_dir'] mapping_msgs = { os.path.join(template_dir, 'msg__type_support.cpp.em'): '%s__type_support.cpp', } mapping_srvs = { os.path.join(template_dir, 'srv__type_support.cpp.em'): '%s__type_support.cpp', } for template_file in mapping_msgs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file for template_file in mapping_srvs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file pkg_name = args['package_name'] known_msg_types = extract_message_types( pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) functions = { 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, } latest_target_timestamp = get_newest_modification_time(args['target_dependencies']) for ros_interface_file in args['ros_interface_files']: extension = os.path.splitext(ros_interface_file)[1] subfolder = os.path.basename(os.path.dirname(ros_interface_file)) if extension == '.msg': spec = parse_message_file(pkg_name, ros_interface_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_msgs.items(): generated_file = os.path.join( args['output_dir'], subfolder, generated_filename % convert_camel_case_to_lower_case_underscore(spec.base_type.type)) data = {'spec': spec, 'subfolder': subfolder} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) elif extension == '.srv': spec = parse_service_file(pkg_name, ros_interface_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_srvs.items(): generated_file = os.path.join( args['output_dir'], subfolder, generated_filename % convert_camel_case_to_lower_case_underscore(spec.srv_name)) data = {'spec': spec} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) return 0
def generate_typesupport_opensplice_cpp(args): template_dir = args['template_dir'] mapping_msgs = { os.path.join(template_dir, 'msg__rosidl_typesupport_opensplice_cpp.hpp.em'): '%s__rosidl_typesupport_opensplice_cpp.hpp', os.path.join(template_dir, 'msg__type_support.cpp.em'): '%s__type_support.cpp', } mapping_srvs = { os.path.join(template_dir, 'srv__rosidl_typesupport_opensplice_cpp.hpp.em'): '%s__rosidl_typesupport_opensplice_cpp.hpp', os.path.join(template_dir, 'srv__type_support.cpp.em'): '%s__type_support.cpp', } for template_file in mapping_msgs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file for template_file in mapping_srvs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file pkg_name = args['package_name'] known_msg_types = extract_message_types( pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) functions = { 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, } # generate_dds_opensplice_cpp() and therefore the make target depend on the additional files # therefore they must be listed here even if the generated type support files are independent latest_target_timestamp = get_newest_modification_time( args['target_dependencies'] + args.get('additional_files', [])) for idl_file in args['ros_interface_files']: extension = os.path.splitext(idl_file)[1] if extension == '.msg': spec = parse_message_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) subfolder = os.path.basename(os.path.dirname(idl_file)) for template_file, generated_filename in mapping_msgs.items(): generated_file = os.path.join(args['output_dir'], subfolder) if generated_filename.endswith('.cpp'): generated_file = os.path.join(generated_file, 'dds_opensplice') generated_file = os.path.join( generated_file, generated_filename % convert_camel_case_to_lower_case_underscore(spec.base_type.type)) data = {'spec': spec, 'subfolder': subfolder} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) elif extension == '.srv': spec = parse_service_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_srvs.items(): generated_file = os.path.join(args['output_dir'], 'srv') if generated_filename.endswith('.cpp'): generated_file = os.path.join(generated_file, 'dds_opensplice') generated_file = os.path.join( generated_file, generated_filename % convert_camel_case_to_lower_case_underscore(spec.srv_name)) data = {'spec': spec} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) return 0
def generate_typesupport_opensplice_c(args): template_dir = args['template_dir'] mapping_msgs = { os.path.join(template_dir, 'msg__type_support_c.cpp.template'): '%s__type_support_c.cpp', } mapping_srvs = { os.path.join(template_dir, 'srv__type_support_c.cpp.template'): '%s__type_support_c.cpp', } for template_file in mapping_msgs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file for template_file in mapping_srvs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file pkg_name = args['package_name'] known_msg_types = extract_message_types( pkg_name, args['ros_interface_files'], args.get('ros_interface_dependencies', [])) functions = { 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, } # generate_dds_opensplice_cpp() and therefore the make target depend on the additional files # therefore they must be listed here even if the generated type support files are independent latest_target_timestamp = get_newest_modification_time( args['target_dependencies'] + args.get('additional_files', [])) for idl_file in args['ros_interface_files']: extension = os.path.splitext(idl_file)[1] if extension == '.msg': spec = parse_message_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) subfolder = os.path.basename(os.path.dirname(idl_file)) for template_file, generated_filename in mapping_msgs.items(): generated_file = os.path.join( args['output_dir'], subfolder, 'dds_opensplice_c', generated_filename % convert_camel_case_to_lower_case_underscore(spec.base_type.type)) data = { 'spec': spec, 'pkg': spec.base_type.pkg_name, 'msg': spec.msg_name, 'type': spec.base_type.type, 'subfolder': subfolder, } data.update(functions) try: expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) except Exception: print("\nException when expanding '{0}' into '{1}':\n" .format(template_file, generated_file)) raise elif extension == '.srv': spec = parse_service_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_srvs.items(): generated_file = os.path.join( args['output_dir'], 'srv', 'dds_opensplice_c', generated_filename % convert_camel_case_to_lower_case_underscore(spec.srv_name)) data = {'spec': spec} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) return 0
def generate_typesupport_freertps_cpp(template_dir, pkg_name, ros_interface_files, ros_interface_dependencies, target_dependencies, additional_files, output_dir): mapping_msgs = { os.path.join(template_dir, 'msg__type_support.hpp.template'): '%s__type_support.hpp', os.path.join(template_dir, 'msg__type_support.cpp.template'): '%s__type_support.cpp', } mapping_srvs = { os.path.join(template_dir, 'srv__type_support.cpp.template'): '%s__type_support.cpp', } for template_file in mapping_msgs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file for template_file in mapping_srvs.keys(): assert os.path.exists(template_file), 'Could not find template: ' + template_file known_msg_types = extract_message_types( pkg_name, ros_interface_files, ros_interface_dependencies) functions = { 'get_header_filename_from_msg_name': convert_camel_case_to_lower_case_underscore, 'enforce_alignment': enforce_alignment, 'enforce_read_alignment': enforce_read_alignment, 'enforce_alignment_buffer_size': enforce_alignment_buffer_size, 'get_alignment': get_alignment, 'msg_type_to_cpp': msg_type_to_cpp, } # generate_dds_freertps_cpp() and therefore the make target depend on the additional files # therefore they must be listed here even if the generated type support files are independent latest_target_timestamp = get_newest_modification_time( target_dependencies + additional_files) for idl_file in ros_interface_files: extension = os.path.splitext(idl_file)[1] if extension == '.msg': spec = parse_message_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) subfolder = os.path.basename(os.path.dirname(idl_file)) for template_file, generated_filename in mapping_msgs.items(): generated_file = os.path.join( output_dir, subfolder, 'freertps', generated_filename % convert_camel_case_to_lower_case_underscore(spec.base_type.type)) data = {'spec': spec, 'subfolder': subfolder} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) elif extension == '.srv': spec = parse_service_file(pkg_name, idl_file) validate_field_types(spec, known_msg_types) for template_file, generated_filename in mapping_srvs.items(): generated_file = os.path.join( output_dir, 'srv', 'freertps', generated_filename % convert_camel_case_to_lower_case_underscore(spec.srv_name)) data = {'spec': spec} data.update(functions) expand_template( template_file, data, generated_file, minimum_timestamp=latest_target_timestamp) return 0