Business interface registration method and device, use method and device, equipment and medium

CN116795336BActive Publication Date: 2026-11-03SHENZHEN XINGUODU TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310745766.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-21
Publication Date
2026-11-03
Estimated Expiration
2043-06-21

AI Technical Summary

Technical Problem

The existing technology for business interface registration methods has the following problems: the existing technology cannot automatically register business interfaces, leading to problems such as forgetting to register, code redundancy, and coding errors.

Method used

By obtaining the target header files and interface files of business requirements during compilation, scanning the interface files using preset matching relationships, creating business objects and global mapping tables, and generating registration files, the automatic registration of business interfaces is achieved.

Benefits of technology

It effectively solves the problems of forgetting to register and coding errors, reduces code redundancy, and improves code maintainability and scalability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116795336B_ABST
    Figure CN116795336B_ABST
Patent Text Reader

Abstract

The application discloses a business interface registration method and device, a use method and device, equipment and a medium, and relates to the technical field of software development. In the business interface registration method, in response to a compilation instruction, a first target header file and an interface file of a business requirement are obtained, the interface file includes a second target header file and a business interface to be registered, the interface file is matched according to a preset matching relationship through scanning, a business interface is obtained, a corresponding business object is created, and a global mapping table of the business interface and the business object is created. Then, a corresponding business callback interface is created according to the business object, the business callback interface is used to create an instantiated business object according to the business interface to process the business requirement. Thus, the business interface is automatically registered, a registration file including the first target header file, the second target header file, the global mapping table and the business callback interface is generated, and problems such as forgetting to register, code redundancy and coding errors are effectively solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of software development technology, and in particular to a business interface registration method and apparatus, a usage method and apparatus, equipment and medium. Background Technology

[0002] In C++ software development, to implement certain functions or business logic, it's necessary to write corresponding functional functions or business processing classes, and then manually register them. However, since manual registration usually occurs during program initialization, it's easily overlooked or forgotten, leading to unusable functionality. Furthermore, requiring registration code for each interface results in code redundancy and is prone to coding errors such as spelling mistakes and parameter errors, increasing the need for debugging and adding extra labor and time costs. Summary of the Invention

[0003] This application aims to address at least one of the technical problems existing in the prior art. To this end, embodiments of this application provide a business interface registration method and apparatus, a usage method and apparatus, a device, and a medium that can automatically register business interfaces during compilation, solving the problem of forgetting to register, and effectively solving the problems of code redundancy and coding errors by automatically generating registration files.

[0004] Firstly, embodiments of this application provide a business interface registration method, including:

[0005] In response to compilation instructions, the system obtains the first target header file and interface file for business requirements; wherein, the interface file includes a second target header file and a business interface to be registered;

[0006] The interface files are scanned and matched according to a preset matching relationship to obtain the business interfaces; wherein, the business interfaces are one or more.

[0007] Create a corresponding business object for the business interface, and create a global mapping table between the business interface and the business object;

[0008] A corresponding business callback interface is created based on the business object; the business callback interface is used to create an instantiated business object based on the business interface, and the instantiated business object is used to handle the business requirements;

[0009] The business interface is automatically registered to generate a registration file; wherein the registration file includes the first target header file, the second target header file, the global mapping table, and the business callback interface.

[0010] In some embodiments of this application, the step of obtaining the first target header file and interface file of the business requirements in response to compilation instructions includes:

[0011] In response to the compilation instructions, the first target header file is obtained; wherein the first target header file is a header file determined according to the business requirements, including at least one of the following: a map header file, a typeinfo header file, or a custom header file;

[0012] Obtain the interface file for the business requirements; wherein, the interface file includes one or more interface sub-files, the interface sub-files are located in the same directory, the interface sub-files include an initial header file and a business interface to be registered, and the initial header file includes the second target header file.

[0013] In some embodiments of this application, the preset matching relationship is a regular expression matching relationship; the step of scanning the interface file and matching the interface file according to the preset matching relationship to obtain the business interface includes:

[0014] The interface sub-files are recursively scanned within the directory of the interface sub-files.

[0015] During each scan, the initial header file of the interface sub-file is matched according to the regular expression matching relationship to obtain the business interface; wherein, the regular expression matching relationship is: (?<=class\s{1})\w+(?=\s*:\s*public\s+business_main_interface), the business interface inherits the business_main_interface, the regular expression matching relationship means matching business interfaces that start with class and inherit the business_main_interface, (?<=class\s{1}) represents matching class and a space, \w+ represents matching one or more letters, numbers or underscores, (?=\s*:\s*public\s+business_main_interface) represents first matching zero or more spaces, matching a colon, then matching zero or more spaces, then matching public and at least one space, and finally matching the business_main_interface;

[0016] Based on the business interface, the second target header file is obtained from the initial header file; wherein the second target header file is a header file containing the business interface.

[0017] In some embodiments of this application, the attributes of the main business interface include: a first attribute and a second attribute, wherein the first attribute is used to determine whether the business interface inheriting the main business interface can handle the business requirement, and the second attribute is used to implement the processing logic of the business interface.

[0018] In some embodiments of this application, std::map is used.<std::string,Base*> Create the global mapping table, where std::string represents the business interface and Base* represents a pointer to the business object.

[0019] Secondly, embodiments of this application also provide a method for using a business interface, including:

[0020] The global mapping table is traversed based on the registration file to determine whether the business object can handle the business requirements; wherein, the registration file is generated by the business interface registration method described in the first aspect embodiment of this application;

[0021] If the business object can handle the business requirement, then the corresponding business callback interface is called to create an instantiated business object according to the corresponding business interface;

[0022] The instantiated business object is invoked to process the business requirement, and the instantiated business object is released after the business requirement is processed.

[0023] Thirdly, embodiments of this application also provide a business interface registration apparatus, which applies the business interface registration method described in the first aspect of this application, including:

[0024] The response module is used to respond to compilation instructions and obtain the first target header file and interface file of the business requirements; wherein, the interface file includes a second target header file and the business interface to be registered;

[0025] A matching module is used to scan the interface file and match the interface file according to a preset matching relationship to obtain the business interface; wherein, the business interface is one or more.

[0026] The mapping module is used to create corresponding business objects for the business interfaces and to create a global mapping table between the business interfaces and the business objects.

[0027] The callback module is used to create a corresponding business callback interface based on the business object; the business callback interface is used to create an instantiated business object based on the business interface, and the instantiated object is used to handle the business requirements;

[0028] The registration module is used to automatically register the business interface and generate a registration file; wherein, the registration file includes the first target header file, the second target header file, the global mapping table, and the business callback interface.

[0029] Fourthly, embodiments of this application also provide a business interface usage apparatus, which applies the business interface usage method described in the second aspect of this application, including:

[0030] The judgment module is used to traverse the global mapping table based on the registration file to determine whether the business object can handle the business requirements; wherein, the registration file is generated by the business interface registration method described in the first aspect embodiment of this application;

[0031] The instantiation module is used to call the corresponding business callback interface to create an instantiated business object according to the corresponding business interface when the business object is able to handle the business requirements.

[0032] The processing module is used to call the instantiated business object to process the business requirement, and release the instantiated business object after the business requirement is processed.

[0033] Fifthly, embodiments of this application also provide an electronic device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the business interface registration method as described in the first aspect of this application or the business interface usage method as described in the second aspect of this application.

[0034] Sixthly, embodiments of this application also provide a computer-readable storage medium storing a program that is executed by a processor to implement the business interface registration method as described in the first aspect of this application or the business interface usage method as described in the second aspect of this application.

[0035] The embodiments of this application include at least the following beneficial effects:

[0036] This application provides a business interface registration method and apparatus, a usage method and apparatus, a device and a medium. In the business interface registration method, in response to compilation instructions, a first target header file and an interface file for business requirements are obtained before compilation. The interface file includes a second target header file and the business interface to be registered. By scanning the interface file and matching it according to a preset matching relationship, one or more business interfaces are obtained. Then, a corresponding business object is created for each business interface, and a global mapping table between the business interface and the business object is created. A corresponding business callback interface is then created based on the business object. Different business callback interfaces are used to create instantiated business objects based on the corresponding business interface to handle business requirements. This automatically registers the business interface, generating a registration file including the first target header file, the second target header file, the global mapping table, and the business callback interfaces, effectively solving problems such as forgetting to register, code redundancy, and coding errors.

[0037] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0038] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0039] Figure 1 This is a flowchart illustrating a business interface registration method provided in one embodiment of this application;

[0040] Figure 2 yes Figure 1 A flowchart illustrating step S102;

[0041] Figure 3 This is a flowchart illustrating a method for using a business interface according to an embodiment of this application;

[0042] Figure 4 This is a schematic diagram of a business interface registration device module provided in one embodiment of this application;

[0043] Figure 5 This is a schematic diagram of a service interface using a device module provided in one embodiment of this application;

[0044] Figure 6 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application.

[0045] Reference numerals: Response module 101, Matching module 102, Mapping module 103, Callback module 104, Registration module 105, Judgment module 201, Instantiation module 202, Processing module 203, Electronic device 1000, Processor 1001, Memory 1002. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0047] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0048] In the description of this application, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0049] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0050] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.

[0051] In object-oriented programming, business interfaces such as business processing classes are typically used to encapsulate specific business logic, providing a higher level of abstraction and encapsulation that makes the code easier to maintain and extend. Business processing classes usually contain methods or functions to execute specific business logic. These methods or functions can read and manipulate data, call other classes or functions, and return results. For example, a bank's business processing class might contain methods such as deposit, withdrawal, and balance inquiry, which implement corresponding business logic such as checking and updating account balances. Business processing classes often work in conjunction with other classes, such as data access object classes for accessing the database and interface control classes for handling the user interface. Together, these classes constitute the overall architecture of the application, implementing various business logics and providing a structured way to organize code.

[0052] Understandably, registering business interfaces such as business processing classes is for decoupling and modularity. In a complex application, business logic often involves collaboration between multiple components and modules. Directly creating and calling instances of business processing classes in the code would result in high coupling, making the code difficult to maintain and extend. Registering business processing classes with the application achieves decoupling and modularity. Specifically, a business processing class can be considered an independent module responsible for handling specific business logic. The application's main class or controller class is responsible for coordinating the interactions between various components, including the business processing classes. By registering business processing classes, the coupling between them and other components is reduced, making the code more modular, reusable, maintainable, and extendable.

[0053] In C++, since there's no automatic mechanism for registering function or business logic classes, manual registration is required. The general process is as follows: First, define a registry to store information about the function or class, such as its name, function pointer, or constructor. Then, at program startup, call the registration function to add the information of the functions or classes to be registered to the registry. Because manual registration typically occurs during program initialization, it's easily overlooked or forgotten, leading to unusable functionality. Furthermore, writing registration code for each interface results in code redundancy and is prone to coding errors, such as spelling mistakes and incorrect parameters, requiring additional debugging and increasing both manual and time costs.

[0054] Based on this, a business interface registration method and apparatus, a usage method and apparatus, a device and a medium are provided. In the business interface registration method, in response to compilation instructions, a first target header file and an interface file for business requirements are obtained before compilation. The interface file includes a second target header file and the business interface to be registered. By scanning the interface file and matching it according to a preset matching relationship, one or more business interfaces are obtained. Then, a corresponding business object is created for each business interface, and a global mapping table between the business interface and the business object is created. A corresponding business callback interface is then created based on the business object. Different business callback interfaces are used to create instantiated business objects based on the corresponding business interface to handle business requirements. This automatically registers the business interface and generates a registration file including the first target header file, the second target header file, the global mapping table, and the business callback interfaces, effectively solving problems such as forgetting to register, code redundancy, and coding errors.

[0055] This application provides a business interface registration method and apparatus, a usage method and apparatus, a device and a medium, which are specifically described through the following embodiments. First, the business interface registration method in this application embodiment is described.

[0056] Reference Figure 1 As shown, this application embodiment provides a business interface registration method, including but not limited to the following steps S101 to S103.

[0057] Step S101: In response to the compilation instructions, obtain the first target header file and interface file of the business requirements.

[0058] In some embodiments, code files are compiled in response to compilation instructions within tools such as Makefiles. A Makefile is a text file used to describe the relationships between source code, object files, and library files in a software project. It is used to automate program building, thereby speeding up the compilation, testing, and deployment process. During compilation, the Makefile can automatically generate object files, check dependencies, and use commands to build and install programs. Compilation is the process of converting source code in a programming language into executable code. During compilation, the compiler converts the source code into object code (such as assembly code or machine code) and packages it into executable files or dynamic link libraries for the computer to run.

[0059] In some embodiments, in response to compilation instructions, before compiling specific modules in the Makefile, the first target header file and interface file required by the business requirements are obtained. The first target header file is a header file determined according to the business requirements, including at least one of the following: a map header file, a typeinfo header file, or a custom header file. Specifically, the map header file is part of the C++ STL (Standard Template Library), which provides an associative container that stores keys and values ​​together and sorts them according to the key order; the typeinfo header file is a type information library provided by C++ STL, mainly used to obtain the type information of objects at runtime; the custom header file is a self-written function library file containing header file contents such as functions and macro definitions, facilitating multiple calls in different programs and increasing reusability. It is understood that, depending on different business requirements, the first target header file may also include general header files such as vector header files, string header files, and algorithm header files; this embodiment of the application does not limit this.

[0060] In some embodiments, an interface file is a code file used to handle business requirements. The interface file includes one or more interface sub-files located in the same directory for easy calling and use by the program or system. Each interface sub-file includes an initial header file and a business interface to be registered. The initial header file includes a second target header file. Specifically, the initial header file consists of all relevant header files used by the interface sub-files, and the second target header file is the header file corresponding to the business interface to be registered.

[0061] Step S102: Scan the interface files and match them according to the preset matching relationship to obtain the business interface.

[0062] In some embodiments, relevant scanning tools can be used to scan the interface files. For example, grep is a powerful command-line tool used to search for matching text lines in the interface files based on preset matching relationships; another example is ack, a powerful code search tool that supports matching using preset matching relationships such as regular expressions and can quickly locate matching items in code files. This implementation does not impose any restrictions on this. Thus, by matching the interface files according to the preset matching relationships, business interfaces that match the preset matching relationships can be obtained.

[0063] Step S103: Create a corresponding business object for the business interface, and create a global mapping table between the business interface and the business object.

[0064] In some embodiments, corresponding business objects are created for each business interface. An object is an abstract concept representing a collection of properties and methods in an interface, such as a class in C++. It is understood that after creating the corresponding business objects, different business interfaces correspond to different business objects. This further leads to the creation of a global mapping table between business interfaces and business objects. Based on this global mapping table, business requirements can be processed quickly and efficiently using the corresponding business interfaces.

[0065] In some embodiments, a global mapping table is created using the map container from the C++ STL standard library; specifically, the std::map container is used.<std::string,Base*> A global mapping table is created, where `std::string` represents the business interface, and `Base*` represents a pointer to a business object. This means that `std::string` keys are mapped to pointers to `base` type objects, storing business objects with the string of the business interface as the key. The corresponding business object can be found and accessed based on the string. For example, the global mapping table is shown below, indicating the creation of a global variable named `g_handlers`, which is a `std::map` object with two template parameters: the first is `std::string`, representing the key type, and the second is `IHandler*`, representing the value type. String keys are mapped to `IHandler` type values, so the corresponding value can be found by the key, facilitating the use of the appropriate business interface for processing according to different business needs. For example, `typeid(*pCGenCSR).name()` retrieves the business interface name of `*pCGencsr` and then points to the corresponding business object.

[0066] std::map<std::string,IHandler*> g_handlers={

[0067] {typeid(*pCGenCSR).name(),pCGenCSR},

[0068] {typeid(*pCMyTest).name(),pCMyTest},

[0069] {typeid(*pCSymKeyEncDec).name(),pCSymKeyEncDec},

[0070] {typeid(*pCRSAKeyEncDec).name(),pCRSAKeyEncDec},

[0071] {typeid(*pCSignAndVerify).name(),pCSignAndVerify},

[0072] }

[0073] Step S104: Create the corresponding business callback interface based on the business object.

[0074] In C++, callback interfaces are used to execute predefined functions when a specific event or operation occurs. In some embodiments, business callback interfaces are created based on business objects; thus, by calling the business callback interface, the corresponding business object can be created. Specifically, when processing related business requirements, the business requirements can be processed by creating the corresponding business object based on the business interface through the business callback interface.

[0075] Step S105: Automatically register the business interface and generate a registration file.

[0076] In some embodiments, the script for automatic registration is a shell script, and the generated registration file is a .cpp file. Specifically, the shell script does not need to be compiled, while the .cpp file refers to a source code file written in C++, which can be compiled into an executable file. The registration file includes a first target header file, a second target header file, a global mapping table, and a business callback interface, thereby realizing the automatic registration of business interfaces and effectively solving problems such as forgetting to register, code redundancy, and coding errors.

[0077] Reference Figure 2 As shown, in some embodiments of this application, step S102 may include, but is not limited to, steps S201 to S203.

[0078] Step S201: Recursively scan the interface subfiles within the directory of the interface subfiles.

[0079] In some embodiments, each interface sub-file is recursively scanned within the directory containing the interface sub-files. Specifically, the relevant scanning code can be written in the automatically registered shell script, and the scanning can be performed simply by running the corresponding script in the terminal. This embodiment does not impose any restrictions on this approach.

[0080] Step S202: During each scan, the initial header file of the interface sub-file is matched according to the regular expression matching relationship to obtain the business interface.

[0081] In some embodiments, the preset matching relationship is a regular expression matching relationship. During each scan, the initial header file of the interface sub-file is matched according to the regular expression matching relationship to match the specific business interface. For example, the regular expression matching relationship is: (?<=class\s{1})\w+(?=\s*:\s*public\s+business_main_interface), where the business interface in this embodiment inherits from the business_main_interface. This regular expression matching relationship indicates matching business interfaces that start with class and inherit from the business_main_interface. Specifically, (?<=class\s{1}) represents matching class and a space, using the "zero-width positive lookahead assertion" of the regular expression; \w+ represents matching one or more letters, numbers, or underscores; (?=\s*:\s*public\s+business_main_interface) uses the "zero-width positive lookahead assertion", which means first matching zero or more spaces, then matching a colon, then matching zero or more spaces, then matching public and at least one space, and finally matching the business_main_interface.

[0082] In some embodiments, the main business interface is a base class in C++, while the business interfaces are derived classes that inherit from the base class. The base class is an abstract class that cannot be instantiated; it defines its attributes through pure virtual functions. Derived classes inherit from the base class and implement the corresponding pure virtual functions. In object-oriented programming, the base class refers to the class inherited by derived classes; it is also called the parent class or superclass. Member variables and member functions in the base class can be inherited and used by derived classes.

[0083] It is understandable that, since business interfaces inherit from the main business interface, the definition of a business interface is in the form of "class xxx:public main business interface". Therefore, the main business interface can be matched and each business interface can be identified by using the regular expression (?<=class\s{1})\w+(?=\s*:\s*public\s+main business interface).

[0084] In some embodiments, the main business interface defines a first attribute and a second attribute through pure virtual functions. The first attribute is used to determine whether a business interface inheriting from the main business interface can handle the business requirement, and the second attribute is used to implement the processing logic of the business interface. For example, the main business interface is IHandle, the first attribute is CanHandle, and the second attribute is HandleRequest. CanHandle receives a request parameter and returns a boolean value indicating whether the current business interface can handle the business request. HandleRequest receives a request parameter and performs specific processing logic on the business request. This embodiment does not impose any limitations on this.

[0085] Step S203: Based on the business interface, obtain the second target header file from the initial header file.

[0086] In some embodiments, a second target header file corresponding to the business interface is obtained from the initial header file. For example, when the processing logic of the business interface is to perform encryption or decryption operations on the Windows operating system, the corresponding second target header file includes the KeyImportExport header file. The KeyImportExport header file is used to perform encryption / decryption operations on the Windows operating system and provides many function and structure declarations for importing and exporting public and private keys.

[0087] This application also provides a method for using a business interface, as described in the embodiments below. Figure 3 As shown, the usage method of the business interface may include, but is not limited to, the following steps S301 to S303.

[0088] Step S301: Based on the registration file, traverse the global mapping table to determine whether the business object can handle the business requirements.

[0089] In some embodiments, when processing business requirements, the global mapping table in the registration file is traversed to determine whether the business object can handle the business requirement. Specifically, the first property of the business object is called to determine whether the current business object can handle the requirement. When the bool value of the first property is 0 or false, it means that the business object cannot handle the business requirement; when the bool value of the first property is 1 or true, it means that the business object can handle the business requirement.

[0090] Step S302: If the business object can handle the business requirements, then call the corresponding business callback interface to create an instantiated business object according to the corresponding business interface.

[0091] In some embodiments, if it is determined through the first attribute that the business object can handle the corresponding business requirement, then the corresponding business callback interface is invoked to create an instantiated business object based on the corresponding business interface. Specifically, the business callback interface is invoked to create an instantiated business object, and the second attribute of the business interface is invoked through the instantiated business object to handle the specific business requirement.

[0092] Understandably, in object-oriented programming, instantiating business objects is necessary because a business interface is merely an abstract model or blueprint that describes the attributes and methods an object should possess. To use the attributes and methods defined by a business interface, an actual business object with those attributes and methods needs to be created—that is, the business object is instantiated. Through instantiation, multiple different business objects with the same attributes and methods can be created, and different operations and processes can be performed on them. Furthermore, instantiating business objects can protect the data and methods of the business interface from modification by other code.

[0093] Step S303: Invoke the instantiated business object to process the business requirements, and release the instantiated business object after the business requirements are processed.

[0094] In some embodiments, an instantiated business object is invoked to handle business requirements, and the instantiated business object is released after the business requirements are processed. It is understandable that instantiated objects in a program require a certain amount of memory space. If instantiated objects are not used for a long time and are not released, these objects will continue to occupy memory space, causing the program to run slowly and potentially leading to memory overflow problems. Therefore, when the program finishes execution or when an instantiated object is no longer needed, the object needs to be released to reclaim memory space and improve the program's execution efficiency and performance.

[0095] This application also provides a business interface registration device that can implement the above-described business interface registration method, see below. Figure 4 As shown, in some embodiments of this application, the service interface registration device includes:

[0096] The response module 101 is used to respond to compilation instructions and obtain the first target header file and interface file of the business requirements; wherein, the interface file includes the second target header file and the business interface to be registered;

[0097] The matching module 102 is used to scan the interface files and match them according to the preset matching relationship to obtain the business interfaces; wherein, the business interfaces are one or more.

[0098] The mapping module 103 is used to create corresponding business objects for business interfaces and to create a global mapping table between business interfaces and business objects.

[0099] Callback module 104 is used to create corresponding business callback interfaces based on business objects; the business callback interface is used to create instantiated business objects based on business interfaces, and the instantiated objects are used to handle business requirements.

[0100] The registration module 105 is used to automatically register business interfaces and generate registration files; the registration files include a first target header file, a second target header file, a global mapping table, and business callback interfaces.

[0101] The specific implementation of the business interface registration device in this embodiment is basically the same as the specific implementation of the business interface registration method described above, and will not be repeated here.

[0102] This application also provides a business interface usage apparatus, which can implement the above-described business interface usage method, see reference. Figure 5 As shown, in some embodiments of this application, the service interface usage device includes:

[0103] The judgment module 201 is used to traverse the global mapping table based on the registration file to determine whether the business object can handle the business requirements; wherein, the registration file is generated by the business interface registration method described in the first aspect embodiment of this application;

[0104] Instantiation module 202 is used to call the corresponding business callback interface to create an instantiated business object based on the corresponding business interface when the business object is able to handle the business requirements.

[0105] Processing module 203 is used to call the instantiated business object to process business requirements and release the instantiated business object after the business requirements are processed.

[0106] The specific implementation of the business interface usage device in this embodiment is basically the same as the specific implementation of the business interface usage method described above, and will not be repeated here.

[0107] Figure 6 An electronic device 1000 provided in an embodiment of this application is shown. The electronic device 1000 includes: a processor 1001, a memory 1002, and a computer program stored on the memory 1002 and executable on the processor 1001. When the computer program is executed, it is used to perform the above-described business interface registration method or business interface usage method.

[0108] The processor 1001 and the memory 1002 can be connected via a bus or other means.

[0109] The memory 1002, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs, such as the business interface registration method or business interface usage method described in the embodiments of this application. The processor 1001 implements the above-described business interface registration method or business interface usage method by running the non-transitory software program and instructions stored in the memory 1002.

[0110] The memory 1002 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function. The data storage area may store the business interface registration method or business interface usage method described above. Furthermore, the memory 1002 may include high-speed random access memory (RAM) and non-transitory memory, such as at least one storage device, flash memory, or other non-transitory solid-state storage device. In some embodiments, the memory 1002 may optionally include remotely located memories 1002 relative to the processor 1001, which can be connected to the electronic device 1000 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks (LANs), mobile communication networks, and combinations thereof.

[0111] The non-transient software program and instructions required to implement the above-described business interface registration method or business interface usage method are stored in memory 1002. When executed by one or more processors 1001, the above-described business interface registration method or business interface usage method is executed, for example, executing... Figure 1 Method steps S101 to S105, Figure 2 Method steps S201 to S203, Figure 3 The method steps S301 to S303.

[0112] This application also provides a storage medium, which is a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the aforementioned business interface registration method or business interface usage method. The memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, the memory may include high-speed random access memory and non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, enterprise intranets, local area networks, mobile communication networks, and combinations thereof.

[0113] The business interface registration method, apparatus, usage method, apparatus, device, and medium provided in this application embodiment include the following: In the business interface registration method, in response to compilation instructions, a first target header file and an interface file for business requirements are obtained before compilation. The interface file includes a second target header file and the business interface to be registered. By scanning the interface file and matching it according to a preset matching relationship, one or more business interfaces are obtained. Then, a corresponding business object is created for each business interface, and a global mapping table between the business interface and the business object is created. Then, a corresponding business callback interface is created based on the business object. Different business callback interfaces are used to create instantiated business objects based on the corresponding business interface to handle business requirements. This automatically registers the business interface and generates a registration file including the first target header file, the second target header file, the global mapping table, and the business callback interface, effectively solving problems such as forgetting to register, code redundancy, and coding errors.

[0114] The embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0115] Those skilled in the art will understand that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, storage device storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically include computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0116] It should also be understood that the various implementation methods provided in this application can be combined arbitrarily to achieve different technical effects. The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the above-described embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application.

Claims

1. A method for registering a business interface, characterized in that, include: In response to compilation instructions, the system obtains the first target header file and interface file for business requirements; wherein, the interface file includes a second target header file and a business interface to be registered; The interface files are scanned and matched according to a preset matching relationship to obtain the business interfaces; wherein, the business interfaces are one or more. Create a corresponding business object for the business interface, and create a global mapping table between the business interface and the business object; A corresponding business callback interface is created based on the business object; the business callback interface is used to create an instantiated business object based on the business interface, and the instantiated business object is used to handle the business requirements; The business interface is automatically registered to generate a registration file; wherein, the registration file includes the first target header file, the second target header file, the global mapping table, and the business callback interface; The step of obtaining the first target header file and interface file of the business requirements in response to the compilation instruction includes: obtaining the first target header file in response to the compilation instruction; wherein the first target header file is a header file determined according to the business requirements, including at least one of the following: a map header file, a typeinfo header file, or a custom header file; obtaining the interface file of the business requirements; wherein the interface file includes one or more interface sub-files, the interface sub-files are located in the same directory, the interface sub-files include an initial header file and a business interface to be registered, and the initial header file includes the second target header file; The preset matching relationship is a regular expression matching relationship; the step of scanning the interface file and matching the interface file according to the preset matching relationship to obtain the business interface includes: The interface sub-files are recursively scanned within their respective directories. During each scan, the initial header file of the interface sub-file is matched against a regular expression to obtain the business interface. The regular expression is: (?<=class\s{1})\w+(?=\s :\s `public\s+business_main_interface`, where the business interface inherits from the business_main_interface. The regular expression matching relationship indicates matching business interfaces that start with `class` and inherit from the business_main_interface. `(?<=class\s{1})` represents matching `class` and a space. `\w+` represents matching one or more letters, numbers, or underscores. `(?=\s` :\s `public\s+business_main_interface)` means first matching zero or more spaces, then matching a colon, then matching zero or more spaces, then matching `public` and at least one space, and finally matching `business_main_interface`; based on the business interface, the second target header file is obtained from the initial header file; wherein, the second target header file is a header file containing the business interface.

2. The business interface registration method according to claim 1, characterized in that, The main business interface has the following attributes: a first attribute and a second attribute. The first attribute is used to determine whether the business interface that inherits from the main business interface can handle the business requirement, and the second attribute is used to implement the processing logic of the business interface.

3. The business interface registration method according to claim 1, characterized in that, Use std::map <std::string,Base Create the global mapping table, where std::string represents the business interface, and Base... This represents a pointer to the business object.

4. A method for using a business interface, characterized in that, include: The global mapping table is traversed based on the registration file to determine whether the business object can handle the business requirements; wherein, the registration file is generated by the business interface registration method according to any one of claims 1 to 3; If the business object can handle the business requirement, then the corresponding business callback interface is called to create an instantiated business object according to the corresponding business interface; The instantiated business object is invoked to process the business requirement, and the instantiated business object is released after the business requirement is processed.

5. A business interface registration device, characterized in that, The apparatus comprising the service interface registration method as described in any one of claims 1 to 3, wherein the apparatus includes: The response module is used to respond to compilation instructions and obtain the first target header file and interface file of the business requirements; wherein, the interface file includes a second target header file and the business interface to be registered; A matching module is used to scan the interface files and match them according to a preset matching relationship to obtain the business interfaces; wherein, the business interfaces are one or more. The mapping module is used to create corresponding business objects for the business interfaces and to create a global mapping table between the business interfaces and the business objects. The callback module is used to create a corresponding business callback interface based on the business object; the business callback interface is used to create an instantiated business object based on the business interface, and the instantiated object is used to handle the business requirements; The registration module is used to automatically register the business interface and generate a registration file; wherein, the registration file includes the first target header file, the second target header file, the global mapping table, and the business callback interface; The step of obtaining the first target header file and interface file of the business requirements in response to the compilation instruction includes: obtaining the first target header file in response to the compilation instruction; wherein the first target header file is a header file determined according to the business requirements, including at least one of the following: a map header file, a typeinfo header file, or a custom header file; obtaining the interface file of the business requirements; wherein the interface file includes one or more interface sub-files, the interface sub-files are located in the same directory, the interface sub-files include an initial header file and a business interface to be registered, and the initial header file includes the second target header file; The preset matching relationship is a regular expression matching relationship; the step of scanning the interface file and matching the interface file according to the preset matching relationship to obtain the business interface includes: The interface sub-files are recursively scanned within their respective directories. During each scan, the initial header file of the interface sub-file is matched against a regular expression to obtain the business interface. The regular expression is: (?<=class\s{1})\w+(?=\s :\s `public\s+business_main_interface`, where the business interface inherits from the business_main_interface. The regular expression matching relationship indicates matching business interfaces that start with `class` and inherit from the business_main_interface. `(?<=class\s{1})` represents matching `class` and a space. `\w+` represents matching one or more letters, numbers, or underscores. `(?=\s` :\s `public\s+business_main_interface)` means first matching zero or more spaces, then matching a colon, then matching zero or more spaces, then matching `public` and at least one space, and finally matching `business_main_interface`; based on the business interface, the second target header file is obtained from the initial header file; wherein, the second target header file is a header file containing the business interface.

6. A business interface application device, characterized in that, The device comprising: The judgment module is used to traverse the global mapping table based on the registration file to determine whether the business object can handle the business requirements; wherein, the registration file is generated by the business interface registration method according to any one of claims 1 to 3; The instantiation module is used to call the corresponding business callback interface to create an instantiated business object according to the corresponding business interface when the business object is able to handle the business requirements. The processing module is used to call the instantiated business object to process the business requirement, and release the instantiated business object after the business requirement is processed.

7. An electronic device, characterized in that, It includes a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, it implements the business interface registration method as described in any one of claims 1 to 3 or the business interface usage method as described in claim 4.

8. A computer-readable storage medium, characterized in that, The storage medium stores a program, which is executed by a processor to implement the business interface registration method as described in any one of claims 1 to 3 or the business interface usage method as described in claim 4.