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

By using a cross-module initialization operation method and dynamically loading implementation classes through initialization configuration files and the SPI mechanism, the problem of high coupling between modules in existing technologies is solved, and the decoupling of the main module and the target functional module is achieved, thereby enhancing the flexibility of the system.

CN119883389BActive Publication Date: 2026-01-23BEIJING 58 INFORMATION TTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411961107.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2026-01-23
Estimated Expiration
2044-12-27

AI Technical Summary

Technical Problem

In existing technologies, when the main module performs initialization operations on the target functional module, it needs to obtain the class names of the relevant classes corresponding to the target functional module in order to locate the implementation class of the target functional module, which results in excessive coupling and makes it difficult to maintain and extend independently.

Method used

A cross-module initialization operation method is adopted. By obtaining the initialization configuration file of the target functional module, the fully qualified name of the implementation class is determined according to the identifier, and the implementation class is dynamically loaded using the SPI mechanism to realize cross-module initialization operation and reduce the coupling between modules.

Benefits of technology

This decouples the main module from the target functional module, enhancing the system's flexibility and scalability, and reducing the difficulty of code maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883389B_ABST
    Figure CN119883389B_ABST
Patent Text Reader

Abstract

The application provides a cross-module initialization operation method, device, storage medium and program product. The method comprises the following steps: in response to an initialization request of a target function module, the request comprising an identifier of the target function module; according to the identifier of the target function module, a preset initialization configuration file is traversed to determine a full qualified name of an implementation class corresponding to the identifier of the target function module; according to the full qualified name, the implementation class corresponding to the target function module is acquired; and the target function module is initialized based on an initialization operation method in the implementation class. According to the above scheme, the full qualified name of the implementation class corresponding to the target function module is written into the initialization configuration file in advance. When the main module performs an initialization operation on the target function module, the corresponding implementation class can be directly read from the configuration file, and the initialization operation is performed based on the initialization operation method in the implementation class. In this way, the specific implementation details of the target function module do not need to be known, and the initialization operation can be completed across modules.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This 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 Technology

[0002] Currently, applications developed based on the HarmonyOS system typically employ a modular design. An application consists of a main module and multiple functional modules, each of which 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 invoking them.

[0003] In existing initialization schemes, the main module obtains the relevant classes declared by the target functional module, dynamically creates instances of each relevant class in the target functional module using reflection based on the class names, and calls the initialization methods within the relevant classes to initialize the target functional module. This approach requires the main module to obtain the class names of each relevant class to locate the corresponding implementation class of the target functional module during initialization. However, if the class name of a relevant class in the target functional module changes, or if a new relevant class is added or deleted, code modification is required, resulting in high coupling and hindering application code maintainability. Summary of the Invention

[0004] This invention provides a cross-module initialization operation method, device, storage medium, and program product to decouple the initialization operation and achieve uncoupled, cross-module initialization operation.

[0005] In a first aspect, embodiments of the present invention provide a cross-module initialization operation method, the method being applied to a main module within an application, the main module being the entry module of the application, the application including the main module and multiple functional modules, each functional module depending on the main module, the method comprising:

[0006] 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 request includes an identifier of the target functional module, and the target functional module is any one of the plurality of functional modules;

[0007] Based on 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;

[0008] Based on 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] Secondly, embodiments of the present invention provide a cross-module initialization operation device, the device comprising:

[0011] A response module is used to respond to an initialization request for a target functional module and obtain an initialization configuration file corresponding to the target functional module. The initialization request includes an identifier of the target functional module, and the target functional module is any one of the plurality of functional modules.

[0012] The traversal module 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;

[0013] The acquisition module is used to acquire the implementation class corresponding to the target functional module based on the fully qualified name;

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

[0015] Thirdly, embodiments of the present invention provide an electronic device, including: 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 as described in the first aspect.

[0016] Fourthly, embodiments of the present invention provide a non-transitory machine-readable storage medium storing executable code, wherein when the executable code is executed by a processor of a transmission device, the processor is able to at least implement the cross-module initialization operation method as described in the first aspect.

[0017] Fifthly, embodiments of the present invention provide a computer program product, the computer program product including a computer program or instructions, which, when executed by a processor, causes the processor 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 this embodiment of the invention, the scheme is applied to the main module within an application. This application includes a main module and multiple functional modules. The main module is the entry point module of the application, and each functional module depends on the main module. The main module can perform initialization operations on each functional module across modules, thereby decoupling the dependencies between the main module and each functional module.

[0019] Specifically, in response to an initialization request for a target functional module, the corresponding initialization configuration file is obtained. This initialization request includes the identifier of the target functional module. The target functional module can be any one of multiple functional modules within the application. Then, based on 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 that identifier. Based on the fully qualified name of the implementation class corresponding to the target functional module, the corresponding implementation class is obtained. Finally, the target functional module is initialized using the initialization operation methods in its corresponding implementation class.

[0020] In the above scheme, 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 initialization operations on the target functional module, it can directly read the corresponding implementation class of the target functional module from the initialization configuration file, and then perform initialization operations on the target functional module based on the initialization operation methods in the implementation class. This achieves that the main module no longer directly references the implementation class in the target functional module to perform initialization operations. In this way, it is no longer necessary to know the specific implementation details of the target functional module or manually instantiate the implementation class, and the initialization operation can be completed across modules, thus achieving decoupling between the main module and the target functional module. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

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

[0023] Figure 2 A flowchart for initializing a target functional module is provided in an embodiment of the present invention;

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

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

[0026] Figure 5 To and Figure 4 The illustrated embodiment provides a schematic diagram of the electronic device corresponding to the cross-module initialization operation device. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0028] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Where there is no conflict between the embodiments, the following embodiments and features can be combined with each other. Furthermore, the timing of the steps in the following method embodiments is merely an example and not a strict limitation.

[0029] In the current initialization scheme, when the main module initializes the target functional module, it first needs to read the relevant classes declared by the target functional module and their class names from the module.json file. Then, it obtains the paths and configuration information of each relevant class in the target functional module. Based on the class names and paths, it locates and loads the relevant classes. Next, it uses reflection to dynamically create instances of each relevant class in the target functional module and calls the initialization methods within the relevant classes to initialize the target functional module.

[0030] However, this approach requires the main module to obtain the class names of all related classes corresponding to the target functional module to locate the corresponding implementation class of the target functional module and instantiate that implementation class to complete the initialization operation. Therefore, if the class name of the related class corresponding to the target functional module changes, or if a new related class is added or an existing related class is deleted from the target functional module, code modifications are required, resulting in excessive coupling and hindering application code maintainability.

[0031] To address the aforementioned technical problems, this invention provides a cross-module initialization scheme. The main module and multiple functional modules all rely on an independent SPI interface library module. The SPI interface library contains only an initialization interface definition and the specific implementation logic. Each functional module provides its own initialization implementation based on the initialization interface definition, and writes the fully qualified names of the corresponding implementation classes of each functional module into the initialization configuration file. Thus, through the SPI mechanism, the main module only needs to know the initialization interface and the fully qualified names of the corresponding implementation classes of each functional module found in the initialization configuration file. It can then dynamically find and load the implementation classes 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. This effectively reduces the coupling between modules and enhances the system's flexibility and scalability.

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

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

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

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

[0036] 102. Traverse 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.

[0037] 103. Obtain the implementation class corresponding to the target functional module based on the fully qualified name.

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

[0039] The cross-module initialization operation method provided in this embodiment of the invention can be applied to the main module within a patterned application. When the main module calls various functional modules within the application, it can perform cross-module initialization operations on each functional module without coupling, thereby reducing the coupling between the main module and each functional module.

[0040] The specific implementation process of the main module in initializing the various functional modules within the application is largely the same. In this embodiment of the invention, only the initialization operation of the target functional module is described by way of example. The target functional module is any one of the multiple functional modules within the application.

[0041] In practice, in response to an initialization request for the target functional module, the system retrieves the initialization configuration file corresponding to the target functional module. This initialization configuration file stores the fully qualified name of the implementation class corresponding to the target functional module, so that the main module can subsequently locate the corresponding implementation class.

[0042] In this context, the implementation class corresponding to the target functional module refers to the concrete class that implements the initialization interface. This implementation class contains the specific initialization methods corresponding to the target functional module. That is, the implementation class follows the predefined initialization interface rules to ensure that all functional modules adhere to a unified method signature and behavior specification. Each functional module can be developed, tested, and deployed independently of other modules, as long as it meets the requirements of the initialization interface definition.

[0043] Before performing initialization operations, the main module can pre-create initialization interfaces for multiple functional modules. These interfaces define the rules for initialization operations of each functional module. In this way, the main module can dynamically load and initialize each functional module without directly referencing the specific implementation classes, achieving decoupling between modules and increasing system flexibility.

[0044] Once a standard initialization interface is created, implementation classes for each functional module within the application can be created according to the initialization interface definition. The specific process for creating these implementation classes can be as follows: obtain the configuration information for the target functional module; based on the initialization interface and the configuration information, create the implementation class for the target functional module, which is used to implement the initialization interface.

[0045] After creating the corresponding implementation classes for the target functional modules, the fully qualified names of the implementation classes can be written 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 the class name.

[0046] In an alternative embodiment, the initialization configuration file corresponding to the target function module can be added to a specific path corresponding to the target function, and the file name of the initialization configuration file can be the full package name of the initialization interface.

[0047] To improve the lookup speed of the fully qualified name of the implementation class corresponding to the target functional module, the fully qualified name of the implementation class corresponding to the target functional module stored in the initialization configuration file can be stored in the form of a mapping table entry. Specifically, the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module are obtained, a mapping table entry corresponding to the identifier of the target functional module is created, and the mapping table entry is used to describe the correspondence 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 then written to the initialization configuration file.

[0048] In this way, when responding to an 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, based on 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. This can be achieved by using the SPI (Service Provider Interface) mechanism.

[0050] Specifically, based on the fully qualified name, the implementation class corresponding to the target functional module is located using the SPI mechanism. If the implementation class is found, it is loaded. Then, the target functional module is initialized based on the initialization methods in the implementation class.

[0051] Loading the implementation class corresponding to the target functional module only loads the definition of the implementation class into memory, but does not create an instance of that 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 these implementation classes are not automatically instantiated.

[0052] In this embodiment of the invention, the target functional module acts as a service provider, providing its own concrete implementation class that implements the initialization interface. In specific implementation, the target functional module can publish a device service so that the main module can discover and load the corresponding implementation class of the target functional module at runtime.

[0053] Therefore, the main module only needs to know the initialization interface (defined in a separate SPI interface library module) to find the implementation class that implements this interface at runtime. This is similar to a "plugin" mechanism; the main module can discover and load "plugins" (i.e., implementation classes of the initialization interface) that conform to the interface specification without needing to know the implementation details in advance. In other words, the SPI mechanism makes the dependency between the main module and the target functional module loose. Both the main module and the sub-module depend on a separate SPI interface library module, which only contains the initialization interface definition and no specific implementation logic.

[0054] In summary, this embodiment of the invention, by pre-writing the fully qualified name of the implementation class corresponding to the target functional module into the initialization configuration file, allows the main module to directly read the corresponding implementation class of the target functional module from the initialization configuration file when it needs to perform initialization operations on the target functional module. Then, based on the initialization operation method in the implementation class, the main module no longer needs to directly reference the implementation class in the target functional module to perform initialization operations. This eliminates the need to know the specific implementation details of the target functional module or manually instantiate the implementation class, enabling cross-module initialization operations and achieving decoupling between the main module and the target functional module.

[0055] The following section, using specific application scenarios, details the implementation process of initializing the target functional module by calling the initialization operation method in the implementation class corresponding to the target functional module in the above embodiments.

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

[0057] 201. Obtain the application's context and preset log path parameters.

[0058] 202. Pass the context and preset log path parameters to the initialization method corresponding to the crash handling to perform initialization operations on the target functional module.

[0059] Once the implementation class corresponding to the target functional module is loaded, the initialization operation method in the implementation class can be called to initialize the target functional module. Specifically, the application context and preset log path parameters are obtained. These parameters are then passed to the initialization method corresponding to the crash handling to perform the initialization operation on the target functional module.

[0060] The context of the application can include configuration information, log records, cache, etc. This information in the context of the application helps the main module understand its running environment, configuration status, and interaction method with the target functional module, so as to complete the initialization operation of the target functional module.

[0061] After the main module calls the initialization method in the implementation class to initialize the target functional module, it can obtain the initialization result of the target functional module. Based on the initialization result, it can determine whether the initialization operation on the target functional module was successful. If the initialization result is successful, the corresponding operation is performed by calling the functions provided by the target functional module.

[0062] The following embodiments will be used to describe in detail the specific implementation process of the main module performing corresponding operations on the functions provided by the target functional module.

[0063] Figure 3 A flowchart of another cross-module initialization operation provided in an embodiment of the present invention, such as... Figure 3 As shown, based on the above embodiments, 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 the target functional module based on the device handle.

[0066] 303. Send the application's context and preset log path parameters to the target functional module so that the target functional module can perform crash handling on the application based on the application's context, preset log path parameters, and crash handling method.

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

[0068] The SPI interface defines a series of general methods for operating various functional modules within the application, covering methods for obtaining and releasing device handles for functional modules, reading and writing data, custom transmission methods, and configuring device attributes. Furthermore, an SPI interface can be defined in a separate SPI interface library and can be shared by the main module and all functional modules.

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

[0070] In one optional embodiment, the specific implementation process of obtaining the device handle corresponding to the target functional module may include: calling the method for obtaining the device handle corresponding to the functional module to obtain the bus number and chip select number corresponding to the target functional module. If successful, the bus number and chip select number corresponding to the target functional module are returned; if unsuccessful, NULL is returned.

[0071] Once the device handle corresponding to the target functional module is obtained, the device attributes of the target functional module can be configured first. For example, the operating mode, clock polarity and phase, data size (e.g., 8-bit or 16-bit), and transmission rate of 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] Once the main module establishes communication with the target functional module, it can send the application's context and preset log path parameters to the target functional module, so that the target functional module can perform crash handling on the application based on the application's context, preset log path parameters, and crash handling method.

[0073] Specifically, based on the device handle corresponding to the target functional module, the online status of the storage application, the buffer pointer of the preset log path parameters, and the length of data to be read, the read / write data methods can be invoked to obtain the context of the application and the preset log path parameters. Data is then sent to the target functional module via the MOSI line, enabling the target functional module to handle application crashes.

[0074] Similarly, after the target functional module completes crash handling for the application, it can send the crash handling results and crash handling records to the main module. The main module can receive the crash handling results and crash handling records sent by the target functional module via the MISO line.

[0075] In this embodiment of the invention, a communication connection is established with the target functional module based on the device handle, and the context corresponding to the application and the preset log path parameters are sent to the target functional module. This allows the target functional module to perform crash handling on the application based on the context corresponding to the application, the preset log path parameters, and the crash handling method. This decouples the initialization operation from the crash handling operation and can better maintain the operation of the application.

[0076] To facilitate understanding, the specific implementation process of cross-module initialization operations in the above embodiments is illustrated with examples from specific application scenarios. First, a unified CrashHandler interface is created for initialization operations to handle crash handling. Furthermore, the CrashHandler interface includes an init method, which provides the entry point for initializing the crash handling logic. In this way, different crash handling strategies can be flexibly implemented, ensuring that all implementations adhere to a unified standard.

[0077] The Crash Handler interface can be defined in the SPI interface library, and it serves as a standard for defining a crash handling mechanism. Any class implementing this interface needs to provide an `init` method to initialize the crash handling logic. The `init` method receives a `Context` object to obtain the application's context information and a log file path.

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

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

[0080] This approach eliminates the need for the main module to directly reference the implementation classes in the functional modules, avoiding the coupling issues that can arise from traditional direct dependencies between modules. For example, without the Crash Handler interface, the main module might need to import the functional module via `implementation project()` or other strong dependencies. This would require corresponding code modifications to the main module should changes to the functional module (e.g., class name or method signature changes). The above method allows the functional modules to develop and update their implementation classes independently, as long as they still conform to the interface definition, the main module can function correctly.

[0081] Next, configure the initialization configuration file, writing the fully qualified names of the implementation classes corresponding to each functional module into the initialization configuration file.

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

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

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

[0085] As described above, defining the CrashHandler interface directly in other functional modules and having the main module call it directly leads to tight coupling between the main module and other functional modules. The main module needs to be fully aware of the internal structure of other functional modules, including the package path of the interface and the specific definition details of the interface. Therefore, when the interface definition of other functional modules changes—for example, adding parameters to the interface method, changing the return type, or changing the package name of the interface—the code in the main module may need to be modified accordingly. This strong coupling reduces the independence between modules, hindering independent development, testing, and maintenance of each module.

[0086] However, in this embodiment of the invention, using SPI technology, the main module and multiple functional modules all depend on an independent SPI interface library module. The main module is only coupled to the interface definitions in the SPI interface library, and does not directly depend on the specific implementations of other functional modules. Other functional modules can independently update and modify their implementation classes, as long as they still conform to the CrashHandler interface specification defined in the SPI interface library, without requiring any modifications to the main module. This approach makes the coupling between modules looser, enhancing module independence and maintainability.

[0087] Furthermore, the direct invocation method has poor extensibility. Adding a new crash handling strategy or changing the implementation of CrashHandler might require modifying the main module's code to accommodate the new implementation class. However, this embodiment of the invention provides better extensibility and flexibility through the SPI approach. It allows the main module to load the new implementation class without modifying the main module's code, by creating a new CrashHandler implementation class in the functional module and updating the initialization configuration file. For example, during development, it's easy to add a crash handling implementation class for the testing environment and a different implementation class for the production environment. Simply changing the fully qualified name of the implementation class in the initialization configuration file allows the main module to automatically load and use the new implementation without recompiling the main module.

[0088] Furthermore, direct calls tightly bind the CrashHandler interface and its implementation class to the functional module, making it difficult to reuse this crash handling mechanism in other functional modules or projects. Other functional modules wishing to use the same crash handling functionality might require related code within that module and would also need to handle inter-module dependencies. However, in this embodiment of the invention, because the SPI interface library is independent, it can be easily reused by other modules or projects. As long as other functional modules also depend on this SPI interface library and implement and configure it according to the SPI specification, they can use the same mechanism to load and apply the crash handling functionality. This improves code reusability and facilitates the sharing of common functional modules across 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 be referred to the methods in the above-mentioned application scenarios, and will not be described in detail here.

[0090] The detailed execution process can be found in the descriptions of the other embodiments mentioned above, and will not be repeated here.

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

[0092] Figure 4 This is a schematic diagram of a cross-module initialization operation device provided in an embodiment of the present invention. The device can be located in the main module of an application, where the main module is the entry module. The application includes one 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 respond to an initialization request for a target functional module and obtain an initialization configuration file corresponding to the target functional module. The initialization request includes an identifier of the target functional module, and the target functional module is any one of the plurality of functional modules.

[0094] Traversal module 12 is used to traverse 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.

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

[0096] Initialization module 14 is used to perform initialization operations 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: find the implementation class corresponding to the target functional module through the SPI mechanism based on the fully qualified name; if the implementation class corresponding to the target functional module is found, then load the implementation class corresponding to the target functional module.

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

[0099] Optionally, the apparatus may further include a writing module. Before obtaining the initialization configuration file corresponding to the target functional module, the writing module is specifically configured to: obtain the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module; create a mapping table entry corresponding to the identifier of the target functional module, the mapping table entry being used to describe the correspondence between the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional 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 the initialization operation result corresponding to the target functional module; if the initialization operation result is successful, then call the function provided by the target functional module to perform the corresponding operation.

[0101] Optionally, the initialization operation method is an initialization method corresponding to crash handling, and the initialization module 14 is specifically used to: obtain the context and preset log path parameters corresponding to the application; and pass the context and the preset log path parameters to the initialization method corresponding to crash handling to perform initialization operation 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 functional module; establish a communication connection with the target functional module based on the device handle; and send the context corresponding to the application and the preset log path parameters to the target functional module, so that the target functional module can perform crash handling on the application based on the context corresponding to the application, the preset log path parameters, and the crash handling method.

[0103] Figure 4 The device shown can execute the cross-module initialization operation method provided in the foregoing embodiments. For details of the execution process and technical effects, please refer to the description in the foregoing embodiments, which 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 code, which, when executed by the processor 21, enables the processor 21 to at least implement the cross-module initialization operation method provided in the foregoing embodiments.

[0105] In addition, embodiments of the present invention provide a non-transitory machine-readable storage medium storing executable code, which, when executed by a processor of an electronic device, enables the processor to at least implement the cross-module initialization operation method provided in the foregoing embodiments.

[0106] In addition, embodiments of the present invention provide a computer program product. This computer program product includes a computer program or instructions. When the computer program or instructions are executed by a processor, the processor is able to perform the above-described functions. Figure 1-3 The steps or functions of the method shown.

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

[0108] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of a necessary general-purpose hardware platform, or by a combination of hardware and software. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a computer product. The present invention can take 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 code.

[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate 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 the main module within an application, which is the entry point of the application. The application includes the main module and multiple functional modules, all of which depend on an SPI interface library. The SPI interface library contains an initialization interface, which includes an initialization interface definition. Each functional module depends on the main module. The method includes: 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 the identifier of the target functional module, and the initialization configuration file includes the fully qualified names of the implementation classes corresponding to the plurality of functional modules. The target functional module is any one of the plurality of functional modules. Based on 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; Using the SPI mechanism, the implementation class corresponding to the target functional module is located and loaded according to the initialization interface and the fully qualified name. The implementation class is the specific initialization implementation provided by the target functional module according to the definition of the initialization interface. The target functional module is initialized based on the initialization operation method in the implementation class. The initialization interface defines a series of general methods for operating various functional modules, including 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.

2. The method according to claim 1, characterized in that, The step of obtaining the implementation class corresponding to the target functional module based on the fully qualified name includes: Based on the fully qualified name, the implementation class corresponding to the target functional module is found using the SPI mechanism; If the implementation class corresponding to the target functional module is found, then the implementation class corresponding to the target functional module is loaded.

3. The method according to claim 1, characterized in that, The method further includes: An initialization interface is created corresponding to the multiple functional modules, and the initialization interface specifies the rules for the multiple functional modules to perform initialization operations; Obtain the configuration information corresponding to the target functional module; Based on the initialization interface and the configuration information, an implementation class corresponding to the target functional module is created, and 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: Obtain the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module; Create a mapping table entry corresponding to the identifier of the target functional module. The mapping table entry is used to describe the correspondence between the identifier of the target functional module and the fully qualified name of the implementation class corresponding to the target functional module. Write the mapping entries into the initialization configuration file.

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

6. The method according to claim 1, characterized in that, The initialization operation method is the initialization method corresponding to crash handling. The initialization operation of the target functional module based on the initialization operation method in the implementation class includes: Obtain the context and preset log path parameters corresponding to the application; The context and the preset log path parameter are passed to the initialization method corresponding to the crash handling to perform initialization operations on the target functional module.

7. The method according to claim 1, characterized in that, The method further includes: Call the SPI interface to obtain the device handle corresponding to the target functional module; Based on the device handle, a communication connection is established with the target functional module; The context corresponding to the application and the preset log path parameters are sent to the target functional module so that the target functional module can perform crash handling on the application based on the context corresponding to the application, the preset log path parameters, and the crash handling method.

8. An electronic device, characterized in that, include: The system includes 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 performs 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 that, when executed by a processor of an electronic device, causes the processor to perform 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 perform the cross-module initialization operation method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Connection method and device, electronic equipment and storage medium

    CN111371851A

  • Profile service architecture

    US6757720B1