CN114356320A - Method and device for generating conversion dynamic library - Google Patents

Method and device for generating conversion dynamic library Download PDF

Info

Publication number
CN114356320A
CN114356320A CN202210012915.9A CN202210012915A CN114356320A CN 114356320 A CN114356320 A CN 114356320A CN 202210012915 A CN202210012915 A CN 202210012915A CN 114356320 A CN114356320 A CN 114356320A
Authority
CN
China
Prior art keywords
interface
dynamic library
function
description
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210012915.9A
Other languages
Chinese (zh)
Inventor
金世良
王磊
王伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Agree Technology Co ltd
Original Assignee
Agree Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Agree Technology Co ltd filed Critical Agree Technology Co ltd
Priority to CN202210012915.9A priority Critical patent/CN114356320A/en
Publication of CN114356320A publication Critical patent/CN114356320A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The method can automatically generate the conversion dynamic library capable of calling the dynamic library to be called according to the interface information of the dynamic library to be called, so that the problems of programming errors, development code quality reduction and high troubleshooting cost caused by operation errors in the manual programming process are solved, the convenience and the robustness of generating the conversion dynamic library for calling the dynamic library to be called are improved, the development efficiency of generating the conversion dynamic library for calling the dynamic library to be called is improved, and the technical requirements on developers are reduced.

Description

Method and device for generating conversion dynamic library
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for generating a conversion dynamic library.
Background
The dynamic library is an indispensable part in the operating system structure, and is used for decomposing a complex program into a plurality of different parts to be provided for different developers/manufacturers to complete.
The functions of each part of the dynamic library are different due to different developers. Therefore, different dynamic library interface designs may differ, and the interface formats for different functions within a dynamic library may differ. Different calling codes are developed aiming at different dynamic libraries and different functional interfaces for each calling, and a similar using process is realized. The number of dynamic libraries and interfaces may be large, and the difference may also be large, so that the process of packaging the same usage flow is very complicated, and manual operation is very easy to make mistakes. Packaging the same using process needs to eliminate the difference between the dynamic libraries and the difference between the interfaces, and some differences look small, so that developers need to understand the relevant technical details of the dynamic libraries deeply, and the method has strong code development capability and high technical threshold.
However, the calling of most existing dynamic libraries and similar dynamic library calling processes may be different under different conditions, and once the difference is generated, the dynamic libraries and interfaces are completely re-developed, and if the difference is generated, a new dynamic library or a new interface is added. And the codes for calling the dynamic library need to be programmed manually, and if the called dynamic library changes, the codes for calling the dynamic library also need to be modified manually. However, in the process of manual programming development, there are problems that programming errors, development code quality degradation, and problem troubleshooting cost are high due to operation errors easily occurring in the manual programming process, so that it is necessary to manually spend a lot of time to repeatedly query the error cause and correct the wrong programming, and further a lot of manpower and time costs are consumed in the process.
Disclosure of Invention
The application provides a method for generating a conversion dynamic library, which can generate a new dynamic library file to be called containing a compatible conversion function for the dynamic library to be called in a high-efficiency, high-quality and low-cost mode, greatly simplifies the process of accessing an application system by the conventional dynamic library to be called, and improves the generation efficiency of the conversion dynamic library.
In a first aspect, the present application provides a method for generating a conversion dynamic library, where the method includes:
acquiring interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information;
generating a function flow interface description corresponding to the function flow interface information according to the function flow interface information;
matching fields in the functional process interface description with the public field information to obtain a global description structure;
and generating the conversion dynamic library according to the function flow interface description and the global description structure.
In a second aspect, the present application provides an apparatus for generating a translation dynamic library, the apparatus comprising:
the information acquisition unit is used for acquiring the interface information of the dynamic library to be called; the interface information comprises functional process interface information and public field information;
the description generating unit is used for generating functional process interface description corresponding to the functional process interface information according to the functional process interface information;
the structure obtaining unit is used for matching the field in the function process interface description with the public field information to obtain a global description structure;
and the link library generating unit is used for generating the conversion dynamic library according to the function flow interface description and the global description structure.
In a third aspect, the present application provides a readable medium comprising executable instructions, which when executed by a processor of an electronic device, perform the method according to any of the first aspect.
In a fourth aspect, the present application provides an electronic device comprising a processor and a memory storing execution instructions, wherein when the processor executes the execution instructions stored in the memory, the processor performs the method according to any one of the first aspect.
It can be seen from the above technical solutions that the present application provides a method for generating a conversion dynamic library, the method including: acquiring interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information; generating a function flow interface description corresponding to the function flow interface information according to the function flow interface information; matching fields in the functional process interface description with the public field information to obtain a global description structure; and generating the conversion dynamic library according to the function flow interface description and the global description structure. Therefore, in the application, the functional flow interface description and the global description structure can be generated according to the interface information of the dynamic library to be called, and then, the conversion dynamic library can be generated by using the functional flow interface description and the global description structure, so that the dynamic library to be called can be called by using the conversion dynamic library. Therefore, the conversion dynamic library capable of calling the dynamic library to be called can be automatically generated according to the interface information of the dynamic library to be called, so that the manual programming development is not needed as in the prior art, the problems of programming errors, reduced development code quality and high troubleshooting cost caused by operation errors in the manual programming process are solved, the convenience and the robustness of generating and calling the conversion dynamic library of the dynamic library to be called are improved, the development efficiency of generating and calling the conversion dynamic library of the dynamic library to be called is improved, and the technical requirements on developers are reduced.
Further effects of the above-mentioned unconventional preferred modes will be described below in conjunction with specific embodiments.
Drawings
In order to more clearly illustrate the embodiments or prior art solutions of the present application, the drawings needed for describing the embodiments or prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments described in the present application, and that other drawings can be obtained by those skilled in the art without inventive exercise.
Fig. 1 is a schematic flowchart illustrating a method for generating a conversion dynamic library according to an embodiment of the present application;
FIG. 2 is a schematic view of an interface provided in an embodiment of the present application;
FIG. 3 is a schematic view of an interface provided in an embodiment of the present application;
fig. 4A is a schematic interface diagram according to an embodiment of the present application;
fig. 4B is a schematic view of a scenario provided in an embodiment of the present application;
fig. 5 is a schematic structural diagram of a device for generating a conversion dynamic library according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following embodiments and accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
At present, the way of calling the dynamic library is usually to put the dynamic library and the executable program on one computer, link when compiling the executable program, or load a specified file when the executable program runs, so as to realize the function that the executable program calls one or more functions in the dynamic library. Whether linked or dynamically loaded, a dynamic library is loaded into a certain address space of an executable program as part of the executable program and is called as a local function is called.
However, the calling of most of the existing dynamic libraries requires manual programming of codes for calling the dynamic libraries, and if the dynamic libraries to be called are changed, the codes for calling the dynamic libraries also need to be modified manually. However, in the process of manual programming development, there is a problem that programming errors due to operation errors easily occur in the manual programming process, so that it takes a lot of time for manual work to repeatedly query the error cause and correct the wrong programming, and further a lot of labor and time costs are consumed in the process.
The application provides a method for generating a conversion dynamic library, which comprises the following steps: acquiring interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information; generating a function flow interface description corresponding to the function flow interface information according to the function flow interface information; matching fields in the functional process interface description with the public field information to obtain a global description structure; and generating the conversion dynamic library according to the function flow interface description and the global description structure. Therefore, in the application, the functional flow interface description and the global description structure can be generated according to the interface information of the dynamic library to be called, and then, the conversion dynamic library can be generated by using the functional flow interface description and the global description structure, so that the dynamic library to be called can be called by using the conversion dynamic library. Therefore, the conversion dynamic library capable of calling the dynamic library to be called can be automatically generated according to the interface information of the dynamic library to be called, so that the manual programming development is not needed as in the prior art, the problems of programming errors, reduced development code quality and high troubleshooting cost caused by operation errors in the manual programming process are solved, the convenience and the robustness of generating and calling the conversion dynamic library of the dynamic library to be called are improved, the development efficiency of generating and calling the conversion dynamic library of the dynamic library to be called is improved, and the technical requirements on developers are reduced.
Various non-limiting embodiments of the present application are described in detail below with reference to the accompanying drawings.
Referring to fig. 1, a method for generating a conversion dynamic library in an embodiment of the present application is shown, and in this embodiment, the method may include the following steps:
s101: and acquiring interface information of the dynamic library to be called.
In this embodiment, the dynamic library to be called may be understood as a dynamic library to be called that needs to be called. The dynamic library to be called can be directly updated through the replacement file, and the calling program for calling the dynamic library to be called does not need to be recompiled without changing the interface information of the dynamic library to be called. In one implementation, because the dynamic library to be called and the calling device may be in different operation languages, in order to ensure that the calling device in different operation languages and the dynamic library to be called can normally operate, the interface of the dynamic library to be called is a C-standard interface. The interface information comprises function flow interface information and public field information. It should be noted that, in this embodiment, an interface may be provided, and a user may input interface information of the dynamic library to be called through the interface.
The common field information is predefined according to scheduling requirements. In one implementation, the common field information may include: the file name, the public parameter and the structure of the called dynamic library to be called; the common parameters may include predefined key variables and added global variables, such as baud rate and port.
The function flow interface information may be understood as function flow information of each function module in the dynamic library to be called. In one implementation, the functional flow interface information may include: returning value type, calling convention, function name, interface calling function type and interface description; wherein the interface call function type comprises synchronous or asynchronous. The return value type may be understood as the type of value returned by the call; the calling convention can be understood as a preset calling rule; the function name can be understood as the identifier of the preset function; the interface call function type can be understood as the type of function calling the interface; the interface description may be understood as the introductory description information of the interface.
In this embodiment, a function flow interface information input interface as shown in fig. 2, fig. 3 and fig. 4 may be provided, through which a user may input or adjust function flow interface information. The term "Test" is used to refer to a method that can directly specify an interface as a Test method, and generally requires that an interface without parameters or with only parameters is used as a Test method, or that an interface with only common parameters such as a port is used. If the interface is an interface with an entry, a default value can be assigned to the interface, and as a default parameter when the test function is called, the description of the interface can be int __ cdecl fun (IN char para ═ qwerty 1234), which is similar to the default value design IN the interface declaration of many languages.
S102: and generating a functional process interface description corresponding to the functional process interface information according to the functional process interface information.
In this embodiment, for each piece of function flow information, a function flow interface description corresponding to the function flow information is generated according to a preset description format. As an example, after the function flow interface information is acquired, the interface essence can be obtained by analyzing the function flow information in the function flow interface information through codes; for example, Interface, call _ way, and emulation are essential descriptions extracted by CT _ SendCommand method information, include all necessary information when using an Interface, and are the basis of a code generation process.
For example, according to the input function flow interface information shown in fig. 2, fig. 3, and fig. 4A, for each piece of function flow information, a function flow interface description corresponding to the piece of function flow information may be generated according to a preset description format, and finally, the function flow interface description corresponding to the piece of function flow interface information is obtained: int __ stdcall CT _ Sendcommand (IN char port, IN char extport, IN char icFlag, IN int nCmdLen, HIN unidimed char pszCmd, OUT int pnRespLen, HOUTunidimed char pszResp)
// call _ way synchronization
And/illtation, namely accessing the COS, sending a C-APDU instruction, and receiving an R-APDU return.
The meaning of this interface description is:
the return value is int, the calling convention is stdcall, and the function name is CT _ SendCommand;
the first parameter is port, char type, is input parameter;
the second parameter is export, char type, is a parameter;
the third parameter is icFlag, char type, is input parameter;
the fourth parameter is nCmdLen, int type, which is a reference;
the fifth parameter is pszCmd, unsigned char type, and is a reference, H in HIN flag indicates that the communication layer is HEX code, (if BIN indicates that it is a reference of BASE64 code);
the sixth parameter is pnRespLen, int type, which is a reference;
the seventh parameter is pszResp, signaled char type, which is a parameter, and the communication layer is HEX code.
The synchronous/asynchronous is used for controlling whether the interface needs to start the thread or not, and is executed in the thread, which can also be automatically generated through the template.
Inside the llstration is the annotation of the interface. It should be noted that the interface description may be in other formats, and the requirement may be satisfied as long as necessary information is included.
S103: and matching the fields in the functional process interface description with the public field information to obtain a global description structure.
In this embodiment, for each field in the function flow interface description, if the common field information includes the target value corresponding to the field, the value of the field in the function flow interface description is adjusted to the target value, so as to obtain an adjusted field. For example, if the common field information includes the field "port" and its corresponding target value "a" and the field "port" is included in the functional flow interface description, the value of the field "port" in the functional flow interface description may be adjusted to "a".
And if the values of all the fields in the function process interface description are adjusted, obtaining the adjusted function process interface description according to all the adjusted fields. It can be understood that, after the values of the fields included in both the functional flow interface description and the common field information in the functional flow interface are adjusted to the target values, the adjusted functional flow interface description can be obtained.
Then, the global scanning structure may be obtained according to the adjusted functional process interface description. Because the structures of all the structural bodies of the global scanning structure are also the basic types or the linked list recursive definitions, and the recursive definitions are generally not considered in the interface, a complete structural body can be obtained by adding a plurality of basic types such as int, char, unsigned char and the like, and meanwhile, a corresponding json analytic function can be generated each time the basic types are added. Since the action range of the global scanning structure is global, if different structures with the same name exist in different interface parameters, the global scanning structure should be renamed to be unrepeated. Note that the first three lines of comments at the beginning of the file may be saved in csv format, comma, or separator, and the description structure of each function may also be saved in a specific location of the code file in a comment manner.
S104: and generating the conversion dynamic library according to the function flow interface description and the global description structure.
In this embodiment, a structure body statement, a common flow interface statement, a global variable statement, a structure body message assembly analysis code, and a common flow interface code may be generated according to the global description structure. For example, the structure body statement, the common flow interface statement, the global variable statement, the structure body message assembly parsing code, and the common flow interface code may be extracted from the global description structure according to a preset extraction rule (e.g., a preset format of each statement or code).
Then, according to the functional flow interface description, export interface type declarations of all functional flow interfaces, import interface type declarations of all functional flow interfaces, and functional flow interface codes can be generated. For example, the export interface type declaration of all the functional flow interfaces, the import interface type declaration of all the functional flow interfaces, and the functional flow interface codes may be extracted from the functional flow interface description according to a preset extraction rule (e.g., a preset format of each declaration or code). In the process of generating a code, in the process of processing a return value of a non-numeric (less than or equal to int) or null (void) type, the return value is used as an argument in the case that the type of the return value is char. If the design is not standard or has special functions, the return value may be a type such as a character string, and the return value is packaged into a resmsg as an argument, and if the return value is an unsigned char type, whether base64 or hex coding is used is also selected. IN the interface description, the interface description may be embodied by adding an OUT flag, such as BOUT unsigned char __ cdecl fun (IN char para), indicating that the return value is used as a reference, and BASE64 encodes.
Then, the structure body statement, the export common process interface statement, the global variable statement, the structure body message assembly analysis code, the common process interface code, the export interface type statements of all the functional process interfaces, the import interface type statements of all the functional process interfaces, and the functional process interface code may be compiled to obtain the conversion dynamic library. That is, the structure body declaration, the export common flow interface declaration, the global variable declaration, the structure body message assembly parsing code, the common flow interface code, the export interface type declarations of all the functional flow interfaces, the import interface type declarations of all the functional flow interfaces, and the functional flow interface code are all translated into object program code equivalent to machine language representation, for example, the structure body statement, the export common flow interface statement, the global variable statement, the structure body message assembly analysis code, the common flow interface code, the export interface type statements of all the functional flow interfaces, the import interface type statements of all the functional flow interfaces, and the functional flow interface code are all translated into a C language program, so that a conversion dynamic library can be obtained.
It should be noted that the global variable declaration may include: a) a global variable customized in the global description structure; b) all parameters and expansion formats of the parameters contained in a common interface in interface design, for example, a global variable default comprises a port of a char type such as 'COM 3' and an iport of an int type such as '3', when an interface is generated, the interface is judged according to the type, for example, the port is regarded as a port, and the intport is regarded as an iport; c) if the global variable used in the process is called, the dynamic library handle to be called; d) and (5) declaring a structural body.
For example, when the public interface includes an initDriver function, the process of generating the initDriver function is as follows: saving a callback function pointer according to the interface design, and packaging the callback function pointer into a local sending message and a log recording function or other functions; according to the file name or path of the dynamic library to be called of the global variable in the global description structure, inquiring and loading the dynamic library to be called, and saving the dynamic library to the global handle; the return value loads a system error code returned by a function (such as loadlibrary, dlopen) of the dynamic library to be called, so that the reason why the dynamic library to be called is loaded with the error can be known.
For example, when the public flow interface includes setportAttr, the process of generating setportAttr is as follows: and according to the interface design, saving the parameters given by setPortAttr to the global variables, and inquiring the fields which are not contained in the interface design in the configstr to obtain values and saving the values to the global variables. The global variable that cannot be found, char is initialized to 0-filled memory of 1024 size, int is initialized to 0.
For example, when the public flow interface includes the fail, the process of generating the fail is as follows: releasing the closing of the dynamic library handle to be called (e.g. freelibrary, dlclose) returns the result of the function execution. The dinit function obtained in this way may not be capable of correctly closing the executing calling resource, if there is a relevant requirement, the interface may be controlled by referring to the way of checking and adding the test method, the check and adding method may be checked and selected as a global cancel function, and the release and closing of the dynamic library handle to be called may be executed only after the execution is successful.
For each interface, the following can be obtained from the functional flow interface description:
1. deriving a function declaration;
the derived function declaration may be: exten "C" __ declspec (dllexport) int method name (char _ args, char _ resmsg, char _ errmsg, intadtimeout, int writeTimeout), e.g., exten "C" __ declspec (dllexport) int CT _ SendCommand (char _ args, char _ resmsg, char _ errmsg, int readTimeout, int writeTimeout); in the actual function flow, the functions are distinguished by the method names, but the formats are kept uniform, so that all the function modules can be directly used by an upper layer module without developing a memory organization module. After the PushMessage and other public parameters are registered, the functional flow of each functional module can be actually required by each interface parameter part and can be combed into entry, exit, return code, error information and overtime. The Json format character string is defined to enter the parameter and exit the parameter, so that the completely universal dynamic library interface design to be called can be realized, and all the dynamic library processes to be called can be realized.
args is a json-formatted join string that most of the time may require a const type to avoid exceptions, but the code complexity within the interface is somewhat increased.
resmsg is a reference character string, generally a calling result, a memory of the resmsg is generally created by a calling party, and a result character string is assigned to the memory by a code in an interface, but sometimes the memory of the resmsg needs to be opened greatly, char can be used for creating the memory from the inside of a dynamic library to be called, the memory utilization rate can be reduced, the development difficulty of the code in the interface is increased, the memory can be difficult to release correctly, the problem is caused, the size of a parameter memory space can be reduced by writing content into a file, then transmitting a file path and the like, and the relatively difficult development form of char is avoided.
The function return value is an error code, generally, 0 is agreed to be successful in execution, a negative number is an error, a positive number is an alarm, the alarm indicates that a problem occurs, but the flow may not be influenced and the flow may continue to be executed, the error code may be agreed according to actual conditions, and the interface itself is not limited. errmsg is error information, and is also generally created by a caller, similar to resmsg, and since error information is generally not very large, it generally does not need to be processed by passing a file path or char. Error information may sometimes be contained in the resmsg, separate processing helps to reduce complexity of the flow, exception detailed information corresponding to the code may be obtained before the complicated resmsg is not analyzed, and an exception mode of warning may exist, that is, the resmsg contains a call result of an available and subsequent flow, but the errmsg still contains some exception information which may not be processed. For example, a bank client inputs a password through an encryption password keyboard, a password ciphertext is contained in the resmsg, although the ciphertext is, if the leakage amount is large enough, risks may exist, the ciphertext cannot be desensitized, the resmsg cannot record a log, the difficulty of troubleshooting problems is increased under abnormal conditions, error information can be effectively obtained through the errmsg at this time, and the difficulty of troubleshooting problems is reduced.
ReadTimeout and writetimeout are io-oriented timeout designs that can generally be changed to a single timeout. Timeout is relatively lack of management in traditional applications, and single Timeout is helpful for avoiding exception and improving development quality. In practical scenarios, the timeout for each function call may be different, so that the timeout cannot be a common parameter, but each function call is provided with a preset timeout.
The meaning of the return value and the correct return code are generally used when the int type returns, and if the correct condition is not 0, the range of the correct return value is specified, and the information of the errmsg corresponding to a specific value can also be specified.
2. Defining the type of an objective function;
typedef int(__stdcall*pCT_SendCommand)(char*port,char*extport,char*icFlag,int nCmdLen,unsigned char*pszCmd,int*pnRespLen,unsigned char*pszResp)。
3. part of deriving a function implementation, comprising:
a) args are entered into parameters for analysis and converted into a target function, and a pre-packaged mode such as getIntFromJsonStr and other functions can be used to directly obtain a converted result without handwriting every time. When a structure is added, a corresponding analytical function is generated at the same time. Such as { "a": 1"," b ": qwer", "c" { \\\ "x \": 2\ ", \" y \ ": asdf \" }; it can be obtained that the value of a is the numerical value 1 or the character string "1", the value of b is the character string "qwer", the value of the structure c, c.x is the numerical value 2 or the character string "2", the value of c.y is the character string "asdf";
since map < string > is recommended, the type of parameter which cannot be directly obtained from json is numerical value or character string, and the actual type and the used analytic function need to be determined by combining with the function interface description structure.
For example int a ═ getIntFromJsonStr (args, "a"), a can be obtained with a value of 1.
Char a (getStrFromJsonStr (args, "a"), which internally creates a memory according to the string length, can obtain the value of a as the string "1", or a is a pointer to the memory in which the string "1" is located.
c obj (getcFromJsonStr), which internally creates memory according to the structure sizeof key and calls for example
The value of c.y can be found as the string "asdf" by obj.
And adding one step to the base64 and hex-coded unscented char data for decoding.
b) Creating a memory for the target function to participate;
the memory size created here is default 1024, or a value saved for the interface description, such as int __ cdecl fun (OUT char [2048] para), indicating that the memory size that the para field should create is 2048.
c) Obtaining target function pointer from global called to-be-called dynamic library handle
The actual function pointer is obtained by GetProcAddress or dlsym.
d) A function is called.
e) Tissue generating;
and converting the output references into string one by one, namely converting int into char, and encoding the unsigned char for base64 or hex, converting the structural body into a character string, and then assembling json, wherein the process is just opposite to the analysis process of the input references, and the principle is the same. It may contain the return value of the function call and the function cannot be missing, but the principle is not different.
f) Organizing the error information;
error information may be processed to match error codes based on the interface description.
g) An error code is returned.
h) If the function is designated as a Test function, a Test function is generated, a new args is created by default, the process is similar to the organization, and the function is called by using the obtained args. If a plurality of functions are designated as the test method, control can be added to the interface, so that a certain field in args of the test method corresponds to a target function, and the method can be realized through simple matching.
i) If the function is an asynchronous function, the name of the generated function implementation needs to be renamed, if a prefix and a suffix are added, the function implementation of an original function name is generated, the original args is copied and is transmitted to a thread as a parameter, the function returns to 0 after the thread is started successfully, the resmsg has content success, the function is called by using the args in the thread, then the function return value, the resmsg and the errmsg are assembled into json, and the json is sent out through an asynchronous message interface.
j) Each node generated by the function may automatically have a log record of the value of each node.
Thus, a code file which can convert the dynamic library interface to be called which does not conform to the standard into the dynamic library interface to be called with the unified standard is obtained, and the converted dynamic library to be called is obtained by compiling through a script or a compiler of a development environment.
The packager only participates in the documents or the old codes, determines the interfaces, inputs the interfaces one by one or imports the batch writing description structure, and then can obtain the conversion to-be-called dynamic library of the to-be-called dynamic library. The development cost of conventional writing codes is greatly reduced. Interface description information is stored in the code, and the code can be guaranteed to be restored to a configurable interface. In this embodiment, manually through a document or an old application code, a description structure may be obtained through a configured interface or a written interface description, and a generation process obtains a code by parsing the description structure.
The code comprises interface description, when the program imports the code, the content is analyzed to obtain a code description structure, and the code description structure can correspond to a configured interface effect, so that modification is facilitated.
If the code is modified manually, when the interface is modified again, the generated code can be firstly described by the previous interface and the original code is compared without difference, and if the generated code is different from the original code, the manual modification is prompted, and the modified content is displayed through file comparison of ide integration or other comparison modes, so that the condition that the code is directly modified before is directly covered when the code is modified through an interactive interface is avoided. The calling convention is modified in the code, such as manually, and then the parameters are added.
The code comparison tool also has the function of combining the differences, and the left side or the right side of each difference can be manually selected to be stored, so that the correct modified code can be quickly obtained. Finally, the correct code of the modified calling convention and parameters is obtained.
It can be seen from the above technical solutions that the present application provides a method for generating a conversion dynamic library, the method including: acquiring interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information; generating a function flow interface description corresponding to the function flow interface information according to the function flow interface information; matching fields in the functional process interface description with the public field information to obtain a global description structure; and generating the conversion dynamic library according to the function flow interface description and the global description structure. Therefore, in the application, the functional flow interface description and the global description structure can be generated according to the interface information of the dynamic library to be called, and then, the conversion dynamic library can be generated by using the functional flow interface description and the global description structure, so that the dynamic library to be called can be called by using the conversion dynamic library. Therefore, the conversion dynamic library capable of calling the dynamic library to be called can be automatically generated according to the interface information of the dynamic library to be called, so that manual programming development is not needed as in the prior art, the problem of programming errors caused by operation errors in the manual programming process is solved, convenience and accuracy of generating and calling the conversion dynamic library of the dynamic library to be called are improved, and development efficiency of generating and calling the conversion dynamic library of the dynamic library to be called is improved. The method and the device can standardize similar use processes into a generation process of the dynamic library file to be called, and automatically convert different dynamic libraries to be called and interfaces into a uniform use process through the generated new dynamic library to be called. The functional flow interface description and the global description structure can be directly regenerated after the unified using process is changed, and the previous steps do not need to be repeated. In the application, the process of converting the basic information into the functional flow interface description and the global description structure does not need developers to understand the different details of the dynamic library to be called, which are different. Is a process that logically abstracts the technical essence of the called interface. In the application, the functional flow interface description and the global description structure are converted into the code or the dynamic library to be called or the unified interface, so that a developer is not required to have large workload, and the requirement on the code development capacity is not high. Is the actual execution process, including generating code and compiling code. Besides, the number of the interfaces is increased, and besides writing increased business logic, only the automatically generated dynamic library file to be called needs to be updated, so that the workload is not obviously increased, only one message structure is added, and the influence on the application is small.
In an implementation manner of this embodiment, the method further includes:
and sending a function field to the conversion dynamic library so that the conversion dynamic library calls the dynamic library to be called to execute the task corresponding to the function field according to the function field to obtain result data corresponding to the function field.
In this embodiment, when the dynamic library to be called needs to be called, a function field may be generated according to a function that needs to be called, and the function field may be sent to the conversion dynamic library. The conversion dynamic library can determine a dynamic library to be called according to the function field, and call the dynamic library to be called to execute the task corresponding to the function field, so that the dynamic library to be called can return result data corresponding to the function field through the conversion dynamic library. As shown in fig. 4B, when the application needs to call the dynamic library to be called, a function field may be generated according to the function that needs to be called, and the function field may be sent to the conversion dynamic library; the conversion dynamic library can determine a dynamic library to be called according to the function field, and call the dynamic library to be called to execute the task corresponding to the function field, so that the dynamic library to be called can return result data corresponding to the function field to the application through the conversion dynamic library, and the process of calling the dynamic library to be called to execute the task is completed.
Fig. 5 shows a specific embodiment of a device for generating a conversion dynamic library according to the present application. The apparatus of this embodiment is a physical apparatus for executing the method of the above embodiment. The device is applied to a service side, the service side includes services, and a technical scheme of the device is substantially consistent with the embodiment, and the device in this embodiment includes:
an information obtaining unit 501, configured to obtain interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information;
a description generating unit 502, configured to generate a function flow interface description corresponding to the function flow interface information according to the function flow interface information;
a structure obtaining unit 503, configured to match a field in the functional process interface description with the common field information to obtain a global description structure;
a link library generating unit 504, configured to generate the conversion dynamic library according to the functional process interface description and the global description structure.
Optionally, the function flow interface information includes: returning value type, calling convention, function name, interface calling function type and interface description; wherein the interface call function type comprises synchronous or asynchronous.
Optionally, the common field information includes: the file name, the public parameter and the structure of the called dynamic library to be called; wherein the common parameters include predefined key variables and added global variables.
Optionally, the description generating unit 502 is configured to:
and generating a function flow interface description corresponding to each function flow information according to a preset description format.
Optionally, the structure obtaining unit 503 is configured to:
for each field in the functional process interface description, if the common field information includes a target value corresponding to the field, adjusting the value of the field in the functional process interface description to the target value to obtain an adjusted field;
if the values of all the fields in the function process interface description are adjusted, obtaining the adjusted function process interface description according to all the adjusted fields;
and obtaining the global scanning structure according to the adjusted functional process interface description.
Optionally, the link library generating unit 504 is configured to:
generating a structural body statement, exporting a public flow interface statement, a global variable statement, a structural body message assembling analysis code and a public flow interface code according to the global description structure;
generating export interface type declarations of all the functional process interfaces, import interface type declarations of all the functional process interfaces and functional process interface codes according to the functional process interface description;
compiling the structure statement, the export common process interface statement, the global variable statement, the structure message assembly analysis code, the common process interface code, the export interface type statement of all the functional process interfaces, the import interface type statement of all the functional process interfaces and the functional process interface code to obtain the conversion dynamic library.
Optionally, the apparatus further includes a query unit, configured to:
and sending a function field to the conversion dynamic library so that the conversion dynamic library calls the dynamic library to be called to execute the task corresponding to the function field according to the function field to obtain result data corresponding to the function field.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application. On the hardware level, the electronic device comprises a processor and optionally an internal bus, a network interface and a memory. The Memory may include a Memory, such as a Random-Access Memory (RAM), and may further include a non-volatile Memory, such as at least 1 disk Memory. Of course, the electronic device may also include hardware required for other services.
The processor, the network interface, and the memory may be connected to each other via an internal bus, which may be an ISA (Industry standard architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry standard architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 6, but that does not indicate only one bus or one type of bus.
And the memory is used for storing the execution instruction. In particular, a computer program that can be executed by executing instructions. The memory may include both memory and non-volatile storage and provides execution instructions and data to the processor.
In a possible implementation manner, the processor reads the corresponding execution instruction from the nonvolatile memory to the memory and then executes the execution instruction, and may also obtain the corresponding execution instruction from other devices to form the program execution device of the terminal on a logic level. The processor executes the execution instructions stored in the memory, so that the program running method of the terminal provided in any embodiment of the application is realized through the executed execution instructions.
The method executed by the program execution device of the terminal according to the embodiment shown in fig. 1 of the present application may be applied to or implemented by a processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or instructions in the form of software. The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in a memory, and a processor reads information in the memory and completes the steps of the method in combination with hardware of the processor.
The embodiment of the present application further provides a readable storage medium, where the readable storage medium stores an execution instruction, and when the stored execution instruction is executed by a processor of an electronic device, the electronic device can be caused to execute the program running method of the terminal provided in any embodiment of the present application, and is specifically configured to execute the method for executing the program running of the terminal.
The electronic device described in the foregoing embodiments may be a computer.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects.
The embodiments in the present application are described in a progressive manner, and the same and similar parts among the embodiments can be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (10)

1. A method for generating a translation dynamic library, the method comprising:
acquiring interface information of a dynamic library to be called; the interface information comprises functional process interface information and public field information;
generating a function flow interface description corresponding to the function flow interface information according to the function flow interface information;
matching fields in the functional process interface description with the public field information to obtain a global description structure;
and generating the conversion dynamic library according to the function flow interface description and the global description structure.
2. The method of claim 1, wherein the functional process interface information comprises: returning value type, calling convention, function name, interface calling function type and interface description; wherein the interface call function type comprises synchronous or asynchronous; and the interface of the dynamic library to be called is a C standard interface.
3. The method of claim 2, wherein the common field information comprises: the file name, the public parameter and the structure of the called dynamic library to be called; wherein the common parameters include predefined key variables and added global variables.
4. The method according to any one of claims 1 to 3, wherein generating a functional process interface description corresponding to the functional process interface information according to the functional process interface information comprises:
and generating a function flow interface description corresponding to each function flow information according to a preset description format.
5. The method according to claim 3, wherein the matching the field in the function flow interface description with the common field information to obtain a global description structure comprises:
for each field in the functional process interface description, if the common field information includes a target value corresponding to the field, adjusting the value of the field in the functional process interface description to the target value to obtain an adjusted field;
if the values of all the fields in the function process interface description are adjusted, obtaining the adjusted function process interface description according to all the adjusted fields;
and obtaining the global scanning structure according to the adjusted functional process interface description.
6. The method according to any one of claims 1-3, wherein the generating the translation dynamic library according to the functional process interface description and the global description structure comprises:
generating a structural body statement, exporting a public flow interface statement, a global variable statement, a structural body message assembling analysis code and a public flow interface code according to the global description structure;
generating export interface type declarations of all the functional process interfaces, import interface type declarations of all the functional process interfaces and functional process interface codes according to the functional process interface description;
compiling the structure statement, the export common process interface statement, the global variable statement, the structure message assembly analysis code, the common process interface code, the export interface type statement of all the functional process interfaces, the import interface type statement of all the functional process interfaces and the functional process interface code to obtain the conversion dynamic library.
7. The method of claim 3, further comprising:
and sending a function field to the conversion dynamic library so that the conversion dynamic library calls the dynamic library to be called to execute the task corresponding to the function field according to the function field to obtain result data corresponding to the function field.
8. An apparatus for generating a translation dynamic library, the apparatus comprising:
the information acquisition unit is used for acquiring the interface information of the dynamic library to be called; the interface information comprises functional process interface information and public field information;
the description generating unit is used for generating functional process interface description corresponding to the functional process interface information according to the functional process interface information;
the structure obtaining unit is used for matching the field in the function process interface description with the public field information to obtain a global description structure;
and the link library generating unit is used for generating the conversion dynamic library according to the function flow interface description and the global description structure.
9. An electronic device, comprising: a processor and a memory for storing a program; the processor is configured to execute the program to implement the program execution method of the terminal according to any one of claims 1 to 3.
10. A computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute a program execution method of a terminal according to any one of claims 1 to 13.
CN202210012915.9A 2022-01-06 2022-01-06 Method and device for generating conversion dynamic library Pending CN114356320A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210012915.9A CN114356320A (en) 2022-01-06 2022-01-06 Method and device for generating conversion dynamic library

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210012915.9A CN114356320A (en) 2022-01-06 2022-01-06 Method and device for generating conversion dynamic library

Publications (1)

Publication Number Publication Date
CN114356320A true CN114356320A (en) 2022-04-15

Family

ID=81107688

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210012915.9A Pending CN114356320A (en) 2022-01-06 2022-01-06 Method and device for generating conversion dynamic library

Country Status (1)

Country Link
CN (1) CN114356320A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117806852A (en) * 2024-03-01 2024-04-02 傲拓科技股份有限公司 Interface calling method, device, storage medium and processor

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117806852A (en) * 2024-03-01 2024-04-02 傲拓科技股份有限公司 Interface calling method, device, storage medium and processor
CN117806852B (en) * 2024-03-01 2024-05-14 傲拓科技股份有限公司 Interface calling method, device, storage medium and processor

Similar Documents

Publication Publication Date Title
US5651111A (en) Method and apparatus for producing a software test system using complementary code to resolve external dependencies
US20040064806A1 (en) Verifiable processes in a heterogeneous distributed computing environment
US7934205B2 (en) Restructuring computer programs
CN111506314B (en) Project development method, device, server and medium
US20090328013A1 (en) Componentization of compiler functionality
US20110126179A1 (en) Method and System for Dynamic Patching Software Using Source Code
Crocker Safe object-oriented software: the verified design-by-contract paradigm
CN112579461A (en) Assertion processing method, system and storage medium
CN114356320A (en) Method and device for generating conversion dynamic library
CN114115884A (en) Management method and related device for programming service
CN114579141A (en) Method and device for converting require frame into VUE frame
CN115348148A (en) Alarm compression processing method for composite condition
Fournier A Rust Backend for Lingua Franca
CN113885844A (en) Business service arranging method and related device
CN113448874A (en) Method and device for generating unit test script
CN111399842A (en) Code compiling method and device
Kleine et al. Llvm2csp: Extracting csp models from concurrent programs
CN112783736A (en) Method and device for monitoring running body time of software component and electronic equipment
CN115857900B (en) Automatic code generation method and device, electronic equipment and storage medium
EP1183596B1 (en) Generating optimized computer data field conversion routines
CN112162776B (en) Dependency relationship acquisition method and device
Sankar Introducing formal methods to software engineers through OMG's CORBA environment and interface definition language
CN114281336A (en) Software interface adaptation method, device and system
CN117055858A (en) Method for constructing front-end scaffold
Blom Model-Based Protocol Testing in an Erlang Environment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination