Disclosure of Invention
The invention provides a method and a device for calling a function, which can call the function in a general way.
In order to achieve the purpose, the technical scheme of the invention is realized as follows:
a method of calling a function, the method comprising:
extracting interface information of a function in application software;
registering interface information of the extracted function in a database;
externally issuing interface information of the function in the database;
receiving a command for calling the function input by a user, searching the interface information of the corresponding function in the database, and calling the function by using the searched interface information.
Preferably, the method further comprises: registering physical binding information of the function in the database;
when the interface information of the function is found in the database, the method further includes: finding out the physical binding information of the function;
the step of calling the function by using the interface information of the searched function comprises the following steps: and carrying out validity check on the parameter assignment input by the user according to the searched interface information of the functional function, and calling the functional function according to the searched physical binding information after the validity check is passed.
Specifically, the method further comprises: distributing corresponding function identification for interface information and physical binding information of the registered function;
the step of externally issuing the interface information of the function in the database comprises the following steps: externally issuing each functional function identification, and when a user selects one functional function identification, externally issuing interface information of a functional function corresponding to the selected functional function identification in the database;
and if the command for calling the function input by the user comprises a function identifier, finding the interface information of the corresponding function and the physical binding information of the function in the database according to the function identifier.
Preferably, the step of registering the interface information of the extracted function in the database includes: and converting the extracted interface information of the functional function into a readable structured document format, and writing the interface information of the functional function into a corresponding directory classification position in a database according to the functional hierarchical relationship of software where the functional function is located.
Specifically, the extracting interface information of the function in the application software is:
determining a function of the application software to be used according to the service requirement of a specific calling party system using the application software, and extracting function interface information of the application software to be used;
or,
and respectively extracting the interface information of all the function functions in all the application software.
Specifically, the step of extracting interface information of a function in application software specifically includes:
loading a Dynamic Link Library (DLL) module file in application software; analyzing type library information in a DLL module file to obtain a class object; and analyzing and extracting the functional function interface information in the class object.
An apparatus for calling a function, the apparatus comprising: an extraction module, a registration module, a database, a view accessor, and a unified proxy middleware, wherein,
the extraction module is used for extracting the interface information of the function in the application software;
the registration module is used for registering the interface information of the function extracted by the extraction module in a database;
the viewing accessor is used for receiving the query of the user and displaying the interface information of the function in the database to the user;
and the unified agent middleware is used for searching the interface information of the corresponding function in the database according to a command for calling the function, which is transmitted by a user, and calling the function by using the searched interface information.
Preferably, the registration module further registers the physical binding information of the function in the database;
the unified agent middleware further searches the interface information of the corresponding function in the database according to the command for calling the function, carries out validity check on the parameter assignment input by the user according to the searched interface information of the function, and calls the function according to the searched physical binding information after the validity check is passed.
Specifically, the registration module further allocates a corresponding function identifier to interface information and physical binding information of the registered function;
the viewing access server is used for externally publishing each function identification, and when detecting that a user selects one function identification, the viewing access server externally publishes interface information of the function corresponding to the selected function identification in the database;
and the unified agent middleware searches the interface information of the corresponding function and the physical binding information of the function in the database according to the function identification in the function calling command.
Preferably, the registration module converts the extracted interface information of the function into a readable structured document format, and then registers the interface information of the function at a corresponding directory classification position in a database according to the function hierarchical relationship of the software where the function is located.
Preferably, the view accessor comprises an interaction module and a code generation module, wherein,
the interaction module is used for receiving a command for inquiring the function input by a user and displaying interface information of the function in the database to the user;
and the code generation module is used for generating and creating a unified agent middleware object code according to the function interface information inquired in the interaction module, automatically generating a parameter assignment code of the function according to the parameter information in the function interface information, and automatically generating a code for calling the function through the unified agent middleware and a code for acquiring a calling result through the unified agent middleware.
Therefore, in the invention, because the interface information of the function in the application software can be extracted, and is uniformly registered in the database, uniformly issued, and the search of the interface information of the function and the call of the function are uniformly carried out, a uniform mode for checking and calling the function is provided for users, and the users do not need to care about the technical details for calling the function in each software application system. Therefore, the invention can call the function in a general way, thereby greatly simplifying the realization of the service.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
The invention provides a method for calling a function, which has the core idea that: extracting interface information of a function in application software; registering interface information of the extracted function in a database; externally issuing interface information of the function in the database; receiving a command for calling a function input by a user, searching the interface information of the function in a database, and calling the function by using the searched interface information.
Therefore, in the invention, because the interface information of the function in the application software can be extracted, and is uniformly registered in the database, uniformly issued, and the search of the interface information of the function and the call of the function are uniformly carried out, a uniform mode for checking and calling the function is provided for users, and the users do not need to care about the technical details for calling the function in each software application system. Therefore, the invention can call the function in a general way, thereby greatly simplifying the realization of the service.
Fig. 1 is a flowchart of a function call according to an embodiment of the present invention. Referring to fig. 1, in an embodiment of the present invention, a process of calling a function specifically includes the following steps:
step 101: and extracting interface information of the functional function in the application software.
The purpose of extracting the functional function interface information in this step is to centrally register and manage these scattered functional interfaces in the following process, so as to facilitate the calling of external users in the following process.
The invention can be applied in various service scenes, and correspondingly, the interfaces of the function functions extracted in the step are different aiming at different service scenes.
For example, one service scenario is: according to the service requirement of the specific caller system using the application software, the function of the application software to be used is determined, and thus, in this step 101, only the interface information of the function of the application software to be used is extracted. For example, the calling system is a purchasing system, and a payment function in the financial application software must be called subsequently, so in this step, interface information of the payment function is extracted.
For another example, another service scenario is: since the development will be in the direction of a standard business logic layer with a layered structure application software in the future, that is, each part of the function of the application software is realized in a layered manner, of course, the interface of the function of the application software needs to be used as a single layer and is open to the outside. For such services, in this step 101, interface information of all function functions in all application software is extracted respectively.
The specific implementation process of the step may include:
1011. loading a Dynamic Link Library (DLL) module file in application software, specifically, locating a physical location of a disk where the DLL module file is located, generally representing the location by a file path, and then reading the DLL module file.
1012. Class objects (Class) in the DLL module file are parsed. The DLL module file generally contains type library information, and a specific class object information can be acquired by analyzing the type library information. The object information of the analysis class is used for obtaining the definition of the function interface.
1013. Functional Function (Function) interface information (metadata) in the class object is parsed and extracted. The class object comprises all the function functions realized by the class object, the information such as the Parameter (Parameter), the Parameter name, the Parameter Type (Type), the Parameter transfer Direction (Direction) and the like of the function can be obtained by analyzing the interface information of the function, and the Parameter information is extracted to be used as the interface information of the function, so that after subsequent registration and publication, the outside can know how to carry out Parameter assignment when calling the interface of the function. For example, referring to fig. 1B, for the function a, the interface information obtained and subsequently registered is as shown in fig. 1B.
The function of extracting the interface information of the function is not limited to supporting the component DLL of COM and NET under the Windows platform.
Step 102: the interface information of the extracted function is registered in a database.
Preferably, in order to perform centralized registration in a standard and consistent manner, so as to facilitate uniform management and maintenance of interface information, in this step, interface information of the extracted function may be registered in the database according to a specified internal specification and a function organization structure.
Wherein the specified internal specification may be: the interface information of the function is described by a readable structured text format (such as XML), which includes Parameter (Parameter), Parameter Type (Type), Parameter transfer Direction (Direction), and other information. Wherein the specified functional organizational structure may be: and classifying the directories of the functional function interfaces according to the functional hierarchical relationship of the software. Thus, the specific implementation process of this step may include: and converting the extracted interface information of the function into a readable structured document format, and then writing the interface information of the current function into a corresponding directory classification position in the database according to the function hierarchical relationship of the software where the current function is located.
For example, for the supply system and the purchase order submission, wherein the purchase order submission is a function in the supply system, and the functional level relationship is a parent-child relationship, so that when finally registered in the database, the functional organization structure is the catalog classification shown in fig. 2.
Step 103: physical binding information of the function is registered in the database.
When a function is called, the operating system of the computer needs to know the address of the function, the calling mode, and other information, which are called physical binding information, such as: server name and program ID information of COM component under Windows platform, DLL file path, Class name (Class) of Net component under Windows platform, etc.
In the invention, in order to shield the technical details of the function from the calling party (outside) in the subsequent process, namely, the physical binding information is only used internally, the external calling party can call the function without concerning the information, knowing the physical deployment position of a DLL module file of the function, knowing whether the function is based on COM or on Net platform, and concerning the Class object (Class) for realizing the function, in the step, the physical binding information of the function is also registered in the database. The processing mode reduces the coupling, reduces the technical dependence degree of an external system on an internal interface, and simultaneously ensures that the calling of an external user is not influenced by the change of the internal function of the software, thereby embodying the technical idea of Service Oriented Architecture (SOA).
Step 104: and distributing a function identifier for the function, and setting the corresponding relation between the registered function interface information and the physical binding information and the function identifier.
In order to distinguish the registration of information of different function functions, in this step, a unique function identifier is assigned to each function. The processing of this step is to make the external calling party able to conveniently inquire the interface information of the function through the function identifier in the subsequent process, thereby directly calling a function.
Step 105: and externally issuing interface information of the function in the database and the corresponding function identification.
If a function is to be called, the external caller must know the parameter information of the function in order to assign values to the parameters, and therefore, the interface information of the function needs to be externally issued.
In the actual service implementation, if the interface information of all the function functions is directly displayed and issued to the outside, the amount of information is too large, and the calling party cannot conveniently find the function to be called. Therefore, in a preferred embodiment of the present invention, in order to solve the problem, the interface information of the function may be firstly issued not directly to the outside, but each function identifier is issued to the outside, the information of each function is visually displayed to the caller through the function identifier, if the user is interested in a certain function and needs to know the registration information, the corresponding function identifier may be clicked, and thus, when it is detected that the user selects one function identifier, the interface information of the function corresponding to the selected function identifier is issued to the outside.
It should be noted that, if in step 102, the interface information of each function is registered in a directory classification manner, in this step, when the interface information of each function is issued, the interface information of each function is also issued in a directory classification manner, so that the calling user can distinguish the hierarchical relationship between the function functions.
Step 106: when a user needs to call a function (for convenience of description, it is referred to as function 1 hereinafter), a command for calling function 1 is input, specifically, the command may be to trigger function identifier 1 of function 1, and perform parameter assignment according to the issued interface information of function 1.
In a preferred embodiment of the present invention, the publishing process in step 105 may be performed by a preset view accessor, through which the user views the interface information and the identifier of each registered function. Thus, in this step 106, the user can assign a parameter according to the interface information of the function displayed by the viewing accessor.
Step 107: and searching functional function interface information and physical binding information corresponding to the triggered functional function identifier 1 in a database.
Step 108: and carrying out validity check on the parameter assignment input by the user according to the searched functional function interface information.
Here, the content of the validity check includes, but is not limited to: parameter types, parameter value ranges, and the like.
Step 109: and after the validity check is passed, loading the DLL module file where the function 1 is located according to the found physical binding information.
Step 110: creating a class object of the function, constructing a physical parameter list, calling the function 1 and returning a calling result.
It should be noted that, in the present invention, a uniform agent middleware (Broker) may be preset to provide a uniform universal entry to Broker the call of all the function functions by the user, so that when the external access software needs to access the externally published function functions, it is not necessary to directly interact with the internal functions of the software, and it is not necessary to know the specific calling technical details of the functions, and it is only necessary to access through a uniform universal entry, i.e. the uniform agent middleware, thereby simplifying the implementation of the service. Thus, when the unified agent middleware is used, various processes are executed by the unified agent middleware in steps 107 to 110.
Although a user does not need to directly interact with the internal function of the software when calling the function by using the unified proxy middleware and does not need to know the specific calling technical details of the function, the user also needs to write codes to trigger the unified proxy middleware to execute calling. In a preferred embodiment of the present invention, in order to further simplify the user's processing, so that the user does not need to write Code, the view accessor may further comprise a Code generating module, which has a function of automatically generating Code, since the interface registration information of the function describes the interface model of the function, and the uniform Broker middleware (Broker) provides a uniform function access entry and way, and based on the two types of information, the Code generating module can automatically generate the function calling Code (Code). The automatic code avoids manual coding, reduces error rate and improves usability.
FIG. 3 is a flow diagram of the automatic generation of function call program code using a code generation module in one embodiment of the invention. Referring to fig. 3, the process specifically includes the following steps:
step 301: the code generation module generates code that creates a unified proxy middleware object.
Step 302: and the code generation module automatically generates a parameter assignment code of the functional function 1 according to the parameter information in the functional function interface information corresponding to the functional function identifier 1, wherein the code has the function of enabling a user to subsequently perform parameter assignment.
Step 303: the code generation module generates code for calling the function 1 through the unified proxy middleware.
The code generated in this step includes Invoke method and parameter transfer code of the calling function.
Step 304: the code generation module generates a code for acquiring a calling result through the unified agent middleware.
The automatic code generation process replaces most of manual coding of users, and the only manual operation required by the users is actual assignment of function parameters. After the flow shown in fig. 3 is executed, a process of calling a function may be actually executed, that is, step 106 in fig. 1 is executed first, then, the user compiles and runs the code, and then the unified proxy middleware may execute the processes of step 107 to step 110.
For example, the code generated by the code generation module may be in the form of:
broker the BKr ═ new Broker ("function ID", …)
theBkr.SetParameterValues(…)
theBkr.Invoke()
The invention also provides a device for calling the function. Referring to fig. 4, the apparatus includes: an extraction module, a registration module, a database, a view accessor, and a unified proxy middleware, wherein,
the extraction module is used for extracting the interface information of the function in the application software;
the registration module is used for registering the interface information of the function extracted by the extraction module in a database;
the viewing accessor is used for receiving the query of the user and displaying the interface information of the function in the database to the user;
and the unified agent middleware is used for searching the interface information of the corresponding function in the database according to a command for calling the function, which is transmitted by a user, and calling the function by using the searched interface information.
In specific implementation, the registration module further registers the physical binding information of the function in the database;
the unified agent middleware further searches the interface information of the corresponding function in the database according to the command for calling the function, carries out validity check on the parameter assignment input by the user according to the searched interface information of the function, and calls the function according to the searched physical binding information after the validity check is passed.
During specific implementation, the registration module further allocates corresponding function identifiers for interface information and physical binding information of the registered function;
the viewing access server is used for externally publishing each function identification, and when detecting that a user selects one function identification, the viewing access server externally publishes interface information of the function corresponding to the selected function identification in the database;
and the unified agent middleware searches the interface information of the corresponding function and the physical binding information of the function in the database according to the function identification in the function calling command.
Preferably, in order to perform centralized registration in a standard and consistent manner and facilitate uniform management and maintenance of interface information, the registration module converts the extracted interface information of the function into a readable structured document format, and then registers the interface information of the function at a corresponding directory classification position in the database according to a function hierarchical relationship of software where the function is located.
In order to further simplify the processing of the user, so that the user does not need to write code, the view accessor can have a function of automatically generating the code, and the specific implementation comprises the following steps: an interaction module and a code generation module are included in the view accessor, wherein,
the interaction module is used for receiving a command for inquiring the function input by a user and displaying interface information of the function in the database to the user;
the code generation module generates and creates a unified agent middleware object code according to the function interface information inquired in the interaction module, automatically generates a parameter assignment code of the function according to the parameter information in the function interface information, automatically generates a code for calling the function through the unified agent middleware and a code for acquiring a calling result through the unified agent middleware, and a user can directly use the function during running after compiling the automatically generated codes.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.