Code generation system and method for service-oriented architecture communication matrix
Through a code generation system for the service-oriented communication matrix, the separation of modular design and parsing plug-in modules and abstract analysis modules is solved, and the problem of high cost and complexity of existing tools is realized, and the flexible analysis and code of multi-format communication matrix is realized. Generate, reducing development costs.
Patent Information
- Application Number
- CN202411177363.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2025-01-07
AI Technical Summary
The existing service-oriented architecture communication matrix code generation tools are expensive to purchase, complex usage processes, high learning costs, and highly bound analysis and code generation, making it difficult to deal with communication matrix files in many different formats.
A code generation system for the communication matrix of the service architecture is designed, including analytical plug-in module, event monitoring interface, abstract parsing module and code generation module. Through modular design and separation of the plug-in module and abstract parsing module, combined with the analysis of events Active monitoring realizes multi-format analysis of the communication matrix and decoupling of code generation.
Improves system flexibility and scalability, reduces development and maintenance costs, and can easily deal with communication matrix files in many different formats, simplifying the code generation process.
Smart Images

Figure CN119271186A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of vehicle networking technology, and in particular to a code generation system and method for a service architecture communication matrix. Background Art
[0002] Service-Oriented Architecture (SOA) has gradually become the mainstream choice for automotive software design due to its advantages of modularity, loose coupling and reusability. The core of SOA lies in the independence and interoperability between services, and service-oriented architecture is built on the basis of service-oriented communication (SOC). Service-oriented communication achieves effective communication and collaboration between services by describing the communication matrix, including the communication interface between services and the data types involved in the interface.
[0003] At present, the communication matrix is generally described in ARXML (AUTOSAR Runtime Interface XML) format. ARXML format has the advantage of being easy to parse by machines, but it cannot be read directly. It needs to be parsed with the help of special tools and displayed on the interface before it can be read. Another more flexible and popular method is to convert the ARXML file into Excel format or directly edit the Excel file to build the communication matrix. The Excel tool can be used to add, delete, modify and query the communication matrix.
[0004] However, whether ARXML or Excel is used as the storage format of the SOA communication matrix, the ultimate goal is to use this information to automatically generate service-oriented communication code. Existing commercial software, such as the Da Vinci tool of German Vector, can efficiently parse the communication matrix and generate code, but its purchase cost is high, the use process is complex, the learning cost is high, and the parsing and code generation are highly bound. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a code generation system and method for a service architecture communication matrix.
[0006] The technical problem solved by the present invention can be achieved by adopting the following technical solutions:
[0007] A code generation system for a service architecture communication matrix, comprising:
[0008] A parsing plug-in module is used to trigger a parsing process when a communication matrix is received; in the parsing process, the received communication matrix in different formats is parsed based on at least one predefined information extraction class to obtain a parsing result;
[0009] An event monitoring interface, connected to the parsing plug-in module and the abstract parsing module respectively, for generating a notification event of the parsing process when detecting that the parsing plug-in module triggers the parsing process, and sending the notification event to the abstract parsing module;
[0010] The abstract parsing module is used to generate a data model according to the parsing result when receiving the notification event, and store the data model in the information container;
[0011] The code generation module is connected to the information container and is used to extract model data from the information container, process the extracted model data based on a preset code template, and generate corresponding code.
[0012] Preferably, the parsing plug-in module includes:
[0013] A plurality of parsing plug-ins, each of the parsing plug-ins corresponding to a format of the communication matrix;
[0014] Each of the parsing plug-ins has the predefined information extraction class.
[0015] Preferably, the predefined information extraction class includes one or more combinations of a data type information extraction class, a service interface information extraction class, and a communication configuration information extraction class.
[0016] Preferably, the event monitoring interface includes an event notification interface;
[0017] Each of the predefined extraction classes corresponds to one of the event notification interfaces, and each of the event notification interfaces predefines a plurality of interface functions corresponding to the predefined extraction class, and each of the interface functions is used to generate a notification event corresponding to a parsing event of the parsing process.
[0018] Preferably, the abstract parsing module is implemented based on a model-view-controller architecture.
[0019] Preferably, the abstract parsing module includes:
[0020] At least one parser, which corresponds one-to-one with the predefined information extraction class and is used to, when called, reversely call the parsing function of the parsing plug-in module to trigger the parsing process; and when listening to the notification event, create and configure a model object based on the notification event, generate model data of the data model, and store the model data of the data model in the information container.
[0021] Preferably, the member attributes of the information container consist of at least one list, each of which is used to store objects corresponding to the predefined extraction class.
[0022] Preferably, the code generation module includes:
[0023] A data type definition code generator, used to extract model data from the information container, process the extracted model data based on a preset data type definition code template, and generate a first code;
[0024] A service client code generator, used to extract model data from the information container, process the extracted model data based on a preset service client code template, and generate a second code;
[0025] A service code generator, used to extract model data from the information container, process the extracted model data based on a preset service code template, and generate a third code;
[0026] A configuration file generator, used for extracting model data from the information container, processing the extracted model data based on a preset configuration file code template, and generating a fourth code;
[0027] Each service correspondingly includes the first code, the second code, the third code and the fourth code.
[0028] Preferably, it also includes: a scheduler, which is respectively connected to the abstract parsing module, the information container, the code generation module and the code template, and is used to schedule the abstract parsing module, the information container, the code generation module and the code template.
[0029] The present invention also provides a code generation method for a service-oriented architecture communication matrix, which is applied to a code generation system for a service-oriented architecture communication matrix as described above, comprising:
[0030] A parsing process is triggered when a communication matrix is received; in the parsing process, the received communication matrix in different formats is parsed based on a predefined information extraction class to obtain a parsing result;
[0031] When the parsing process is detected to be triggered, a notification event of the parsing process is generated, and the notification event is sent to the abstract parsing module;
[0032] When receiving the notification event, the abstract parsing module converts the parsing result into a data model and stores the data model in an information container;
[0033] The model data is extracted from the information container, and the extracted model data is processed based on a preset code template to generate corresponding codes.
[0034] The advantages or beneficial effects of the technical solution of the present invention are:
[0035] The present invention realizes the decoupling of communication matrix parsing and code generation by adopting modular design, thereby improving the flexibility and scalability of the system. At the same time, a parsing plug-in module and an abstract parsing module are adopted to divide the parsing process into two parts, file parsing and abstract parsing. Combined with the active monitoring of parsing events, the parsing of SOA communication matrix and the specific format of the file are decoupled. There is no need to develop a separate parser for each format, and communication matrix files of various different formats can be easily handled and parsed, thereby reducing development and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is a structural block diagram of a code generation system for a service-oriented architecture communication matrix in a preferred embodiment of the present invention;
[0037] Figure 2 A flowchart of a code generation method for a service-oriented architecture communication matrix in a preferred embodiment of the present invention;
[0038] Figure 3 A flowchart of the steps of parsing data types and generating model objects in a preferred embodiment of the present invention;
[0039] Figure 4 A flowchart of the steps of service information parsing and service model object generation in a preferred embodiment of the present invention;
[0040] Figure 5 The figure is a flow chart of data type definition code generation in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0041] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0042] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0043] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments, but they are not intended to limit the present invention.
[0044] See also Figure 1 In a preferred embodiment of the present invention, based on the above problems existing in the prior art, a code generation system for a service architecture communication matrix is provided, comprising:
[0045] The parsing plug-in module 1 is used to trigger a parsing process when a communication matrix is received; during the parsing process, the received communication matrix in different formats is parsed based on at least one predefined information extraction class to obtain a parsing result;
[0046] The event monitoring interface 2 is connected to the parsing plug-in module and the abstract parsing module respectively, and is used to generate a notification event of the parsing process when it is detected that the parsing plug-in module triggers the parsing process, and send the notification event to the abstract parsing module 3;
[0047] The abstract analysis module 3 is used to generate a data model according to the analysis result when receiving a notification event, and store the data model in the information container 4;
[0048] The code generation module 5 is connected to the information container 4 and is used to extract model data from the information container, process the extracted model data based on a preset code template 6, and generate corresponding codes.
[0049] Specifically, in view of the problems that existing tools for parsing communication matrices and generating codes have, such as high procurement cost, complex usage process, high learning cost, and high binding between parsing and code generation, this embodiment provides an efficient, flexible and easy-to-use system to implement the parsing of communication matrices in different formats, as well as the generation of code and configuration information.
[0050] The system architecture includes a parsing plug-in module 1, an event monitoring interface 2, an abstract parsing module 3, an information container 4, a code generation module 5 and a code template 6. This general architectural framework adopts a modular design to decouple communication matrix parsing from generated code and configuration information, thereby improving the flexibility and scalability of the system.
[0051] At the same time, the parsing plug-in module and the abstract parsing module are used to divide the parsing process into two parts: file parsing and abstract parsing. Combined with the active monitoring of parsing events, the parsing of the SOA communication matrix and the specific format of the file are decoupled. There is no need to develop a separate parser for each format, and it can easily cope with and parse communication matrix files of various different formats, reducing development and maintenance costs.
[0052] The system provided by the embodiment of the present invention is implemented based on Python language programming. Compared with other compiled languages, Python language is simpler and more convenient.
[0053] As a preferred embodiment, the parsing plug-in module 1 includes:
[0054] A plurality of parsing plug-ins, each parsing plug-in corresponding to a format of the communication matrix;
[0055] Each parsing plugin has predefined information extraction classes.
[0056] As a preferred implementation, the predefined information extraction class includes one or more combinations of a data type information extraction class 11 , a service interface information extraction class 12 , and a communication configuration information extraction class 13 .
[0057] Specifically, considering that different users may use different formats to describe the composition of the SOA communication matrix, in order to adapt to the parsing of SOA communication matrices in different formats, in this embodiment, the corresponding format file parsing function is separated by the parsing plug-in module 1, and the file parsing function is completed based on a predefined information extraction class.
[0058] Exemplarily, the predefined information extraction classes include the following three:
[0059] 1.1) Data type information extraction class 11;
[0060] 1.2) Service interface information extraction class 12;
[0061] 1.3) Communication configuration information extraction class 13.
[0062] The specific implementation of the above three information extraction classes depends on the specific SOA communication matrix format. Therefore, each file format needs to implement these three different information extraction classes.
[0063] Since the above three information extraction classes are bound to specific file formats, in this embodiment, the above three information extraction classes are designed as plug-ins. When the parsing process is triggered, different plug-ins are loaded to implement the file parsing process of SOA communication matrices of different formats.
[0064] The data type information extraction class 11 mainly completes the extraction of some composite data type information, such as:
[0065] 1.1.1) Array type;
[0066] 1.1.2)Structure data type;
[0067] 1.1.3) Union data type;
[0068] 1.1.4) Enumerated data types.
[0069] Exemplarily, the information extracted for the array type includes:
[0070] 1.1.1.1) The type names corresponding to the members of the array;
[0071] 1.1.1.2) Whether the array is a fixed-length array or a variable-length array.
[0072] Exemplarily, the information extracted for the structure type includes:
[0073] 1.1.2.1) The name of the structure type;
[0074] 1.1.2.2) The data type and parameter name of each member of the structure.
[0075] Exemplarily, the information extracted for the enumeration type includes:
[0076] 1.1.3.1) What basic type is used to represent the enumeration value?
[0077] 1.1.3.2) The name and value corresponding to each enumeration value.
[0078] The service interface information extraction class 12 mainly completes the extraction of service information. A service is mainly composed of a series of interfaces.
[0079] Exemplarily, this series of interfaces are divided into the following three categories: method call interface, event notification interface, Field interface; wherein, the field interface includes the method call interface and the event notification interface; the method call is composed of set and get methods.
[0080] Exemplarily, when extracting service interface information, the interface information is classified as follows:
[0081] 1.2.1) The service name to which it belongs;
[0082] 1.2.2) Interface name and corresponding ID; if it is a method call, it is the method ID; if it is an event interface, it is the Event ID;
[0083] 1.2.3) The types of interfaces are divided into three types: method, event, and field;
[0084] 1.2.4) Communication reliability of the interface, such as whether the communication is reliable transmission;
[0085] 1.2.5) If the service interface is a field interface, the extracted information also includes the specific type of the field interface. For example, there are three types of field interfaces:
[0086] 1.2.5.1)Set interface;
[0087] 1.2.5.2)Get interface;
[0088] 1.2.5.3) Event notification interface.
[0089] 1.2.6) If it is an event notification interface, the event group information to which the event notification interface belongs must also be extracted.
[0090] 1.2.7) The type information of the input and output parameters of the interface.
[0091] The communication configuration information extraction class 13 mainly completes the extraction of communication configuration information. Exemplarily, the information extracted for the communication configuration includes:
[0092] 1.3.1) The name of the communication middleware bound to the service;
[0093] 1.3.2) Some configuration parameters related to 1.3.1) above.
[0094] As a preferred embodiment, the event monitoring interface 2 includes an event notification interface;
[0095] Each predefined extraction class corresponds to an event notification interface, and each event notification interface predefines a plurality of interface functions corresponding to the predefined extraction class, and each interface function is used to generate a notification event corresponding to a parsing event of a parsing process.
[0096] Specifically, in order to achieve the decoupling of the parsing plug-in module 1 of the SOA communication matrix file from other modules, the system of this embodiment is designed using the observer pattern, the observer is the abstract parsing module 3, and the observed is the parsing plug-in module 1, and the decoupling between the two is achieved through a defined event monitoring interface 2.
[0097] Event monitoring interface 2 is an empty implementation interface class that requires observers to implement these interfaces. Each information extraction class corresponds to an interface class. The interface class contains several interface functions. These interfaces correspond to some message notifications of information extraction, so they are also called event notification interfaces.
[0098] Exemplarily, the data type information extraction notification interface includes the following interface:
[0099] 2.1.1) Notify the start of a new structure data type. The interface parameter needs to provide the type name of the new structure.
[0100] 2.1.2) Notify a member message of a structure. The interface parameter needs to provide the name of the member and the corresponding data type name.
[0101] 2.1.3) Notify a structure of the end message. This interface has no parameters.
[0102] 2.1.4) Notify a new enumeration type message. This interface contains three parameters:
[0103] Enumeration type name;
[0104] The basic type name corresponding to the enumeration value;
[0105] Enumeration value dictionary; the key of the dictionary is the name corresponding to the enumeration value, and the value of the dictionary corresponds to the enumeration value.
[0106] 2.1.5) Notify an array type message. This interface contains four parameters:
[0107] The type name corresponding to the array;
[0108] The type name corresponding to the array member;
[0109] The minimum number of members in an array;
[0110] The maximum number of elements in an array.
[0111] 2.1.6) The union type defines three interfaces similar to the structure type.
[0112] For the service information extraction notification interface, first define a class (ServiceApiMeta) that encapsulates all the information of the interface. The ServiceApiMeta class contains all the useful information of a service interface. The service information notification interface uses the ServiceApiMeta class as a parameter.
[0113] Exemplarily, the service information notification interface includes the following interface:
[0114] 2.2.1) Notify a new service to start; this interface contains three parameters: service name, service id, instanceID.
[0115] 2.2.2) Notify an event notification interface; the parameter of this interface is of ServiceApiMeta type.
[0116] 2.2.3) Notify a method interface; the parameter of this interface is of ServiceApiMeta type.
[0117] 2.2.4) Notify a field interface; the parameter of this interface is a dictionary, and the dictionary key is the following three types: Set, Get, Notification;
[0118] The value type of the dictionary is ServiceApiMeta type;
[0119] 2.2.5) Notify the end of a service.
[0120] The abstract parsing module 3 communicates with the parsing plug-in module 1 through the event listening interface 2. The event listening interface 2 implements the observer mode through the above-mentioned predefined interface class. The abstract parsing module mainly implements the event listening interface 2, and then processes various notification messages to realize subsequent parsing, thereby realizing the decoupling of the file parsing of the abstract parsing module 3 and the parsing plug-in module 1, so that the code implementation of the file parsing logic and the abstract parsing logic can be shared.
[0121] As a preferred implementation, the abstract parsing module 3 is implemented based on a Model-View-Controller (MVC) architecture.
[0122] Specifically, in this embodiment, the MVC framework is used to construct the abstract parsing module 3, and the parsed data is represented as model data, corresponding to the model in the MVC architecture; the parsed data is stored in the class of the information container 4, which corresponds to the view in the MVC architecture, and the control of the entire parsing process corresponds to the controller in the MVC architecture. The MVC architecture has the characteristics of clear design structure, clear layering, module decoupling, and easy implementation.
[0123] As a preferred implementation, the abstract parsing module 3 includes:
[0124] At least one parser, which corresponds one-to-one to a predefined information extraction class, and is used to reversely call the parsing function of the parsing plug-in module to trigger the parsing process when called; and when a notification event is listened to, create and configure a model object based on the notification event, generate model data of the data model, and store the model data of the data model in the information container 4.
[0125] Furthermore, the parser includes a data type parser 31 , a service interface parser 32 and a configuration information parser 33 .
[0126] For the abstract analysis of data types, a new python data type is first defined, which is a class used to represent a data type (DataType). The function of the abstract analysis module 3 is to parse out DataType objects one by one, and then store these objects in the information container 4.
[0127] The DataType class contains attributes and corresponding attribute operation methods. It is an abstract representation of all types.
[0128] For example, the properties of DataType include the following:
[0129] 3.1.1) Type aliases;
[0130] 3.1.2) Type name;
[0131] 3.1.3) Type categories: The categories include Struct, Array, Enum, and Union.
[0132] 3.1.4) Minimum value: For array types, it indicates the minimum number of arrays;
[0133] 3.1.5) Maximum value: For array type, it indicates the maximum number of arrays;
[0134] 3.1.6) Enumeration dictionary attribute: only included when the type is Enumeration (Enum), otherwise None;
[0135] 3.1.7) Member type list: This attribute is included for Struct and Union types; the member type is represented by a Python dictionary. The key and value of the Python dictionary correspond to each other as follows:
[0136] When the key is memberName, the values are the member names.
[0137] When the key is memberType, the value is the type name corresponding to the member.
[0138] When the key is MemberDataType, the value is an instance of DataType. This key is present only when the member type is not a basic type.
[0139] For the abstract analysis of service information, modeling is required first. One service corresponds to one class (Service), and the Service class contains the following member attributes:
[0140] 3.2.1) Service Name
[0141] 3.2.2) Service ID
[0142] 3.2.3) Service method interface array, members are of ServiceApiMeta type
[0143] 3.2.4) Service event interface array, members are of ServiceApiMeta type
[0144] 3.2.5) Service field interface array.
[0145] After completing the data modeling, the controller is used to trigger the parsing process in the parsing plug-in module 1 and implement the event monitoring interface. Once the parsing process is triggered, the notification event of the parsing plug-in module 1 is processed and the parsing structure is converted into model data. After the parsing is completed, the abstract parsing module 3 stores the data type and service type object in the information container 4.
[0146] Depending on the specific communication technology stack used by the service, the service configuration will also be different. This embodiment sets a Python configuration structure for each different service implementation, which is represented by Python's inherent dictionary type and list type. The parsing plug-in is responsible for parsing the specific configuration file format and saving the parsed data in a dictionary type. After the parsing is completed, the abstract parsing module 3 is notified in the form of an event, and then the abstract parsing module 3 is responsible for saving the dictionary object corresponding to the configuration into the information container 4.
[0147] As a preferred embodiment, the member attributes of the information container 4 are composed of at least one list, and each list is used to store objects corresponding to a predefined extraction class.
[0148] Specifically, in this embodiment, the information container 4 is also represented by a python class, which represents the parsed data view, where the view mainly refers to the storage of the data model.
[0149] Exemplarily, the member attributes of the information container 4 mainly include three Python lists:
[0150] DataType object list: used to store objects of DataType type;
[0151] Service object list: used to store objects of Service type;
[0152] Configuration information list: used to store configuration information.
[0153] This embodiment stores the parsed model data in the information container 4, which is suitable for displaying the data of the SOA communication matrix, and is convenient for various subsequent operations, such as generating codes, displaying on the interface, or generating communication matrix files in other formats.
[0154] As a preferred embodiment, the code generation module 5 includes:
[0155] The data type definition code generator 51 is used to extract the model data from the information container 4, process the extracted model data based on a preset data type definition code template, and generate a first code;
[0156] The service client code generator 52 is used to extract the model data from the information container 4, process the extracted model data based on the preset service client code template, and generate the second code;
[0157] A service code generator 53 is used to extract model data from the information container 4, process the extracted model data based on a preset service code template, and generate a third code;
[0158] A configuration file generator 54, used to extract model data from the information container 4, process the extracted model data based on a preset configuration file code template, and generate a fourth code;
[0159] Each service correspondingly includes a first code, a second code, a third code and a fourth code.
[0160] Specifically, code generation is mainly divided into the following four parts:
[0161] 5.1) Service user data type definition header file;
[0162] 5.2) Service Client code generation;
[0163] 5.3) Server code generation;
[0164] 5.4) Service configuration generation.
[0165] The entire code generation process is cycled with services as units, and the generation of each service includes the above four parts.
[0166] The steps of the data type definition code generator 51 are described in detail below:
[0167] First, traverse the Service class instance array in the information container 4, and obtain a Service instance each time;
[0168] Then, traverse all method, event, and field interfaces of the Service instance;
[0169] Next, for each interface, traverse the input parameter type and output parameter type of the interface to determine whether the parameter type is a basic type supported by the compiler. If not, generate a definition for the data type;
[0170] Then, based on the obtained type name, the corresponding type object is searched in the type object set of information container 4, and the corresponding type object method is called according to the matching type object to determine the type classification, and the header file code is generated using corresponding different syntaxes according to different classifications.
[0171] For example, for data structures, struct syntax is used to generate code; for enumerated types, enum syntax is used to generate code; for variable-length arrays, vector syntax is used to generate code; for fixed-length arrays, array syntax is used to generate code; for strings, string syntax is used to generate code.
[0172] The service code is divided into two parts according to the idea of SOA: Client and Server. The Client is the proxy of the service, while the Server is the stub of the service. The code generation of this part can be realized by template replacement.
[0173] It should be noted that the code generation steps on the client and server sides are basically the same, and the input is the model data of the service saved in the information container. The only difference is the template file used.
[0174] The steps of the configuration file generator 54 are described in detail below:
[0175] First, retrieve the service configuration object from the information container;
[0176] Next, generate the corresponding JSON configuration file based on the service name in the service configuration object;
[0177] Finally, all key-value pairs in the service configuration object are iterated over and written to a JSON file in JSON syntax format.
[0178] The embodiment of the present invention adopts a parsing plug-in and an abstract parsing event interface to divide the parsing process into two parts: file parsing and abstract parsing, thereby achieving the decoupling of SOA communication matrix parsing from a specific file format.
[0179] As a preferred implementation, it also includes: a scheduler 7, which is respectively connected to the abstract parsing module 3, the information container 4, the code generation module 5 and the code template 6, and is used to schedule the abstract parsing module 3, the information container 4, the code generation module 5 and the code template 6.
[0180] Specifically, each module completes its specific functions and has clear division of responsibilities. All modules are implemented using the object-oriented programming method of the Python language, which has the advantages of clear interfaces, good encapsulation, and simple and fast implementation. The parsing plug-in module 1, the event listening interface 2, the abstract parsing module 3, the information container 4, the code generation module 5, and the code template 6 each independently complete a part of the function. The scheduler 7 can be regarded as the entrance of the program and is also the client of each module.
[0181] The scheduler 7 is responsible for instantiating the objects of each module and connecting them together, and then triggering the entire parsing process and code generation process by calling the methods of these objects.
[0182] The entire parsing process is driven by the scheduler 7. The scheduler 7 is responsible for building the MVC framework and binding the abstract parser with the parsing plug-in. After the binding is completed, the scheduler 7 can trigger the parsing process.
[0183] The scheduler 7 constructs the MVC framework, which means creating a specific parsing plug-in module 1, an information container class, and an abstract parsing class. Binding is based on the relationship between these classes, and the instantiated classes are associated. For example, the abstract parsing class needs to be set to the parsing class of the parsing plug-in as the implementation of the event interface. At the same time, when creating the abstract parsing interface, the instantiated information container class instance needs to be brought in as a parameter.
[0184] After parsing the communication matrix, the scheduler 7 can continue to trigger code generation. The parsing process is as follows:
[0185] First, the scheduler 7 calls the parser interface of the abstract parsing module 3;
[0186] Next, the parser interface of the abstract parsing module 3 reversely triggers the parser function of the parsing plug-in to actually parse the specific SOA communication matrix file;
[0187] Next, the abstract parsing module 3 monitors the notification events generated by the parsing plug-in during the parsing process and processes the event notification messages;
[0188] Finally, after processing and parsing the event message, the abstract parsing module 3 generates model data and stores the model data into the information container 4 .
[0189] See also Figure 2 The present invention also provides a code generation method for a service-oriented architecture communication matrix, which is applied to the code generation system for the service-oriented architecture communication matrix as described above, comprising:
[0190] S100, triggering a parsing process when a communication matrix is received; in the parsing process, parsing the received communication matrices in different formats based on a predefined information extraction class to obtain a parsing result;
[0191] S200, when a parsing process is detected to be triggered, a notification event of the parsing process is generated, and the notification event is sent to the abstract parsing module;
[0192] S300, when receiving a notification event, the abstract parsing module converts the parsing result into a data model and stores the data model in an information container;
[0193] S400, extracting model data from the information container, processing the extracted model data based on a preset code template, and generating corresponding codes.
[0194] like Figure 3 A flowchart showing the steps of data type parsing and generating model objects is shown, which includes the following steps:
[0195] Load the communication matrix file;
[0196] Create a parsing information container python object;
[0197] Start parsing;
[0198] Parse data type information;
[0199] If it is a structure parsing start event, create a python data Type object of structure type;
[0200] If it is a structure member type parsing event, create a member python object and call the add_member method of data Type;
[0201] If the structure ends parsing event, the current data Type object is added to the parsing information container object;
[0202] If it is an enumeration type parsing event, create a Python datatype object of the enumeration type and store it in the parsing information container object;
[0203] If none of the above four events are true, but an array type parsing event, a python data Type object of the array type is created, and the type attribute of the array member is stored in the data Type object, and the data Type is stored in the information container object.
[0204] The above events will be judged in sequence, and only when the judgment result of the current event is "no" will the judgment of the next event proceed.
[0205] like Figure 4 A flow chart showing the steps of service information parsing and service model object generation is shown, which includes the following steps:
[0206] Load the communication matrix file;
[0207] Create a parsing information container python object;
[0208] Start parsing;
[0209] Analyze service information;
[0210] If it is a new service information start event, create a Python service object based on the service name information;
[0211] If it is a method call parsing event, create a Python interface object of the method call type, and call the addMethod method of the service object to add the newly created interface;
[0212] If it is an event notification parsing event, create a Python interface object of the event notification type, and call addEvent of the service object to add the newly created interface;
[0213] If it is a field parsing event, create a Python interface object of the field type, and call the addfield of the service object to add the newly created interface;
[0214] If none of the above three events occurs, but a new service parsing end event occurs, the Python service object is added to the information container 4 for storage.
[0215] The above events will be judged in sequence, and only when the judgment result of the current event is "no" will the judgment of the next event proceed.
[0216] like Figure 5 A schematic diagram of the process of generating data type definition code is shown, which includes the following steps:
[0217] Take out a service object from the information container 4;
[0218] Create a data type definition header file belonging to this sub-service;
[0219] Get a new interface object from the service object;
[0220] Create a Python data type data Type object empty list dataTypelist;
[0221] If it is a method call interface, then the Python object corresponding to the data type model of the input parameter is taken out from the information container 4; if the input parameter is a non-basic data type, then the data type is added to the dataTypelist; if the input parameter is a basic data type, then the Python object corresponding to the data type model of the return value is taken out from the information container 4; if the return value is a non-basic data type, then the data type is added to the dataTypelist, and if the return value is a basic data type, then each data type in the dataTypelist is traversed: if it is a data structure, the struct syntax is used to generate the code; if it is an enumeration type, the enum syntax is used to generate the code; if it is a variable-length array, the vector syntax is used to generate the code; if it is a fixed-length array, the array syntax is used to generate the code; if it is a string, the string syntax is used to generate the code.
[0222] If it is an event notification interface, take out the Python object corresponding to the data type model of the input parameter from information container 4; if the input parameter is a non-basic data type, add the data type to dataTypelist; if the input parameter is a basic data type, traverse each data type in dataTypelist in the same way as above.
[0223] If it is the get interface of field, then take out the Python object corresponding to the data type model of the input parameter from information container 4; if the input parameter is a non-basic data type, then add the data type to dataTypelist; if the input parameter is a basic data type, then traverse each data type of dataTypelist in the same way as above.
[0224] If it is the set interface of field, then take out the Python object corresponding to the data type model of the input parameter from information container 4; if the input parameter is a non-basic data type, then add the data type to dataTypelist; if the input parameter is a basic data type, then traverse each data type in dataTypelist in the same way as above.
[0225] The above events will be judged in sequence, and only when the judgment result of the current event is "no" will the judgment of the next event proceed.
[0226] In the new electronic and electrical architecture of automobiles, the Ethernet-based service-oriented architecture (SOA) is widely used, and the communication middleware usually uses the SOME / IP protocol stack. According to the design method of SOA, tools are needed to automatically generate service codes based on the communication matrix so that applications can use the functions provided by the service. As a protocol stack supplier, you will first receive the communication matrix file in ARXML format provided by the OEM, and then design Python tools to parse the communication matrix file and generate corresponding code. The design of the entire tool code follows the following directory structure:
[0227]
[0228]
[0229] The top-level main.py is the entry point for tool implementation and also the scheduler role mentioned above. Release.sh is a running script that represents the tool itself, responsible for executing Python code and creating a directory for tool output. The Test directory is the unit test code. The Plugin directory stores parsing codes for different Excel formats. The Core directory is the core code of the entire tool. The Core code is divided into three directories according to the MVC framework: control, view, and model. The control directory is further divided into two sub-directories, parser and generator, for abstract parsing code and code generation code respectively. The Model directory stores some Python class codes defined for data modeling. View is the implementation of the corresponding information container, storing all parsed model data. The Code_templates directory stores code template files. The Interface directory contains some interface classes and auxiliary classes, which is a bridge between the Excel parsing plug-in and the core code.
[0230] Place the code template files in the Code_templates directory. The three files SrvProxy.h, SrvProxy.cpp, and SrvProxyIF.h are template files on the client side.
[0231] SrvSkeleton.h and SrvSkeleton.cpp are template files on the server side.
[0232] The following is the generated product for a service after parsing:
[0233]
[0234] For each service, the generated artifacts include a specific directory that contains the following subdirectories:
[0235] Message directory: This directory contains the data types needed by the service and is shared by both the client and the server.
[0236] Client directory: This directory contains the client interface library code for the generated service.
[0237] Server directory: This directory contains the interface library code for the generated service server.
[0238] Config directory: This directory is the communication configuration file corresponding to the service.
[0239] The advantages or beneficial effects of adopting the above technical solution are: the present invention realizes the decoupling of communication matrix parsing and code generation by adopting modular design, thereby improving the flexibility and scalability of the system; at the same time, a parsing plug-in module and an abstract parsing module are used to divide the parsing process into two parts, file parsing and abstract parsing, and the active monitoring of parsing events is combined to realize the decoupling of the parsing of the SOA communication matrix and the specific format of the file. There is no need to develop a separate parser for each format, and communication matrix files of various different formats can be easily handled and parsed, thereby reducing development and maintenance costs.
[0240] The above are only preferred embodiments of the present invention, and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should be aware that all solutions obtained by equivalent substitutions and obvious changes made using the contents of this specification and illustrations should be included in the protection scope of the present invention.
Claims
1. A code generation system for a service architecture communication matrix, characterized in that: include: A parsing plug-in module, used to trigger the parsing process when receiving the communication matrix; In the parsing process, the received communication matrices in different formats are parsed based on at least one predefined information extraction class to obtain parsing results; An event monitoring interface, connected to the parsing plug-in module and the abstract parsing module respectively, for generating a notification event of the parsing process when detecting that the parsing plug-in module triggers the parsing process, and sending the notification event to the abstract parsing module; The abstract parsing module is used to generate a data model according to the parsing result when receiving the notification event, and store the data model in the information container; The code generation module is connected to the information container and is used to extract model data from the information container, process the extracted model data based on a preset code template, and generate corresponding code.
2. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The parsing plug-in module includes: A plurality of parsing plug-ins, each of the parsing plug-ins corresponding to a format of the communication matrix; Each of the parsing plug-ins has the predefined information extraction class.
3. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The predefined information extraction class includes one or more combinations of a data type information extraction class, a service interface information extraction class, and a communication configuration information extraction class.
4. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The event monitoring interface includes an event notification interface; Each of the predefined extraction classes corresponds to one of the event notification interfaces, and each of the event notification interfaces predefines a plurality of interface functions corresponding to the predefined extraction class, and each of the interface functions is used to generate a notification event corresponding to a parsing event of the parsing process.
5. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The abstract parsing module is implemented based on the model-view-controller architecture.
6. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The abstract parsing module includes: At least one parser, which corresponds one-to-one with the predefined information extraction class and is used to, when called, reversely call the parsing function of the parsing plug-in module to trigger the parsing process; and when listening to the notification event, create and configure a model object based on the notification event, generate model data of the data model, and store the model data of the data model in the information container.
7. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The member attributes of the information container are composed of at least one list, each of which is used to store objects corresponding to the predefined extraction class.
8. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: The code generation module includes: A data type definition code generator, used to extract model data from the information container, process the extracted model data based on a preset data type definition code template, and generate a first code; A service client code generator, used for extracting model data from the information container, processing the extracted model data based on a preset service client code template, and generating a second code; A service code generator, used to extract model data from the information container, process the extracted model data based on a preset service code template, and generate a third code; A configuration file generator, used for extracting model data from the information container, processing the extracted model data based on a preset configuration file code template, and generating a fourth code; Each service correspondingly includes the first code, the second code, the third code and the fourth code.
9. The code generation system for a service-oriented architecture communication matrix according to claim 1, characterized in that: Also includes: The scheduler is connected to the abstract parsing module, the information container, the code generation module and the code template respectively, and is used for scheduling the abstract parsing module, the information container, the code generation module and the code template.
10. A code generation method for a service-oriented architecture communication matrix, characterized in that: A code generation system applied to a service-oriented architecture communication matrix as claimed in any one of claims 1 to 9, comprising: A parsing process is triggered when a communication matrix is received; in the parsing process, the received communication matrix in different formats is parsed based on a predefined information extraction class to obtain a parsing result; When the parsing process is detected to be triggered, a notification event of the parsing process is generated, and the notification event is sent to the abstract parsing module; When receiving the notification event, the abstract parsing module converts the parsing result into a data model and stores the data model in an information container; The model data is extracted from the information container, and the extracted model data is processed based on a preset code template to generate corresponding codes.