def process(self, class_definition_name, class_definition_dict): class_definition = class_definition_dict.get(class_definition_name) idl_field_definitions = [self.process_field(field, class_definition_dict, class_definition.enums) for field in class_definition.fields] include_list = self.process_includes(class_definition, class_definition_dict) if MiddlewareType.DDS in class_definition.middlewares: dds_middleware_definition = class_definition.middlewares[MiddlewareType.DDS] module_name = split_namespace_class(dds_middleware_definition.class_name)[0] class_name = split_namespace_class(dds_middleware_definition.class_name)[-1] sequence_fields = dds_middleware_definition.sequence_fields else: sequence_fields = [] module_name = '' class_name = '' if class_definition.parent_class is not None: parent_class_definition = self.process(class_definition.parent_class, class_definition_dict) include_list = parent_class_definition.include_list.union(include_list) idl_field_definitions = parent_class_definition.fields + idl_field_definitions return IdlDefinition(class_name, module_name, include_list, idl_field_definitions, sequence_fields)
def process_field(self, field, class_definition_dict, enums): if field.field_type in self.fundamental_types: field_dds_type = split_namespace_class(self.dds_types.get(field.field_type))[-1] else: if field.field_type in enums: field_dds_type = self.dds_types.get('enum') else: dds_middleware_definition = class_definition_dict.get(field.field_type).middlewares[MiddlewareType.DDS] field_dds_type = dds_middleware_definition.class_name if field.is_vector: if field.use_smart_pointer: field_dds_type = self.type_modifiers_dds\ .get('smart_pointer_vector')\ .replace("#0", field.field_name)\ .replace("#1", field_dds_type) else: if field.use_raw_pointer: field_dds_type = self.type_modifiers_dds.get('raw_pointer_vector') \ .replace("#0", field.field_name) \ .replace("#1", field_dds_type) else: field_dds_type = self.type_modifiers_dds.get('vector')\ .replace("#0", field.field_name) \ .replace("#1", field_dds_type) else: if field.is_array: field_dds_type = self.type_modifiers_dds\ .get('fix_size_array') \ .replace("#0", field.field_name) \ .replace("#1", field_dds_type)\ .replace("#2", field.size) else: field_dds_type = "%s %s" % (field_dds_type, field.field_name) return IdlFieldDefinition(field.field_name, field_dds_type)
def process(self, class_definition_name, class_definition_dict, include_path): class_definition = class_definition_dict.get(class_definition_name) serializer_field_definitions = [ field.field_name for field in class_definition.fields ] include_list = self.process_includes(class_definition, class_definition_dict, include_path) cereal_include_list = self.process_cereal_includes(class_definition) if class_definition.parent_class is not None: parent_class_definition = self.process( class_definition.parent_class, class_definition_dict, include_path) include_list = parent_class_definition.include_list.union( include_list) cereal_include_list = parent_class_definition.cereal_include_list.union( cereal_include_list) serializer_field_definitions = parent_class_definition.field_names + serializer_field_definitions serializer_class_name = "%sSerializer" % split_namespace_class( class_definition_name)[-1] return SerializerDefinition( convert_to_lower_case_underscores(serializer_class_name).upper(), class_definition_name, include_list, cereal_include_list, serializer_field_definitions)
def process(self, class_definition_name, class_definition_dict): class_definition = class_definition_dict.get(class_definition_name) ros_middleware_definition = class_definition.middlewares[ MiddlewareType.ROS] handler_name = split_namespace_class( class_definition.class_name)[-1] + "Handler" message_name = ros_middleware_definition.class_name project_name = ros_middleware_definition.project_name return NodeHandlerDefinition(handler_name, message_name, project_name)
def process_includes(self, class_definition, class_definition_dict): include_list = set() for field in class_definition.fields: if not field.is_enum and field.field_type not in self.fundamental_types: dds_middleware_definition = class_definition_dict.get(field.field_type).middlewares[MiddlewareType.DDS] if dds_middleware_definition.idl_file: include_list.add("\"%s\"", dds_middleware_definition.idl_file) else: class_name = split_namespace_class(dds_middleware_definition.class_name)[-1] include_list.add("\"%s.idl\"" % convert_to_lower_case_underscores(class_name)) return include_list
def process_includes(self, class_definition, class_definition_dict, include_path): include_list = set() if class_definition.already_exists: include_list.add(class_definition.include_file) else: class_name = split_namespace_class(class_definition.class_name)[-1] if include_path: include = "<%s/%s.h>" % ( include_path, convert_to_lower_case_underscores(class_name)) include_list.add(include.replace("//", "/")) else: include_list.add("<%s.h>" % convert_to_lower_case_underscores(class_name)) for field in class_definition.fields: if not field.is_enum and field.field_type not in self.fundamental_types: zmq_middleware_definition = class_definition_dict.get( field.field_type).middlewares[MiddlewareType.ZMQ] if zmq_middleware_definition.serializer_include_file: include_list.add( "\"%s\"", zmq_middleware_definition.serializer_include_file) else: class_name = split_namespace_class(field.field_type)[-1] if include_path: include = "<%s/cereal/%s_serializer.h>" % ( include_path, convert_to_lower_case_underscores(class_name)) include_list.add(include.replace("//", "/")) else: include = "<cereal/%s.h>" % convert_to_lower_case_underscores( class_name) include_list.add(include.replace("//", "/")) return include_list
def process_field(self, field, class_definition_dict, enums): if field.field_type in self.fundamental_types: project_name = None field_ros_type = split_namespace_class( self.ros_types.get(field.field_type))[-1] else: if field.field_type in enums: project_name = None field_ros_type = self.ros_types.get('enum') else: ros_middleware_definition = class_definition_dict.get( field.field_type).middlewares[MiddlewareType.ROS] project_name = ros_middleware_definition.project_name field_ros_type = ros_middleware_definition.class_name if field.is_vector: if field.use_smart_pointer: field_ros_type = self.type_modifiers_ros.get( 'smart_pointer_vector').replace("#1", field_ros_type) else: if field.use_raw_pointer: field_ros_type = self.type_modifiers_ros.get( 'raw_pointer_vector').replace("#1", field_ros_type) else: field_ros_type = self.type_modifiers_ros.get( 'vector').replace("#1", field_ros_type) else: if field.is_array: field_ros_type = self.type_modifiers_ros.get( 'fix_size_array').replace("#1", field_ros_type).replace( "#2", field.size) if project_name is not None: field_ros_type = "%s/%s" % (project_name, field_ros_type) return MsgFieldDefinition(field.field_name, field_ros_type)
def generate_code(self, class_definition_dict, include_path, input_dir, main_kidl_file, output_dir, disable_ros, disable_dds, disable_zmq): main_class_definition = self.read_kidl_file(input_dir, main_kidl_file, disable_zmq) poco_definition = self.poco_processor.process( main_class_definition.class_name, class_definition_dict, include_path) if not main_class_definition.already_exists: class_name = split_namespace_class( main_class_definition.class_name)[-1] poco_file_name = output_dir + "/poco/include/" + include_path + "/" + \ convert_to_lower_case_underscores(class_name) + ".h" poco_template_content = self.poco_template.render( definition=poco_definition) write_contents_to_file(poco_file_name, poco_template_content) ros_middleware_definition = main_class_definition.middlewares.get( MiddlewareType.ROS) if (not disable_ros) and ros_middleware_definition is not None: if not ros_middleware_definition.mapper_include_file: ros_mapper_definition = self.ros_mapper_processor.process( main_class_definition.class_name, class_definition_dict, include_path) ros_mapper_file_name = output_dir + "/rosstg/include/" + ros_middleware_definition.project_name + "/" \ + convert_to_lower_case_underscores(class_name) + "_ros_mapper.h" ros_mapper_template_content = self.ros_mapper_template.render( definition=ros_mapper_definition) write_contents_to_file(ros_mapper_file_name, ros_mapper_template_content) if not ros_middleware_definition.already_exists: ros_msg_definition = self.ros_msg_processor.process( main_class_definition.class_name, class_definition_dict) ros_msg_file_name = output_dir + "/rosstg/msg/" + ros_middleware_definition.class_name + ".msg" ros_msg_template_content = self.ros_msg_template.render( definition=ros_msg_definition) write_contents_to_file(ros_msg_file_name, ros_msg_template_content) node_handler_definition = self.node_handler_processor.process( main_class_definition.class_name, class_definition_dict) node_handler_file_name = convert_to_lower_case_underscores( node_handler_definition.handler_name) + ".js" node_handler_file_path = output_dir + "/rosstg/node/" + node_handler_file_name node_handler_template_content = self.node_handler_template.render( definition=node_handler_definition) write_contents_to_file(node_handler_file_path, node_handler_template_content) if (not disable_dds) and (main_class_definition.middlewares.get( MiddlewareType.DDS) is not None): if not main_class_definition.middlewares.get( MiddlewareType.DDS).mapper_include_file: dds_mapper_definition = self.dds_mapper_processor.process( main_class_definition.class_name, class_definition_dict, include_path) dds_mapper_file_name = output_dir + "/dds/include/" + include_path + "/dds/" \ + convert_to_lower_case_underscores(class_name) + "_dds_mapper.h" dds_mapper_template_content = self.dds_mapper_template.render( definition=dds_mapper_definition) write_contents_to_file(dds_mapper_file_name, dds_mapper_template_content) if not main_class_definition.middlewares.get( MiddlewareType.DDS).already_exists: dds_idl_definition = self.dds_idl_processor.process( main_class_definition.class_name, class_definition_dict) dds_idl_file_name = output_dir + "/dds/idl/" + \ convert_to_lower_case_underscores(dds_idl_definition.class_name) + ".idl" dds_idl_template_content = self.dds_idl_template.render( definition=dds_idl_definition) write_contents_to_file(dds_idl_file_name, dds_idl_template_content) if (not disable_zmq) and main_class_definition.middlewares.get( MiddlewareType.ZMQ) is not None: if not main_class_definition.middlewares.get( MiddlewareType.ZMQ).serializer_include_file: class_name = split_namespace_class( main_class_definition.class_name)[-1] zmq_serializer_definition = self.zmq_serializer_processor.process( main_class_definition.class_name, class_definition_dict, include_path) zmq_serializer_file_name = output_dir + "/serialization/include/" + include_path + "/cereal/" \ + convert_to_lower_case_underscores(class_name) + "_serializer.h" zmq_serializer_template_content = self.zmq_serializer_template.render( definition=zmq_serializer_definition) write_contents_to_file(zmq_serializer_file_name, zmq_serializer_template_content)