Main program interface callback method and device, equipment and storage medium
By registering request information and callback functions through a dynamic library, the main program authorizes the dynamic library to call the interface, which solves the problem that the dynamic library cannot call the main program's interface in both directions, realizes bidirectional interface calls, and improves the user experience.
Patent Information
- Application Number
- CN202111195679.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-14
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2041-10-14
AI Technical Summary
In existing technologies, dynamic libraries cannot make bidirectional calls to the main program interface, resulting in a poor user experience.
By registering request information and callback functions through the dynamic library, the main program traverses the linked list to obtain and authorize the dynamic library to call the main program's interface, thus realizing bidirectional interface calls between the main program and the dynamic library.
It improves the user experience, enables bidirectional calls between dynamic libraries and the main program, and enhances the system's flexibility and functional scalability.
Smart Images

Figure CN113867849B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of library calling technology, and in particular to a main program interface callback method, apparatus, device, and storage medium. Background Technology
[0002] Generally, the main program implements the core functionality, while dynamic libraries need to be customized for different users. The mechanisms and methods provided in related technologies for the main program to call dynamic libraries are one-way interface designs. However, in some scenarios, dynamic libraries may also need to use the main program's functionality. In these cases, the interfaces used by the dynamic library are related to the main program's logic, and the dynamic library itself does not have the ability to implement these interfaces. Summary of the Invention
[0003] This application provides a main program interface callback method, apparatus, device, and storage medium. The method enables a dynamic library to acquire the ability to call the main program interface, thereby realizing bidirectional calling functionality based on the bidirectional interface between the main program and the dynamic library, and improving the user experience.
[0004] In a first aspect, embodiments of this application provide a main program interface callback method, the method comprising: obtaining first request information sent by a dynamic library for callback of the main program interface; and if it is determined that the dynamic library has registered an agreed interface corresponding to the first request information, authorizing the dynamic library to call the interface function corresponding to the first request information.
[0005] Furthermore, the step of determining that the dynamic library has registered the agreed interface corresponding to the first request information, and then authorizing the dynamic library to call the interface function corresponding to the first request information, includes: traversing the first linked list to determine whether the dynamic library has registered the agreed interface corresponding to the first request information; if it is determined that the dynamic library has registered the agreed interface corresponding to the first request information, then making the main program interface corresponding to the first request information in the second linked list available for the dynamic library to call.
[0006] Furthermore, the first request information includes request description information, and the request description information is used to describe the capability information that the dynamic library wishes to acquire.
[0007] Furthermore, the step of traversing the first linked list to determine whether the dynamic library has registered the agreed interface corresponding to the first request information includes: traversing the first linked list and determining whether the dynamic library has registered the agreed interface corresponding to the first request information based on the request description information in the first request information.
[0008] Furthermore, the step of providing the main program interface corresponding to the first request information in the second linked list for the dynamic library to call includes: obtaining the callback function corresponding to the request description information in the first request information from the first linked list and saving it to the second linked list, and assigning the callback function corresponding to the request description information in the first request information in the second linked list to the dynamic library, so that the dynamic library can call the callback function to implement the capability corresponding to the main program.
[0009] Furthermore, before obtaining the first request information sent by the dynamic library for calling back the main program interface, the method further includes: obtaining the second request information sent by the dynamic library for registering the interface; and loading the corresponding parameters into the linked list based on the second request information to complete the interface agreement.
[0010] Furthermore, the second request information includes the request description information and callback function of the dynamic library; the step of loading the corresponding parameters into the linked list based on the second request information to complete the interface agreement includes: loading the request description information and callback function in the second request information sent by the dynamic library into the first linked list.
[0011] Secondly, embodiments of this application also provide a main program interface callback device, the device comprising: a processor and a memory, the memory being used to store at least one instruction, the instruction being loaded and executed by the processor to implement the main program interface callback method provided in the first aspect.
[0012] In some implementations, the main program interface callback device provided by the second aspect can be a chip or a chip module.
[0013] Thirdly, embodiments of this application also provide an electronic device that may include the main program interface callback device provided in the second aspect. In some embodiments, the main program interface callback device may be a component of the electronic device, such as a chip.
[0014] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the main program interface callback method provided in the first aspect.
[0015] By using the above technical solution, the dynamic library can obtain the first request information sent by the dynamic library for calling the main program interface; and if it is determined that the dynamic library has registered the agreed interface corresponding to the first request information, the dynamic library is authorized to call the interface function corresponding to the first request information. This enables the dynamic library to obtain the ability to call the main program interface, and thus realizes the bidirectional calling function based on the bidirectional interface between the main program and the dynamic library, thereby improving the user experience. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart of a main program interface callback method provided in one embodiment of this application;
[0018] Figure 2 This is a schematic diagram of the main program interface callback device provided in another embodiment of this application. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0020] Generally, the main program implements the core functionality, while dynamic libraries need to be customized for different users. The mechanisms and methods provided in related technologies for the main program to call the dynamic library are one-way interface designs. However, in actual project development, sometimes the dynamic library also needs to use the main program's functionality. In these cases, the interfaces used by the dynamic library are related to the logic of the main program, and the dynamic library itself does not have the ability to implement these interfaces.
[0021] To overcome the aforementioned technical problems, this application provides a main program callback method. This method allows the main program and dynamic libraries to agree on a registration interface, which carries the dynamic library's "request description information" and "callback function." The dynamic library registers the main program interface capability information it needs. The main program iterates through all dynamic libraries, obtains the registration information, processes the requested information, and returns the processing result to the dynamic library. This enables the dynamic library to acquire the ability to call the main program's interface, thereby achieving bidirectional calling functionality based on the bidirectional interface between the main program and the dynamic library, improving the user experience.
[0022] Figure 1 A flowchart of the main program interface callback method provided in one embodiment of this application is shown below. Figure 1 As shown, the method includes the following steps:
[0023] Step 101: The main program obtains the first request information sent by the dynamic library for calling back the main program interface.
[0024] Step 102: If the main program determines that the dynamic library has registered the agreed interface corresponding to the first request information, then it authorizes the dynamic library to call the interface function corresponding to the first request information.
[0025] Step 103: When the main program ends, remove the corresponding processing result according to the first request information.
[0026] In the specific implementation of step 101, when the dynamic library wants to call back the main program interface to implement the corresponding function, it can send the first request information for calling back the main program interface to the main program. After the main program obtains the first request information sent by the dynamic library for calling back the main program interface, it executes step 102.
[0027] In the specific implementation of step 102, after the main program obtains the first request information sent by the dynamic library for calling back the main program interface, it can determine whether the dynamic library has registered a conventional interface. If it is determined that the dynamic library has registered a conventional interface, then the callback function corresponding to the request description information in the first request information is obtained from the first linked list (linked list head[1]) and saved to the second linked list (linked list head[2]), and the callback function corresponding to the request description information in the first request information in the second linked list is assigned to the dynamic library so that the dynamic library can call the callback function to realize the capability corresponding to the main program. In other words, according to the "request description information", the specific interface of the main program corresponding to the linked list head[2] is provided to the dynamic library for callback, thereby realizing the ability of the dynamic library to obtain the main program interface.
[0028] In the specific implementation of step 103, at the end of the main program, the linked list head[2] is traversed according to the "request description information". If the description exists, the corresponding node is deleted.
[0029] In a specific implementation, before executing step 101, the agreed interface registration can also be achieved through the following steps:
[0030] Step S1: The main program obtains the second request information sent by the dynamic library for registering the interface.
[0031] Step S2: The main program loads the corresponding parameters into the linked list based on the second request information to complete the interface agreement.
[0032] In the specific implementation of step S1, if the dynamic library wants to obtain the main program's interface capabilities, it needs to implement the registration interface. To implement the registration interface, the dynamic library can send a second request message to the main program for registering the interface. Specifically, the registration interface registers two parameters: the dynamic library's request description information and a callback function. The request description information describes the specific capabilities the dynamic library wants to obtain, and the callback function represents the main program interface that the dynamic library wants to obtain. This interface type must be consistent with the final obtained main program interface function type. Furthermore, the request description information and the callback function are two necessary parameters agreed upon by the main program and the dynamic library and correspond one-to-one.
[0033] In the specific implementation of step S2, the main program traverses all dynamic libraries, opens the agreed registration interface, obtains the request description information and callback function registered in the dynamic library, and loads them into the linked list head[1].
[0034] After completing the interface registration through steps S1 and S2, when the dynamic library calls back the main program interface, the main program traverses the linked list head[1] and determines whether the dynamic library has registered the agreed interface based on the "request description information". If it has been registered, the corresponding main program specific interface in the linked list head[2] is provided to the dynamic library for callback based on the "request description information", thereby enabling the dynamic library to obtain the main program interface.
[0035] Figure 2 A schematic diagram of the main program interface callback device provided in another embodiment of this application is shown below. Figure 2 As shown, the main program interface callback device may include a processor 201 and a memory 202. The memory 202 is used to store at least one instruction, which, when loaded and executed by the processor 201, implements the main program interface callback method provided in any embodiment of this application. In one embodiment, Figure 2 The main program interface callback device provided in the illustrated embodiment can be a chip or a chip module.
[0036] In another embodiment of this application, an electronic device is also provided, which may include... Figure 2 The illustrated embodiment provides a main program interface callback device. In one implementation, the main program interface callback device can be a component of the electronic device, such as a chip.
[0037] In another embodiment of this application, a computer-readable storage medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, it implements the main program interface callback method provided in any embodiment of this application.
[0038] It should be noted that the terminals involved in the embodiments of this application may include, but are not limited to, personal computers (PCs), personal digital assistants (PDAs), wireless handheld devices, tablet computers, mobile phones, MP3 players, MP4 players, etc.
[0039] It is understood that the application may be a native application installed on the terminal, or it may be a web application of a browser on the terminal. This application embodiment does not limit this.
[0040] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0041] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0042] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0043] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units.
[0044] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0045] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
[0046] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A main program interface callback method, characterized in that, The method includes: The main program obtains the first request information sent by the dynamic library for the callback to the main program interface; and If the main program determines that the dynamic library has registered the agreed interface corresponding to the first request information, it authorizes the dynamic library to call the interface function corresponding to the first request information. Before the main program receives the first request information sent by the dynamic library for calling back the main program interface, it also includes: Obtain the second request information sent by the dynamic library for registering the interface; and Based on the second request information, the corresponding parameters are loaded into the linked list to complete the interface agreement; The second request information includes the request description information and callback function of the dynamic library; The step of loading the corresponding parameters into the linked list based on the second request information to complete the interface agreement includes: The request description information and callback function in the second request information sent by the dynamic library are loaded into the first linked list.
2. The method according to claim 1, characterized in that, The step of determining that the dynamic library has registered the agreed interface corresponding to the first request information, and then authorizing the dynamic library to call the interface function corresponding to the first request information, includes: Traverse the first linked list to determine whether the dynamic library has registered the convention interface corresponding to the first request information. If it is determined that the dynamic library has registered the convention interface corresponding to the first request information, then make the main program interface corresponding to the first request information in the second linked list available for the dynamic library to call.
3. The method according to claim 2, characterized in that, The first request information includes request description information, and the request description information is used to describe the capability information that the dynamic library wants to obtain.
4. The method according to claim 3, characterized in that, The step of traversing the first linked list to determine whether the dynamic library has registered the agreed-upon interface corresponding to the first request information includes: Traverse the first linked list and determine, based on the request description information in the first request information, whether the dynamic library has registered the agreed interface corresponding to the first request information.
5. The method according to claim 3, characterized in that, The step of making the main program interface corresponding to the first request information in the second linked list available for the dynamic library to call includes: The callback function corresponding to the request description information in the first request information is obtained from the first linked list and saved to the second linked list. The callback function corresponding to the request description information in the first request information in the second linked list is then assigned to the dynamic library so that the dynamic library can call the callback function to implement the capability corresponding to the main program.
6. A main program interface callback device, characterized in that, The device includes: A processor and a memory, the memory being used to store at least one instruction, which, when loaded and executed by the processor, implements the main program interface callback method as described in any one of claims 1-5.
7. An electronic device, characterized in that, The electronic device includes the main program interface callback device as described in claim 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the main program interface callback method as described in any one of claims 1-5.
Citation Information
Patent Citations
Method and application for moving bottom half portion of interrupt handler to application layer
CN103870326A