Summary of the invention
In view of this, the purpose of the embodiment of the present invention is to provide a kind of generation method and device of list item operation-interface function, improves the formation efficiency of interface function, reduces cost of development.
For solving the problems of the technologies described above, the embodiment of the present invention provides scheme as follows:
A kind of generation method of list item operation-interface function is applied to network processing unit, comprising:
Obtain the Table Properties defined file of corresponding traffic table, preserve the Table Properties parameter of corresponding traffic table in this document;
Obtain the handling function template of corresponding traffic table;
According to Table Properties defined file and the handling function template of corresponding traffic table, generate the operation-interface function of corresponding traffic table.
Preferably, in said method, described Table Properties parameter comprises at least a in following parameter:
Traffic table title, traffic table place memory interface, read-write position degree, table size, table start address, the key assignments of tabling look-up, handling function corresponding to traffic table identify and the traffic table field.
Preferably, in said method, further the handling function sign corresponding according to the traffic table in described Table Properties parameter, from the template base of preserving a plurality of handling function templates, extract the handling function template of corresponding traffic table.
Preferably, in said method, described Table Properties defined file and handling function template according to corresponding traffic table, the operation-interface function of the corresponding traffic table of generation comprises:
Resolve the Table Properties defined file of corresponding traffic table, obtain the Table Properties parameter of corresponding traffic table;
With the Table Properties parameter of corresponding traffic table, be filled in the handling function template of corresponding traffic table, obtain the operation-interface function of corresponding traffic table, and generate the code of the operation-interface function of corresponding traffic table.
Preferably, in said method, before obtaining the Table Properties defined file of corresponding traffic table, described method also comprises:
Receive and preserve the modification of the Table Properties parameter in user's his-and-hers watches attribute definition file; And/or
Receive and preserve the user to the modification of handling function template.
The embodiment of the present invention also provides a kind of generating apparatus of list item operation-interface function, is applied to network processing unit, comprising:
The first acquiring unit for the Table Properties defined file that obtains corresponding traffic table, is preserved the Table Properties parameter of corresponding traffic table in this document;
Second acquisition unit is for the handling function template of obtaining corresponding traffic table;
The function generation unit is used for Table Properties defined file and handling function template according to corresponding traffic table, generates the operation-interface function of corresponding traffic table.
Preferably, in said apparatus, described Table Properties parameter comprises at least a in following parameter:
Traffic table title, traffic table place memory interface, read-write position degree, table size, table start address, the key assignments of tabling look-up, handling function corresponding to traffic table identify and the traffic table field.
Preferably, in said apparatus, described second acquisition unit, further the handling function sign corresponding according to the traffic table in described Table Properties parameter, from the template base of preserving a plurality of handling function templates, extract the handling function template of corresponding traffic table.
Preferably, in said apparatus, described function generation unit comprises:
Resolution unit for the Table Properties defined file of resolving corresponding traffic table, obtains the Table Properties parameter of corresponding traffic table;
Code obtains the unit, is used for the Table Properties parameter with corresponding traffic table, is filled in the handling function template of corresponding traffic table, obtains the operation-interface function of corresponding traffic table, and generates the code of the operation-interface function of corresponding traffic table.
Preferably, in said apparatus, also comprise:
User interaction unit is for the modification of the Table Properties parameter that receives and preserve user's his-and-hers watches attribute definition file; And/or receive and preserve the user to the modification of handling function template.
Can find out that from the above generation method and the device of the list item operation-interface function that the embodiment of the present invention provides when driving the developer in needs increase, deletion or revising table definition, only need his-and-hers watches attribute definition file to modify; When needs Modification growth function framework, only need to modify to function template, so the method has greatly reduced peopleware's workload, reduction software cost, raising software development efficiency.
Embodiment
The embodiment of the invention discloses a kind of method of automatic generation list item operation-interface function, can alleviate to a great extent software developer's workload, reduced software development cost, improve software development efficiency.For making the purpose, technical solutions and advantages of the present invention clearer, describe the present invention below in conjunction with the accompanying drawings and the specific embodiments.
Inventor's discovery, for every a network processing unit, list item operation-interface function structure is identical, difference just is the parameters such as memory interface, read-write bit wide, table start address and table size under function.
By way of example, certain traffic table tableA, its list item add function and the deletion function is as follows: (for convenience of understanding, describing with simple version)
Therefore, the traffic table association attributes part (as tableA, tableB, sram_64) of these variations can be defined in a list item attribute text, constant part is defined in the function template file.The function Core Generator reads list item attribute text and template file simultaneously, the attribute that changes is filled in template, thus automatic code generating.
Based on above design, the embodiment of the present invention provides a kind of generation method of list item operation-interface function, is applied to network processing unit.As shown in Figure 1, the method comprises:
Step 11 is obtained the Table Properties defined file of corresponding traffic table, preserves the Table Properties parameter of corresponding traffic table in this document.
Here, described Table Properties parameter comprises at least a in following parameter: traffic table title, traffic table place memory interface, read-write position degree, table size, table start address, the key assignments of tabling look-up, handling function corresponding to traffic table identifies and traffic table field etc.
Step 12 is obtained the handling function template of corresponding traffic table.
In the present embodiment, can preserve a plurality of handling function templates in template base in advance.Then, in this step 12, the handling function sign corresponding according to the traffic table in described Table Properties parameter from the template base of preserving a plurality of handling function templates, extracted the handling function template of corresponding traffic table.
Step 13 according to Table Properties defined file and the handling function template of corresponding traffic table, generates the operation-interface function of corresponding traffic table.
This step 13 specifically can comprise: resolve the Table Properties defined file of corresponding traffic table, obtain the Table Properties parameter of corresponding traffic table; With the Table Properties parameter of corresponding traffic table, be filled in the handling function template of corresponding traffic table, obtain the operation-interface function of corresponding traffic table, and generate the code of the operation-interface function of corresponding traffic table.
As for the Table Properties defined file that uses in the present embodiment and handling function template, user's self-defining or establishment as required in advance.Then, by receiving and preserve the modification of the Table Properties parameter in user's his-and-hers watches attribute definition file; And/or receive and preserve the user to the modification of handling function template, obtain Table Properties defined file and handling function template.
Can find out from the above, after adopting said method, when driving the developer in needs increase, deletion or revising table definition, only need his-and-hers watches attribute definition file to modify; When needs Modification growth function framework, only need to modify to function template, so the method has greatly reduced peopleware's workload, reduction software cost, raising software development efficiency.
The embodiment of the present invention also provides a kind of device of implementing said method, and this installs as shown in Figure 2, and the generating apparatus of this list item operation-interface function comprises:
The first acquiring unit for the Table Properties defined file that obtains corresponding traffic table, is preserved the Table Properties parameter of corresponding traffic table in this document; Here, described Table Properties parameter can comprise at least a in following parameter: traffic table title, traffic table place memory interface, read-write position degree, table size, table start address, the key assignments of tabling look-up, handling function corresponding to traffic table identify and the traffic table field.
Second acquisition unit is for the handling function template of obtaining corresponding traffic table.
The function generation unit is used for Table Properties defined file and handling function template according to corresponding traffic table, generates the operation-interface function of corresponding traffic table.
As a kind of preferred implementation, described second acquisition unit, can be further corresponding according to the traffic table in described Table Properties parameter handling function sign from the template base of preserving a plurality of handling function templates, is extracted the handling function template of corresponding traffic table.
As a kind of preferred implementation, described function generation unit specifically can comprise:
Resolution unit for the Table Properties defined file of resolving corresponding traffic table, obtains the Table Properties parameter of corresponding traffic table;
Code obtains the unit, is used for the Table Properties parameter with corresponding traffic table, is filled in the handling function template of corresponding traffic table, obtains the operation-interface function of corresponding traffic table, and generates the code of the operation-interface function of corresponding traffic table.
Said apparatus can also comprise a user interaction unit (not shown), for the modification of the Table Properties parameter that receives and preserve user's his-and-hers watches attribute definition file; And/or receive and preserve the user to the modification of handling function template.
The embodiment of the present invention also provides another structure of implementing said method, and as shown in Figure 3, this structure comprises:
Table Properties database 101 has wherein defined the attribute of each traffic table.The text formatting structure of certain the traffic table attribute that for example, defines in this example is as follows:
Code Template storehouse 102 has wherein defined the template of various handling functions.It is as follows that certain type list that defines in this example adds function template:
Wherein tableName, RAM_Type, op_width are the variablees such as Table Properties parameter, extract and are substituted in template in the Table Properties database that need to create from 101.
Function Core Generator 103 produces the function of code automatically, specifically comprises resolver 104 and maker 105 two parts.
Resolver 104 is used for resolution table attribute definition file, therefrom obtains the various attributes of traffic table.
Maker 105 is used for selecting its template No. ID according to the template of traffic table attribute, and the Table Properties that will obtain from resolver is filled in template, finally outputs in handling function corresponding to this traffic table.
Object code 106 is for the various handling function codes of each traffic table of output.
Above-mentioned modules, wherein:
Table Properties file in Table Properties database 101 modules is stored with comparatively simple txt text formatting in this example.In fact as required flexible choice, such as the csv form, the forms such as XML are so long as the form that the resolver 104 in function Core Generator 103 can be resolved gets final product.
Stencil-chosen in Code Template storehouse 102 has multiple.There is at present the template framework of increasing income of multiple maturation available.This example can adopt the web framework bottle based on the python language, specifically can be with reference to httn: //www.oschina.net/p/bottle? relevant introduction in from=rss (official website httn: //bottlepy.org)
To sum up, network processing unit list item flexible design, list item are changeable, so table handling function (add, deletion, upgrade) needs often to revise according to definition, cause a large amount of software maintenance costs.The embodiment of the present invention is by pulling out changing unit and fixed part with the table function code, fixed part is defined in template file, changing unit is defined into the Table Properties defined file, by script from the information extraction of Table Properties file, automatically be embedded in template file, quick generating code, thus software cost greatly reduced, improved development efficiency.
Many functional parts described in this instructions all are called as module, in order to emphasize more especially the independence of its implementation.
In the embodiment of the present invention, module can realize with software, in order to carried out by various types of processors.For instance, the executable code module of a sign can comprise one or more physics or the logical block of computer instruction, and for instance, it can be built as object, process or function.However, the executable code of institute's identification module need not to be physically located in together, but can comprise and be stored in different different instructions physically, when combining on these command logics, and its composition module and realize the regulation purpose of this module.
In fact, executable code module can be individual instructions or many instructions, and even can be distributed on a plurality of different code segments, is distributed in the middle of distinct program, and crosses over a plurality of memory devices distributions.Similarly, service data can be identified in module, and can realize and be organized in the data structure of any suitable type according to any suitable form.Described service data can be used as the individual data collection and is collected, and perhaps can be distributed on diverse location (to be included on different storage device), and can only be present on system or network as electronic signal at least in part.
When module can utilize software to realize, consider the level of existing hardware technique, so can be with the module of software realization, in the situation that do not consider cost, those skilled in the art can build corresponding hardware circuit and realize corresponding function, and described hardware circuit comprises conventional ultra-large integrated (VLSI) circuit or gate array and the existing semiconductor such as logic chip, transistor or other discrete element.Module can also be used programmable hardware device, realizations such as field programmable gate array, programmable logic array, programmable logic device.
The above is only embodiments of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.