Code callback method, device and system
By setting up an intermediate layer in cross-platform development and generating identification for the method to be called back, the problem of not being able to call back directly between different programming languages is solved, and effective code callbacks and cross-platform development are achieved.
Patent Information
- Application Number
- CN202411775748.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-08
AI Technical Summary
In cross-platform development, since the callback cannot be performed directly between different programming languages, the code cannot continue to run, and a method is needed to implement the callback of the code.
By setting an intermediate layer between the code layers in which the two programming languages are located, the intermediate layer generates an identification for the method name of the method to be called back, and passes the identification between the presentation layer and the business logic layer to implement the callback of the method.
By adding an intermediate layer and creating an identifier for the method names of each callback method in the intermediate layer, the called methods can find the correct callback method and call back to the correct code execution location, the problem of callback cannot be solved in cross-platform development.
Smart Images

Figure CN119781875A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of software engineering, and in particular, to a code callback method, device, and system. Background Art
[0002] With the development of computer technology, the environment in which software runs is becoming more and more diverse. Software developers need to develop software that can run on different operating systems and platforms to meet the needs of different users. For this reason, cross-platform development has gradually become the mainstream way of software development. Cross-platform development allows developers to share code on multiple platforms without having to write code for each platform separately, which improves the overall software development speed.
[0003] In cross-platform development, business logic codes are often written in a specific programming language, and then the cross-platform development framework related to the language is used to integrate these business logic codes into the software projects of each platform. For a specific platform, the user interface (UI) and related interaction methods are often written in another programming language. In the integration process, calls and callbacks between methods written in two programming languages are often involved.
[0004] However, due to the characteristics of some platforms, when method 1 in a certain programming language A calls method 2 in another programming language B, the called method 2 cannot directly call back to the method in programming language A, resulting in the callback being interrupted and the code unable to continue running. Therefore, a method is needed to implement code callback. Summary of the invention
[0005] One or more embodiments of this specification describe a code callback method, device, and system to solve the aforementioned problems.
[0006] In a first aspect, a code callback method is provided, comprising:
[0007] The presentation layer receives a first call request for a second method from the middle layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0008] The presentation layer calls the second method according to the first calling request to obtain a first result;
[0009] The presentation layer sends the first result and the first callback request including the first identifier to the middle layer;
[0010] The intermediate layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0011] In some possible implementations, before the intermediate layer sends the call information of the third method to the business logic layer, the method further includes:
[0012] The middle layer obtains the method name of the third method by searching the target storage area according to the first identifier received in the first callback request.
[0013] In some possible implementations, each identifier and its corresponding method name in the target storage area are stored in the form of a key-value pair.
[0014] In some possible implementations, the presentation layer sends the first result and the first callback request including the first identifier to the intermediate layer, including:
[0015] The presentation layer calls the target communication method and sends the first result and the first callback request to the intermediate layer.
[0016] In some possible implementations, the presentation layer runs in a first operating environment, and the business logic layer runs in a second operating environment, and the first operating environment and the second operating environment cannot communicate directly with each other.
[0017] In some possible implementations, before the presentation layer receives the first call request for the second method from the middle layer, the method further includes:
[0018] The business logic layer sends the first call request and the method name of the third method to the middle layer;
[0019] The middle layer generates a first identifier for the received method name of the third method and stores it in the target storage area;
[0020] The intermediate layer sends the first calling request and the first identifier to the presentation layer.
[0021] In some possible implementations, before the business logic layer sends the first call request and the method name of the third method to the middle layer, the method further includes:
[0022] The presentation layer registers the second method with the intermediate layer.
[0023] In some possible implementations, the following further includes:
[0024] The business logic layer executes the third method to process the received first result.
[0025] In the second aspect, a code callback method is provided, which is executed by the presentation layer and includes:
[0026] Receiving a first call request for a second method from a business logic layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0027] Calling the second method according to the first calling request to obtain a first result;
[0028] The first result and the first callback request including the first identifier are sent to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0029] Thirdly, a code callback method is provided, which is executed by the middle layer and includes:
[0030] Receiving a first call request for a second method from a business logic layer, and a method name of a third method as a callback method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0031] generating a first identifier for the method name of the third method and storing the first identifier in the target storage area;
[0032] Sending the first call request and the first identifier to the presentation layer;
[0033] receiving a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request;
[0034] The calling information of the third method is sent to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
[0035] In a fourth aspect, a code callback system is provided, including a business logic layer, an intermediate layer and a presentation layer, wherein:
[0036] The presentation layer is used to receive a first call request for a second method from the middle layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0037] The presentation layer is further used to call the second method according to the first call request to obtain a first result;
[0038] The presentation layer is further used to send the first result and the first callback request including the first identifier to the middle layer;
[0039] The intermediate layer is used to send the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0040] In a fifth aspect, a code callback device is provided, which is deployed in a presentation layer and includes:
[0041] A receiving unit is configured to receive a first call request for a second method from a business logic layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0042] a calling unit configured to call the second method according to the first calling request to obtain a first result;
[0043] The sending unit is configured to send the first result and the first callback request including the first identifier to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0044] In a sixth aspect, a code callback device is provided, which is deployed in the middle layer and includes:
[0045] A first receiving unit is configured to receive a first call request for a second method from a business logic layer, and a method name of a third method as a callback method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0046] an identifier generating unit, configured to generate a first identifier for the method name of the third method and store the first identifier in a target storage area;
[0047] A first sending unit, configured to send the first call request and the first identifier to a presentation layer;
[0048] A second receiving unit is configured to receive a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request;
[0049] The second sending unit is configured to send the calling information of the third method to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
[0050] In a seventh aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed in a computer, the computer executes the method of the first aspect, the second aspect, or the third aspect.
[0051] In an eighth aspect, a computing device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method of the first aspect, the second aspect, or the third aspect is implemented.
[0052] The code callback method, device and system proposed in the embodiments of this specification are implemented by setting an intermediate layer between the code layers where two programming languages are located. When the business logic layer initiates a call to the second method of the presentation layer and uses its own third method as the callback method, the intermediate layer generates a first identifier for the method name of the third method to be called back, and then sends the first identifier to the presentation layer. After the presentation layer executes the second method, it returns the execution result and the first identifier to the intermediate layer. The intermediate layer then sends the call information of the third method to the business logic layer to complete the callback process. By adding an intermediate layer and creating an identifier for the method name of each callback method in the intermediate layer, each called method can find the correct callback method and call back to the correct code execution position. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions of the multiple embodiments disclosed in this specification, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only the multiple embodiments disclosed in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0054] Figure 1 A schematic diagram showing an implementation scenario of a code callback method according to an embodiment is shown;
[0055] Figure 2 A flowchart showing a code callback method according to an embodiment;
[0056] Figure 3 A flowchart showing a code callback method according to another embodiment;
[0057] Figure 4 A flowchart showing a code callback method according to yet another embodiment;
[0058] Figure 5 A schematic block diagram of a code callback system according to an embodiment is shown;
[0059] Figure 6 A schematic block diagram of a code callback device according to an embodiment is shown;
[0060] Figure 7 A schematic block diagram of a code callback device according to another embodiment is shown. DETAILED DESCRIPTION
[0061] The solution provided in this specification is described below in conjunction with the accompanying drawings.
[0062] As mentioned above, in cross-platform development, business logic code is often written in a certain programming language, and then the cross-platform development framework related to the language is used to integrate the business logic code into the software projects of each platform. For example, common cross-platform development frameworks may include React Native, Kotlin Multiplatform (KMP), etc., and their corresponding programming languages are JavaScript and Kotlin respectively. The code layer where the business logic code is located can be called the business logic layer (Business Logic Layer).
[0063] For the platform where the software and applications run, it is also necessary to use platform-related programming languages to write UI and interaction-related codes. For example, for the iOS system, the programming language used can be Swift or Objective-C, for the Android system, the programming language used can be Kotlin or Java, and for the HarmonyOS system, the programming language used can be ArkTS. The code layer where these codes are located can be called the Presentation Layer.
[0064] In the process of integrating the business logic layer code into the software project where the presentation layer is located, there will be interactions between the methods of the two code layers, which are specifically manifested as calls and callbacks between methods. Among them, method callback is a commonly used design pattern in programming, which allows a method to be passed as a parameter to another method and be called when a specific event occurs or a specific operation is completed.
[0065] Generally speaking, methods written in two different programming languages cannot be called directly. An additional encapsulation framework is needed to encapsulate the method written in one programming language into an interface for the method of the other programming language to call and manage related memory and resources. The code layer where the interface encapsulated by the encapsulation framework is located can be called the middle layer.
[0066] When the encapsulation framework manages resources, it uses the call stack to track and manage method calls. When a method is called, a new stack frame is created at the top of the stack, which contains the method's local variables, passed parameters, and return address. After the method is executed, the corresponding stack frame will be destroyed to prevent memory leaks.
[0067] Specifically, in the aforementioned calling scenario, the business logic layer contains methods 1 and 3 written in programming language A, and the presentation layer contains method 2 written in programming language B. The encapsulation framework encapsulates method 2 and turns it into method 2' in the middle layer. Method 1 in the business logic layer calls method 2' in the middle layer, and sets the callback method to method 3. The middle layer executes method 2' to call method 2 in the presentation layer, and creates a stack frame for method 2' in the call stack. The method name of method 3, which is the callback method, is also saved in this stack frame. When method 2 is executed, the stack frame of method 2' in the call stack will be destroyed, and the method name of method 3 will also be destroyed. It is impossible to know where to call back, resulting in callback interruption.
[0068] Based on the above analysis, the embodiment of this specification proposes a code callback method, which adds a storage area in the middle layer to solve the problem of being unable to callback during cross-platform development. Figure 1 A schematic diagram of an implementation scenario of a code callback method according to an embodiment is shown. Figure 1 In the example, the business logic layer contains methods 1 and 3 written in programming language A, and the presentation layer contains method 2 written in programming language B. The encapsulation framework encapsulates method 2 into method 2' in the middle layer.
[0069] First, in step 1, method 1 of the business logic layer calls method 2' of the middle layer, and sets the callback method to method 3. In step 2, the middle layer generates a corresponding identifier (id) for method 3, such as identifier 1, and then saves the key-value pair of identifier 1-method name of method 3 to the storage area. Then, in step 3, the middle layer executes method 2' to call method 2 of the presentation layer, and sends identifier 1 to the presentation layer.
[0070] After executing method 2, the presentation layer cannot directly call back to the middle layer due to the aforementioned reasons. At this time, in step 4, the presentation layer calls a preset global method, and sends the running result of method 2 and identifier 1 to the middle layer through this global method, so that the middle layer can find the corresponding callback method and call back to the business logic layer. Next, in step 5, the middle layer queries the method name of the corresponding method 3 through identifier 1, and finally, in step 6, the middle layer calls back method 3, and the business logic layer executes method 3 to process the running result of method 2.
[0071] exist Figure 1 In the scenario, method 1 can be a method for the business logic layer to initiate a specific interaction request with the user. Method 2 can be a method for the presentation layer to display the request to the user and interact with the user. After receiving the user's specific interaction, method 2 processes the interaction, obtains the interaction processing result, and further processes the interaction processing result through the global method callback method 3.
[0072] For example, in a payment scenario, method 1 can be a method initiated by the business logic layer to request the user to pay for an order, method 2 can be a method for the presentation layer to display the order interface and interact with the user, and method 3 can be a method for processing payment results. After determining parameters such as the order amount and order number, method 1 calls method 2, instructing the presentation layer to display data such as the order amount and order number to the user, and requesting the user to pay for the order. After the user performs the corresponding interaction (for example, paying an order or canceling an order), method 2 calls the global method callback method 3, instructing method 3 to process the payment result (payment success / payment failure / cancellation of payment).
[0073] For another example, in a question answering scenario, method 1 can be a method initiated by the business logic layer to generate questions and options, method 2 can be a method for displaying questions and options at the presentation layer, and method 3 can be a method for processing the answering results. After generating questions and options, method 1 calls method 2 to instruct the presentation layer to display the questions and options to the user and request the user to answer. After the user performs the corresponding interaction (clicks on an option), method 2 calls the global method callback method 3 to instruct method 3 to process the payment result (the option clicked by the user). Method 3 can determine the user's answer result based on the received options.
[0074] The specific implementation steps of the above code callback method are described below in conjunction with a specific embodiment.
[0075] Figure 2 A flowchart of a code callback method according to an embodiment is shown, and the execution subject of the method can be any platform or server or device cluster with computing and processing capabilities. Figure 2As shown, the method at least includes: step 208, the presentation layer receives a first call request for the second method from the middle layer, and a first identifier of the third method as a callback method; the first identifier is used to indicate the method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; step 210, the presentation layer calls the second method according to the first call request to obtain a first result; step 212, the presentation layer sends the first result and the first callback request including the first identifier to the middle layer; step 216, the middle layer sends the call information of the third method to the business logic layer; the call information includes the method name of the third method and the first result.
[0076] The specific execution process of each of the above steps is described below.
[0077] First, in step 208, the presentation layer receives a first call request for the second method from the middle layer, and a first identifier of a third method serving as a callback method; the first identifier is used to indicate the method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language.
[0078] Methods written in the first programming language and the second programming language cannot directly call each other. That is, the second method and the third method cannot directly call each other.
[0079] In one embodiment, the presentation layer runs in a first operating environment, and the business logic layer runs in a second operating environment, and the first operating environment and the second operating environment cannot communicate directly.
[0080] In a specific embodiment, the first programming language may be TypeScript or ArkTS, the second programming language may be Kotlin, the cross-platform framework used by Kotlin may be KMP, and the encapsulation framework may be the NAPI (Node-API) framework. Correspondingly, the first operating environment may be the V8 engine or the ArkUI engine, and the second operating environment may be the JVM (Java Virtual Machine). The software project may be a Hongmeng application. The NAPI framework destroys the stack frame corresponding to the method in the call stack after the method is executed.
[0081] Then, in step 210, the presentation layer calls the second method according to the first calling request to obtain a first result.
[0082] The second method may be, for example, a method of interacting with a user; the first result may be, for example, a result obtained by receiving an input from a user and processing the result using the second method.
[0083] Next, in step 212, the presentation layer sends the first result and the first callback request including the first identifier to the middle layer.
[0084] In one embodiment, the presentation layer calls a target communication method and sends the first result and the first callback request to the intermediate layer.
[0085] The target communication method may be a preset global method, which is used to send the method execution result of the presentation layer and the identifier of the callback method to the middle layer, so that the middle layer searches for the corresponding callback method according to the identifier and calls back the callback method to the business logic layer.
[0086] In other embodiments, step 212 may also be initiated by the second method, that is, after the second method obtains the first result through processing, the second method sends the first result and the first callback request to the middle layer at the end of the method body.
[0087] Finally, in step 216, the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0088] The middle layer determines the method name of the third method according to the first identifier, and puts the method name of the third method and the first result into the call information of the third method, and sends it to the business logic layer. The business logic layer can execute the third method to process the first result. The first result can be input into the third method in the form of an input parameter.
[0089] In one embodiment, the first identifier is the method name of the third method, that is, the middle layer directly transmits the method name of the third method to the presentation layer.
[0090] Through the above steps, an intermediate layer is set between the code layers where the two programming languages are located. When calling, the intermediate layer creates an identifier for the callback method. When calling back, the intermediate layer determines the corresponding callback method according to the identifier and calls back to the corresponding position, so that the business logic layer executes the corresponding callback method, which can realize the calling and callback between the methods written in the two programming languages.
[0091] In some possible implementations, before step 216, the method further includes:
[0092] In step 214, the middle layer queries the target storage area to obtain the method name of the third method according to the first identifier received in the first callback request.
[0093] In this embodiment, each identifier and its corresponding method name in the target storage area are stored in the form of a key-value pair. It is understandable that the business logic layer may initiate calls to multiple methods of the presentation layer simultaneously or successively, and correspondingly multiple methods of the business logic layer will be called back. Therefore, multiple identifier-callback method name key-value pairs can be stored in the target storage area at the same time. At the same time, the identifier is unique.
[0094] Through the above steps, the target storage area is set in the middle layer. When calling, the middle layer creates an identifier for the callback method and stores it in the target storage area. When calling back, the middle layer queries the corresponding callback method from the target according to the identifier and calls back to the corresponding position, allowing the business logic layer to execute the corresponding callback method, which can realize the call and callback between methods written in two programming languages.
[0095] In some possible implementations, after step 216, the method further includes:
[0096] Step 218: The business logic layer executes the third method to process the received first result.
[0097] This round of call-callback process is completed by calling the third method to process the first result.
[0098] In some possible implementations, in order to make the middle layer aware of which methods of the presentation layer can be called by the business logic layer, the method further includes:
[0099] The presentation layer registers the second method to the middle layer, and obtains a second encapsulation method corresponding to the second method, where the second encapsulation method is located in the middle layer.
[0100] It is understandable that the presentation layer can also register other methods with the middle layer.
[0101] In some possible implementations, in order to integrate the method in the business logic layer into the software project, the method further includes:
[0102] The business logic layer imports the compilation result of the third method into the software project. And, the business logic layer imports the compilation result of the first method into the software project.
[0103] It is understandable that the business logic layer can also compile other methods and import them into the software project.
[0104] In some possible implementations, before step 208 , the method further includes steps 202 to 206 .
[0105] In step 202, the business logic layer sends the first call request and the method name of the third method to the middle layer.
[0106] The first call request may be initiated by a first method in the business logic layer. Similar to the third method, the first method is also implemented using the first programming language, and the first method and the second method cannot directly call each other.
[0107] In one embodiment, the first call request includes calling a second encapsulation method located in the middle layer. The second encapsulation method is obtained by encapsulating the second method through an encapsulation framework related to the presentation layer. The callback method accepted in the input parameter of the second encapsulation method is the third method.
[0108] Then, in step 204, the middle layer generates a first identifier for the received method name of the third method and stores it in the target storage area.
[0109] The middle layer stores the key-value pair of the first identifier and the method name of the third method in the target storage area.
[0110] Next, in step 206, the intermediate layer sends the first call request and the first identifier to the presentation layer.
[0111] In one embodiment, the middle layer initiates a call request to the second method of the presentation layer by executing the second encapsulation method.
[0112] In the above steps, the first method may be a method in which the business logic layer initiates a specific interaction request with the user. The second method may be a method in which the presentation layer displays the interaction request to the user and interacts with the user. The third method may be a method for processing the interaction result (first result) of the second method.
[0113] At the same time, in the cross-platform development scenario, each method in the business logic layer, middle layer, and presentation layer is located in the software project, such as the Hongmeng application, which runs on the Hongmeng client.
[0114] For cross-platform development of Hongmeng system applications using the Kotlin programming language, the relevant solutions usually require the use of the NAPI framework to write bridge layer code to implement calls between Kotlin code and Hongmeng's ArkTS code (but callbacks cannot be implemented). By using the method provided in the embodiments of this specification, developers only need to write Kotlin code and ArkTS code (corresponding to business logic layer code and presentation layer code), without using the NAPI framework to write bridge layer code. Calls and callbacks between Kotlin code and Hongmeng's ArkTS code can be implemented through the intermediate layer and the preset global method (target communication method).
[0115] According to another embodiment, a code callback method is also provided, which is executed by the presentation layer. Figure 3A flowchart of a code callback method according to another embodiment is shown, and the execution subject of the method can be any platform or server or device cluster with computing and processing capabilities. Figure 3 As shown, the method is executed by the presentation layer and includes:
[0116] Step 302, receiving a first call request for a second method from a business logic layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0117] Step 304: calling the second method according to the first calling request to obtain a first result;
[0118] Step 306, sending the first result and the first callback request including the first identifier to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0119] According to yet another embodiment, a code callback method is also provided, which is executed by the middle layer. Figure 4 A flowchart of a code callback method according to another embodiment is shown, and the execution subject of the method can be any platform or server or device cluster with computing and processing capabilities. Figure 4 As shown, the method is performed by the middle layer and includes:
[0120] Step 402, receiving a first call request for a second method from a business logic layer, and a method name of a third method as a callback method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0121] Step 404, generating a first identifier for the method name of the third method and storing it in a target storage area;
[0122] Step 406, sending the first call request and the first identifier to the presentation layer;
[0123] Step 408, receiving a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request;
[0124] Step 412: Send the calling information of the third method to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
[0125] According to an embodiment of another aspect, a code callback system is also provided, including a business logic layer, a middle layer and a presentation layer. Figure 5 A schematic block diagram of a code callback system according to an embodiment is shown.
[0126] The presentation layer 506 is used to receive a first call request for a second method and a first identifier of a third method as a callback method from the middle layer 504; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0127] The presentation layer 506 is further configured to call the second method according to the first call request to obtain a first result;
[0128] The presentation layer 506 is further used to send the first result and the first callback request including the first identifier to the middle layer 504;
[0129] The middle layer 504 is used to send the calling information of the third method to the business logic layer 502; the calling information includes the method name of the third method and the first result.
[0130] According to another embodiment, a code callback device is also provided, which is deployed in the presentation layer. Figure 6 FIG. 1 is a schematic block diagram of a code callback device according to an embodiment, which can be deployed in any device, platform or device cluster with computing and processing capabilities. Figure 6 As shown, the device 600 is deployed at the presentation layer and includes:
[0131] The receiving unit 602 is configured to receive a first call request for a second method from a business logic layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0132] The calling unit 604 is configured to call the second method according to the first calling request to obtain a first result;
[0133] The sending unit 606 is configured to send the first result and the first callback request including the first identifier to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
[0134] According to yet another embodiment, a code callback device is deployed in a middle layer. Figure 7FIG. 1 is a schematic block diagram of a code callback device according to another embodiment, which can be deployed in any device, platform or device cluster with computing and processing capabilities. Figure 7 As shown, the device 700 is deployed in the middle layer and includes:
[0135] The first receiving unit 702 is configured to receive a first call request for a second method from the business logic layer, and a method name of a third method as a callback method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language;
[0136] The identifier generating unit 704 is configured to generate a first identifier for the method name of the third method and store it in the target storage area;
[0137] A first sending unit 706 is configured to send the first call request and the first identifier to a presentation layer;
[0138] The second receiving unit 708 is configured to receive a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request;
[0139] The second sending unit 712 is configured to send the calling information of the third method to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
[0140] In some possible implementations, the device 700 further includes:
[0141] The query unit 710 is configured to query the method name of the third method from the target storage area according to the first identifier received in the first callback request.
[0142] According to another aspect of the embodiment, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is caused to execute the method described in any of the above embodiments.
[0143] According to yet another embodiment, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in any one of the above embodiments is implemented.
[0144] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0145] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0146] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0147] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0148] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A code callback method, comprising: The presentation layer receives a first call request for the second method and a first identifier of a third method as a callback method from the middle layer; The first identifier is used to indicate the method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; The presentation layer calls the second method according to the first calling request to obtain a first result; The presentation layer sends the first result and the first callback request including the first identifier to the middle layer; The intermediate layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
2. The method according to claim 1, wherein: Before the intermediate layer sends the call information of the third method to the business logic layer, the method further includes: The middle layer obtains the method name of the third method by searching the target storage area according to the first identifier received in the first callback request.
3. The method according to claim 2, wherein: Each identifier and its corresponding method name in the target storage area are stored in the form of a key-value pair.
4. The method according to claim 1, wherein: The presentation layer sends the first result and the first callback request including the first identifier to the middle layer, including: The presentation layer calls the target communication method and sends the first result and the first callback request to the intermediate layer.
5. The method according to claim 1, wherein: The presentation layer runs in a first operating environment, and the business logic layer runs in a second operating environment. The first operating environment and the second operating environment cannot communicate directly with each other.
6. The method according to claim 5, before the presentation layer receives the first call request for the second method from the middle layer, the method further comprises: The business logic layer sends the first call request and the method name of the third method to the middle layer; The middle layer generates a first identifier for the received method name of the third method and stores it in the target storage area; The intermediate layer sends the first calling request and the first identifier to the presentation layer.
7. The method according to claim 6, before the business logic layer sends the first call request and the method name of the third method to the middle layer, the method further comprises: The presentation layer registers the second method with the intermediate layer.
8. The method according to claim 1, further comprising: The business logic layer executes the third method to process the received first result.
9. A code callback method, executed by the presentation layer, comprising: Receiving a first call request for a second method and a first identifier of a third method as a callback method from a business logic layer; The first identifier is used to indicate the method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; Calling the second method according to the first calling request to obtain a first result; The first result and the first callback request including the first identifier are sent to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
10. A code callback method, executed by the middle layer, comprising: Receiving a first call request for a second method from a business logic layer, and a method name of a third method as a callback method; The second method is implemented using a first programming language, and the third method is implemented using a second programming language; generating a first identifier for the method name of the third method and storing the first identifier in the target storage area; Sending the first call request and the first identifier to the presentation layer; receiving a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request; The calling information of the third method is sent to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
11. A code callback system, comprising a business logic layer, an intermediate layer and a presentation layer, wherein: The presentation layer is used to receive a first call request for a second method from the middle layer, and a first identifier of a third method as a callback method; the first identifier is used to indicate a method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; The presentation layer is further used to call the second method according to the first call request to obtain a first result; The presentation layer is further used to send the first result and the first callback request including the first identifier to the middle layer; The intermediate layer is used to send the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
12. A code callback device, deployed in the presentation layer, comprising: A receiving unit configured to receive a first call request for a second method and a first identifier of a third method as a callback method from a business logic layer; The first identifier is used to indicate the method name of the third method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; a calling unit configured to call the second method according to the first calling request to obtain a first result; The sending unit is configured to send the first result and the first callback request including the first identifier to the middle layer, so that the middle layer sends the calling information of the third method to the business logic layer; the calling information includes the method name of the third method and the first result.
13. A code callback device, deployed in the middle layer, comprising: A first receiving unit is configured to receive a first call request for a second method from a business logic layer, and a method name of a third method as a callback method; the second method is implemented using a first programming language, and the third method is implemented using a second programming language; an identifier generating unit, configured to generate a first identifier for the method name of the third method and store the first identifier in a target storage area; A first sending unit, configured to send the first call request and the first identifier to a presentation layer; A second receiving unit is configured to receive a first result from the presentation layer and a first callback request including the first identifier; the first result is obtained by the presentation layer calling the second method according to the first calling request; The second sending unit is configured to send the calling information of the third method to the business logic layer, so that the business logic layer executes the third method to process the received first result; the calling information includes the method name of the third method and the first result.
14. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 10.
15. A computing device comprising a memory and a processor, wherein: The memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Application operation method and device
CN105718313A
Method and device for interaction between native end and H5 end of mobile terminal
CN110543372A