CN112162790A - API dynamic calling method and system - Google Patents
API dynamic calling method and system Download PDFInfo
- Publication number
- CN112162790A CN112162790A CN202011001952.7A CN202011001952A CN112162790A CN 112162790 A CN112162790 A CN 112162790A CN 202011001952 A CN202011001952 A CN 202011001952A CN 112162790 A CN112162790 A CN 112162790A
- Authority
- CN
- China
- Prior art keywords
- api
- dynamic link
- link library
- dynamic
- source
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 28
- 230000007246 mechanism Effects 0.000 claims description 13
- 238000004088 simulation Methods 0.000 claims description 7
- 238000012544 monitoring process Methods 0.000 claims description 6
- 230000006399 behavior Effects 0.000 claims description 3
- 230000008859 change Effects 0.000 claims description 2
- 238000013507 mapping Methods 0.000 claims 1
- 238000011161 development Methods 0.000 abstract description 8
- 230000008569 process Effects 0.000 abstract description 8
- 230000000694 effects Effects 0.000 abstract description 6
- 230000001737 promoting effect Effects 0.000 abstract description 3
- 239000008186 active pharmaceutical agent Substances 0.000 description 105
- 230000003247 decreasing effect Effects 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 230000000903 blocking effect Effects 0.000 description 1
- 230000007717 exclusion Effects 0.000 description 1
- 230000003631 expected effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The invention provides an API dynamic calling method and a system thereof, the invention appoints a source dynamic link library with better API in the configuration information in advance, after a certain API is requested, the API is executed through the appointed source dynamic link library, when the API execution effect in the source dynamic link library is not ideal, the source dynamic link library is re-appointed through the modified configuration information, the dynamic calling of the API is realized, so that in the development process of an application program, a complete API library is not relied on any more, and the dynamic link library is not required to be reloaded by restarting the application program, thereby greatly improving the development efficiency and promoting the project progress.
Description
Technical Field
The invention belongs to the technical field of API calling, and particularly relates to an API dynamic calling method and an API dynamic calling system.
Background
In order to adapt a platform application to different devices of different device manufacturers (such as a T-BOX or a gateway of a car manufacturer), the software platform defines a set of uniform APIs (such as an API for reading and controlling a vehicle state) for the device manufacturers, and the device manufacturers provide all APIs to the application call of the software platform in a dynamic link library manner.
In the process of developing the application program, a device manufacturer can provide dynamic link libraries for many times according to the development progress, different device manufacturers can also provide respective dynamic link libraries, but a problem that part of interfaces are unstable to implement exists in each library, and the application program expects that each API can return reliable data, so that the execution flow of the application program is not influenced, which is particularly important in the process of automatic testing. Therefore, the device manufacturer is often required to provide a complete or overall better dynamic link library, but the development efficiency is greatly influenced, and the project progress is slow.
Disclosure of Invention
Based on the above, the API dynamic calling method and system are provided to solve the above technical problems.
In order to solve the technical problems, the invention adopts the following technical scheme:
in one aspect, a method for API dynamic call is provided, including:
s101, loading all dynamic link libraries to a memory, and generating API source data through configuration information;
s102, responding to a request of an application program, and according to the API source data, appointing a source dynamic link library corresponding to the requested API to execute the requested API, wherein the source dynamic link library is one of all dynamic link libraries;
meanwhile, monitoring whether the configuration information is modified in real time, if so, executing step S103;
s103, releasing all dynamic link libraries, and executing the step 101 to regenerate the API source data.
In another aspect, an API dynamic call system is provided, which includes a storage module including instructions loaded and executed by a processor, and when executed, the instructions cause the processor to execute the API dynamic call method.
The invention appoints the source dynamic link library with better API in the configuration information in advance, after some API is requested, the API is executed through the appointed source dynamic link library, when the API execution effect in the source dynamic link library is not ideal, the source dynamic link library is appointed again through the modified configuration information, the dynamic calling of the API is realized, so that the application program development process does not depend on a complete API library any more, and the application program does not need to be restarted to reload the dynamic link library, thereby greatly improving the development efficiency and promoting the project progress.
Drawings
The invention is described in detail below with reference to the following figures and detailed description:
FIG. 1 is a flow chart of the present invention.
Detailed Description
As shown in fig. 1, an embodiment of the present specification provides an API dynamic call method, where the method is implemented by an API multiplexer, and the API multiplexer includes a configuration Parser (Config Parser), a dynamic Library Loader (Library Loader), a configuration Monitor (Config Monitor), a lock module (Locker), and an API execution interface (API execute).
The method comprises the following steps:
and S101, loading all dynamic link libraries to a memory, and generating API source data through configuration information.
All the dynamic link libraries refer to dynamic link libraries provided by different equipment manufacturers and dynamic link libraries provided by the same equipment manufacturer at different periods, and all the APIs required to be called by the application program are packaged in the dynamic link libraries.
The configuration parser and the dynamic library loader are responsible for generating API source data. The specific process is as follows:
1. and the configuration analyzer analyzes the corresponding relation between the API and the source dynamic link library from the configuration information.
2. And temporarily storing the corresponding relation in a memory. In this embodiment, the API identifier and the dynamic link library identifier represent the corresponding relationship, and the corresponding relationship is temporarily stored in the memory through the array.
The API id and the dynamic link library id may be an API name and a dynamic link library name, respectively, such as:
API_Name1=Lib_A
API_Name2=Lib_B
…
the definition of the array is as follows:
wherein, the API corresponds to a certain API name; "library" corresponds to the source dynamic link library name of the API.
Of course, other data structures may be used to represent the above correspondence, such as a linked list or a hash table.
3. And after loading all the dynamic link libraries into the memory, the dynamic library loader binds each API to the API realization pointer of the corresponding source dynamic link library according to the corresponding relation in the memory.
Data structure of binding relationship:
where "API" is an API name and "hdlr" is an implementation pointer for the API.
All APIs are pre-planned and defined, and we declare each API in a separate header file in the form of a function pointer, which the API mux loads during compilation.
In this embodiment, the correspondence and the binding relationship constitute the API source data.
S102, the API execution interface responds to the request of the application program, and according to the API source data, a source dynamic link library corresponding to the requested API is appointed to execute the requested API, and the source dynamic link library is one of all dynamic link libraries.
The application program needs to call a uniform API execution interface and send an API request.
The API execution interface is a unified interface for executing all APIs provided by the API multiplexer for the application program, and is presented in a macro interface mode, the application program needs to load the API multiplexer and then uses the API execution interface to send an API request, and the API execution interface completes the functions of API name matching, lock obtaining and releasing and corresponding API execution:
#defineAPI_EXEC(API,...)\
…
where "API _ EXEC" is a uniform call entry name, "API" is an API name that needs to be called, "API" is a variable length parameter, with different APIs having different parameters.
Preferably, step 102 further comprises:
according to the preset lock configuration, whether the appointed source dynamic link library supports multi-thread reentry is judged, if yes, a global lock mechanism (library level lock) is applied to the source dynamic link library, and if not, a local lock (API lock) mechanism is applied to the requested API.
The lock module is responsible for applying a global lock mechanism or a local lock mechanism, and the lock configuration can be preset in the configuration information.
The dynamic link library provided by the equipment provider may support multithreading reentry, which means that multiple threads of one application program can call the API of a certain dynamic link library at the same time, or not.
When the dynamic link library supports multithread reentry, all APIs in the dynamic link library can be called for multiple times simultaneously, the library level lock is used, as long as any API in the library is called, the lock is held, when the API is called, if the lock is held, the lock is not required to be held, but the number of the APIs which are being executed is stored by a counter, the counter is dynamically increased or decreased along with the number of the APIs which are being executed in the library, and when the last API call is finished, the counter is decreased to 0, the library level lock is released.
When the dynamic link library does not support multithread reentry, the API lock is used, any API in the dynamic link library is locked before being executed, the lock is released after the calling is completed, and the API can be executed in sequence after being requested by the same application program for multiple times.
There are multiple mechanisms for the API lock, and in this embodiment, we use the mutual exclusion lock mechanism:
1. the API lock is acquired in a blocking manner (additional timeout mechanism).
2. Acquiring the lock and executing the API.
3. And releasing the API lock after the execution is finished.
During the execution of steps S101 and S102, the configuration monitor monitors whether the configuration information is modified in real time, and if so, step S103 is executed.
In this embodiment, the configuration information is stored in a database or a configuration file (e.g., an ini file). Monitoring whether the configuration information is modified in real time in an independent thread mode: and monitoring through a database change notification mechanism or an inotify mechanism of the Linux platform.
In an actual application scenario, the API analyzed from the configuration information and the source dynamic link library are only the better source dynamic link library set by human, for example, the API of API _ Name1 may have a better execution effect from Lib _ a library, and the API of API _ Name2 may have a better execution effect from Lib _ B library, but the execution process may not have the expected effect, and at this time, the configuration information may be modified, for example, the ini file may be modified and saved by using tools such as VI, etc., the source dynamic link library is reassigned to the API, and the API is attempted to be executed by the reassigned source dynamic link library.
Specifically, after monitoring that the configuration information is modified, the configuration monitor needs the states of the global lock and the local lock to determine the time for updating the API source data, and the specific process is as follows:
when the appointed source dynamic link library supports multithread reentry, whether the source dynamic link library holds a global lock is judged, if yes, step 103 is executed after the global lock is released, and if not, step 103 is directly executed.
When the designated source dynamic link library does not support multithread reentry, whether the requested API holds a local lock is judged, if yes, step 103 is executed after the local lock is released, and if not, step 103 is directly executed.
S103, releasing all dynamic link libraries, and executing the step 101 to regenerate the API source data.
The invention pre-designates the source dynamic link library with better API in the configuration information, executes the API through the designated source dynamic link library after a certain API is requested, and re-designates the source dynamic link library through the modified configuration information when the API execution effect in the source dynamic link library is not ideal, thereby realizing the dynamic calling of the API, ensuring that the application program does not depend on a complete API library in the development process, greatly improving the development efficiency and promoting the project progress.
Preferably, in this embodiment, all the dynamic link libraries include a simulation library, the simulation library simulates implementation behavior and feedback result of a specific API, and a corresponding relationship between the specific API and the simulation library is preset in the configuration information, and may also be modified according to an execution effect.
When the application program requests to call the specific API, the implementation behavior and the feedback result of the application program are simulated through the simulation library according to the configuration information, so that the application program can receive the normal feedback result, the execution flow of the application program is not influenced, and the development efficiency of the application program is further improved.
Based on the same inventive concept, the embodiments of the present specification further provide an API dynamic call system, which includes a storage module, where the storage module includes instructions (program code) loaded and executed by a processor, and when executed, the instructions cause the processor to execute the steps according to the various exemplary embodiments of the present invention described in the above API dynamic call method section of the present specification.
The memory module may include a readable medium in the form of a volatile memory unit, such as a random access memory unit (RAM) and/or a cache memory unit, and may further include a read only memory unit (ROM).
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
However, those skilled in the art should realize that the above embodiments are illustrative only and not limiting to the present invention, and that changes and modifications to the above described embodiments are intended to fall within the scope of the appended claims, provided they fall within the true spirit of the present invention.
Claims (9)
1. An API dynamic calling method, comprising:
s101, loading all dynamic link libraries to a memory, and generating API source data through configuration information;
s102, responding to a request of an application program, and according to the API source data, appointing a source dynamic link library corresponding to the requested API to execute the requested API, wherein the source dynamic link library is one of all dynamic link libraries;
meanwhile, monitoring whether the configuration information is modified in real time, if so, executing step S103;
s103, releasing all dynamic link libraries, and executing the step 101 to regenerate the API source data.
2. The API dynamic calling method according to claim 1, wherein said step S101 further comprises:
analyzing the corresponding relation between the API and the source dynamic link library from the configuration information;
temporarily storing the corresponding relation in a memory;
and binding each API to an API realization pointer of the corresponding source dynamic link library according to the corresponding relation.
3. The API dynamic calling method of claim 2, wherein the mapping relationship is represented by an API id and a dynamic link library id, and is temporarily stored in a memory via an array, a linked list or a hash table.
4. The API dynamic calling method of claim 3, wherein the configuration information is saved in a database or a configuration file.
5. The API dynamic calling method according to claim 4, wherein the configuration information is monitored in real time in a thread-independent manner whether it is modified:
monitoring is carried out through a database change notification mechanism or an inotify mechanism.
6. The API dynamic calling method according to claim 1 or 5, wherein the step S102 further comprises:
and judging whether the appointed source dynamic link library supports multi-thread reentry according to preset lock configuration, if so, applying a global lock mechanism to the source dynamic link library, and if not, applying a local lock mechanism to the requested API.
7. The API dynamic calling method of claim 6, wherein said executing step S103 further comprises:
when the appointed source dynamic link library supports multithread reentry, judging whether the source dynamic link library holds a global lock, if so, executing a step 103 after waiting for the release of the global lock, otherwise, directly executing the step 103;
when the appointed source dynamic link library does not support multithread reentry, judging whether the requested API holds a local lock, if so, executing step 103 after waiting for the release of the local lock, otherwise, directly executing step 103.
8. The method according to claim 7, wherein all the dynamic link libraries include a simulation library, the simulation library simulates implementation behavior and feedback result of a specific API, and the corresponding relationship between the specific API and the simulation library is preset in the configuration information.
9. An API dynamic call system comprising a memory module including instructions loaded and executed by a processor, the instructions when executed causing the processor to perform an API dynamic call method according to any of claims 1-8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011001952.7A CN112162790B (en) | 2020-09-22 | 2020-09-22 | API dynamic calling method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011001952.7A CN112162790B (en) | 2020-09-22 | 2020-09-22 | API dynamic calling method and system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112162790A true CN112162790A (en) | 2021-01-01 |
CN112162790B CN112162790B (en) | 2024-06-21 |
Family
ID=73864400
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011001952.7A Active CN112162790B (en) | 2020-09-22 | 2020-09-22 | API dynamic calling method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112162790B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US11675593B2 (en) | 2021-08-31 | 2023-06-13 | International Business Machines Corporation | Dynamically updating a dynamic library |
CN120066617A (en) * | 2025-04-23 | 2025-05-30 | 浙江恒业电子股份有限公司 | Multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5481706A (en) * | 1993-11-01 | 1996-01-02 | International Business Machines Corporation | System and method for creating thread-safe shared libraries |
US6253257B1 (en) * | 1997-07-31 | 2001-06-26 | Bea Systems, Inc. | Software Interface for dynamic API mapping |
-
2020
- 2020-09-22 CN CN202011001952.7A patent/CN112162790B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5481706A (en) * | 1993-11-01 | 1996-01-02 | International Business Machines Corporation | System and method for creating thread-safe shared libraries |
US6253257B1 (en) * | 1997-07-31 | 2001-06-26 | Bea Systems, Inc. | Software Interface for dynamic API mapping |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US11675593B2 (en) | 2021-08-31 | 2023-06-13 | International Business Machines Corporation | Dynamically updating a dynamic library |
CN120066617A (en) * | 2025-04-23 | 2025-05-30 | 浙江恒业电子股份有限公司 | Multi-cache and type fingerprint dynamic execution method for flexible drive electric energy meter calibration |
Also Published As
Publication number | Publication date |
---|---|
CN112162790B (en) | 2024-06-21 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP4866864B2 (en) | Method and program for managing access to shared resources in a multi-processor environment | |
US9015702B2 (en) | Determining compatibility of an application with different versions of an operating system | |
US8788569B2 (en) | Server computer system running versions of an application simultaneously | |
US10360141B2 (en) | Automated application test system | |
US8621419B2 (en) | Automating the life cycle of a distributed computing application | |
US8984534B2 (en) | Interfacing between a receiving component of a server application and a remote application | |
US7398519B2 (en) | Inheritance breakpoints for use in debugging object-oriented computer programs | |
US7562349B2 (en) | Version adaptation interface for integration of different virtual machines | |
US20040003122A1 (en) | Method and system for managing non-compliant objects | |
US20090172636A1 (en) | Interactive development tool and debugger for web services | |
US20090276660A1 (en) | Server computer component | |
US9996331B1 (en) | Customized application state transition | |
US8510712B1 (en) | Testing in-container software objects | |
US8099735B2 (en) | Method and system for module initialization | |
US7934084B2 (en) | Method and system for module initialization with an arbitrary number of phases | |
US20170123777A1 (en) | Deploying applications on application platforms | |
US6901583B1 (en) | Method for testing of a software emulator while executing the software emulator on a target machine architecture | |
CN108733589B (en) | Method and device for realizing distributed transaction hot deployment | |
US20230091587A1 (en) | Docker image creation apparatus and method | |
CN112162790A (en) | API dynamic calling method and system | |
US20240311113A1 (en) | Bytecode transformations using virtual artifacts | |
US10467027B1 (en) | Dynamic script loading resource files | |
US20040172407A1 (en) | Method and system of processing an encapsulated file at a management computer | |
Van Der Burg et al. | Disnix: A toolset for distributed deployment | |
US7685472B1 (en) | Method and apparatus for testing object-oriented-programming methods |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |