A method and device for generating a conversion dynamic library
By obtaining the interface information of the dynamic library to generate the functional process interface description and global description structure, the conversion dynamic library is automatically generated, which solves the programming errors and high cost problems caused by manual programming and realizes efficient and low-cost dynamic library calling.
Patent Information
- Application Number
- CN202210012915.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-06
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2042-01-06
AI Technical Summary
The calling process of existing dynamic libraries requires manual programming, which is prone to programming errors, resulting in high development costs and low efficiency. In addition, the interfaces of different dynamic libraries vary greatly, resulting in a complicated packaging process and high technical barriers.
By obtaining the interface information of the dynamic library to be called, generating the functional process interface description and the global description structure, the conversion dynamic library is automatically generated to avoid manual programming and automatically call the dynamic library using the interface information.
It improves the convenience and robustness of dynamic library generation, reduces the technical requirements of developers, improves the efficiency of generating and calling dynamic libraries, and simplifies the process of accessing application systems.
Smart Images

Figure CN114356320B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and device for generating a conversion dynamic library. Background Art
[0002] As an essential part of the operating system structure, dynamic libraries are used to decompose a complex program into multiple different parts and provide them to different developers / manufacturers for completion.
[0003] Because different developers have different functions in different parts of the dynamic library, the functions are also different. Therefore, the interface design of different dynamic libraries may be different, and the interface format of different functions within a dynamic library may be different. Each call must develop different calling codes for different dynamic libraries and different functional interfaces to achieve similar usage processes. The number of dynamic libraries and interfaces may be large, and the differences may also be large, which makes the process of packaging them into the same usage process very complicated and manual operations are very prone to errors. Packaging into the same usage process requires eliminating the differences between dynamic libraries and interfaces. Some differences may seem small, but in fact require developers to have a deep understanding of the technical details related to the dynamic library and have strong code development capabilities. There is a high technical threshold.
[0004] However, the calling process of the vast majority of existing dynamic libraries may be different under different circumstances. Once there is a difference, the dynamic library and interface must be completely redeveloped. If there is a change, it is equivalent to adding a new dynamic library or a new interface. In addition, it is necessary to manually program the code for calling the dynamic library. Moreover, if the called dynamic library changes, it is also necessary to manually modify the code for calling the dynamic library. However, in the process of manual programming and development, there are problems such as programming errors caused by operational errors, reduced development code quality, and high cost of troubleshooting. As a result, a lot of time is needed to repeatedly query the cause of the error and correct the incorrect programming, which leads to a lot of manpower and time costs in the process. Summary of the Invention
[0005] The present application provides a method for generating a conversion dynamic library, which can generate a new to-be-called dynamic library file containing a compatible conversion function for the to-be-called dynamic library in a highly efficient, high-quality, and low-cost manner, greatly simplifying the process of connecting a conventional to-be-called dynamic library to an application system and improving the generation efficiency of the conversion dynamic library.
[0006] In a first aspect, the present application provides a method for generating a conversion dynamic library, the method comprising:
[0007] Obtaining interface information of the dynamic library to be called; wherein the interface information includes function process interface information and public field information;
[0008] Generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information;
[0009] Matching the fields in the functional process interface description with the common field information to obtain a global description structure;
[0010] The conversion dynamic library is generated according to the functional process interface description and the global description structure.
[0011] In a second aspect, the present application provides a device for generating a conversion dynamic library, the device comprising:
[0012] An information acquisition unit, configured to acquire interface information of a dynamic library to be called; wherein the interface information includes function flow interface information and public field information;
[0013] A description generating unit, configured to generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information;
[0014] A structure acquisition unit, configured to match the fields in the functional process interface description with the common field information to obtain a global description structure;
[0015] The link library generation unit is used to generate the conversion dynamic library according to the functional process interface description and the global description structure.
[0016] In a third aspect, the present application provides a readable medium comprising execution instructions. When a processor of an electronic device executes the execution instructions, the electronic device executes any method described in the first aspect.
[0017] In a fourth aspect, the present application provides an electronic device comprising a processor and a memory storing execution instructions. When the processor executes the execution instructions stored in the memory, the processor executes any method described in the first aspect.
[0018] It can be seen from the above technical solution that the present application provides a method for generating a conversion dynamic library, the method comprising: obtaining the interface information of the dynamic library to be called; wherein the interface information comprises functional process interface information and public field information; generating a functional process interface description corresponding to the functional process interface information according to the functional process interface information; matching the fields in the functional process interface description with the public field information to obtain a global description structure; generating the conversion dynamic library according to the functional process interface description and the global description structure. It can be seen that in the present application, the functional process 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 functional process interface description and the global description structure can be used to generate a conversion dynamic library, so that the conversion dynamic library can be used to call the dynamic library to be called. In this way, it is possible to automatically generate a conversion dynamic library that can call the dynamic library to be called based on the interface information of the dynamic library to be called, thereby eliminating the need for manual programming and development as in the prior art, avoiding programming errors caused by operational errors during manual programming, reduced development code quality, and high problem troubleshooting costs, thereby improving the convenience and robustness of generating a conversion dynamic library that calls the dynamic library to be called, improving the development efficiency of generating a conversion dynamic library that calls the dynamic library to be called, and reducing the technical requirements for developers.
[0019] The further effects of the above-mentioned non-conventional preferred embodiment will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the existing technical solutions, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] Figure 1 A schematic diagram of a flow chart of a method for generating a conversion dynamic library provided in one embodiment of the present application;
[0022] Figure 2 A schematic diagram of an interface provided in one embodiment of the present application;
[0023] Figure 3 A schematic diagram of an interface provided in one embodiment of the present application;
[0024] Figure 4A A schematic diagram of an interface provided in one embodiment of the present application;
[0025] Figure 4BA schematic diagram of a scenario provided in an embodiment of the present application;
[0026] Figure 5 A schematic diagram of the structure of a device for generating a conversion dynamic library provided in one embodiment of the present application;
[0027] Figure 6 A schematic structural diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0028] To make the objectives, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0029] Currently, the typical method for calling a dynamic library is to place the dynamic library and the executable program on the same computer. The executable program is then linked to the dynamic library during compilation, or a specified file is loaded during runtime. This allows the executable program to call one or more functions in the dynamic library. Regardless of whether the linking or dynamic loading method is used, the dynamic library is loaded into a certain address segment of the executable program as part of the executable program and can be called like a local function.
[0030] However, most existing dynamic library calls require manual programming of the call code. Furthermore, if the dynamic library being called changes, the code must be manually modified. However, manual programming is prone to programming errors due to operational errors, which can lead to time-consuming and labor-intensive troubleshooting and corrections.
[0031] The present application provides a method for generating a conversion dynamic library, the method comprising: obtaining the interface information of the dynamic library to be called; wherein the interface information comprises functional process interface information and public field information; generating a functional process interface description corresponding to the functional process interface information according to the functional process interface information; matching the fields in the functional process interface description with the public field information to obtain a global description structure; generating the conversion dynamic library according to the functional process interface description and the global description structure. It can be seen that in the present application, the functional process 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 functional process interface description and the global description structure can be used to generate a conversion dynamic library, so that the conversion dynamic library can be used to call the dynamic library to be called. In this way, it is possible to automatically generate a conversion dynamic library that can call the dynamic library to be called based on the interface information of the dynamic library to be called, thereby eliminating the need for manual programming and development as in the prior art, avoiding programming errors caused by operational errors during manual programming, reduced development code quality, and high problem troubleshooting costs, thereby improving the convenience and robustness of generating a conversion dynamic library that calls the dynamic library to be called, improving the development efficiency of generating a conversion dynamic library that calls the dynamic library to be called, and reducing the technical requirements for developers.
[0032] Various non-limiting embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0033] See also Figure 1 , shows a method for generating a conversion dynamic library in an embodiment of the present application. In this embodiment, the method may include the following steps:
[0034] S101: Obtaining interface information of a dynamic library to be called.
[0035] In this embodiment, the dynamic library to be called can be understood as the dynamic library to be called that needs to be called. The dynamic library to be called can be directly updated by replacing the file, and the interface information of the dynamic library to be called does not change, so there is no need to recompile the calling program for calling the dynamic library to be called. In one implementation, since the dynamic library to be called and the calling device may use different operating languages, in order to ensure that the calling device and the dynamic library to be called in different operating languages can work normally, the interface of the dynamic library to be called is a C standard interface. Wherein, the interface information includes functional process interface information and public field information. It should be noted that, in this embodiment, an interface can be provided, through which the user can input the interface information of the dynamic library to be called.
[0036] Public field information is predefined based on scheduling requirements. In one implementation, the public field information may include the file name, public parameters, and structure of the dynamic library being called. The public parameters may include predefined key variables and added global variables, such as baud rate and port.
[0037] Functional flow interface information can be understood as the functional flow information of each functional module in the dynamic library to be called. In one implementation, the functional flow interface information may include: return value type, calling convention, function name, interface call function type, and interface description; wherein, the interface call function type includes synchronous or asynchronous. The return value type can be understood as the type of value returned by the call; the calling convention can be understood as the preset calling rules; the function name can be understood as the identifier of the preset functional function; the interface call function type can be understood as the type of function calling the interface; and the interface description can be understood as the introduction and description information of the interface.
[0038] In this embodiment, the following can be provided: Figure 2 、 Figure 3 The functional process interface information input interface shown in Figure 4 allows users to input or adjust the functional process interface information through this interface. It should be noted that adding as Test means that you can directly specify an interface as a Test method. Generally, the interface is required to have no parameters or only output parameters as the Test method, or it can be a method with only public parameters such as port. If it is an interface with input parameters, you can specify a default value for the interface as the default parameter when calling the test function. The interface description can be int__cdecl fun(IN char*para="qwerty1234"), which is similar to the default value design in interface declarations in many languages.
[0039] S102: Generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information.
[0040] In this embodiment, for each functional flow information, a functional flow interface description corresponding to the functional flow information is generated according to a preset description format. As an example, after obtaining the functional flow interface information, the functional flow information in the functional flow interface information can be parsed through code to obtain the interface essence; for example, Interface, Call_way, and Illstration are the descriptions of the essence extracted from the CT_SendCommand method information, which contain all the necessary information when using the interface and are the basis for the code generation process.
[0041] For example, according to Figure 2 、 Figure 3 and Figure 4AThe input function flow interface information shown can generate a function flow interface description corresponding to each function flow information according to a preset description format, and finally obtain the function flow interface description corresponding to the function flow interface information: / / interface:int__stdcall CT_SendCommand(IN char*port,IN char*extport,IN char*icFlag,IN int nCmdLen,HINunsigned char*pszCmd,OUT int*pnRespLen,HOUT unsigned char*pszResp)
[0042] / / call_way: synchronization
[0043] / / illstration: Access COS, send C-APDU command, and receive R-APDU return.
[0044] The meaning of this interface description is:
[0045] The return value is int, the calling convention is stdcall, and the function name is CT_SendCommand;
[0046] The first parameter is port, char* type, which is the input parameter;
[0047] The second parameter is export, char* type, which is the input parameter;
[0048] The third parameter is icFlag, char* type, which is the input parameter;
[0049] The fourth parameter is nCmdLen, int type, which is the input parameter;
[0050] The fifth parameter is pszCmd, of unsigned char* type, which is the input parameter. The H in the HIN identifier indicates that the communication layer is HEX-encoded (if it is BIN, it indicates a BASE64-encoded input parameter).
[0051] The sixth parameter is pnRespLen, int type, which is an output parameter;
[0052] The seventh parameter is pszResp, unsigned char* type, which is the output parameter and the communication layer is HEX encoded.
[0053] Synchronous\asynchronous is used to control whether the interface needs to start a thread and execute within the thread. This can also be automatically generated through the template.
[0054] Illstration contains the interface comments. It should be noted that the interface description can also be in other formats, as long as it contains the necessary information.
[0055] S103: Match the fields in the functional process interface description with the common field information to obtain a global description structure.
[0056] In this embodiment, for each field in the functional flow interface description, if the common field information includes a target value corresponding to the field, the value of the field in the functional flow interface description is adjusted to the target value to obtain the adjusted field. For example, if the common field information includes the field "port" and its corresponding target value "a", and the functional flow interface description includes the field "port", the value of the field "port" in the functional flow interface description can be adjusted to "a".
[0057] If the values of all fields in the functional process interface description are adjusted, the adjusted functional process interface description is obtained based on all the adjusted fields. It is understandable that after the values of the fields included in the functional process interface description and the public field information are adjusted to the target values in the functional process interface, the adjusted functional process interface description can be obtained.
[0058] Then, the global description structure can be obtained according to the adjusted functional flow interface description. Because the structures of all structures in the global description structure are also basic types or linked list recursive definitions, and recursive definitions are generally not considered in interfaces, a complete structure can be obtained by adding several basic types such as int, char*, unsigned char*, etc., and a corresponding json parsing function can be generated each time it is added. Since the global description structure has a global scope, if different interface parameters have different structures with the same name, they should be renamed to be non-duplicate. Among them, the first three lines of comments at the beginning of the file can be saved in csv format or comma or delimiter format, and the description structure of each function is also saved in a specific position of the code file in the form of comments.
[0059] S104: Generate the conversion dynamic library according to the functional process interface description and the global description structure.
[0060] In this embodiment, the structure declaration, the derived public process interface declaration, the global variable declaration, the structure message assembly parsing code, and the public process interface code can be generated based on the global description structure. For example, the structure declaration, the derived public process interface declaration, the global variable declaration, the structure message assembly parsing code, and the public process interface code can be extracted from the global description structure based on a preset extraction rule (e.g., a preset format of each declaration or code).
[0061] Then, based on the functional process interface description, the export interface type declarations of all functional process interfaces, the import interface type declarations of all functional process interfaces, and the functional process interface codes can be generated. For example, based on a preset extraction rule (such as the preset format of each declaration or code), the export interface type declarations of all functional process interfaces, the import interface type declarations of all functional process interfaces, and the functional process interface codes can be extracted from the functional process interface description. In the process of generating code, when processing non-numeric values (less than or equal to int) or empty (void) type return values, the return value is often used as an output parameter in the case where the return value type is char*, because generally speaking, if the return value is not a numerical type or void type that is not greater than int in memory, it often causes memory leaks, so it should be avoided in the interface design that the return value is either int or void. If the design is not standardized or there are some special functions, the return value may be a string or other type. At this time, it should be packaged into resmsg as an output parameter. If it is an unsigned char* type, it is also necessary to choose whether to use base64 or hex encoding. In the interface description, this can be reflected by adding the OUT flag, such as BOUT unsignedchar*__cdecl fun(IN char*para), which means that the return value is used as the output parameter and is BASE64 encoded.
[0062] Then, the structure declaration, the export public process interface declaration, the global variable declaration, the structure message assembly parsing code, the public process interface code, the export interface type declaration of all functional process interfaces, the import interface type declaration of all functional process interfaces, and the functional process interface code can be compiled to obtain the conversion dynamic library. That is to say, the structure declaration, the export public process interface declaration, the global variable declaration, the structure message assembly parsing code, the public process interface code, the export interface type declaration of all functional process interfaces, the import interface type declaration of all functional process interfaces, and the functional process interface code are all translated into target program codes equivalent to machine language representation. For example, the structure declaration, the export public process interface declaration, the global variable declaration, the structure message assembly parsing code, the public process interface code, the export interface type declaration of all functional process interfaces, the import interface type declaration of all functional process interfaces, and the functional process interface code are all translated into C language programs, thereby obtaining a conversion dynamic library.
[0063] It should be noted that global variable declarations can include: a) customized global variables in the global description structure; b) all parameters and extended formats of parameters contained in the public interface in the interface design. For example, global variables by default include char* type port such as "COM3" and int type iport such as "3". When generating the interface, the type is used to determine which one to use. For example, char*port is considered to be port, and int port is considered to be iport; c) global variables that will be used in the process, such as the handle of the dynamic library to be called; d) structure declaration.
[0064] For example, when the public interface includes the initDriver function, the process of generating the initDriver function is: according to the interface design, save the callback function pointer, and package it into a local message sending and logging function or other functions; according to the global variable to-be-called dynamic library file name or path in the global description structure, query and load the called dynamic library to be called, and save it to the global handle; the return value loads the system error code returned by the dynamic library function to be called (such as loadlibrary, dlopen), and the reason for the error in loading the dynamic library to be called can be known.
[0065] For example, if a public process interface includes setPortAttr, the process for generating setPortAttr is as follows: Based on the interface design, the parameters given by setPortAttr are saved to global variables. For fields not included in the interface design, the values retrieved from configstr are saved to global variables. For global variables that cannot be found, char* is initialized to 1024 zero-padded memory, and int is initialized to 0.
[0066] For example, when a public process interface includes deinit, the deinit process is generated as follows: release and close the handle to the dynamic library to be called (such as freelibrary, dlclose), and return the result of the function execution. The resulting deinit function may not properly close the currently executing call resources. If relevant requirements are required, you can refer to the method of adding a test method, add a control to the interface, and check the deinit method to serve as a global cancellation function. Only after successful execution will the deinit method release and close the handle to the dynamic library to be called.
[0067] For each interface, the following can be obtained based on the functional process interface description:
[0068] 1. Export function declaration;
[0069] The exported function declaration can be: extern "C" __declspec (dllexport) int method name (char *args, char *resmsg, char *errmsg, int readTimeout, int writeTimeout), for example, extern "C" __declspec (dllexport) int CT_SendCommand (char *args, char *resmsg, char *errmsg, int readTimeout, int writeTimeout); in the actual functional flow, the functions themselves are distinguished by method names, but the format remains unified. This allows upper-level modules to directly use all functional modules without developing memory organization modules. After the PushMessage and other public parameters of each functional module have been registered, the functional flow of each functional module can actually be organized into input parameters, output parameters, return code, error message, and timeout. By stipulating that the input and output parameters are JSON format strings, a completely universal dynamic library interface design to be called can be implemented, which can be compatible with all dynamic library processes to be called.
[0070] args is an input parameter string in JSON format. Most of the time, it may be required to be a const type to avoid some exceptions, but the code complexity in the interface will be slightly increased.
[0071] resmsg is an output string, usually the result of a call. Its memory is usually created by the caller, and the result string is assigned to the memory by the code in the interface. However, this sometimes requires a large memory for resmsg. You can use char* to create memory inside the dynamic library to be called, which can reduce memory usage. However, it will increase the difficulty of developing the code in the interface, and it may be difficult to release the memory correctly, causing problems. You can also write the content to a file and then pass the file path to reduce the size of the parameter memory space, avoiding the relatively difficult-to-develop form of char*.
[0072] The return value of the function is an error code. Generally speaking, 0 means successful execution, a negative number means an error, and a positive number means a warning. A warning indicates that a problem has occurred, but it may not affect the process from continuing to execute. The error code can be agreed upon based on the actual situation, and the interface itself has no restrictions. Errmsg is the error message, which is similar to resmsg and is generally created by the caller. Since the error message is generally not very large, it is generally not necessary to process it by passing a file path or char*. The error message may sometimes be included in resmsg. Processing it separately helps reduce the complexity of the process. You can get detailed information about the exception corresponding to the code before parsing the complex resmsg. There can also be a warning exception mode, that is, resmsg contains the call results that can be used in subsequent processes, but errmsg still contains some exception information that may not be processed. For example, a bank customer enters his password using an encrypted password keyboard, and the ciphertext of the password is included in resmsg. Although it is ciphertext, if the number of leaks is large enough, there may be risks. Moreover, the ciphertext cannot be desensitized, so resmsg cannot be recorded in the log. In abnormal situations, it will increase the difficulty of troubleshooting. At this time, through errmsg, you can effectively obtain error information, reducing the difficulty of troubleshooting.
[0073] ReadTimeout and WriteTimeout are timeouts designed for I / O and can generally be replaced with a single timeout. Timeouts are often poorly managed in traditional applications, and a single timeout helps avoid exceptions and improve development quality. In real-world scenarios, the timeout for each function call may vary. Therefore, they cannot be shared parameters. Instead, each function call must have a preset timeout setting.
[0074] The meaning of the return value and the correct return code are generally used when the int type is returned. If the correct situation is not 0, you need to specify the range of the correct return value and the errmsg information corresponding to the specific value.
[0075] 2. Objective function type definition;
[0076] typedef int(__stdcall*pCT_SendCommand)(char*port,char*extport,char*icFlag,int nCmdLen,unsigned char*pszCmd,int*pnRespLen,unsigned char*pszResp).
[0077] 3. The part of exporting function implementation includes:
[0078] a) Parse the Args parameter and convert it into the target function. You can use pre-packaged methods such as getIntFromJsonStr and other functions to directly get the converted result without having to write it manually each time. For structures, when adding structures, the corresponding parsing function is generated at the same time. For example, {"a":"1","b":"qwer","c":"{\"x\":\"2\",\"y\":\"asdf\"}"}; it can be obtained that the value of a is the number 1 or the string "1", the value of b is the string "qwer", the value of structure c, cx is the number 2 or the string "2", and the value of cy is the string "asdf";
[0079] Since it is recommended to use map<string,string> Therefore, it is not possible to directly get the parameter type from json, whether it is a number or a string. It is necessary to combine the function interface description structure to determine the actual type and the parsing function to be used.
[0080] For example, int a = getIntFromJsonStr(args, "a"), the value of a can be obtained as 1.
[0081] Char*a=getStrFromJsonStr(args,"a"), internally, memory will be created according to the length of the string, and the value of a can be obtained as the string "1", or a is a pointer to the memory where the string "1" is located.
[0082] c obj=getcFromJsonStr(args,c), it will create memory based on the sizeof keyword of the structure and call
[0083] obj.y = getStrFromJsonStr(args.c, "y") can get the value of cy as the string "asdf", and obj.x is similar to a.
[0084] For base64 and hex encoded unsigned char* data, add a step to the decoding process.
[0085] b) Create memory for the output parameters of the target function;
[0086] The default memory size created here is 1024, or the value saved in the interface description, such as int__cdecl fun(OUT char
[2048] para), which indicates that the memory size of the para field should be created as 2048.
[0087] c) Get the target function pointer from the global dynamic library handle to be called
[0088] Get the actual function pointer through GetProcAddress or dlsym.
[0089] d) Call the function.
[0090] e) Organize participation;
[0091] Convert each output parameter to a string, including converting int to char*, performing base64 or hex encoding on unsigned char*, converting the structure to a string, and then assembling the JSON. This is the reverse of the input parameter parsing process, but the principles are the same. This may include the return value of the function call, which is essential, but the principles are the same.
[0092] f) Organizing misinformation;
[0093] You can process error information and match error codes according to the interface description.
[0094] g) Return an error code.
[0095] h) If the function is designated as a test function, a test function is generated, and a new args is created using the default values. The process is similar to organizing the output parameters, and the function is called using the obtained args. If multiple functions are designated as test methods, controls can be added to the interface to make a field in the test method's args correspond to a target function, which can be achieved through simple matching.
[0096] i) If the function is an asynchronous function, the name of the generated function implementation needs to be renamed, such as adding a prefix or suffix, and generating a function implementation with the original function name. The original args is copied and passed to the thread as a parameter. After the thread is successfully started, the function returns 0, and resmsg contains the content of success. The function is called with args in the thread, and then the function return value, resmsg and errmsg are assembled into json and sent through the asynchronous message interface.
[0097] j) Each node generated by the function can automatically have a log to record the value of each node.
[0098] In this way, a code file is obtained that can convert the non-standard to-be-called dynamic library interface into a unified standard to-be-called dynamic library interface. The converted to-be-called dynamic library is compiled through a script or a compiler in a development environment.
[0099] The encapsulator only needs to access the documentation or existing code, determine the interface, enter it one by one, or write a description structure in batches and import it. This will then result in a conversion of the called dynamic library to the dynamic library to be called. This significantly reduces the development cost of conventional code writing. The code stores the interface description information, ensuring that the code can be restored to a configurable interface. In this embodiment, the description structure is manually obtained from the documentation or existing application code, either through a configurable interface or by writing an interface description. The generation process then parses the description structure to obtain the code.
[0100] The above code contains an interface description. When the program imports the code, it parses the content and obtains the code description structure. The code description structure can correspond to the configurable interface effect and is easy to modify.
[0101] If the code has been manually modified, when modifying the interface again, you can first use the code generated by the previous interface description to compare with the original code. If there are no differences, overwrite the code. If there are differences, it will indicate that it has been manually modified. The IDE's integrated file comparison or other comparison methods will display the modified content to avoid directly overwriting the previous changes made directly to the code when making changes through the interactive interface. For example, manually modify the calling convention in the code and then add parameters.
[0102] Code comparison tools generally also have a function for merging differences. You can manually choose whether to save the left or right side of each difference, so you can quickly get the correct code after modification. Finally, you get the correct code with the modified calling convention and parameters.
[0103] It can be seen from the above technical solution that the present application provides a method for generating a conversion dynamic library, the method comprising: obtaining the interface information of the dynamic library to be called; wherein the interface information comprises functional process interface information and public field information; generating a functional process interface description corresponding to the functional process interface information according to the functional process interface information; matching the fields in the functional process interface description with the public field information to obtain a global description structure; generating the conversion dynamic library according to the functional process interface description and the global description structure. It can be seen that in the present application, the functional process 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 functional process interface description and the global description structure can be used to generate a conversion dynamic library, so that the conversion dynamic library can be used to call the dynamic library to be called. In this way, it is possible to automatically generate a conversion dynamic library that can call the dynamic library to be called based on the interface information of the dynamic library to be called, thereby eliminating the need for manual programming development as in the prior art, avoiding the problem of programming errors caused by operational errors during the manual programming process, thereby improving the convenience and accuracy of generating a conversion dynamic library that calls the dynamic library to be called, and improving the development efficiency of generating a conversion dynamic library that calls the dynamic library to be called. The present application can standardize similar usage processes into a generation process of a dynamic library file to be called, and automatically convert different dynamic libraries to be called and interfaces into a unified usage process through the generated new dynamic library to be called. The functional process interface description and global description structure of the present application can be directly regenerated after the unified usage process changes, without repeating the previous steps. The process of converting basic information into functional process interface description and global description structure in the present application does not require developers to understand the difference details of different dynamic libraries to be called. It is a process of logically extracting the technical essence of the called interface. The process of converting the functional flow interface description and global description structure into code, a dynamic library to be called, or a unified interface in this application does not require a large workload from the developer and does not require high code development skills. It is the actual execution process, including code generation and compilation. Moreover, as the number of interfaces increases, in addition to writing the additional business logic, only the automatically generated dynamic library file to be called needs to be updated. This does not significantly increase the workload, and only adds a message structure, which has a minimal impact on the application.
[0104] In one implementation of this embodiment, the method further includes:
[0105] The function field is sent to the conversion dynamic library, so that the conversion dynamic library calls the dynamic library to be called according to the function field to execute the task corresponding to the function field and obtain result data corresponding to the function field.
[0106] In this embodiment, when a dynamic library to be called needs to be called, a function field can be generated according to the function to be called, and the function field can be sent to the conversion dynamic library. The conversion dynamic library can determine the dynamic library to be called based on the function field, and call the dynamic library to be called to perform the task corresponding to the function field, so that the dynamic library to be called can return the result data corresponding to the function field through the conversion dynamic library. Figure 4B As shown, when an application needs to call a dynamic library to be called, a function field can be generated according to the function to be called, and the function field can be sent to the conversion dynamic library; the conversion dynamic library can determine the dynamic library to be called that needs 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 the result data corresponding to the function field to the application through the conversion dynamic library, thereby completing the process of calling the dynamic library to be called to execute the task.
[0107] like Figure 5 The figure shows a specific embodiment of a device for generating a conversion dynamic library described in this application. The device described in this embodiment is a physical device for executing the method described in the above embodiment. The device is applied to the service side, which includes services. Its technical solution is essentially the same as that of the above embodiment. The device described in this embodiment includes:
[0108] The information acquisition unit 501 is used to acquire the interface information of the dynamic library to be called; wherein the interface information includes function process interface information and public field information;
[0109] A description generating unit 502 is configured to generate a functional flow interface description corresponding to the functional flow interface information according to the functional flow interface information;
[0110] A structure acquisition unit 503 is configured to match the fields in the functional process interface description with the common field information to obtain a global description structure;
[0111] The link library generation unit 504 is used to generate the conversion dynamic library according to the functional process interface description and the global description structure.
[0112] Optionally, the functional process interface information includes: return value type, calling convention, function name, interface calling function type, interface description; wherein, the interface calling function type includes synchronous or asynchronous.
[0113] Optionally, the public field information includes: the file name, public parameters, and structure of the dynamic library to be called; wherein the public parameters include predefined key variables and added global variables.
[0114] Optionally, the description generating unit 502 is configured to:
[0115] For each piece of functional process information, a functional process interface description corresponding to the functional process information is generated according to a preset description format.
[0116] Optionally, the structure acquisition unit 503 is configured to:
[0117] 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;
[0118] If the values of all fields in the functional process interface description are adjusted, the adjusted functional process interface description is obtained according to all adjusted fields;
[0119] The global description structure is obtained according to the adjusted functional flow interface description.
[0120] Optionally, the link library generating unit 504 is configured to:
[0121] Generate structure declaration, export public process interface declaration, global variable declaration, structure message assembly and parsing code, and public process interface code according to the global description structure;
[0122] Generate export interface type declarations, import interface type declarations, and function flow interface codes for all function flow interfaces based on the function flow interface description;
[0123] The structure declaration, the exported public process interface declaration, the global variable declaration, the structure message assembly and parsing code, the public process interface code, the exported interface type declaration of all functional process interfaces, the imported interface type declaration of all functional process interfaces, and the functional process interface code are compiled to obtain the conversion dynamic library.
[0124] Optionally, the device further includes a query unit, configured to:
[0125] The function field is sent to the conversion dynamic library, so that the conversion dynamic library calls the dynamic library to be called according to the function field to execute the task corresponding to the function field and obtain result data corresponding to the function field.
[0126] Figure 6: This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. Among them, the memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0127] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0128] Memory is used to store execution instructions. Specifically, execution instructions are computer programs that can be executed. Memory can include internal memory and non-volatile memory, and provides execution instructions and data to the processor.
[0129] In one possible implementation, the processor reads the corresponding execution instructions from the non-volatile memory into the internal memory and then executes them. The processor may also obtain the corresponding execution instructions from other devices to form a terminal program execution device at the logical level. The processor executes the execution instructions stored in the memory to implement the terminal program execution method provided in any embodiment of the present application through the execution of the execution instructions.
[0130] The above application Figure 1The method executed by the program running device of the terminal provided in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by an integrated logic circuit of the hardware in the processor or an instruction in the form of software. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0131] The steps of the method disclosed in the embodiments of this application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.
[0132] An embodiment of the present application also proposes a readable storage medium, which stores execution instructions. When the stored execution instructions are executed by a processor of an electronic device, the electronic device can execute the program running method of the terminal provided in any embodiment of the present application, and is specifically used to execute the method described in the program running of the above-mentioned terminal.
[0133] The electronic device described in each of the aforementioned embodiments may be a computer.
[0134] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods or computer program products. Therefore, the present application may adopt a completely hardware embodiment, a completely software embodiment, or a combination of software and hardware.
[0135] The various embodiments in this application are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences from other embodiments. In particular, the device embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the partial description of the method embodiments.
[0136] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0137] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for generating a conversion dynamic library, characterized in that: The method comprises: Obtaining interface information of the dynamic library to be called; wherein the interface information includes function process interface information and public field information; Generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information; Matching the fields in the functional process interface description with the common field information to obtain a global description structure; generating the conversion dynamic library according to the functional process interface description and the global description structure; Generating the conversion dynamic library according to the functional process interface description and the global description structure includes: Generate structure declaration, export public process interface declaration, global variable declaration, structure message assembly and parsing code, and public process interface code according to the global description structure; Generate export interface type declarations, import interface type declarations, and function flow interface codes for all function flow interfaces based on the function flow interface description; Compile the structure declaration, the exported public process interface declaration, the global variable declaration, the structure message assembly and parsing code, the public process interface code, the exported interface type declarations of all functional process interfaces, the imported interface type declarations of all functional process interfaces, and the functional process interface code to obtain the conversion dynamic library; The matching of the fields in the functional process interface description with the common field information to obtain a global description structure includes: 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 fields in the functional process interface description are adjusted, the adjusted functional process interface description is obtained according to all adjusted fields; The global description structure is obtained according to the adjusted functional flow interface description.
2. The method according to claim 1, characterized in that The functional process interface information includes: return value type, calling convention, function name, interface calling function type, interface description; wherein, the interface calling function type includes synchronous or asynchronous; wherein, the interface of the dynamic library to be called is a C standard interface.
3. The method according to claim 2, characterized in that The public field information includes: the file name, public parameters, and structure of the dynamic library to be called; wherein the public parameters include predefined key variables and added global variables.
4. The method according to any one of claims 1 to 3, characterized in that: Generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information, including: For each piece of functional process information, a functional process interface description corresponding to the functional process information is generated according to a preset description format.
5. The method according to claim 3, characterized in that The method further comprises: The function field is sent to the conversion dynamic library, so that the conversion dynamic library calls the dynamic library to be called according to the function field to execute the task corresponding to the function field and obtain result data corresponding to the function field.
6. A device for generating a conversion dynamic library, characterized in that: The device comprises: An information acquisition unit, configured to acquire interface information of a dynamic library to be called; wherein the interface information includes function flow interface information and public field information; A description generating unit, configured to generate a functional process interface description corresponding to the functional process interface information according to the functional process interface information; A structure acquisition unit, configured to match the fields in the functional process interface description with the common field information to obtain a global description structure; A link library generation unit, configured to generate the conversion dynamic library according to the functional process interface description and the global description structure; Generating the conversion dynamic library according to the functional process interface description and the global description structure includes: Generate structure declaration, export public process interface declaration, global variable declaration, structure message assembly and parsing code, and public process interface code according to the global description structure; Generate export interface type declarations, import interface type declarations, and function flow interface codes for all function flow interfaces based on the function flow interface description; Compile the structure declaration, the exported public process interface declaration, the global variable declaration, the structure message assembly and parsing code, the public process interface code, the exported interface type declarations of all functional process interfaces, the imported interface type declarations of all functional process interfaces, and the functional process interface code to obtain the conversion dynamic library; Match the fields in the functional process interface description with the common field information to obtain a global description structure, including: 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 fields in the functional process interface description are adjusted, the adjusted functional process interface description is obtained according to all adjusted fields; The global description structure is obtained according to the adjusted functional flow interface description.
7. An electronic device, characterized in that: include: A processor and a memory, wherein the memory is used to store programs; The processor is used to run the program to implement the method for generating a conversion dynamic library according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method for generating a conversion dynamic library according to any one of claims 1 to 5.