Function-as-a-service implementation method and unknown type function calling method and system

By defining the base class and template subclass of known types in C++ language, unknown type functions are implemented, function-as-a-service is solved, and the problem of saving and calling unknown type functions is improved, and calling efficiency and scalability are improved.

CN119179469APending Publication Date: 2024-12-24XJ GRP CORP +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310747890.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-21
Publication Date
2024-12-24

AI Technical Summary

Technical Problem

In service programs implemented in C++ language, due to the strong type mechanism, pointers of unknown types cannot be defined, and the storage and calling of unknown types cannot be supported, making functions as services difficult to apply, resulting in low call efficiency and poor scalability.

Method used

By defining the base class of a known type and a template subclass used to match unknown type functions, the unknown type function is encapsulated in the template subclass, and the base class of the known type is called to the template subclass to implement the unknown type function's Register and call, borrow the defined base class type to generate encapsulation definitions of functions of unknown type.

Benefits of technology

It solves the problem that unknown type functions cannot be saved and called, improves the efficiency of calling function functions, simplifies the testing and integration process of service software, and improves the scalability of software applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119179469A_ABST
    Figure CN119179469A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of software engineering design, and particularly relates to a function as a service implementation method and an unknown type function calling method and system. An unknown type definition is packaged in a template subclass, then a base class of a known type is called to a subclass of the unknown type, equivalently, an unknown type function is packaged into a type corresponding to the base class of the known type, and on the basis that the unknown type function is not defined, by means of the type of the defined base class, the function of the known type is called to the subclass of the unknown type. According to the method, the packaging definition of the function of the unknown type is generated, and the problem that the unknown type cannot be stored and called is solved, so that the function-as-a-service can be realized under the service program system realized by the C + + language, the calling efficiency of the subsequent performance function is improved, and the expandability of software application is improved; in addition, the method can be compiled and generated into an executive program or a library, and when function expansion is needed, the performance function is directly called through the scheme of the invention, so that corresponding function services can be provided, and more efficient and simpler function expansion is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of software engineering design, and specifically relates to a function-as-a-service implementation method, an unknown type function calling method and a system. Background Art

[0002] The function service program in the existing technology runs on a physical machine and is usually implemented in C++. At present, the conventional implementation method of implementing service functions in the C++ technology stack requires the implementation of a series of functions including port monitoring, link keep-alive, identity authentication, permission identification, data transmission encryption, etc., which requires high personnel quality, and the testing and integration of service software are relatively complex. Function as a service means that when a new service is needed, that is, when an extended function needs to be called, you only need to create a function. After the function is submitted and loaded and run, it can provide the service. The current mainstream function as a service is a form of cloud computing, which is implemented based on the microservice framework. The typical way to call extended functions is registration and callback mechanisms, such as Figure 1 and Figure 2 As shown, it can be seen that function as a service can improve calling efficiency, simplify the testing and integration process of service software, and improve the scalability of software applications.

[0003] However, in terms of service programs implemented in C++, due to the strong typing mechanism of C++, that is, the calling object must be a function of a known type, a pointer of an unknown type cannot be defined, and an unknown defined function type cannot be saved in a conventional way. Therefore, it is impossible to support data types defined in the "future", and it is difficult to achieve the corresponding function-as-a-service effect, which makes it difficult to apply function-as-a-service to the physical machine where the existing service program runs, resulting in low calling efficiency of service functions in the C++ technology stack and poor scalability of software applications. Summary of the invention

[0004] The purpose of the present invention is to provide a function-as-a-service implementation method, an unknown type function calling method and system, which are used to solve the problem that function-as-a-service is difficult to apply to the physical machine running the existing service program implemented based on the C++ language, resulting in low calling efficiency of the service function and poor scalability of the software application.

[0005] In order to achieve the above object, the present invention provides a method for implementing function as a service, the steps of which are as follows:

[0006] 1) defining basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types;

[0007] 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0008] 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

[0009] The beneficial effects of the above technical solution are as follows: by encapsulating an unknown type definition in a template subclass, and then calling the unknown type subclass through a known type base class, it is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is borrowed to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved. In this way, function as a service can be realized in the service program system implemented in C++ language, thereby improving the efficiency of calling subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications.

[0010] Furthermore, the basic content required for the function call also includes a list for saving registration results, which is used to record registered functions so that the called function can be found when a call is required later.

[0011] The present invention also provides a function-as-a-service system, comprising a processor, wherein the processor is used for the following steps:

[0012] 1) defining basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types;

[0013] 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0014] 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

[0015] The beneficial effects of the above technical solution are as follows: by encapsulating an unknown type definition in a template subclass, and then calling the unknown type subclass through a known type base class, it is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is borrowed to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved. In this way, function as a service can be realized in the service program system implemented in C++ language, thereby improving the efficiency of calling subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications.

[0016] Furthermore, the basic content required for the function call also includes a list for saving registration results.

[0017] The present invention also provides a method for calling a function of an unknown type, the steps of which are as follows:

[0018] 1) defining the basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types and callback functions corresponding to the function calls;

[0019] 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0020] 3) Define a registration function. When an unknown type function needs to be registered, instantiate the template subclass generated in step 2) that corresponds to the base class of the known type and encapsulates the unknown type function that needs to be called, so as to realize the registration of the unknown type function that needs to be called; and call the corresponding template subclass according to the base class of the known type and the callback function corresponding to the function call, so as to realize the call of the unknown type function that needs to be called.

[0021] The beneficial effects of the above technical solution are as follows: by encapsulating an unknown type definition in a template subclass, and then calling the unknown type subclass through a known type base class, it is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is borrowed to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved. In this way, function as a service can be realized in the service program system implemented in C++ language, thereby improving the efficiency of calling subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications.

[0022] Furthermore, the basic content required for the function call also includes a list for saving registration results.

[0023] The present invention also provides an unknown type function calling system, comprising a processor, wherein the processor is used for the following steps:

[0024] 1) defining the basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types and callback functions corresponding to the function calls;

[0025] 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0026] 3) Define a registration function. When an unknown type function needs to be registered, instantiate the template subclass generated in step 2) that corresponds to the base class of the known type and encapsulates the unknown type function that needs to be called, so as to realize the registration of the unknown type function that needs to be called; and call the corresponding template subclass according to the base class of the known type and the callback function corresponding to the function call, so as to realize the call of the unknown type function that needs to be called.

[0027] The beneficial effects of the above technical solution are as follows: by encapsulating an unknown type definition in a template subclass, and then calling the unknown type subclass through a known type base class, it is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is borrowed to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved. In this way, function as a service can be realized in the service program system implemented in C++ language, thereby improving the efficiency of calling subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications.

[0028] Furthermore, the basic content required for the function call also includes a list for saving registration results, which is used to record registered functions so that the called function can be found when a call is required later. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a flowchart of a registration mechanism for calling an extended function in the background technology of the present invention;

[0030] Figure 2 It is a flowchart of a callback mechanism for calling an extended function in the background technology of the present invention;

[0031] Figure 3It is a flowchart of function expansion based on function as a service in the embodiment of the unknown type function calling method of the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described in detail below with reference to the accompanying drawings and embodiments.

[0033] Unknown type function calling method implementation example

[0034] This embodiment provides a technical solution for a method for calling a function of an unknown type, and the steps are as follows:

[0035] 1) Define the basic content required for function calling. In this embodiment, the basic content required for defining function calling includes a base class of a known type and a callback function corresponding to the function call, and also includes a list for saving registration results. The list saves the known type objects after encapsulating the unknown type, which is used to determine the corresponding unknown type function through the known type when the function needs to be called, so that the called function can be found when it needs to be called later. This step is implemented in C++ language as follows:

[0036] class IInvoke{

[0037] public:

[0038] virtual void func();

[0039] };

[0040] QMap<QString,IInvoke*> funs;

[0041] void call(QString topic){

[0042] if (_funs.contains(topic)){

[0043] _funs[topic]->func();

[0044] }

[0045] };

[0046] Among them, IInvoke is the base class of the defined known type, QMap<QString,IInvoke*> The funs function is used to save the list of registration results, and void call (QString topic) is a function for calling the extended function according to the registration name. In this embodiment, the registered function name corresponding to the registration result can be a descriptive symbol (such as a string).

[0047] 2) Define a template subclass for matching unknown type functions, encapsulate the unknown type function to be called in the template subclass, and call the base class of the known type defined in step 1) to the defined template subclass, and generate a template subclass corresponding to the base class and encapsulating the unknown type function to be called; this step is implemented in C++ language as follows:

[0048] template<class T,typename RT>

[0049] class ImplP0:public IInvoke{

[0050] typedef RT(T::*fun)();

[0051] public:

[0052] ImplP0(T*impl,fun ifun):IInvoke(),_f(impl),_funp(ifun){};

[0053] inline void func(){

[0054] (_f->*_funp)();

[0055] };

[0056] protected:

[0057] fun_funp;

[0058] T*_f;

[0059] };

[0060] Among them, ImplP0 is a template subclass used to match unknown type functions, and ImplP0(T*impl,fun ifun):IInvoke(),_f(impl),_funp(ifun){} is a template subclass generated corresponding to the base class IInvoke and encapsulating the unknown type function that needs to be called.

[0061] The unknown type function calling method of this embodiment encapsulates the unknown type definition in a template subclass, and then calls the unknown type subclass through the known type base class. This is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is used to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved.

[0062] 3) Define the registration function. When the unknown type function needs to be registered, instantiate the template subclass generated in step 2) that corresponds to the base class of the known type and encapsulates the unknown type function to be called, so as to realize the registration of the unknown type function to be called. In this way, the function as a service can be realized in the service program system implemented in C++ language, thereby improving the calling efficiency of subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications; and according to the base class of the known type and the callback function corresponding to the function call, call the corresponding template subclass that encapsulates the unknown type function to be called, so as to realize the calling of the unknown type function to be called; the registration function defined in this step is implemented in C++ language as follows:

[0063] template<class T,typename RT>

[0064] void regFun(QString topic,T*ct,RT(T::*funp)()){

[0065] ImplP0*=new ImplP0<T,RT> (ct, funp);

[0066] Funs[topic] = ImplP0;

[0067] };

[0068] In this embodiment, the above-mentioned unknown type function calling step can be compiled and generated into an execution program or library. When the function is expanded in the future, there is no need to modify the already generated program (that is, there is no need to add new definitions). The corresponding function function is directly created. By calling the function function through the unknown type function calling method step, the corresponding function service can be provided, thereby realizing more efficient and simpler function expansion; specifically, the function expansion method refers to Figure 3 The first step is to define the function to be extended, the second step is to implement the definition to create the function implementation body, the third step is to call the function registration, the third step function registration will trigger the fourth step to generate the corresponding subclass through template instantiation according to the function registration content, the fifth step is to convert the instantiated subclass into the defined base class object, and the sixth step is to register the base class object to the function list; the function extension effect of the above function extension method steps implemented by C++ language is as follows:

[0069] class TestA(){

[0070] public:

[0071] TestA();

[0072] void printa();

[0073] }

[0074] TestA::TestA(){

[0075] regFun("PA",this,&TestA::printa);

[0076] }

[0077] void TestA::printa(){

[0078] qDebug()<<"A";

[0079] }

[0080] Among them, TestA::printa() is an unknown type function that needs to be called, that is, an extended function function, and "PA" is the function name of TestA::printa() encapsulated according to the unknown type function calling method of this embodiment. According to the above program content, call("PA") is executed at any call to the extended function to call the TestA::printa function and output "A". These calling locations do not require the definition of the class TestA, so there is no need to add the definition of the extended function, and when the function printa is upgraded, no modification is required at other calling functions, and the new function can be used through the unknown type function calling method of this embodiment.

[0081] In summary, the unknown type function calling method of this embodiment uses a template class to encapsulate an unknown defined type, and through the preprocessing mechanism of the template compilation period, borrows the type of the defined base class to automatically generate the encapsulation definition of the undefined type, thereby solving the problem of preserving the undefined type. The call to the free expansion function can then be completed through the callback mechanism, thereby realizing function-based expansion, so that the function can be expressed as a service being called, thereby achieving the effect of calling an undefined function through a descriptive symbol (that is, the base class of a known type).

[0082] Unknown type function call system implementation example

[0083] This embodiment provides a technical solution for an unknown type function calling system, including a processor, the processor is used for the following steps, i.e., the steps corresponding to the above-mentioned unknown type function calling method:

[0084] 1) defining the basic content required for a function call. In this embodiment, the basic content required for defining a function call includes a base class of a known type and a callback function corresponding to the function call;

[0085] 2) define a template subclass for matching unknown type functions, encapsulate the unknown type function to be called in the template subclass, and call the defined base class of known type to the defined template subclass, to generate a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0086] 3) Define a registration function. When an unknown type function needs to be registered, instantiate the template subclass generated in step 2) that corresponds to the base class of the known type and encapsulates the unknown type function that needs to be called, so as to realize the registration of the unknown type function that needs to be called; and call the corresponding template subclass according to the base class of the known type and the callback function corresponding to the function call, so as to realize the call of the unknown type function that needs to be called.

[0087] Since the specific examples and principles of the unknown type function calling system in this embodiment have been described in detail in the above-mentioned unknown type function calling method, they will not be repeated here.

[0088] Function as a Service Implementation Method Embodiment

[0089] This embodiment provides a technical solution for a method for implementing a function as a service, and the steps are as follows:

[0090] 1) Define the basic content required for function calling. In this embodiment, the basic content required for defining the function calling includes a base class of a known type and a list for storing registration results; wherein the base class of a known type can be a descriptive symbol (such as a string).

[0091] 2) define a template subclass for matching unknown type functions, encapsulate the unknown type function to be called in the template subclass, and call the defined base class of known type to the defined template subclass, to generate a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0092] The function-as-a-service implementation method of this embodiment encapsulates an unknown type definition in a template subclass, and then calls the unknown type subclass through a known type base class. This is equivalent to encapsulating the unknown type function as a type corresponding to a known type base class. Without defining the unknown type function, the type of the defined base class is used to generate an encapsulation definition of the unknown type function, thereby solving the problem that the unknown type cannot be saved and called.

[0093] 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

[0094] In this embodiment, the above-mentioned function-as-a-service implementation method can be compiled and generated into an execution program or library. When the function is expanded in the future, there is no need to modify the already generated program (that is, there is no need to add new definitions). The corresponding function function can be directly created, and the function function can be called through the function-as-a-service implementation method to provide the corresponding function service, thereby achieving more efficient and simpler function expansion.

[0095] Since the specific examples and principles of the function-as-a-service implementation method in this embodiment have been described in detail in the above-mentioned unknown type function calling method, they will not be repeated here.

[0096] Function as a Service System Implementation

[0097] This embodiment provides a technical solution for a function-as-a-service system, including a processor, which is used for the following steps, i.e., the steps corresponding to the above-mentioned function-as-a-service implementation method:

[0098] 1) Define the basic content required for function calls, including base classes of known types;

[0099] 2) define a template subclass for matching unknown type functions, encapsulate the unknown type function to be called in the template subclass, and call the defined base class of known type to the defined template subclass, to generate a template subclass corresponding to the base class and encapsulating the unknown type function to be called;

[0100] 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

[0101] Since the specific examples and principles of the function-as-a-service system in this embodiment have been described in detail in the above-mentioned unknown type function calling method and function-as-a-service implementation method, they will not be repeated here.

[0102] The present invention has the following characteristics:

[0103] By encapsulating an unknown type definition in a template subclass and then calling the unknown type subclass through a known type base class, it is equivalent to encapsulating the unknown type function into a type corresponding to a known type base class. On the basis of not defining the unknown type function, the type of the defined base class is used to generate an encapsulation definition of the unknown type function. Therefore, the problem that the unknown type cannot be saved and called can be solved. In this way, function as a service can be realized in the service program system implemented in C++ language, thereby improving the efficiency of calling subsequent functional functions, simplifying the testing and integration process of service software, and improving the scalability of software applications.

[0104] Furthermore, the unknown type function calling method steps of the present invention can be used to compile and generate an execution program or library. When the functions are expanded in the future, there is no need to modify the already generated program (that is, there is no need to add new definitions). The corresponding function functions can be directly created. By calling the function functions through the unknown type function calling method steps, the corresponding function services can be provided, thereby achieving more efficient and simpler function expansion.

[0105] It should be understood that the above specific embodiments of the present invention are only used to illustrate or explain the principles of the present invention, but do not constitute a limitation to the present invention.

Claims

1. A method for implementing function as a service, characterized in that: Here are the steps: 1) defining basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types; 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called; 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

2. The method for implementing function as a service according to claim 1, characterized in that: The basic content required for the function call also includes a list for saving registration results, which is used to record the registered functions so that the called function can be found when it is needed to be called later.

3. A function-as-a-service system, characterized in that: The method comprises a processor configured to: 1) defining basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types; 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called; 3) When an unknown type function needs to be registered, the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called is instantiated to realize the registration of the unknown type function to be called.

4. The function-as-a-service system according to claim 3, characterized in that: The basic content required for the function call also includes a list for saving registration results.

5. A method for calling a function of unknown type, characterized in that: Here are the steps: 1) defining the basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types and callback functions corresponding to the function calls; 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called; 3) defining a registration function, when an unknown type function needs to be registered, instantiating the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called, so as to realize the registration of the unknown type function to be called; And according to the base class of the known type and the callback function corresponding to the function call, the corresponding template subclass is called to implement the call of the unknown type function that needs to be called.

6. The method for calling a function of unknown type according to claim 5, characterized in that: The basic content required for the function call also includes a list for saving registration results.

7. A system for calling a function of an unknown type, characterized in that: The method comprises a processor configured to: 1) defining the basic content required for function calls, wherein the basic content required for defining function calls includes base classes of known types and callback functions corresponding to the function calls; 2) defining a template subclass for matching unknown type functions, encapsulating the unknown type function to be called in the template subclass, and calling the defined base class of the known type to the defined template subclass, generating a template subclass corresponding to the base class and encapsulating the unknown type function to be called; 3) defining a registration function, when an unknown type function needs to be registered, instantiating the template subclass generated in step 2) corresponding to the base class of the known type and encapsulating the unknown type function to be called, so as to realize the registration of the unknown type function to be called; And according to the base class of the known type and the callback function corresponding to the function call, the corresponding template subclass is called to implement the call of the unknown type function that needs to be called.

8. The unknown type function calling system according to claim 7, characterized in that: The basic content required for the function call also includes a list for saving registration results, which is used to record the registered functions so that the called function can be found when it is needed to be called later.