Cross-module initialization operation method and device, storage medium and program product

By using the initialization configuration file and SPI mechanism in the main module, the implementation classes of functional modules are dynamically loaded, which solves the problem of high coupling of initialization operations in the prior art, realizes uncoupled and cross-module initialization operations, and improves the flexibility and scalability of the system.

CN119883389AActive Publication Date: 2025-04-25BEIJING 58 INFORMATION TTECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411961107.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-04-25
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

The prior art initializes application function modules based on the Hongmeng system, the coupling is too high, resulting in inconvenient code maintenance. When the class name of the functional module changes or class addition/delete, the main module code needs to be modified.

Method used

By using the initialization configuration file in the main module, traverse the configuration file according to the identification of the functional module to obtain the fully qualified name of the implementation class, and dynamically load the implementation class through the SPI mechanism to complete the initialization operation of the functional module.

Benefits of technology

It realizes uncoupled and cross-module initialization operations, reduces the coupling between the main module and the functional module, improves the flexibility and scalability of the system, and simplifies code maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883389A_ABST
    Figure CN119883389A_ABST
Patent Text Reader

Abstract

The invention provides a cross-module initialization operation method and device, a storage medium and a program product, and the method comprises the steps: responding to an initialization request for a target function module, and the request comprises an identifier of the target function module; and traversing a preset initialization configuration file according to the identifier of the target function module, and determining a full-definition name of the implementation class corresponding to the identifier of the target function module. And obtaining an implementation class corresponding to the target function module according to the full definition name. And performing initialization operation on the target function module based on the initialization operation method in the implementation class. According to the scheme, the full-definition name of the implementation class corresponding to the target function module is written into the initialization configuration file in advance, when the main module carries out initialization operation on the target function module, the corresponding implementation class can be directly read from the configuration file, and the initialization operation is executed based on the initialization operation method in the implementation class; in this way, initialization operation can be completed in a cross-module mode without knowing specific implementation details of the target function module.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a cross-module initialization operation method, device, storage medium and program product. Background Art

[0002] Currently, in applications developed based on the Hongmeng system, modular design is usually adopted. The application consists of a main module and multiple functional modules. Each functional module depends on the main module and provides specific functional methods. In order to call these functional methods, the main module needs to initialize the functional modules before calling these functional methods.

[0003] In the existing initialization scheme, the main module obtains the related classes declared by the target function module, and dynamically creates each related class instance in the target function module according to the class name of the related class by using the reflection mechanism, and calls the initialization method in the related class to initialize the target function module. In this way, when initializing the target function module, the main module needs to obtain the class names of each related class corresponding to the target function module to locate the implementation class corresponding to the target function module. However, when the class name of a related class in the target function module changes or a new related class is added or deleted in the target function module, the code needs to be modified, the coupling is too high, and the application code maintenance is not utilized. Summary of the invention

[0004] The embodiments of the present invention provide a cross-module initialization operation method, device, storage medium and program product, which are used to decouple the initialization operation and realize the non-coupling, cross-module initialization operation.

[0005] In a first aspect, an embodiment of the present invention provides a cross-module initialization operation method, the method is applied to a main module in an application, the main module is an entry module of the application, the application includes a main module and multiple functional modules, each functional module depends on the main module, the method includes:

[0006] In response to an initialization request for a target functional module, acquiring an initialization configuration file corresponding to the target functional module, wherein the initialization request includes an identifier of the target functional module, and the target functional module is any one of the multiple functional modules;

[0007] Traversing the initialization configuration file according to the identifier of the target functional module to determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module;

[0008] According to the fully qualified name, obtain the implementation class corresponding to the target functional module;

[0009] The target functional module is initialized based on the initialization operation method in the implementation class.

[0010] In a second aspect, an embodiment of the present invention provides a cross-module initialization operation device, the device comprising:

[0011] a response module, configured to obtain an initialization configuration file corresponding to the target functional module in response to an initialization request for the target functional module, wherein the initialization request includes an identifier of the target functional module, and the target functional module is any one of the multiple functional modules;

[0012] A traversal module, used to traverse the initialization configuration file according to the identifier of the target functional module, and determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module;

[0013] An acquisition module, used for acquiring the implementation class corresponding to the target functional module according to the fully qualified name;

[0014] An initialization module is used to perform an initialization operation on the target functional module based on the initialization operation method in the implementation class.

[0015] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor can at least implement the cross-module initialization operation method described in the first aspect.

[0016] In a fourth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of a transmission device, the processor can at least implement the cross-module initialization operation method described in the first aspect.

[0017] In a fifth aspect, an embodiment of the present invention provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is enabled to implement the cross-module initialization operation method as described in the first aspect above.

[0018] In the cross-module initialization operation scheme provided in the embodiment of the present invention, the scheme is applied to the main module in the application, the application includes a main module and multiple functional modules, the main module is the entry module of the application, and each functional module depends on the main module. The main module can implement the initialization operation of each functional module across modules to decouple the dependency between the main module and each functional module.

[0019] Specifically, in response to an initialization request for a target functional module, an initialization configuration file corresponding to the target functional module is obtained. The initialization request includes an identifier of the target functional module. The target functional module is any one of multiple functional modules in the application. Then, the initialization configuration file is traversed according to the identifier of the target functional module to determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module. And according to the fully qualified name of the implementation class corresponding to the target functional module, the implementation class corresponding to the target functional module is obtained. Finally, the target functional module is initialized based on the initialization operation method in the implementation class corresponding to the target functional module.

[0020] In the above scheme, by writing the fully qualified name of the implementation class corresponding to the target functional module into the initialization configuration file in advance, when the main module needs to perform initialization operations on the target functional module, the implementation class of the corresponding target functional module can be directly read from the initialization configuration file, and then the initialization operation is performed on the target functional module based on the initialization operation method in the implementation class, so that the main module no longer directly references the implementation class in the target functional module to perform the initialization operation. In this way, there is no need to know the specific implementation details corresponding to the target functional module or manually instantiate the implementation class, and the initialization operation can be completed across modules, thereby realizing the decoupling between the main module and the target functional module. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0022] Figure 1 A flowchart of a cross-module initialization operation method provided by an embodiment of the present invention;

[0023] Figure 2 A flowchart of an initialization operation on a target functional module provided by an embodiment of the present invention;

[0024] Figure 3 A flowchart of another cross-module initialization operation provided by an embodiment of the present invention;

[0025] Figure 4 A schematic diagram of the structure of a cross-module initialization operation device provided by an embodiment of the present invention;

[0026] Figure 5 For Figure 4 A schematic diagram of the structure of an electronic device corresponding to the cross-module initialization operation device provided in the illustrated embodiment. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the case where there is no conflict between the embodiments, the following embodiments and the features in the embodiments can be combined with each other. In addition, the step sequence in the following method embodiments is only an example and not a strict limitation.

[0029] In the current initialization scheme, when the main module initializes the target function module, it needs to first read the relevant classes declared by the target function module and the class names of the relevant classes in the module.json file, and then obtain the paths and configuration information of each relevant class in the target function module, locate the relevant class according to the class name and path of the relevant class, and load the relevant class. Then, the reflection mechanism is used to dynamically create each relevant class instance in the target function module, and the initialization method in the relevant class is called to initialize the target function module.

[0030] However, in this way, when initializing the target function module, the main module needs to obtain the class names of the corresponding related classes of the target function module to locate the implementation class corresponding to the target function module, and instantiate the corresponding implementation class to complete the initialization operation. Then, when the class name of the related class corresponding to the target function module changes or a new related class is added or an existing related class is deleted in the target function module, the code needs to be modified, the coupling is too high, and the code maintenance of the application is not utilized.

[0031] In order to solve the above technical problems, the embodiment of the present invention provides a cross-module initialization operation scheme, in which the main module and multiple functional modules all rely on an independent SPI interface library module, and the SPI interface library only contains an initialization interface definition and specific implementation logic. Each functional module provides its own initialization implementation according to the initialization interface definition, and writes the fully qualified name of the implementation class corresponding to each functional module into the initialization configuration file. In this way, through the SPI mechanism, the main module only needs to know the initialization interface and find the fully qualified name of the implementation class corresponding to each functional module from the initialization configuration file, and can dynamically find and load the implementation class of each functional module at runtime to complete the initialization operation of each functional module without directly referencing the specific implementation classes in these modules, which can effectively reduce the coupling between modules and enhance the flexibility and scalability of the system.

[0032] The cross-module initialization operation scheme provided by the embodiment of the present invention is described in detail below.

[0033] The cross-module initialization operation method provided in the embodiment of the present invention can be performed by an electronic device, which can be a terminal device such as a PC, a laptop, a smart phone, or a server. The server can be a physical server including an independent host, or a virtual server, or a server or server cluster in the cloud.

[0034] Figure 1 A flowchart of a cross-module initialization operation method provided by an embodiment of the present invention, such as Figure 1 As shown, the method is applied to the main module in the application program. The application program includes the main module and multiple functional modules. The main module is the entry module of the application program. Each functional module depends on the main module. Specifically, the method may include the following steps:

[0035] 101. In response to an initialization request for a target functional module, obtain an initialization configuration file corresponding to the target functional module, wherein the initialization request includes an identifier of the target functional module.

[0036] 102. According to the identifier of the target functional module, the initialization configuration file is traversed to determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module.

[0037] 103. According to the fully qualified name, obtain the implementation class corresponding to the target functional module.

[0038] 104. Perform initialization operation on the target functional module based on the initialization operation method in the implementation class.

[0039] The cross-module initialization operation method provided by the embodiment of the present invention can be applied to the main module in a modularly designed application. When the main module calls each functional module in the application, the cross-module initialization operation for each functional module can be completed without coupling, thereby reducing the coupling between the main module and each functional module.

[0040] The specific implementation process of the main module performing initialization operations on various functional modules in the application is roughly the same. In the embodiment of the present invention, only the initialization operation of the target functional module is exemplified. The target functional module is any functional module among the multiple functional modules in the application.

[0041] In specific implementation, in response to an initialization request for a target functional module, an initialization configuration file corresponding to the target functional module is obtained, wherein the initialization configuration file is used to store the fully qualified name of the implementation class corresponding to the target functional module so that the subsequent main module can find the implementation class corresponding to the target functional module.

[0042] The implementation class corresponding to the target functional module refers to the specific class that implements the initialization interface, and the implementation class contains the specific initialization method corresponding to the target functional module. That is, the implementation class follows the predefined initialization interface rules to ensure that all functional modules follow the unified method signature and behavior specifications. Each functional module can be developed, tested, and deployed independently of other modules as long as it meets the requirements defined by the initialization interface.

[0043] Among them, before performing the initialization operation, the main module can pre-create the initialization interfaces corresponding to multiple functional modules, and the initialization interfaces specify the rules for the initialization operations of multiple functional modules. In this way, the main module can dynamically load and initialize each functional module without directly referencing the specific implementation class, thus achieving decoupling between modules and system flexibility.

[0044] After creating a standard initialization interface, you can create implementation classes corresponding to each functional module in the application according to the definition of the initialization interface. The specific implementation process of creating implementation classes corresponding to each functional module in the application can be: obtaining configuration information corresponding to the target functional module; creating implementation classes corresponding to the target functional module according to the initialization interface and configuration information, and the implementation classes are used to implement the initialization interface.

[0045] After creating the implementation class corresponding to the corresponding target functional module, you can write the fully qualified name of the implementation class into the initialization configuration file so that the main module can find and load these implementation classes at runtime. The fully qualified name of the implementation class includes the package name and class name of the implementation class.

[0046] In addition, in an optional embodiment, the initialization configuration file corresponding to the target functional module may also be added to the specific path corresponding to the target function, and the file name of the initialization configuration file may be the full package name of the initialization interface.

[0047] In order to improve the search speed of the fully qualified name of the implementation class corresponding to the target function module, the fully qualified name of the implementation class corresponding to the target function module stored in the initialization configuration file can be stored in the form of a mapping table entry. Specifically, obtain the identifier of the target function module and the fully qualified name of the implementation class corresponding to the target function module, create a mapping table entry corresponding to the identifier of the target function module, and the mapping table entry is used to describe the correspondence between the identifier of the target function module and the fully qualified name of the implementation class corresponding to the target function module. Write the mapping table entry into the initialization configuration file.

[0048] In this way, when responding to the initialization request for the target functional module, the initialization configuration file can be traversed according to the identifier of the target functional module to determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module.

[0049] Next, the implementation class corresponding to the target functional module is obtained according to the fully qualified name of the implementation class corresponding to the target functional module. The implementation class corresponding to the target functional module can be obtained by using the SPI (Service Provider Interface) mechanism.

[0050] Specifically, according to the fully qualified name, the implementation class corresponding to the target functional module is searched through the SPI mechanism; if the implementation class corresponding to the target functional module is found, the implementation class corresponding to the target functional module is loaded. Then, the target functional module is initialized based on the initialization operation method in the implementation class.

[0051] Loading the implementation class corresponding to the target functional module only loads the definition of the implementation class corresponding to the target functional module into the memory, but does not create an instance object of the implementation class. In other words, when using the SPI mechanism, only the implementation classes corresponding to all target functional modules that implement the initialization interface are loaded, but it does not automatically instantiate these implementation classes.

[0052] In the embodiment of the present invention, the target function module acts as a service provider, providing a corresponding specific implementation class that implements the initialization interface. In the specific implementation, the target function module can publish a device service so that the main module can find and load the implementation class corresponding to the target function module at runtime.

[0053] Therefore, the main module only needs to know the initialization interface (defined in an independent SPI interface library module) to find the implementation class that implements this interface at runtime. This is similar to a "plug-in" mechanism. The main module can discover and load "plug-ins" (i.e., implementation classes of the initialization interface) that conform to the interface specification without knowing the implementation details in advance. In other words, the SPI mechanism loosens the dependency between the main module and the target functional module. Both the main module and the submodule depend on an independent SPI interface library module, which only contains the initialization interface definition and has no specific implementation logic.

[0054] In summary, the embodiments of the present invention, by pre-writing the fully qualified name of the implementation class corresponding to the target functional module into the initialization configuration file, when the main module needs to perform an initialization operation on the target functional module, the implementation class of the corresponding target functional module can be directly read from the initialization configuration file, and then the initialization operation is performed on the target functional module based on the initialization operation method in the implementation class, so that the main module no longer directly references the implementation class in the target functional module to perform the initialization operation. In this way, there is no need to know the specific implementation details corresponding to the target functional module or manually instantiate the implementation class, and the initialization operation can be completed across modules, thereby realizing the decoupling between the main module and the target functional module.

[0055] The following describes in detail the specific implementation process of the initialization operation method in the implementation class corresponding to the calling target functional module in the above embodiment and the initialization operation on the target functional module in combination with the specific application scenario.

[0056] Figure 2 A flowchart of an initialization operation for a target functional module provided by an embodiment of the present invention, such as Figure 2 As shown, specifically, the initialization operation method is an initialization method corresponding to the crash processing, and the method may include the following steps:

[0057] 201. Obtain the context and preset log path parameters corresponding to the application.

[0058] 202. The context and the preset log path parameters are passed into the initialization method corresponding to the crash processing to perform initialization operations on the target functional module.

[0059] After loading into the implementation class corresponding to the target functional module, the initialization operation method in the implementation class can be called to perform initialization operations on the target functional module. Specifically, the context and preset log path parameters corresponding to the application are obtained. The context and preset log path parameters are passed to the initialization method corresponding to the crash processing to perform initialization operations on the target functional module.

[0060] Among them, the context corresponding to the application may include configuration information, logging, cache, etc. This information in the context corresponding to the application helps the main module understand its operating environment, configuration status, and interaction method with the target functional module to complete the initialization operation of the target functional module.

[0061] After the main module calls the initialization operation method in the implementation class to perform the initialization operation on the target functional module, it can also obtain the initialization operation result corresponding to the target functional module. And judge whether the initialization operation performed on the target functional module is successful according to the initialization operation result. If the initialization operation result is successful, the function provided by the target functional module is called to perform the corresponding operation.

[0062] The specific implementation process of the main module performing corresponding operations on the functions provided by the target functional module is described in detail below in conjunction with the following embodiments.

[0063] Figure 3 Another flow chart of cross-module initialization operation provided by an embodiment of the present invention is as follows: Figure 3 As shown, based on the above embodiment, specifically, the method may further include the following steps:

[0064] 301. Call the SPI interface to obtain the device handle corresponding to the target functional module.

[0065] 302. Establish a communication connection with a target functional module based on the device handle.

[0066] 303. Send the context corresponding to the application and the preset log path parameter to the target function module, so that the target function module performs crash processing on the application based on the context corresponding to the application, the preset log path parameter and the crash processing method.

[0067] After the main module successfully initializes the target function module, it can establish a communication connection with the target function module to call the crash handling method corresponding to the target function module to handle the crash of the application. In specific implementation, the main module can first call the SPI interface to obtain the device handle corresponding to the target function module.

[0068] Among them, the SPI interface defines a series of common methods for operating various functional modules in the application, covering methods for obtaining device handles corresponding to functional modules, methods for releasing device handles corresponding to functional modules, methods for reading and writing data, custom transmission methods, and configuration of device attributes. In addition, an SPI interface can be defined in an independent SPI interface library, which can be shared by the main module and all functional modules.

[0069] The SPI device handle can be used to identify and access the device object corresponding to the target functional module. When the main module wants to communicate with the target functional module, it can first obtain the device handle corresponding to the target functional module.

[0070] In an optional embodiment, the specific implementation process of obtaining the device handle corresponding to the target functional module may include: calling the method of obtaining the device handle corresponding to the functional module, obtaining the bus number and chip select number corresponding to the target functional module, returning the bus number and chip select number corresponding to the target functional module if successful, and returning NULL if failed.

[0071] After obtaining the device handle corresponding to the target functional module, the device properties corresponding to the target functional module can be configured first. For example, the operating mode, clock polarity and phase, data size (such as 8 bits or 16 bits), transmission rate, etc. corresponding to the target functional module can be configured. Then, the main module establishes a communication connection with the target functional module based on the device handle.

[0072] After the main module establishes communication with the target functional module, the context corresponding to the application and the preset log path parameters can be sent to the target functional module, so that the target functional module can perform crash processing on the application based on the context corresponding to the application, the preset log path parameters and the crash processing method.

[0073] Among them, the read and write data method can be called according to the device handle corresponding to the target functional module, the buffer pointer storing the online question corresponding to the application and the preset log path parameter, and the length of the data to be read, to obtain the context corresponding to the application and the preset log path parameter. The data is sent to the target functional module through the MOSI line, so that the target functional module can handle the crash of the application.

[0074] Similarly, after the target functional module completes the crash processing of the application, the target functional module can send the crash processing result and the crash processing record to the main module. The main module can receive the crash processing result and the crash processing record sent by the target functional module through the MISO line.

[0075] An embodiment of the present invention establishes a communication connection with a target functional module based on a device handle, and sends the context corresponding to the application and preset log path parameters to the target functional module, so that the target functional module performs crash processing on the application based on the context corresponding to the application, preset log path parameters and crash processing method, thereby decoupling the initialization operation from the crash processing operation and better maintaining the operation of the application.

[0076] For ease of understanding, the specific implementation process of the cross-module initialization operation in each of the above embodiments is illustrated with examples in combination with specific application scenarios. First, a CrashHandler interface is created that is uniformly used to handle the initialization operation of crash handling. In addition, the Crash Handler interface includes an init method, which provides an entry point for initializing the crash handling logic. In this way, different crash handling strategies can be flexibly implemented, and all implementations can be ensured to follow a unified standard.

[0077] Among them, the Crash Handler interface can be defined in the SPI interface library, and the Crash Handler interface is used to define a standard for a crash handling mechanism. Any class that implements this interface needs to provide an init method to initialize the crash handling logic. The init method receives a Context object to obtain the context information of the application and a log file path.

[0078] Then, create the Crash Handler implementation class corresponding to each functional module in the application.

[0079] Specifically, create a specific Crash Handler implementation class for the target functional module, namely the DefaultCrash Handler implementation class, which provides the specific implementation of all methods defined in the CrashHandler interface. For example, the actual crash handling initialization logic can be added in its init method.

[0080] In this way, the main module does not need to directly reference the implementation class in the functional module, avoiding the coupling problem that may be caused by direct dependencies between traditional modules. For example, if there is no Crash Handler interface, the main module may need to introduce the functional module through implementation project() or other strong dependency methods. In this way, when the functional module changes (such as class name changes, method signature changes, etc.), the main module may also need to modify the code accordingly. The above method allows the functional module to independently develop and update the implementation class, and as long as it still conforms to the interface definition, the main module can work normally.

[0081] Next, configure the initialization configuration file and write the fully qualified name of the implementation class corresponding to each functional module into the initialization configuration file.

[0082] Specifically, create a META-INF / services folder in the resources directory, and then create a file named com.example.myapplication.CrashHandler in the folder (the file name must be the fully qualified name of the interface to be loaded). In this file, write the fully qualified name of the implementation class corresponding to each functional module so that you know which specific implementation class to call when making subsequent calls.

[0083] Finally, in the Application class, the CrashHandler is loaded and initialized through the SPI technology.

[0084] Specifically, each functional module can publish device services first. The main module discovers the implementation class CrashHandler corresponding to the target functional module through the SPI mechanism, and loads the CrashHandler implementation class in the onCreate method of the MyApplication class, traverses and calls the init method of the implementation class corresponding to the target functional module, and passes in the context information corresponding to the application and the specified log path parameters, thereby completing the initialization operation of CrashHandler.

[0085] From the above description, we can see that if the CrashHandler interface is defined directly in other functional modules and the main module calls it directly, this will lead to a tight coupling between the main module and other functional modules. The main module needs to know the internal structure of other functional modules, including the package path where the interface is located, the specific definition details of the interface, etc. In this way, when the interface definition of other functional modules changes, such as the increase of parameters in the interface method, the change of the return value type, or the change of the package name of the interface, the code of the main module may need to be modified accordingly. This strong coupling makes the independence between modules worse, which is not conducive to the independent development, testing and maintenance of modules.

[0086] However, in the embodiment of the present invention, through SPI technology, the main module and multiple functional modules all rely on an independent SPI interface library module. The main module is only coupled with the interface definition in the SPI interface library, and does not directly rely on the specific implementation of other functional modules. Other functional modules can independently update and modify the implementation class, as long as it still complies with the CrashHandler interface specification defined in the SPI interface library, the main module does not need to make any modifications. This approach makes the coupling between modules looser and enhances the independence and maintainability of the modules.

[0087] Moreover, the direct calling method has poor scalability. If you want to add a new crash handling strategy or change the implementation of CrashHandler, you may need to modify the code of the main module to adapt to the new implementation class. However, the embodiment of the present invention provides better scalability and flexibility through the SPI method. Without modifying the main module code, you can create a new CrashHandler implementation class in the functional module and update the initialization configuration file to allow the main module to load the new implementation class. For example, during the development process, you can easily add a crash handling implementation class for the test environment and a different implementation class for the production environment. You only need to switch the fully qualified name of the implementation class in the initialization configuration file, and the main module can automatically load and use the new implementation without recompiling the main module.

[0088] In addition, direct calling makes the CrashHandler interface and its implementation class tightly bound in the functional module, making it difficult to reuse the crash handling mechanism in other functional modules or projects. If other functional modules want to use the same crash handling function, they may need the relevant code in the functional module, and also need to deal with issues such as dependencies between modules. However, in an embodiment of the present invention, since the SPI interface library is independent, it can be easily reused by other modules or projects. As long as other functional modules also rely on this SPI interface library and are implemented and configured according to the SPI specification, the same mechanism can be used to load and apply the crash handling function, which improves the reusability of the code and is conducive to sharing common functional modules in multiple projects or modules.

[0089] The embodiments of the present invention can be applied not only to the above-mentioned application scenarios, but also to many different application scenarios. The specific implementation methods can refer to the methods in the above-mentioned application scenarios, which will not be described in detail here.

[0090] The detailed execution process can be referred to the related descriptions in other aforementioned embodiments and will not be repeated here.

[0091] The following will describe in detail the cross-module initialization operation device of one or more embodiments of the present invention. Those skilled in the art will appreciate that these devices can be configured using commercially available hardware components through the steps taught in this solution.

[0092] Figure 4 A schematic diagram of the structure of a cross-module initialization operation device provided by an embodiment of the present invention, the device can be located in a main module in an application, the main module is an entry module in the application, and the application includes a main module and multiple functional modules, such as Figure 4 As shown, the device includes: a response module 11, a traversal module 12, an acquisition module 13, and an initialization module 14.

[0093] The response module 11 is used to obtain an initialization configuration file corresponding to the target functional module in response to an initialization request for the target functional module, wherein the initialization request includes an identifier of the target functional module, and the target functional module is any one of the multiple functional modules.

[0094] The traversal module 12 is used to traverse the initialization configuration file according to the identifier of the target functional module, and determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module.

[0095] The acquisition module 13 is used to acquire the implementation class corresponding to the target functional module according to the fully qualified name.

[0096] The initialization module 14 is used to perform an initialization operation on the target functional module based on the initialization operation method in the implementation class.

[0097] Optionally, the acquisition module 13 is specifically used to: search for the implementation class corresponding to the target functional module through the SPI mechanism according to the fully qualified name; if the implementation class corresponding to the target functional module is found, load the implementation class corresponding to the target functional module.

[0098] Optionally, the device may also include a creation module, which is specifically used to: create an initialization interface corresponding to the multiple functional modules, the initialization interface specifies the rules for initialization operations of the multiple functional modules; obtain configuration information corresponding to the target functional module; and create an implementation class corresponding to the target functional module based on the initialization interface and the configuration information, the implementation class being used to implement the initialization interface.

[0099] Optionally, the device may further include a writing module, which, before obtaining the initialization configuration file corresponding to the target function module, is specifically used to: obtain the identifier of the target function module and the fully qualified name of the implementation class corresponding to the target function module; create a mapping table entry corresponding to the identifier of the target function module, the mapping table entry being used to describe the correspondence between the identifier of the target function module and the fully qualified name of the implementation class corresponding to the target function module; and write the mapping table entry into the initialization configuration file.

[0100] Optionally, the device may further include an execution module, which is specifically used to: obtain an initialization operation result corresponding to the target functional module; if the initialization operation result is successful, call the function provided by the target functional module to perform a corresponding operation.

[0101] Optionally, the initialization operation method is an initialization method corresponding to crash processing, and the initialization module 14 is specifically used to: obtain the context and preset log path parameters corresponding to the application; pass the context and the preset log path parameters into the initialization method corresponding to the crash processing to perform initialization operations on the target functional module.

[0102] Optionally, the execution module can also be used to: call the SPI interface to obtain the device handle corresponding to the target function module; establish a communication connection with the target function module based on the device handle; send the context and preset log path parameters corresponding to the application to the target function module, so that the target function module performs crash processing on the application based on the context corresponding to the application, the preset log path parameters and the crash processing method.

[0103] Figure 4 The device shown can execute the cross-module initialization operation method provided in the aforementioned embodiment. The detailed execution process and technical effects are described in the aforementioned embodiment and will not be repeated here.

[0104] In one possible design, the above Figure 4 The structure of the cross-module initialization operation device shown can be implemented as an electronic device, such as Figure 5 As shown, the electronic device may include: a processor 21, a memory 22, and a communication interface 23. The memory 22 stores executable codes, and when the executable codes are executed by the processor 21, the processor 21 can at least implement the cross-module initialization operation method provided in the above-mentioned embodiment.

[0105] In addition, an embodiment of the present invention provides a non-temporary machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor can at least implement the cross-module initialization operation method provided in the aforementioned embodiment.

[0106] In addition, an embodiment of the present invention provides a computer program product. The computer program product includes a computer program or an instruction. When the computer program or the instruction is executed by a processor, the processor is enabled to implement the above Figure 1-3 The steps or functions of the method shown.

[0107] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. Those of ordinary skill in the art may understand and implement the present invention without creative effort.

[0108] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by combining hardware and software. Based on such an understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a computer product, and the present invention can be in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A cross-module initialization operation method, characterized in that: The method is applied to a main module in an application program, the main module being an entry module of the application program, the application program comprising a main module and a plurality of functional modules, each functional module being dependent on the main module, and the method comprising: In response to an initialization request for a target functional module, acquiring an initialization configuration file corresponding to the target functional module, wherein the initialization request includes an identifier of the target functional module, and the target functional module is any one of the multiple functional modules; Traversing the initialization configuration file according to the identifier of the target functional module to determine the fully qualified name of the implementation class corresponding to the identifier of the target functional module; According to the fully qualified name, obtain the implementation class corresponding to the target functional module; The target functional module is initialized based on the initialization operation method in the implementation class.

2. The method according to claim 1, characterized in that: The step of obtaining the implementation class corresponding to the target functional module according to the fully qualified name includes: According to the fully qualified name, searching for the implementation class corresponding to the target functional module through the SPI mechanism; If the implementation class corresponding to the target functional module is found, the implementation class corresponding to the target functional module is loaded.

3. The method according to claim 1, characterized in that The method further comprises: Creating initialization interfaces corresponding to the multiple functional modules, wherein the initialization interfaces specify rules for performing initialization operations on the multiple functional modules; Obtaining configuration information corresponding to the target functional module; An implementation class corresponding to the target functional module is created according to the initialization interface and the configuration information, wherein the implementation class is used to implement the initialization interface.

4. The method according to claim 1, characterized in that: Before obtaining the initialization configuration file corresponding to the target functional module, the method further includes: Obtaining the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module; Creating a mapping table entry corresponding to the identifier of the target functional module, wherein the mapping table entry is used to describe the corresponding relationship between the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module; The mapping table entry is written into the initialization configuration file.

5. The method according to claim 1, characterized in that The method further comprises: Obtaining the initialization operation result corresponding to the target functional module; If the initialization operation result is that the initialization is successful, the function provided by the target function module is called to perform the corresponding operation.

6. The method according to claim 1, characterized in that The initialization operation method is an initialization method corresponding to the crash processing, and the initialization operation is performed on the target functional module based on the initialization operation method in the implementation class, including: Obtaining the context and preset log path parameters corresponding to the application; The context and the preset log path parameters are passed into the initialization method corresponding to the crash processing to perform an initialization operation on the target functional module.

7. The method according to claim 1, characterized in that The method further comprises: Call the SPI interface to obtain the device handle corresponding to the target functional module; Establishing a communication connection with the target functional module based on the device handle; The context corresponding to the application and the preset log path parameters are sent to the target function module, so that the target function module performs crash processing on the application based on the context corresponding to the application, the preset log path parameters and the crash processing method.

8. An electronic device, characterized in that: include: A memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the cross-module initialization operation method as described in any one of claims 1 to 7.

9. A non-transitory machine-readable storage medium, characterized in that: The non-transitory machine-readable storage medium stores executable code, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the cross-module initialization operation method as described in any one of claims 1 to 7.

10. A computer program product, characterized in that include: A computer program, when executed by a processor of an electronic device, causes the processor to execute the cross-module initialization operation method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Modularized routing decoupling method, storage medium, electronic equipment and system

    CN110795091A

  • Connection method and device, electronic equipment and storage medium

    CN111371851A

  • Vehicle-mounted Android operating system architecture, vehicle-mounted operating system calling method, electronic equipment and storage medium

    CN112380033A

  • Application program modularization method and device, application program component calling method and device, application program component initialization method and device

    CN112698888A

  • Update device memory system and method, and computer storage medium

    CN112905392A